@pipeup/agents 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/dist/agents.esm.js +16 -2
- package/dist/agents.min.js +16 -2
- package/dist/pipeup+agents.min.js +17 -3
- package/package.json +3 -3
package/dist/agents.esm.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)
|
|
1
|
+
var Y=/^\/__pipeup\/[A-Za-z0-9_-]{16,}$/;function B(e){let t=document.documentElement,s=t.getAttribute("data-pipeup-link")??"",r=Y.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 G=/```[ \t]*pipeup-replies[^\n]*\n([\s\S]*?)(?:\n[ \t]*```|$)/g,Z=/^[ \t]*(agent|thread|reply|addressed|signed)[ \t]*:[ \t]?(.*)$/i,I="Agent";function C(e){let t=[];for(let[,s]of e.replace(/\r\n?/g,`
|
|
2
|
+
`).matchAll(G)){let r=I,n=null,i=null;for(let p of s.split(`
|
|
3
|
+
`)){let c=Z.exec(p);if(c){let a=c[1].toLowerCase(),l=c[2].trim();a==="agent"?(r=l||I,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 L=(e,t)=>e.replace(/\s+/g," ").trim()===t.replace(/\s+/g," ").trim();function q(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 M(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=q(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)&&L(c.body.text??"",n.reply)&&(a?L(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 A=(e,t,s)=>`${e} ${e===1?t:s}`,O=e=>{let t=[...new Set(e)];return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`};function D(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(`${A(t.length,"reply","replies")} signed by ${O(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=O(l.map(f=>f.entry.agent)),d=l.length===1;i.push(`${A(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(`${A(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 J(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 V(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 W=e=>{try{let t=new URL(e);return t.protocol==="file:"?decodeURIComponent(t.pathname).replace(/^\/([A-Za-z]:\/)/,"$1"):t.href}catch{return e}},S=e=>e.replace(/\s+/g," ").trim();function R(e){let{cli:t,fallback:s}=J(e.version),r=`https://pipeup-ai.github.io/pipeup/${e.version?.includes("-")?"next/":""}`,{page:n,served:i}=V(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 ${S(e.title)} (${S(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 ${S(W(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 _=()=>["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 w=(e,t)=>t?t.getAttribute(e):globalThis.Pipeup?.setting?.(e)??globalThis.document?.documentElement.getAttribute(e)??null;var Oe=2n**256n-2n**32n-977n;var re=/^[A-Za-z0-9_-]{43}$/,oe="pipeupReplies",se=4e3,ie=4e3,ae=/^AI assistant\s*·?\s*/;function k(e){let t=w("data-pipeup-agents",e)??"";return[...new Set(t.split(/[\s,]+/).filter(s=>re.test(s)))]}function T(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 H(e){let t=k(),s=0,r="",n=null;async function i(){let d=globalThis[oe];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(ae,""))):s++}}return h.length?e.merge(h):0}function p(){let d=T();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"),se);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,ie),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 N=`.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 de=()=>globalThis.Pipeup?.checkOp;function z(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=de(),g=await M(C(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}=D(l);n.replaceChildren(...m.map(F=>b("li",{},F))),p.textContent=v?`Add ${v} ${v===1?"reply":"replies"}`:"Add replies",p.disabled=!v;let U=!!u.trim()&&!l.length;c.hidden=!U,i.textContent=U?"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(_()).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 j=()=>globalThis.Pipeup??{},pe=["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"],le=["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],ce=["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"],ue="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.",E=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";async function K(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 fe(){return{id:"agents",api:1,version:"0.6.0",needs:["menu","status","notify","listnote","dialog","styles","paste"],network:{when:"page-configured",to:["page"],says:ue},setup(e){let t=H(e),s=e.addStyles(N),r=()=>e.document.threads().filter(o=>!o.resolved).length,n=B({snapshot:async()=>{let o=j();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(E(y))}finally{c()}}}})},a=[e.addMenuItem({id:"prompt",icon:pe,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=j();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 K(R({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:T(),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(E(o))}}}),e.addMenuItem({id:"paste",icon:ce,label:()=>"Paste my agent's replies",hint:()=>"Adds the answers your agent gave in a chat",select:()=>z(e,o=>K(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:le,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(E(o))}c()}}));let l=e.document.onChange(c);return c(),()=>{l(),s(),t.destroy(),n.destroy()}}}}export{fe as default};
|
package/dist/agents.min.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
"use strict";(()=>{function
|
|
2
|
-
`)
|
|
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());})();
|