pipeup 0.8.2 → 0.9.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Comments and feedback right on any HTML page: documents, slide decks and whole sites.
4
4
 
5
- > **Alpha (0.8.2).** The API and the stored comment format may change before 1.0; pin an exact version.
5
+ > **Alpha (0.9.0).** The API and the stored comment format may change before 1.0; pin an exact version.
6
6
  > Website and Try pages: https://pipeup-ai.github.io/pipeup/ · Source: https://github.com/pipeup-ai/pipeup
7
7
 
8
8
  Pipeup: signed comment operations, threads with one-level replies, anchors that survive page changes,
@@ -16,14 +16,20 @@ colour on a tint of it) at the top right of their comments; once they add a name
16
16
  identity row at the top of the menu) the avatar shows their initial in the same colours. Copy for AI names unnamed reviewers by
17
17
  their colour and animal.
18
18
 
19
- As a classic script (also works from `file://`), it mounts itself on pages that carry a document id:
19
+ As a classic script (also works from `file://`), it mounts itself (`data-pipeup-auto="off"` stops that). The script
20
+ line alone is enough; a document id on `<html>` keeps comments with the page wherever it is opened, instead of with
21
+ its address:
20
22
 
21
23
  ```html
22
24
  <html data-pipeup-doc="<id>:<key>">
23
25
  ...
24
- <script src="https://cdn.jsdelivr.net/npm/pipeup@0.8.2/dist/pipeup.min.js" integrity="sha384-…" crossorigin="anonymous" defer></script>
26
+ <script src="https://cdn.jsdelivr.net/npm/pipeup@0.9.0/dist/pipeup.min.js" integrity="sha384-…" crossorigin="anonymous" defer></script>
25
27
  ```
26
28
 
29
+ On a host that writes its own `<html>` (claude.ai Artifacts, for example), put the same settings on the script
30
+ line instead: `<script src="…/pipeup.min.js" data-pipeup-doc="<id>:<key>" …>`. Every `data-pipeup-*` setting works
31
+ there, for add-ons too.
32
+
27
33
  Each release's notes on GitHub give the `integrity` value
28
34
  (`node scripts/sri.mjs` prints it for a local build). Make a document key with
29
35
  `await Pipeup.newDocumentAttribute()` and keep it once people have commented.
@@ -39,11 +45,21 @@ Install with `npm i pipeup`. From a bundler (no side effects; call `mount` yours
39
45
 
40
46
  ```js
41
47
  import { mount } from "pipeup";
42
- const pipeup = await mount({ name: "Sam" }); // options: root, name (optional), store, slides
48
+ const pipeup = await mount({ name: "Sam" }); // options: root, name, store, slides, doc, layout, theme, select
43
49
  await pipeup.flush(); // write any unsaved changes now (this also happens when the page is hidden)
44
50
  pipeup.unmount(); // remove Pipeup from the page; the comments stay saved
45
51
  ```
46
52
 
53
+ A page with its own review controls (a Comment button in its header, a name field) drives Pipeup without reaching
54
+ inside it:
55
+
56
+ ```js
57
+ await pipeup.setCommentMode(true); // resolves once comment mode is on; pipeup.commentMode reads it
58
+ await pipeup.setName("Ada"); // kept as if the reviewer had typed it; pipeup.name reads it
59
+ const stop = pipeup.on("change", ({ commentMode, name }) => label(commentMode, name)); // however it changed
60
+ mount().catch((e) => show(e.code, e.message)); // "another-copy" or "failed", with words for people
61
+ ```
62
+
47
63
  Pages designed for review can reserve a comment gutter: add `data-pipeup-reserve` to `<html>` and lay the
48
64
  page out with `var(--pipeup-gutter, 0px)`. While All comments is open the page is moved over for it and its
49
65
  width is published as `--pipeup-panel`, so fixed bars can use `right: var(--pipeup-panel, 0px)` — see [examples/review-document.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-document.html).
@@ -64,14 +80,17 @@ Examples in the source repository, one per kind of page, each following the agen
64
80
  - [examples/review-site.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-site.html) — a site: clear blocks with stable ids for comment mode and pins; navigation ignored.
65
81
  - [examples/review-deck.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-deck.html) — a deck: one marked element per slide; slide controls ignored so they keep working, and one line so Pipeup can go to a comment's slide.
66
82
 
83
+ Selecting words offers a comment icon beside them, in comment mode or out of it; outside it, the comment leaves
84
+ comment mode off and the page keeps working (`data-pipeup-select="comment-mode"` keeps it to comment mode).
67
85
  Comments show whether comment mode is on or off: highlights, bubbles and the column can be read and opened, and
68
86
  outside comment mode the rest of the page works as normal. **Hide comments** in the control's menu puts them out
69
87
  of sight on that page (remembered in the browser); the control still counts the open threads, and comment mode,
70
88
  All comments or a comment being written show them again while they last.
71
89
 
72
90
  The comment control is a small square of frosted glass tucked into the bottom-right corner: the comment icon, or
73
- the number of open threads inside a comment bubble. Pointed at, it reaches left to show its shortcut; clicking (or tapping) it opens its menu of
74
- one-line rows, each explained by a tooltip on hover or focus. From the top: who you are (avatar and name, with
91
+ the number of open threads inside a comment bubble. One click (or tap) starts comment mode and another stops it.
92
+ Pointed at, it reaches left to show its shortcut and **⋯**, which opens its menu (by touch, press and hold the
93
+ control; from the keyboard, ↑ on it): one-line rows, each explained by a tooltip on hover or focus. From the top: who you are (avatar and name, with
75
94
  Add name, edited in place in that row), Copy comments (as Markdown for AI, or as text), Theme, All comments, a Hide comments switch, and nearest the button **Start commenting** with its shortcut and a switch, which leaves the menu open so you see it move. The menu closes on Esc, a click outside, or 3 seconds after the pointer leaves it.
76
95
  **All comments** is a panel on the right that moves the page over to make room: every thread in page order as a
77
96
  card, threads whose content is gone under "No longer on the page", and two icon toggles in its header, **@** (mentions
@@ -86,7 +105,7 @@ comment goes away; deleting a thread's first comment removes the thread. The com
86
105
  reply boxes have Cancel and Comment (Reply) buttons; Enter also sends. Elements the page
87
106
  fixes to the window don't move over with the page.
88
107
 
89
- Comment mode (press **Shift+Alt+C**, or **⇧⌥C** on a Mac, or switch on Start commenting in the control's menu) lets reviewers comment on blocks and drop pins
108
+ Comment mode (click the comment control, press **Shift+Alt+C**, or **⇧⌥C** on a Mac) lets reviewers comment on blocks and drop pins
90
109
  (Option-click, Alt-click, or the naming bar's Pin) on any page. While it is on, clicks and submits on the page do
91
110
  nothing, and selecting text offers a comment icon, clicking a highlight opens its thread, and
92
111
  clicking a block opens its comment box at once (a bar names the block; Around it and Inside it move the box to the
package/cli/asks.d.mts ADDED
@@ -0,0 +1,33 @@
1
+ import type { Thread } from "../src/model/types";
2
+
3
+ export interface PageAsk {
4
+ id: string;
5
+ question: string;
6
+ kind: "open" | "agree" | "choice";
7
+ options: string[];
8
+ other: boolean;
9
+ needed: boolean;
10
+ }
11
+ export interface ReadAnswer {
12
+ thread: string;
13
+ name: string;
14
+ author: string;
15
+ choice: string;
16
+ words: string;
17
+ text: string;
18
+ at: string;
19
+ edited: boolean;
20
+ replies: number;
21
+ askedAs?: string;
22
+ }
23
+ export function asksIn(html: string): PageAsk[];
24
+ export function parseAnswer(ask: PageAsk, text: string): { choice: string; words: string } | null;
25
+ export function asksWithAnswers(
26
+ html: string,
27
+ threads: readonly Thread[],
28
+ agents?: readonly string[],
29
+ ): (PageAsk & { answers: ReadAnswer[] })[];
30
+ export function asksMarkdown(
31
+ asks: (PageAsk & { answers: ReadAnswer[] })[],
32
+ nameOf: (key: string) => string,
33
+ ): string;
package/cli/asks.mjs ADDED
@@ -0,0 +1,131 @@
1
+ // The asks a page puts in its content (spec §11b, the inline add-on), with each reviewer's latest answer, for
2
+ // `pipeup read`. Read from the page's markup and the comments, as the add-on reads them: an answer is a comment on the
3
+ // ask's block, kept with the question it answered ("Asked: …"), whose words fit the ask's kind.
4
+
5
+ const ASKED = "Asked: ";
6
+ const AGREE = "Agree";
7
+ const CHANGE = "Needs change";
8
+ const OTHER = "Other";
9
+
10
+ const unescape = (s) =>
11
+ s
12
+ .replace(/&quot;/g, '"')
13
+ .replace(/&#39;|&apos;/g, "'")
14
+ .replace(/&lt;/g, "<")
15
+ .replace(/&gt;/g, ">")
16
+ .replace(/&amp;/g, "&");
17
+
18
+ /** A tag's attributes, by name (lower case); a bare attribute is "". */
19
+ function attrs(tag) {
20
+ const out = {};
21
+ for (const m of tag.matchAll(/\s([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g))
22
+ out[m[1].toLowerCase()] = unescape(m[2] ?? m[3] ?? m[4] ?? "");
23
+ return out;
24
+ }
25
+
26
+ /** The page's asks, in page order: { id, question, kind, options, other, needed }. */
27
+ export function asksIn(html) {
28
+ const asks = [];
29
+ for (const m of html.matchAll(/<[a-z][a-z0-9-]*\b(?:[^>"']|"[^"]*"|'[^']*')*>/gi)) {
30
+ const a = attrs(m[0]);
31
+ if (!("data-pipeup-ask" in a)) continue;
32
+ const id = a["data-pipeup-id"] ?? "";
33
+ const question = a["data-pipeup-ask"].replace(/\s+/g, " ").trim();
34
+ if (!id || !question) continue;
35
+ const given = a["data-pipeup-ask-kind"];
36
+ const kind = given === "agree" || given === "choice" ? given : "open";
37
+ const options =
38
+ kind === "agree"
39
+ ? [AGREE, CHANGE]
40
+ : kind === "choice"
41
+ ? [
42
+ ...new Set(
43
+ (a["data-pipeup-ask-options"] ?? "")
44
+ .split("|")
45
+ .map((o) => o.trim())
46
+ .filter(Boolean),
47
+ ),
48
+ ]
49
+ : [];
50
+ if (kind === "choice" && (options.length < 2 || options.length > 6)) continue;
51
+ asks.push({
52
+ id,
53
+ question,
54
+ kind,
55
+ options,
56
+ other: kind === "choice" && "data-pipeup-ask-other" in a,
57
+ needed: "data-pipeup-ask-needed" in a,
58
+ });
59
+ }
60
+ return asks;
61
+ }
62
+
63
+ /** A comment's words as an answer to `ask` ({ choice, words }), or null. */
64
+ export function parseAnswer(ask, text) {
65
+ const t = text.trim();
66
+ if (!t) return null;
67
+ if (ask.kind === "open") return { choice: "", words: t };
68
+ for (const choice of [...ask.options, ...(ask.other ? [OTHER] : [])]) {
69
+ if (t === choice && choice !== CHANGE && choice !== OTHER) return { choice, words: "" };
70
+ if ((ask.kind === "agree" || choice === OTHER) && t.startsWith(`${choice}:`)) {
71
+ const words = t.slice(choice.length + 1).trim();
72
+ if (words || choice === AGREE) return { choice, words };
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+
78
+ /** Pipeup's name for AI writers: "AI assistant", or that and more words. */
79
+ const AI_NAME = "AI assistant";
80
+
81
+ /**
82
+ * Each ask with every reviewer's latest answer (and the question it answered, when the words have changed since).
83
+ * Agents never answer asks: a thread there by an agent the page lists (`agents`), or under an AI name, isn't counted.
84
+ */
85
+ export function asksWithAnswers(html, threads, agents = []) {
86
+ return asksIn(html).map((ask) => {
87
+ const latest = new Map();
88
+ for (const t of [...threads].sort((a, b) => a.root.at - b.root.at)) {
89
+ if (t.anchor.id !== ask.id || t.root.deleted || !t.anchor.snapshot?.startsWith(ASKED)) continue;
90
+ const name = t.root.name ?? "";
91
+ if (agents.includes(t.root.author) || name === AI_NAME || name.startsWith(`${AI_NAME} `)) continue;
92
+ const answer = parseAnswer(ask, t.root.text);
93
+ if (!answer) continue;
94
+ const was = t.anchor.snapshot.slice(ASKED.length);
95
+ latest.set(t.root.author, {
96
+ thread: t.id,
97
+ name: t.root.name,
98
+ author: t.root.author,
99
+ ...answer,
100
+ text: t.root.text,
101
+ at: new Date(t.root.at).toISOString(),
102
+ edited: t.root.edited,
103
+ replies: t.root.replies.length,
104
+ ...(was && was !== ask.question.slice(0, was.length) ? { askedAs: was } : {}),
105
+ });
106
+ }
107
+ return { ...ask, answers: [...latest.values()] };
108
+ });
109
+ }
110
+
111
+ /** The asks as Markdown, after the comments: each question, its kind, and who answered what. */
112
+ export function asksMarkdown(asks, nameOf) {
113
+ if (!asks.length) return "";
114
+ const lines = ["", "## Asks", ""];
115
+ for (const a of asks) {
116
+ const kind =
117
+ a.kind === "choice"
118
+ ? `choice: ${[...a.options, ...(a.other ? [OTHER] : [])].join(", ")}`
119
+ : a.kind === "agree"
120
+ ? "agree or needs change"
121
+ : "open";
122
+ lines.push(`### "${a.question}"`, "", `- Name: \`${a.id}\` · ${kind}${a.needed ? " · needed" : ""}`);
123
+ if (!a.answers.length) lines.push("- No answers yet.");
124
+ for (const r of a.answers)
125
+ lines.push(
126
+ `- ${r.name || nameOf(r.author)}: ${r.text.split("\n")[0]}${r.edited ? " (changed)" : ""}${r.askedAs ? ` (asked as: "${r.askedAs}")` : ""} — thread ${r.thread}`,
127
+ );
128
+ lines.push("");
129
+ }
130
+ return lines.join("\n");
131
+ }
package/cli/pipeup.mjs CHANGED
@@ -31,6 +31,7 @@ pipeup read <page.html> [--from <file or folder>]… [--deep] [--all] [--json] [
31
31
  feedback files and folders of them (--deep looks in folders inside), the page's shared copy (with @pipeup/share
32
32
  installed; --no-share reads nothing from the network) and its replies file. Every comment is checked as the page
33
33
  checks it; what was read, skipped or left out is said on standard error. --out writes one merged feedback file.
34
+ Asks the page puts in its content (the inline add-on) follow, each with its question, kind and answers.
34
35
  Exit codes: 0 done, 1 a source couldn't be read, 2 the command needs something first.
35
36
 
36
37
  pipeup skills install|remove|list [--project] [--agent claude|codex|all] [--yes] [--replace] [--dry-run]
@@ -61,6 +62,10 @@ pipeup reply --page <file.html> --thread <id> "<words>" [--addressed "<short not
61
62
  next to the page, or the file the page names. The page is the HTML file that runs Pipeup, never a file it shows.
62
63
  It never resolves, reopens, edits or deletes anything: the author closes threads.
63
64
 
65
+ pipeup reply --print (--doc <document id> | --page <file.html>) --thread <id> "<words>" [--addressed "<short note>"]
66
+ Prints the same signed reply as a replies block for the person to paste into the page (Paste my agent's replies),
67
+ for an agent that can't write next to the page. Copy for my agent gives the document id. Nothing is written.
68
+
64
69
  Agents run these as \`npx --yes pipeup@0 …\`: any release from 0.6 answers agent, reply and comments the same way.`;
65
70
 
66
71
  /** How agents are told to run this command line: never stopping to ask, and any release npm will give. */
@@ -75,7 +80,7 @@ const DOC = /<html\b[^>]*\sdata-pipeup-doc\s*=\s*["']([^"']+)["']/i;
75
80
  */
76
81
  const KNOWN = {
77
82
  agent: ["name", "page", "yes"],
78
- reply: ["page", "thread", "addressed"],
83
+ reply: ["page", "thread", "addressed", "print", "doc"],
79
84
  comments: ["all", "json"],
80
85
  watch: ["agent", "port"],
81
86
  };
@@ -201,15 +206,67 @@ async function readReplies(path, doc) {
201
206
  }
202
207
  }
203
208
 
209
+ /** One entry of a replies block, signed: the person pastes it into the page, which checks it against the listed keys. */
210
+ function printBlock(name, thread, words, note, ops) {
211
+ const field = (key, text) =>
212
+ text
213
+ .split("\n")
214
+ .map((line, i) => (i ? ` ${line}` : `${key}: ${line}`))
215
+ .join("\n");
216
+ return [
217
+ "```pipeup-replies",
218
+ `agent: ${name}`,
219
+ `thread: ${thread}`,
220
+ field("reply", words),
221
+ ...(note ? [field("addressed", note)] : []),
222
+ `signed: ${b64u(new TextEncoder().encode(JSON.stringify(ops)))}`,
223
+ "```",
224
+ ].join("\n");
225
+ }
226
+
204
227
  async function reply(args) {
205
228
  const page = args.page;
206
229
  const thread = args.thread;
207
230
  const words = args._[0]?.trim();
208
- if (typeof page !== "string" || typeof thread !== "string" || !words)
209
- fail(`missing words, --page or --thread\n\n${USAGE}`);
231
+ const print = args.print === true;
232
+ const given = typeof args.doc === "string" && print ? args.doc.trim() : "";
233
+ if ((typeof page !== "string" && !given) || typeof thread !== "string" || !words)
234
+ fail(`missing words, ${print ? "--doc" : "--page"} or --thread\n\n${USAGE}`);
235
+ if (given && given.length > 64) fail("that isn't a document id");
210
236
  const note = typeof args.addressed === "string" ? args.addressed.trim() : "";
211
- const { id: doc, listed, replies: out } = await pageDoc(page);
237
+ const {
238
+ id: doc,
239
+ listed,
240
+ replies: out,
241
+ } = given ? { id: given, listed: null, replies: "" } : await pageDoc(page);
212
242
  const { identity, name } = await loadAgent();
243
+ if (print) {
244
+ let clock = Math.floor(Date.now() / 1000);
245
+ let at = Date.now();
246
+ const { computeOpId, signOp } = await core();
247
+ const make = async (fields) => {
248
+ const body = {
249
+ v: 1,
250
+ ...fields,
251
+ id: "",
252
+ doc,
253
+ author: identity.publicKey,
254
+ name: signedName(name),
255
+ clock: clock++,
256
+ at: at++,
257
+ };
258
+ body.id = await computeOpId(body);
259
+ return signOp(body, identity);
260
+ };
261
+ const ops = [await make({ kind: "reply", thread, target: thread, text: words })];
262
+ if (note) ops.push(await make({ kind: "addressed", thread, text: note }));
263
+ if (listed && !listed.includes(identity.publicKey))
264
+ console.error(
265
+ `pipeup: this page doesn't list your key, so these replies will show as pasted by the person.\n To be listed: <html data-pipeup-agents="${identity.publicKey}">`,
266
+ );
267
+ console.log(printBlock(name, thread, words, note, ops));
268
+ return;
269
+ }
213
270
  const linked = await readFile(page.replace(/\.[^./\\]*$/, "") + ".comments.json", "utf8").then(
214
271
  () => true,
215
272
  () => false,
package/cli/read.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
  import { readdir, readFile, stat, writeFile } from "node:fs/promises";
4
4
  import { basename, dirname, join, resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
+ import { asksMarkdown, asksWithAnswers } from "./asks.mjs";
6
7
 
7
8
  const core = () => import("../dist/pipeup.core.js");
8
9
  const MAX_MERGE = 5000;
@@ -118,6 +119,7 @@ export async function read(o) {
118
119
  parseDocumentAttribute,
119
120
  readFeedbackFile,
120
121
  agentComments,
122
+ animalName,
121
123
  } = await core();
122
124
  let id;
123
125
  let key;
@@ -286,6 +288,16 @@ export async function read(o) {
286
288
  all: o.all,
287
289
  });
288
290
 
291
+ // The asks the page puts in its content (§11b), each with every reviewer's latest answer, so an agent can work through them.
292
+ const asks = asksWithAnswers(
293
+ html,
294
+ threads,
295
+ (attrOf(html, "data-pipeup-agents") ?? "").split(/[\s,]+/).filter(Boolean),
296
+ );
297
+ if (asks.length) {
298
+ out.asks = asks;
299
+ out.markdown = `${out.markdown.trimEnd()}\n${asksMarkdown(asks, animalName)}`;
300
+ }
289
301
  if (o.out) {
290
302
  try {
291
303
  await writeFile(o.out, await doc.exportFile());
package/dist/addons.json CHANGED
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "share": {
3
- "integrity": "sha384-wql/NFYQR4jzJgnXOS/Ch9FC7wydHsfjDtacKSSwiglNCFsRHEAFu+NV77BtQK7a",
3
+ "integrity": "sha384-Iv18knaI4OXVXr5FnKqan6+Voq4wXHJQEVVqjw8X8yGjnnQmIJDq5Le8SGkaAT22",
4
4
  "says": "Sends the comments you choose to share, sealed so only people with this page can read them, to the sharing service the page names. That service sees when and how much is sent, and your network address."
5
5
  },
6
6
  "voice": {
7
- "integrity": "sha384-eq8QijeWKjzubQyL1eH5khy4VFRKEyyQkJcsYg3U4brv8N8QsDKDwY+5XrNC7OKs",
7
+ "integrity": "sha384-Y7tU5injzCcaZRunW+X89e83ZZP0GndlNqBX2n0x4psJYYEHK+1m/uCbmUyxGWAV",
8
8
  "says": "Only when you press the microphone: your browser may download a speech pack once, and, only if it can't work on this device, your voice goes to the browser maker's speech service."
9
9
  },
10
10
  "live": {
11
- "integrity": "sha384-RSVdnK2BRkBSTApk5bOpSe2DEDfk4I+g9yjaXioPnGv8t2L4N6TosjpEH1cSf0DF",
11
+ "integrity": "sha384-S6BH6HAroTc5spdAhf/sKucop6NwJrFgcr3A68t0kJDRPks0oM38FAMDtFYpIqGy",
12
12
  "says": "When you go live, you connect directly to other people viewing this page. They see your network address; the meeting-point services see your network address and when you connect, never your comments."
13
13
  },
14
14
  "assist": {
15
- "integrity": "sha384-AScldYlxP5WwWHTGwyi6+2Z5+Hu7KM89zm7Yk8U9D3pOTsoBXPkteg2JlKy0BHAj",
15
+ "integrity": "sha384-Tn760J2DRZcf/t4Wh4uCqOzPDj/UOj4e9j+2O0ipyNPCXSAYcyryEsul26/uMPMK",
16
16
  "says": "Only after you turn it on: your browser may download a small AI model once. Comments and the page are read on this device and never sent anywhere; if the page's author named notes files, they are read from this site."
17
17
  },
18
18
  "agents": {
19
- "integrity": "sha384-5CVpIwX4Kz1uscPidtGqGlGuQrJ4Q/jCH8XXOoqyAcrrc7YSXrBJPiCmCQMh1+tg",
20
- "says": "Reads a replies file next to this page. When the page is shown through pipeup watch, and only after you switch it on, it sends this page's comments to the program running on this computer. Nothing leaves this computer."
19
+ "integrity": "sha384-XGyYk3WwvxcaMOk/vL/SRy1It8qQROWbKDFaBiB/zppZNkFskQ41lcFGjkZW2PkW",
20
+ "says": "Reads a replies file next to this page, and replies you paste from your agent. When the page is shown through pipeup watch, and only after you switch it on, it sends this page's comments to the program running on this computer. Nothing leaves this computer."
21
21
  },
22
22
  "emoji": {
23
- "integrity": "sha384-RSEPcw/wigVNhrEv3MnJtqr2eXSmQtteFrGlNxBKKi/zLG+PrB9V484tJImp0Acl",
23
+ "integrity": "sha384-PabpVVan4/2cFL2D1kKYLRUVAsFtx/I8dCXsmDZHHb3AWgaFyZ8CEGST3n1+YBB4",
24
24
  "says": "Nothing is sent anywhere: the emoji are part of this script."
25
25
  },
26
26
  "github": {
27
- "integrity": "sha384-NTSohG4/5QrH2JlSjsT4WBzWAIUe+CrgqG9kdDxd49TwdvKdhCXE+1LsE7jiLPvR",
27
+ "integrity": "sha384-juzqkImsqHDSsplZ/LXAJdXNaiOBVC2p1bbtlmmQiAEcewiDwmfyHEzTmXLZFS/Q",
28
28
  "says": "Only when you press Mention on GitHub: your browser opens GitHub's new-issue page with the person's @name and the comment's words filled in; nothing is sent until you submit it there.",
29
29
  "asks": {
30
30
  "attr": "data-pipeup-github-repo",
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "updates": {
37
- "integrity": "sha384-tCLIdgybLTEfmrfkBV1cH3GSYTIXv/g9ivN7fBB2/hHkX+NdsyfMpTgSragOCaUP",
37
+ "integrity": "sha384-Ywds4XdYUEguFHXGNbwsHUcTQetCnD8wh4N8VkqMgrG2s0ap6L7hnBBMeIjLiioX",
38
38
  "says": "Checks the Pipeup project's published update list (GitHub Pages) once a day, only on this computer or where the page's author asked; that service can see your network address."
39
39
  },
40
40
  "inbox": {
41
- "integrity": "sha384-7bQh3sG8fhxekWjQFsPogPesPzCLMzw0DmJPecvTdkG/KuXNSaJQWbTZ2GHfVNXV",
41
+ "integrity": "sha384-Z490DtLPVSgn0+BOMNSRocB2BVVtA8CAQtyeAAipcftU/+0+4b21zWYLvbPaOXQH",
42
42
  "says": "Only after you switch on Mentions by inbox: when you mention someone, a short note (who, your words, the page's address) is left for them at the page's inbox service, sealed so only they can read it; and your own inbox is checked there. The service sees that a note arrived, its size and when, and your network address, never who it is from or what it says.",
43
43
  "asks": {
44
44
  "attr": "data-pipeup-inbox",
@@ -48,7 +48,11 @@
48
48
  }
49
49
  },
50
50
  "identity": {
51
- "integrity": "sha384-KTS/eDFIsZUSp67Ag+SdKf0+GbH9Z/O8T5boIE7MWASPnHjuyiWt8P2xX/VqWOK9",
51
+ "integrity": "sha384-Ay3J1FiQokTyK73407sJALq0VMWUjn5iiF+miAA0/HfE4N16wPM59056fbabU+O0",
52
52
  "says": "Nothing. Your recovery code stays on this device unless you copy it or save it as a file yourself."
53
+ },
54
+ "inline": {
55
+ "integrity": "sha384-2NGEoJQyDvbPFzGnuwKI2HQm1aOjOEnBTAMV6ovpv+Kh785FftCbyCpFB4eNwAwX",
56
+ "says": "Sends nothing: answers to asks are ordinary comments, kept and sent the way the page's other comments are."
53
57
  }
54
58
  }
@@ -1,2 +1,16 @@
1
- "use strict";(()=>{function b(e){let n=globalThis;(n.pipeupAddons||=[]).push(e),typeof addEventListener=="function"&&addEventListener("load",()=>{n.Pipeup||console.error(`pipeup: the "${e.id}" add-on needs Pipeup on the page too; load pipeup.min.js.`)},{once:!0})}var se=2n**256n-2n**32n-977n;var L=/^\/__pipeup\/[A-Za-z0-9_-]{16,}$/;function P(e){let n=document.documentElement,t=n.getAttribute("data-pipeup-link")??"",o=L.test(t),i=!1,a=0,m=()=>{};async function r(){let c=!1;try{c=(await fetch(`${t}/comments`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(await e.snapshot())})).ok}catch{}if(!c)throw new Error("pipeup: the link to your agent isn't reachable; your comments are safe here")}let d=()=>{window.clearTimeout(a),m(),m=()=>{},i=!1};return{enabled:o,agent:n.getAttribute("data-pipeup-link-agent")??"",file:n.getAttribute("data-pipeup-link-file")??"",on:()=>i,set:async c=>{if(o){if(!c){d(),e.refresh();return}await r(),i=!0,m=e.changes(()=>{window.clearTimeout(a),a=window.setTimeout(()=>{r().catch(y=>{d(),e.refresh(),globalThis.reportError?.(y)})},300)}),e.refresh()}},destroy:d}}function C(e){if(!e)return{cli:"npx --yes pipeup@0",fallback:null};let t=`npx --yes pipeup@${e.split(".")[0]??"0"}`;return e.includes("-")?{cli:`npx --yes pipeup@${e}`,fallback:t}:{cli:t,fallback:null}}function R(e,n=""){if(n)return{page:n,served:!1};try{let t=new URL(e),o=decodeURIComponent(t.pathname);return o.endsWith("/")&&(o+="index.html"),t.protocol==="file:"?{page:/^\/[A-Za-z]:\//.test(o)?o.slice(1):o,served:!1}:{page:o,served:!0}}catch{return{page:"<the page's HTML file>",served:!1}}}var _=e=>{try{let n=new URL(e);return n.protocol==="file:"?decodeURIComponent(n.pathname).replace(/^\/([A-Za-z]:\/)/,"$1"):n.href}catch{return e}};function T(e){let n=d=>d.replace(/\s+/g," ").trim(),{cli:t,fallback:o}=C(e.version),i=`https://pipeup-ai.github.io/pipeup/${e.version?.includes("-")?"next/":""}`,{page:a,served:m}=R(e.url,e.file),r=m?`<the HTML file your site serves at ${a}>`:a;return[`Act on the review comments on this page, which uses Pipeup: ${n(e.title)} (${n(e.url)}).`,"",e.file?`1. Read the comments: \`${t} comments ${e.file}\` (add --all for resolved ones). If it says nothing is shared, ask me to switch on Share with my agent.`:"1. Read the comments. Open the page in a browser and run `await Pipeup.comments()`, then read `.markdown`. If you can't run the page, ask me to paste its comments (Copy comments \u203A As Markdown).","2. Work through the open threads in order. For each, make the change I approved, or say why you didn't. Ask me before changing anything I haven't approved, and answer a question with an answer.",e.replies?`3. Answer in each thread: \`${t} reply --page ${r} --thread <Thread id> "what you changed and where" --addressed "short note"\`. Pass that file, the one that runs Pipeup, not a file it shows. It writes ${n(_(e.replies))}, which the page reads by itself.`+(e.listed?"":` The page doesn't list you yet. Ask me first; after my yes, run \`${t} agent --name <your name> --page ${r} --yes\`.`)+(o?` If npm refuses ${t.split(" ").at(-1)}, use ${o.split(" ").at(-1)}: it answers these commands the same way.`:""):"3. Tell me what you would reply in each thread, in words I can paste.","4. Only mark a thread addressed. Never resolve, reopen, edit or delete: I close threads. Keep your key out of the page and its folder, and never answer as me.","",`Guide: ${i}skills/pipeup-apply/SKILL.md`].join(`
2
- `)}var D=/^[A-Za-z0-9_-]{43}$/,H="pipeupReplies";var N=/^AI assistant\s*·?\s*/;function x(e=document.documentElement){let n=e.getAttribute("data-pipeup-agents")??"";return[...new Set(n.split(/[\s,]+/).filter(t=>D.test(t)))]}function k(e=location,n=document.documentElement){let t=n.getAttribute("data-pipeup-replies");try{let o=e.href.split(/[?#]/)[0],i=new URL(t??(/\/$/.test(o)?`${o}index.replies.js`:o.replace(/\.[^./]*$/,"")+".replies.js"),e.href),a=i.protocol==="file:"?e.protocol==="file:":i.origin===e.origin;return a||console.warn("pipeup: the replies file must be on this site or this computer; ignoring it"),a?i.href:null}catch{return null}}function U(e){let n=x(),t=0,o="",i=null;async function a(){let u=globalThis[H];if(!Array.isArray(u))return 0;let l=u.splice(0),g=[];for(let f of l){let h=f;if(!(h?.format!=="pipeup-replies"||h.doc!==e.document.id||!Array.isArray(h.ops)))for(let s of h.ops){let p=s?.body;p&&n.includes(p.author)&&(p.kind==="reply"||p.kind==="addressed"||p.kind==="react"||p.kind==="unreact")?(g.push(s),(p.name==="AI assistant"||p.name.startsWith("AI assistant "))&&(o=p.name.replace(N,""))):t++}}return g.length?e.merge(g):0}function m(){let u=k();return u?(i?.remove(),new Promise((l,g)=>{let f=document.createElement("script");i=f,f.src=`${u}?${Date.now()}`;let h=p=>{window.clearTimeout(s),f.remove(),i===f&&(i=null),p?g(new Error(`pipeup: ${p}`)):l()},s=window.setTimeout(()=>h("the replies file didn't answer"),4e3);f.addEventListener("load",()=>h()),f.addEventListener("error",()=>h("there is no replies file yet")),e.overlay().append(f)})):Promise.reject(new Error("pipeup: the replies file can't be read from here"))}async function r(){if(!n.length)return 0;let u=await a();return await m(),u+await a()}let d=!1,c=()=>{d||document.hidden||(d=!0,r().catch(()=>{}).finally(()=>d=!1))},y=0;return n.length?(c(),y=window.setInterval(c,4e3),document.addEventListener("visibilitychange",c)):a(),{enabled:n.length>0,ignored:()=>t,who:()=>o,check:r,tally:u=>{let l=u.filter(s=>!s.resolved),g=s=>s.root.replies.some(p=>n.includes(p.author)),f=new Set(u.map(s=>s.id));return{stray:new Set(e.document.ops().filter(s=>n.includes(s.body.author)&&!f.has(s.body.thread)).map(s=>s.body.thread)).size,open:l.length,answered:l.filter(g).length,addressed:l.filter(s=>s.addressed).length}},destroy:()=>{window.clearInterval(y),document.removeEventListener("visibilitychange",c),i?.remove()}}}var z=()=>globalThis.Pipeup??{},K=["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],j=["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],F="Reads a replies file next to this page. When the page is shown through pipeup watch, and only after you switch it on, it sends this page's comments to the program running on this computer. Nothing leaves this computer.",S=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";async function Z(e,n){try{await navigator.clipboard.writeText(e);return}catch{}let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.cssText="position:fixed;opacity:0;pointer-events:none",n.append(t),t.select();let o=document.execCommand("copy");if(t.remove(),!o)throw new Error("pipeup: your browser blocked copying")}function E(){return{id:"agents",api:1,version:"0.6.0",needs:["menu","status","notify","listnote"],network:{when:"page-configured",to:["page"],says:F},setup(e){let n=U(e),t=P({snapshot:async()=>{let r=z();if(!r.comments)throw new Error("pipeup: this page has no Pipeup to read comments from");let[d,c]=await Promise.all([r.comments(),r.comments({all:!0})]);return{v:1,at:new Date().toISOString(),title:document.title,open:d,all:c}},changes:r=>e.document.onChange(r),refresh:()=>i()}),o=()=>n.who()||t.agent,i=()=>{if(e.setStatus(n.enabled||t.enabled?{text:t.on()?`Sharing comments with ${o()||"your agent"}`:`${o()||"An AI agent"} can answer comments here`}:null),!n.enabled)return e.setListNote(null);let r=n.tally(e.document.threads()),d=o()||"An agent",c=r.answered?`${d} has answered ${r.answered} of ${r.open} open comments${r.addressed?`; ${r.addressed} ${r.addressed===1?"is":"are"} marked addressed`:""}`:"No replies from an agent yet",y=n.ignored(),u=(t.on()?`Sharing with ${t.agent||"your agent"} \xB7 `:"")+c+(y?` \xB7 ${y} from other writers ignored`:"")+(r.stray?` \xB7 replies for ${r.stray} comment${r.stray===1?"":"s"} this page doesn't have`:"");e.setListNote({text:u,action:{label:"Check for replies",run:async()=>{try{let l=await n.check();e.notify(l?`${l} new ${l===1?"reply":"replies"}`:"No new replies")}catch(l){e.notify(S(l))}finally{i()}}}})},a=[e.addMenuItem({id:"prompt",icon:K,label:()=>"Copy a prompt for my agent",hint:()=>"Tells an AI agent where the comments are and how to answer them",select:async()=>{try{await Z(T({title:document.title,url:location.href,replies:k(),file:t.enabled?t.file:"",listed:x().length>0,version:globalThis.Pipeup?.VERSION}),e.overlay()),e.notify("Copied a prompt for your agent")}catch(r){e.notify(S(r))}}})];t.enabled&&a.push(e.addMenuItem({id:"link",icon:j,label:()=>"Share with my agent",hint:()=>"Sends this page's comments to the program running on this computer, and nothing else",checked:()=>t.on(),select:async()=>{try{await t.set(!t.on())}catch(r){e.notify(S(r))}i()}}));let m=e.document.onChange(i);return i(),()=>{m(),n.destroy(),t.destroy()}}}}b(E());})();
1
+ "use strict";(()=>{function x(e){let t=globalThis;(t.pipeupAddons||=[]).push(e),typeof addEventListener=="function"&&addEventListener("load",()=>{t.Pipeup||console.error(`pipeup: the "${e.id}" add-on needs Pipeup on the page too; load pipeup.min.js.`)},{once:!0})}var w=(e,t)=>t?t.getAttribute(e):globalThis.Pipeup?.setting?.(e)??globalThis.document?.documentElement.getAttribute(e)??null;var Ie=2n**256n-2n**32n-977n;var X=/^\/__pipeup\/[A-Za-z0-9_-]{16,}$/;function I(e){let t=document.documentElement,s=t.getAttribute("data-pipeup-link")??"",r=X.test(s),n=!1,i=0,p=()=>{};async function c(){let l=!1;try{l=(await fetch(`${s}/comments`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(await e.snapshot())})).ok}catch{}if(!l)throw new Error("pipeup: the link to your agent isn't reachable; your comments are safe here")}let a=()=>{window.clearTimeout(i),p(),p=()=>{},n=!1};return{enabled:r,agent:t.getAttribute("data-pipeup-link-agent")??"",file:t.getAttribute("data-pipeup-link-file")??"",on:()=>n,set:async l=>{if(r){if(!l){a(),e.refresh();return}await c(),n=!0,p=e.changes(()=>{window.clearTimeout(i),i=window.setTimeout(()=>{c().catch(o=>{a(),e.refresh(),globalThis.reportError?.(o)})},300)}),e.refresh()}},destroy:a}}var Q=/```[ \t]*pipeup-replies[^\n]*\n([\s\S]*?)(?:\n[ \t]*```|$)/g,ee=/^[ \t]*(agent|thread|reply|addressed|signed)[ \t]*:[ \t]?(.*)$/i,L="Agent";function M(e){let t=[];for(let[,s]of e.replace(/\r\n?/g,`
2
+ `).matchAll(Q)){let r=L,n=null,i=null;for(let p of s.split(`
3
+ `)){let c=ee.exec(p);if(c){let a=c[1].toLowerCase(),l=c[2].trim();a==="agent"?(r=l||L,i=null):a==="thread"?(n={agent:r,thread:l,reply:"",addressed:"",signed:""},t.push(n),i=null):n&&(n[a]=l,i=a)}else n&&i&&i!=="signed"&&p.trim()?n[i]=`${n[i]}
4
+ ${p.trim()}`:n&&i==="signed"&&(n.signed+=p.trim())}}return t.filter(s=>s.thread&&s.reply)}var O=(e,t)=>e.replace(/\s+/g," ").trim()===t.replace(/\s+/g," ").trim();function te(e){try{let t=e.replace(/-/g,"+").replace(/_/g,"/"),s=Uint8Array.from(atob(t+"=".repeat((4-t.length%4)%4)),r=>r.charCodeAt(0));return JSON.parse(new TextDecoder().decode(s))}catch{return null}}async function D(e,t){let s=new Set(t.threads.map(n=>n.id)),r=[];for(let n of e){if(!s.has(n.thread)){r.push({kind:"gone",entry:n});continue}if(!n.signed){r.push({kind:"unsigned",entry:n,why:"none"});continue}let i=te(n.signed),p=Array.isArray(i)?i:[],c=p.find(d=>d?.body?.kind==="reply"),a=p.find(d=>d?.body?.kind==="addressed"),l=c?.body.author??"";!!c&&p.length===(a?2:1)&&p.every(d=>d.body.doc===t.doc&&d.body.thread===n.thread&&d.body.author===l)&&O(c.body.text??"",n.reply)&&(a?O(a.body.text??"",n.addressed):!n.addressed)&&(await Promise.all(p.map(t.check))).every(Boolean)?t.listed.includes(l)?r.push({kind:"signed",entry:n,ops:p,author:l}):r.push({kind:"unsigned",entry:n,why:"unlisted"}):r.push({kind:"unsigned",entry:n,why:"changed"})}return r}var $=(e,t,s)=>`${e} ${e===1?t:s}`,C=e=>{let t=[...new Set(e)];return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`};function R(e){let t=e.filter(a=>a.kind==="signed"),s=e.filter(a=>a.kind==="unsigned"),r=e.filter(a=>a.kind==="gone"),n=t.length+s.length,i=[];t.length&&i.push(`${$(t.length,"reply","replies")} signed by ${C(t.map(a=>a.entry.agent))}, whom this page lists`);let p=(a,l)=>a==="none"?`${l?"is":"are"} not signed`:a==="unlisted"?`${l?"is":"are"} signed with a key this page doesn't list`:l?"was changed after it was signed":"were changed after they were signed";for(let a of["none","changed","unlisted"]){let l=s.filter(f=>f.why===a);if(!l.length)continue;let o=C(l.map(f=>f.entry.agent)),d=l.length===1;i.push(`${$(l.length,"reply","replies")} from ${o} ${p(a,d)}, so ${d?"it":"they"} will show as pasted by you`)}let c=[...t,...s].filter(a=>a.entry.addressed).length;return c&&i.push(`${c} of them ${c===1?"says":"say"} the comment is addressed`),r.length&&i.push(`${$(r.length,"reply is","replies are")} for a comment that's no longer here, so ${r.length===1?"it":"they"} will be left out`),{lines:i,adds:n}}function ne(e){if(!e)return{cli:"npx --yes pipeup@0",fallback:null};let s=`npx --yes pipeup@${e.split(".")[0]??"0"}`;return e.includes("-")?{cli:`npx --yes pipeup@${e}`,fallback:s}:{cli:s,fallback:null}}function re(e,t=""){if(t)return{page:t,served:!1};try{let s=new URL(e),r=decodeURIComponent(s.pathname);return r.endsWith("/")&&(r+="index.html"),s.protocol==="file:"?{page:/^\/[A-Za-z]:\//.test(r)?r.slice(1):r,served:!1}:{page:r,served:!0}}catch{return{page:"<the page's HTML file>",served:!1}}}var oe=e=>{try{let t=new URL(e);return t.protocol==="file:"?decodeURIComponent(t.pathname).replace(/^\/([A-Za-z]:\/)/,"$1"):t.href}catch{return e}},T=e=>e.replace(/\s+/g," ").trim();function _(e){let{cli:t,fallback:s}=ne(e.version),r=`https://pipeup-ai.github.io/pipeup/${e.version?.includes("-")?"next/":""}`,{page:n,served:i}=re(e.url,e.file),p=i?`<the HTML file your site serves at ${n}>`:n,c=`\`${t} reply --print --doc ${e.doc} --thread <thread id> "what you changed and where" --addressed "short note"\``;return[`Please act on my review comments on ${T(e.title)} (${T(e.url)}). The page uses Pipeup.`,"The comments were left in my browser. They are not in the page's file, so don't look for them there. Everything you need is below.","",`## ${e.open} open comment${e.open===1?"":"s"}${e.edition?` on the ${e.edition} edition`:""}`,"",e.comments.trim(),...e.resolved||e.earlier?["",`(${[e.resolved?`${e.resolved} resolved comment${e.resolved===1?"":"s"}`:"",e.earlier?`${e.earlier} open comment${e.earlier===1?"":"s"} on earlier editions`:""].filter(Boolean).join(" and ")} left out.)`]:[],"","## How to answer","","- For each thread, make the change I approved, or say why you didn't. Answer a question with an answer. Ask me before changing anything I haven't approved.","- Reply in one block I can paste back into the page with Paste my agent's replies, and tell me what you changed and where. Don't say the page was updated unless you updated it.","","```pipeup-replies","agent: <your name>","thread: <thread id>","reply: what you changed and where","addressed: short note, only if you made the change","```","",e.listed?`- This page lists an agent's key. If it's yours, sign the block so it shows as yours, not as pasted by me: ${c} prints each reply signed with the key you keep (in ~/.pipeup/agent.json). Without your key, send the same block unsigned.`:`- If you keep a Pipeup key between sessions, sign the block with ${c}, and ask me whether to list you on the page (\`${t} agent\` prints the line to add). If you can't keep a key, don't ask to be listed: the plain block works.`,...e.file?[`- You're on this computer, with a live link running: \`${t} comments ${e.file}\` reads the comments and \`${t} reply --page ${p} --thread <thread id> "\u2026" --addressed "\u2026"\` answers in the page by itself.`]:e.replies?[`- If you can write next to the page on this computer, \`${t} reply --page ${p} --thread <thread id> "\u2026" --addressed "\u2026"\` writes ${T(oe(e.replies))}, and your replies appear by themselves. Pass the HTML file that runs Pipeup, not a file it shows.`]:[],...(e.file||e.replies)&&!e.listed?[`- The page doesn't list you yet. Ask me first; after my yes, run \`${t} agent --name <your name> --page ${p} --yes\`.`]:[],...s?[`- If npm refuses ${t.split(" ").at(-1)}, use ${s.split(" ").at(-1)}: it answers these commands the same way.`]:[],"- Only mark a thread addressed. Never resolve, reopen, edit or delete: I close threads. Never answer as me, and keep your key out of the page and its folder.","",`Guide: ${r}skills/pipeup-apply/SKILL.md`].join(`
5
+ `)}var H=()=>["Please send your replies again in one block I can paste into the page, like this:","","```pipeup-replies","agent: <your name>","thread: <thread id>","reply: what you changed and where","addressed: short note, only if you made the change","```"].join(`
6
+ `);var se=/^[A-Za-z0-9_-]{43}$/,ie="pipeupReplies",ae=4e3,de=4e3,pe=/^AI assistant\s*·?\s*/;function k(e){let t=w("data-pipeup-agents",e)??"";return[...new Set(t.split(/[\s,]+/).filter(s=>se.test(s)))]}function E(e=location,t){let s=w("data-pipeup-replies",t);try{let r=e.href.split(/[?#]/)[0],n=new URL(s??(/\/$/.test(r)?`${r}index.replies.js`:r.replace(/\.[^./]*$/,"")+".replies.js"),e.href),i=n.protocol==="file:"?e.protocol==="file:":n.origin===e.origin;return i||console.warn("pipeup: the replies file must be on this site or this computer; ignoring it"),i?n.href:null}catch{return null}}function N(e){let t=k(),s=0,r="",n=null;async function i(){let d=globalThis[ie];if(!Array.isArray(d))return 0;let f=d.splice(0),h=[];for(let u of f){let y=u;if(!(y?.format!=="pipeup-replies"||y.doc!==e.document.id||!Array.isArray(y.ops)))for(let g of y.ops){let m=g?.body;m&&t.includes(m.author)&&(m.kind==="reply"||m.kind==="addressed"||m.kind==="react"||m.kind==="unreact")?(h.push(g),(m.name==="AI assistant"||m.name.startsWith("AI assistant "))&&(r=m.name.replace(pe,""))):s++}}return h.length?e.merge(h):0}function p(){let d=E();return d?(n?.remove(),new Promise((f,h)=>{let u=document.createElement("script");n=u,u.src=`${d}?${Date.now()}`;let y=m=>{window.clearTimeout(g),u.remove(),n===u&&(n=null),m?h(new Error(`pipeup: ${m}`)):f()},g=window.setTimeout(()=>y("the replies file didn't answer"),ae);u.addEventListener("load",()=>y()),u.addEventListener("error",()=>y("there is no replies file yet")),e.overlay().append(u)})):Promise.reject(new Error("pipeup: the replies file can't be read from here"))}async function c(){if(!t.length)return 0;let d=await i();return await p(),d+await i()}let a=!1,l=()=>{a||document.hidden||(a=!0,c().catch(()=>{}).finally(()=>a=!1))},o=0;return t.length?(l(),o=window.setInterval(l,de),document.addEventListener("visibilitychange",l)):i(),{enabled:t.length>0,ignored:()=>s,who:()=>r,check:c,tally:d=>{let f=d.filter(g=>!g.resolved),h=g=>g.root.replies.some(m=>t.includes(m.author)||m.name.startsWith("AI assistant \xB7 ")),u=new Set(d.map(g=>g.id));return{stray:new Set(e.document.ops().filter(g=>t.includes(g.body.author)&&!u.has(g.body.thread)).map(g=>g.body.thread)).size,open:f.length,answered:f.filter(h).length,addressed:f.filter(g=>g.addressed).length}},destroy:()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l),n?.remove()}}}var z=`.ag-t{margin:0 0 8px;font-size:15px;font-weight:600}
7
+ .ag-f{display:block;width:100%;height:96px;margin:4px 0 8px;padding:8px;border:1px solid var(--ln);border-radius:8px;background:var(--so);color:var(--k);font:12px/1.5 ui-monospace,monospace;resize:vertical}
8
+ .ag-l{margin:0;padding:0;list-style:none;font-size:12.5px;line-height:1.45;color:var(--k)}
9
+ .ag-l li{padding:5px 0;border-top:1px solid var(--ln);opacity:1;transition:opacity .25s var(--eo)}
10
+ .ag-p{margin:8px 0 0;font-size:12px;line-height:1.5;color:var(--mu)}
11
+ .ag-a{display:flex;gap:6px;justify-content:flex-end;margin-top:10px}
12
+ .ag-b{padding:6px 12px;border:1px solid var(--ln);border-radius:8px;font-size:13px;color:var(--k);transition:background-color .2s var(--eo),opacity .2s var(--eo)}
13
+ .ag-b:hover,.ag-b:focus-visible{background:var(--ho);outline:none}
14
+ .ag-b.primary{border-color:var(--pu-accent);color:var(--pu-accent)}
15
+ .ag-b:disabled{opacity:.45;pointer-events:none}
16
+ @media (pointer:coarse){.ag-b{min-height:40px}}`;function b(e,t={},...s){let r=document.createElement(e);for(let[n,i]of Object.entries(t))r.setAttribute(n,i);return r.append(...s),r}var le=()=>globalThis.Pipeup?.checkOp;function j(e,t,s){let r=b("textarea",{class:"ag-f","aria-label":"Your agent's answer",placeholder:"Paste your agent's whole answer here",spellcheck:"false"}),n=b("ul",{class:"ag-l",role:"status"}),i=b("p",{class:"ag-p"}),p=b("button",{class:"ag-b primary",type:"button"},"Add replies"),c=b("button",{class:"ag-b",type:"button"},"Copy that request"),a=b("button",{class:"ag-b",type:"button"},"Cancel");p.disabled=!0,c.hidden=!0;let l=[],o=0,d=async()=>{let h=++o,u=r.value,y=le(),g=await D(M(u),{doc:e.document.id,threads:e.document.threads(),listed:k(),check:y??(async()=>!1)});if(h!==o)return;l=g;let{lines:m,adds:v}=R(l);n.replaceChildren(...m.map(G=>b("li",{},G))),p.textContent=v?`Add ${v} ${v===1?"reply":"replies"}`:"Add replies",p.disabled=!v;let B=!!u.trim()&&!l.length;c.hidden=!B,i.textContent=B?"There are no replies here that this page can read. Ask your agent to answer in the replies block from Copy for my agent.":v?"Replies show in their threads under the agent's name, marked as AI. They can't change your comments.":""};r.addEventListener("input",()=>void d());let f=e.openDialog(b("div",{},b("h2",{class:"ag-t"},"Paste your agent's replies"),r,n,i,b("div",{class:"ag-a"},a,c,p)),"Paste your agent's replies");queueMicrotask(()=>r.focus()),a.addEventListener("click",()=>f.close()),c.addEventListener("click",()=>{t(H()).then(()=>i.textContent="Copied. Paste it to your agent, then paste its answer here.",()=>i.textContent="Your browser blocked copying.")}),p.addEventListener("click",async()=>{p.disabled=!0;let h=0;try{for(let u of l)u.kind==="signed"?h+=await e.merge(u.ops)?1:0:u.kind==="unsigned"&&(await e.paste(u.entry.thread,u.entry.agent,u.entry.reply,u.entry.addressed||void 0),h++)}catch(u){i.textContent=u instanceof Error?u.message.replace(/^pipeup: /,""):"Something went wrong",p.disabled=!1;return}f.close(),s(h,l.find(u=>u.kind!=="gone")?.entry.agent??"")})}var K=()=>globalThis.Pipeup??{},ce=["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],ue=["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],fe=["M7 5h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2z","M10 3h4a1 1 0 0 1 1 1v2H9V4a1 1 0 0 1 1-1z","M12 10v7m-3-3 3 3 3-3"],ge="Reads a replies file next to this page, and replies you paste from your agent. When the page is shown through pipeup watch, and only after you switch it on, it sends this page's comments to the program running on this computer. Nothing leaves this computer.",U=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";async function F(e,t){try{await navigator.clipboard.writeText(e);return}catch{}let s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(s),s.select();let r=document.execCommand("copy");if(s.remove(),!r)throw new Error("pipeup: your browser blocked copying")}function Y(){return{id:"agents",api:1,version:"0.6.0",needs:["menu","status","notify","listnote","dialog","styles","paste"],network:{when:"page-configured",to:["page"],says:ge},setup(e){let t=N(e),s=e.addStyles(z),r=()=>e.document.threads().filter(o=>!o.resolved).length,n=I({snapshot:async()=>{let o=K();if(!o.comments)throw new Error("pipeup: this page has no Pipeup to read comments from");let[d,f]=await Promise.all([o.comments(),o.comments({all:!0})]);return{v:1,at:new Date().toISOString(),title:document.title,open:d,all:f}},changes:o=>e.document.onChange(o),refresh:()=>c()}),i="",p=()=>t.who()||n.agent||i,c=()=>{if(e.setStatus(t.enabled||n.enabled?{text:n.on()?`Sharing comments with ${p()||"your agent"}`:`${p()||"An AI agent"} can answer comments here`}:null),!t.enabled)return e.setListNote(null);let o=t.tally(e.document.threads()),d=p()||"An agent",f=o.answered?`${d} has answered ${o.answered} of ${o.open} open comments${o.addressed?`; ${o.addressed} ${o.addressed===1?"is":"are"} marked addressed`:""}`:"No replies from an agent yet",h=t.ignored(),u=(n.on()?`Sharing with ${n.agent||"your agent"} \xB7 `:"")+f+(h?` \xB7 ${h} from other writers ignored`:"")+(o.stray?` \xB7 replies for ${o.stray} comment${o.stray===1?"":"s"} this page doesn't have`:"");e.setListNote({text:u,action:{label:"Check for replies",run:async()=>{try{let y=await t.check();e.notify(y?`${y} new ${y===1?"reply":"replies"}`:"No new replies")}catch(y){e.notify(U(y))}finally{c()}}}})},a=[e.addMenuItem({id:"prompt",icon:ce,label:()=>"Copy for my agent",hint:()=>{let o=r();return`Your ${o} open comment${o===1?"":"s"}, and how to answer them`},select:async()=>{try{let o=K();if(!o.comments)throw new Error("pipeup: this page has no Pipeup to read comments from");let[d,f,h]=await Promise.all([o.comments({edition:!0}),o.comments({all:!0,edition:!0}),o.comments()]);await F(_({title:document.title,url:location.href,doc:e.document.id,comments:d.markdown,open:d.threads.length,resolved:f.threads.length-d.threads.length,edition:w("data-pipeup-edition")?.trim()||"",earlier:h.threads.length-d.threads.length,replies:E(),file:n.enabled?n.file:"",listed:k().length>0,version:globalThis.Pipeup?.VERSION}),e.overlay());let u=d.threads.length;e.notify(`Copied ${u} open comment${u===1?"":"s"} for your agent`)}catch(o){e.notify(U(o))}}}),e.addMenuItem({id:"paste",icon:fe,label:()=>"Paste my agent's replies",hint:()=>"Adds the answers your agent gave in a chat",select:()=>j(e,o=>F(o,e.overlay()),(o,d)=>{d&&(i=d),e.notify(o?`Added ${o} ${o===1?"reply":"replies"}`:"No replies added"),c()})})];n.enabled&&a.push(e.addMenuItem({id:"link",icon:ue,label:()=>"Share with my agent",hint:()=>"Sends this page's comments to the program running on this computer, and nothing else",checked:()=>n.on(),select:async()=>{try{await n.set(!n.on())}catch(o){e.notify(U(o))}c()}}));let l=e.document.onChange(c);return c(),()=>{l(),s(),t.destroy(),n.destroy()}}}}x(Y());})();