notemend 0.1.13 → 0.1.15

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.
@@ -0,0 +1 @@
1
+ import{agentName as d}from"../store/thread.mjs";import{api as p}from"./api";function f(c,r){let a=null,i=null;const e=document.querySelector(".dt-turbo"),u="/notemend:turbo",s=()=>{const n=!!a&&Date.now()-Date.parse(a.at)<18e4,t=n?i?.paused?"paused":"on":"none",o=n?d(a.agent):"",l=t==="none"?`Turbo is off. Run ${u} in Claude Code and comments for the agent are taken as they land \u2014 click to copy it`:t==="on"?`Turbo on: ${o} takes comments for the agent as they land \u2014 click to pause`:`Turbo paused: ${o} is listening but waits \u2014 click to resume`;e.dataset.state=t,e.dataset.tip=l,e.setAttribute("aria-label",l),e.setAttribute("aria-checked",String(t==="on")),c&&(e.hidden=!0)};return setInterval(s,3e4),e.addEventListener("click",async()=>{const n=e.dataset.state;if(n==="none"){await navigator.clipboard?.writeText(u).catch(()=>{}),r(`Copied ${u} \u2014 paste it in Claude Code`);return}const t=n==="on"?"off":"on";i={paused:t==="off"},s();try{const o=await p("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({turbo:t})});if(!o.ok)throw new Error(String(o.status));r(t==="off"?"Turbo paused":"Turbo on")}catch{i={paused:t==="on"},s(),r("Could not switch turbo \u2014 try again")}}),n=>{a=n.listening??null,i=n.turbo??null,s()}}export{f as turbo};
package/src/hosting.mjs CHANGED
@@ -1 +1 @@
1
- import{tmpdir as p}from"node:os";import{join as l}from"node:path";import{notemendHandler as u,titled as h}from"./server/middleware.mjs";import{BACKEND as g,cloudStore as y}from"./store/cloud.mjs";function w({project:e,token:c,email:a,sitemap:m=[],backend:n}){n&&Object.assign(g,n);const r=l(p(),"notemend",e),s=y(r,e,{access_token:c,email:a}),d=t=>t==="/"?"Home":h(t.split("/").filter(Boolean).pop());return async t=>{const i=new Set(m);if(t.url.startsWith("/__devbar/config"))try{for(const o of(await s.load()).comments)/^\/(?!\/)/.test(o.route)&&i.add(o.route)}catch{}const f=Object.fromEntries([...i].map(o=>[o,[d(o)]]));return u({root:r,options:{pages:f},routes:()=>[],open:async()=>s,crossOrigin:!0})(t)}}export{w as hostedHandler};
1
+ import{tmpdir as l}from"node:os";import{join as u}from"node:path";import{notemendHandler as g,titled as h}from"./server/middleware.mjs";import{BACKEND as y,cloudStore as H}from"./store/cloud.mjs";function w({project:e,token:a,email:m,sitemap:f=[],backend:n}){n&&Object.assign(y,n);const r=u(l(),"notemend",e),s=H(r,e,{access_token:a,email:m}),p=t=>t==="/"?"Home":h(t.split("/").filter(Boolean).pop()),i={pages:{}},d=g({root:r,options:i,routes:()=>[],open:async()=>s,crossOrigin:!0});return async t=>{const c=new Set(f);if(t.url.startsWith("/__devbar/config"))try{for(const o of(await s.load()).comments)/^\/(?![\/\\])/.test(o.route)&&c.add(o.route)}catch{}return i.pages=Object.fromEntries([...c].map(o=>[o,[p(o)]])),d(t)}}export{w as hostedHandler};
@@ -1 +1 @@
1
- import{readFileSync as b,existsSync as F,statSync as Q,readdirSync as X}from"node:fs";import{mask as Y}from"../store/mask.mjs";import{join as k,isAbsolute as q}from"node:path";import{isIP as H}from"node:net";import{pathToFileURL as tt}from"node:url";import{openStore as et,retry as rt,CABINET as nt,session as G}from"../store/cloud.mjs";import{mentionsIn as ot,cleanAssignee as _,STAGES as M,frameOf as st}from"../store/thread.mjs";import{CATEGORIES as at}from"../store/categories.mjs";import{BREAKPOINTS as it,DEVICES as ct,ICONS as z,SHELLS as J,BROWSERS as W}from"../presets.mjs";const U={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp",gif:"image/gif",svg:"image/svg+xml",webm:"video/webm",m4a:"audio/mp4"},V=t=>t.split(".").slice(0,2).map(Number).reduce((r,c)=>r*100+(Number.isNaN(c)?9999:c),0),ut=(t,r)=>{try{const u=b(q(r)?r:k(t,r),"utf8").match(/title="([^"]+)"|\btitle:\s*["'`]([^"'`]+)["'`]/);return(u?.[1]??u?.[2])?.split("\u2014").pop()?.trim()||null}catch{return null}};function It(t){const r=["app","src/app"].map(l=>k(t,l)).find(F),c=[],u=(l,g)=>{for(const a of X(l,{withFileTypes:!0})){const m=a.name;if(a.isDirectory()){if(/^[_@]|^\(\./.test(m))continue;u(k(l,m),/^\(.+\)$/.test(m)?g:[...g,m])}else/^page\.(jsx?|tsx?|mdx?)$/.test(m)&&c.push({origin:"project",type:"page",pattern:"/"+g.join("/"),entrypoint:k(l,m)})}};return r&&u(r,[]),c}const lt=t=>t[0].toUpperCase()+t.slice(1).replace(/[-_]+/g," ");function mt({root:t,options:r,routes:c}){const u=r.pages??{},l=(e,f,S)=>({route:e,name:f,label:f.replace(/^[\d.]+[A-Z]?\.\s*/,""),group:S}),g=c.filter(e=>e.origin==="project"&&e.type==="page"&&!e.pattern.includes("[")).map(e=>({route:e.pattern.replace(/\/+$/,"")||"/",entrypoint:e.entrypoint})),a=new Set(g.map(e=>e.route)),m=[...g,...Object.keys(u).filter(e=>!a.has(e)).map(e=>({route:e}))],O={};for(const{route:e}of m){const f=e.split("/")[1];f&&(O[f]=(O[f]||0)+1)}const E=e=>{const f=e.split("/")[1];return f&&O[f]>1?lt(f):"Pages"},C=r.groups?()=>r.groups[r.groups.length-1]:E,T=m.map(({route:e,entrypoint:f})=>{const[S,j]=u[e]??[];return l(e,S??(f&&ut(t,f))??e,j??C(e))}),s=r.groups??[...new Set([...Object.values(u).map(([,e])=>e).filter(Boolean),"Pages",...T.map(e=>e.group).sort()])],d=T.sort((e,f)=>s.indexOf(e.group)-s.indexOf(f.group)||V(e.name)-V(f.name)||e.route.localeCompare(f.route)),n=(r.breakpoints??it).map(e=>({id:e.id,label:e.label,min:e.min,ideal:e.ideal,max:Number.isFinite(e.max)?e.max:null,icon:e.icon??z[e.id]??z.desktop})),o=(r.devices??ct).filter(e=>e.w>0&&e.h>0&&J.includes(e.shell)&&W.includes(e.browser)?!0:(console.warn(`[notemend] device "${e.id}" skipped: it needs w and h, shell (${J.join(", ")}) and browser (${W.join(", ")})${e.frame?"; `frame` pictures were replaced by shell + browser in 0.3":""}`),!1));return{pages:d,groups:s.filter(e=>d.some(f=>f.group===e)),breakpoints:n,devices:o,categories:at,sanity:!!r.sanity,shortcuts:r.shortcuts!==!1,ignore:r.ignore??[],grid:{container:"container",grid:"grid",columns:12,...r.grid},zIndex:r.zIndex??2000000020}}const ft=t=>{const r=k(t,"notemend.config.mjs");let c=0,u={};return async()=>{if(!F(r))return{};const l=Q(r).mtimeMs;if(l===c)return u;c=l;try{const{default:g,...a}=await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ `${tt(r).href}?t=${l}`);u={...a,...g}}catch(g){console.warn(`[notemend] notemend.config.mjs: ${g.message}`)}return u}},dt=t=>{const r=String(t.headers.host||"").toLowerCase(),c=r.startsWith("[")?r.slice(1,r.indexOf("]")):r.replace(/:\d+$/,"");return c.includes(":")?H(c)===6:!c||!c.includes(".")||H(c)===4||/\.(localhost|local|test|internal|lan|home\.arpa)$/.test(c)},p=(t,r)=>String(t??"").replace(/[\u0000-\u001f\u007f]+/g," ").trim().slice(0,r),gt=t=>({route:p(t.route,500),text:String(t.text??"").slice(0,1e4),selector:p(t.selector,2e3),rx:Number.isFinite(t.rx)?t.rx:0,ry:Number.isFinite(t.ry)?t.ry:0,label:p(t.label,200),ctx:p(t.ctx,120),breakpoint:p(t.breakpoint,40),browser:p(t.browser,80),device:p(t.device,80),tag:p(t.tag,40),classes:Array.isArray(t.classes)?t.classes.slice(0,20).map(r=>p(r,80)):[],nth:Number.isInteger(t.nth)?t.nth:null,category:p(t.category,40),...["urgent","high","normal","low"].includes(t.priority)?{priority:t.priority}:{},...t.shared===!0?{shared:!0}:{},viewport:t.viewport&&Number.isFinite(t.viewport.w)&&Number.isFinite(t.viewport.h)?{w:t.viewport.w,h:t.viewport.h}:null,..._(t.assignee)?{assignee:_(t.assignee)}:{},...M.includes(t.stage)?{stage:t.stage}:{},...typeof t.host=="string"&&/^[a-z0-9.-]{1,120}(:\d{1,5})?$/i.test(t.host)?{host:t.host.toLowerCase()}:{},...Array.isArray(t.logs)&&t.logs.length?{logs:t.logs.slice(-20).map(r=>({at:p(r?.at,30),kind:["console","error","rejection","network"].includes(r?.kind)?r.kind:"console",text:Y(p(r?.text,500))})).filter(r=>r.text)}:{},...t.suggest&&typeof t.suggest.from=="string"&&typeof t.suggest.to=="string"&&t.suggest.to.trim()?{suggest:{from:t.suggest.from.slice(0,2e3),to:t.suggest.to.slice(0,2e3)}}:{}}),pt=t=>{const r={};return(t.status==="open"||t.status==="done")&&(r.status=t.status),"doneBy"in t&&(r.doneBy=t.doneBy==="you"?"you":null),typeof t.category=="string"&&(r.category=p(t.category,40)),"priority"in t&&(r.priority=["urgent","high","normal","low"].includes(t.priority)?t.priority:null),typeof t.shared=="boolean"&&(r.shared=t.shared||null),"assignee"in t&&(r.assignee=_(t.assignee)),"stage"in t&&(r.stage=M.includes(t.stage)?t.stage:null),r},K=async(t,r,c,u,l)=>{if(typeof u!="string")return;const g=r.comments.find(a=>a.id===Number(c))?.images?.filter(a=>st(a)===l)??[];if(await t.attach(r,c,u,l))for(const a of g)await t.detach(r,c,a)},ht=t=>{const r=t.headers.origin;if(!r)return!1;try{return new URL(r).host!==t.headers.host}catch{return!0}};function wt({root:t,options:r,routes:c,open:u=()=>et(t),crossOrigin:l=!1}){const g=ft(t),a=(s,d=200)=>({status:d,type:"application/json",body:JSON.stringify(s)}),m=(s,d)=>({status:s,type:"text/plain",body:d}),O=async s=>{const d=await s.body();if(d.length>45e5)throw Object.assign(new Error("too large"),{status:413});try{return d.length?JSON.parse(d.toString("utf8")):{}}catch{throw Object.assign(new Error("not JSON"),{status:400})}},E=async(s,d)=>{const n=async o=>{const e=await d(o);if(e.status>=400)throw Object.assign(new Error("not written"),{out:e});return e};try{if(s.cloud)return await rt(s,n);const o=s.load(),e=await n(o);return s.save(o),e}catch(o){if(o.out)return o.out;throw o}},C=async(s,d)=>{if(s.method!=="GET"&&!l&&ht(s))return m(403,"Cross-origin write refused");const n=await u();if(s.method==="GET"){const i=d.searchParams.get("route"),h=n.version?String(await n.version()):null;if(h&&d.searchParams.get("since")===h)return{status:204,type:"text/plain",body:""};const w=await n.load();return a({version:h,comments:i?w.comments.filter(I=>I.route===i):w.comments,listening:w.listening??null,turbo:w.turbo??null})}let o=null,e=null;const f=n.cloud&&s.method!=="DELETE"?n.people().then(i=>{o=i,e=i.me},i=>{throw i}).catch(i=>i):Promise.resolve(),S=async()=>{const i=await f;if(i instanceof Error)throw i},j=i=>{if(e&&i){i.by=e.email,i.byName=e.name;const h=ot(i.text,o.team.filter(w=>w.email!==e.email));h.length&&(i.mentions=h)}return i};if(s.method==="POST"){const{image:i,images:h,before:w,...I}=await O(s),A=gt(I);return A.text.trim()?A.route.startsWith("/")?E(n,async B=>{await S();const v=j(n.add(B,A));for(const P of[].concat(h??i??[]))await n.attach(B,v.id,P);return await K(n,B,v.id,w,"before"),a(v,201)}):a({error:"route must be a path"},400):a({error:"empty comment"},400)}if(s.method==="PATCH"){const i=await O(s);if(i.turbo==="on"||i.turbo==="off")return E(n,async x=>(x.turbo={paused:i.turbo==="off",at:new Date().toISOString()},a({turbo:x.turbo})));const{id:h,reply:w,image:I,images:A,removeImage:B,edit:v,after:P,...Z}=i,y=Number(h);if(!Number.isInteger(y))return a({error:"bad id"},400);const $=pt(Z);return E(n,async x=>{if(await S(),v){const N=x.comments.find(L=>L.id===Number(y)),R=v.at?N?.replies?.find(L=>L.at===v.at):N;if(e&&R?.by&&R.by!==e.email||!(v.text?.trim?.()&&n.edit(x,y,v.at??null,v.text.trim().slice(0,1e4))))return a({error:`no message of yours to edit in #${y}`},404)}w?.trim?.()&&j(n.reply(x,y,"you",w.trim().slice(0,1e4))?.replies.at(-1));for(const N of[].concat(A??I??[]))await n.attach(x,y,N);for(const N of[].concat(B||[]))await n.detach(x,y,N);await K(n,x,y,P,"after"),e&&$.status==="done"&&Object.assign($,{confirmedBy:e.email,confirmedAt:new Date().toISOString()}),e&&$.status==="open"&&Object.assign($,{confirmedBy:null,confirmedAt:null});const D=Object.keys($).length||!w?n.patch(x,y,$):x.comments.find(N=>N.id===Number(y));return D?a(D):a({error:`no comment #${y}`},404)})}if(s.method==="DELETE"){const i=Number(d.searchParams.get("id"));return E(n,async h=>await n.remove(h,i)?a({ok:!0,id:i}):a({error:`no comment #${i}`},404))}return m(405,"Method not allowed")},T=(s,d)=>{const n=d.replace(/^.*[/\\]/,""),o=n.split(".").pop()?.toLowerCase()??"";if(!/^[\w.-]+$/.test(n)||!U[o])return m(400,"Bad name");const e=k(s,n);return F(e)?{status:200,type:U[o],body:b(e)}:m(404,"Not found")};return async s=>{const d=new URL(s.url,"http://devbar"),n=d.pathname.slice(10);if(!l&&!dt(s))return m(403,"Notemend answers local addresses only");try{if(n==="config"){const o=mt({root:t,options:{...await g(),...r},routes:c()}),e=await u();return e.cloud&&Object.assign(o,await e.people().catch(()=>({}))),(e.cloud||await G().catch(()=>null))&&(o.voice=!0),a(o)}if(n==="transcribe"&&s.method==="POST"){const o=await u(),e=o.cloud?await o.token():(await G().catch(()=>null))?.access_token;if(!e)return m(401,"Voice replies need Notemend \u2014 run `npx notemend login`.");const{audio:f}=await O(s),S=/^data:(audio\/(?:webm|mp4))(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(f||""));if(!S)return m(400,"Not a recording");const j=await fetch(`${nt}/api/transcribe`,{method:"POST",body:Buffer.from(S[2],"base64"),headers:{authorization:`Bearer ${e}`,"content-type":S[1]}});return{status:j.status,type:"application/json",body:await j.text()}}if(n==="comments")return await C(s,d);if(n==="image"){const o=await u(),e=(d.searchParams.get("name")||"").replace(/^.*[/\\]/,"");return o.cloud&&/^[\w.-]+$/.test(e)&&await o.fetchImage(e).catch(()=>null),T(o.imageDir,e)}return m(404,"Not found")}catch(o){return o.status===400||o.status===413?m(o.status,o.message):(console.error("[notemend]",o),m(500,"Something went wrong \u2014 the dev server log says what."))}}}function At(t){const r=wt(t),c=u=>new Promise((l,g)=>{const a=[];u.on("data",m=>a.push(m)),u.on("end",()=>l(Buffer.concat(a))),u.on("error",g)});return async function(l,g,a){if(!l.url||!l.url.startsWith("/__devbar/"))return a();const m=await r({method:l.method,url:l.url,headers:l.headers,body:()=>c(l)});g.statusCode=m.status,g.setHeader("content-type",m.type),g.setHeader("cache-control","no-store"),g.end(m.body)}}export{mt as buildConfig,wt as notemendHandler,At as notemendMiddleware,It as scanApp,ut as titleOf,lt as titled};
1
+ import{readFileSync as z,existsSync as F,statSync as q,readdirSync as tt}from"node:fs";import{mask as et}from"../store/mask.mjs";import{join as T,isAbsolute as nt}from"node:path";import{isIP as G}from"node:net";import{pathToFileURL as rt}from"node:url";import{openStore as ot,retry as st,CABINET as J,session as b}from"../store/cloud.mjs";import{mentionsIn as at,cleanAssignee as D,STAGES as M,frameOf as it}from"../store/thread.mjs";import{CATEGORIES as ct,categoryOf as ut}from"../store/categories.mjs";import{BREAKPOINTS as lt,DEVICES as mt,ICONS as U,SHELLS as W,BROWSERS as V}from"../presets.mjs";const K={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp",gif:"image/gif",svg:"image/svg+xml",webm:"video/webm",m4a:"audio/mp4",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"},Z=t=>t.split(".").slice(0,2).map(Number).reduce((n,m)=>n*100+(Number.isNaN(m)?9999:m),0),ft=(t,n)=>{try{const l=z(nt(n)?n:T(t,n),"utf8").match(/title="([^"]+)"|\btitle:\s*["'`]([^"'`]+)["'`]/);return(l?.[1]??l?.[2])?.split("\u2014").pop()?.trim()||null}catch{return null}};function Bt(t){const n=["app","src/app"].map(u=>T(t,u)).find(F),m=[],l=(u,p)=>{for(const a of tt(u,{withFileTypes:!0})){const c=a.name;if(a.isDirectory()){if(/^[_@]|^\(\./.test(c))continue;l(T(u,c),/^\(.+\)$/.test(c)?p:[...p,c])}else/^page\.(jsx?|tsx?|mdx?)$/.test(c)&&m.push({origin:"project",type:"page",pattern:"/"+p.join("/"),entrypoint:T(u,c)})}};return n&&l(n,[]),m}const dt=t=>t[0].toUpperCase()+t.slice(1).replace(/[-_]+/g," ");function pt({root:t,options:n,routes:m}){const l=n.pages??{},u=(e,f,w)=>({route:e,name:f,label:f.replace(/^[\d.]+[A-Z]?\.\s*/,""),group:w}),p=m.filter(e=>e.origin==="project"&&e.type==="page"&&!e.pattern.includes("[")).map(e=>({route:e.pattern.replace(/\/+$/,"")||"/",entrypoint:e.entrypoint})),a=new Set(p.map(e=>e.route)),c=[...p,...Object.keys(l).filter(e=>!a.has(e)).map(e=>({route:e}))],j={};for(const{route:e}of c){const f=e.split("/")[1];f&&(j[f]=(j[f]||0)+1)}const k=e=>{const f=e.split("/")[1];return f&&j[f]>1?dt(f):"Pages"},L=n.groups?()=>n.groups[n.groups.length-1]:k,A=c.map(({route:e,entrypoint:f})=>{const[w,N]=l[e]??[];return u(e,w??(f&&ft(t,f))??e,N??L(e))}),r=n.groups??[...new Set([...Object.values(l).map(([,e])=>e).filter(Boolean),"Pages",...A.map(e=>e.group).sort()])],d=A.sort((e,f)=>r.indexOf(e.group)-r.indexOf(f.group)||Z(e.name)-Z(f.name)||e.route.localeCompare(f.route)),s=(n.breakpoints??lt).map(e=>({id:e.id,label:e.label,min:e.min,ideal:e.ideal,max:Number.isFinite(e.max)?e.max:null,icon:e.icon??U[e.id]??U.desktop})),o=(n.devices??mt).filter(e=>e.w>0&&e.h>0&&W.includes(e.shell)&&V.includes(e.browser)?!0:(console.warn(`[notemend] device "${e.id}" skipped: it needs w and h, shell (${W.join(", ")}) and browser (${V.join(", ")})${e.frame?"; `frame` pictures were replaced by shell + browser in 0.3":""}`),!1));return{pages:d,groups:r.filter(e=>d.some(f=>f.group===e)),breakpoints:s,devices:o,categories:ct,sanity:!!n.sanity,shortcuts:n.shortcuts!==!1,ignore:n.ignore??[],grid:{container:"container",grid:"grid",columns:12,...n.grid},zIndex:n.zIndex??2000000020}}const gt=t=>{const n=T(t,"notemend.config.mjs");let m=0,l={};return async()=>{if(!F(n))return{};const u=q(n).mtimeMs;if(u===m)return l;m=u;try{const{default:p,...a}=await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ `${rt(n).href}?t=${u}`);l={...a,...p}}catch(p){console.warn(`[notemend] notemend.config.mjs: ${p.message}`)}return l}},ht=t=>{const n=String(t.headers.host||"").toLowerCase(),m=n.startsWith("[")?n.slice(1,n.indexOf("]")):n.replace(/:\d+$/,"");return m.includes(":")?G(m)===6:!m||!m.includes(".")||G(m)===4||/\.(localhost|local|test|internal|lan|home\.arpa)$/.test(m)},v=(t,n)=>String(t??"").replace(/[\u0000-\u001f\u007f]+/g," ").trim().slice(0,n),wt=t=>({route:v(t.route,500),text:String(t.text??"").slice(0,1e4),selector:v(t.selector,2e3),rx:Number.isFinite(t.rx)?t.rx:0,ry:Number.isFinite(t.ry)?t.ry:0,label:v(t.label,200),ctx:v(t.ctx,120),breakpoint:v(t.breakpoint,40),browser:v(t.browser,80),device:v(t.device,80),tag:v(t.tag,40),classes:Array.isArray(t.classes)?t.classes.slice(0,20).map(n=>v(n,80)):[],nth:Number.isInteger(t.nth)?t.nth:null,category:v(t.category,40),...["urgent","high","normal","low"].includes(t.priority)?{priority:t.priority}:{},...t.shared===!0?{shared:!0}:{},viewport:t.viewport&&Number.isFinite(t.viewport.w)&&Number.isFinite(t.viewport.h)?{w:t.viewport.w,h:t.viewport.h}:null,...D(t.assignee)?{assignee:D(t.assignee)}:{},...M.includes(t.stage)?{stage:t.stage}:{},...typeof t.host=="string"&&/^[a-z0-9.-]{1,120}(:\d{1,5})?$/i.test(t.host)?{host:t.host.toLowerCase()}:{},...Array.isArray(t.logs)&&t.logs.length?{logs:t.logs.slice(-20).map(n=>({at:v(n?.at,30),kind:["console","error","rejection","network"].includes(n?.kind)?n.kind:"console",text:et(v(n?.text,500))})).filter(n=>n.text)}:{},...t.suggest&&typeof t.suggest.from=="string"&&typeof t.suggest.to=="string"&&t.suggest.to.trim()?{suggest:{from:t.suggest.from.slice(0,2e3),to:t.suggest.to.slice(0,2e3)}}:{}}),yt=t=>{const n={};return(t.status==="open"||t.status==="done")&&(n.status=t.status),"doneBy"in t&&(n.doneBy=t.doneBy==="you"?"you":null),typeof t.category=="string"&&(n.category=ut(t.category).id),"priority"in t&&(n.priority=["urgent","high","normal","low"].includes(t.priority)?t.priority:null),typeof t.shared=="boolean"&&(n.shared=t.shared||null),"assignee"in t&&(n.assignee=D(t.assignee)),"stage"in t&&(n.stage=M.includes(t.stage)?t.stage:null),n},Q=async(t,n,m,l,u)=>{if(typeof l!="string")return;const p=n.comments.find(a=>a.id===Number(m))?.images?.filter(a=>it(a)===u)??[];if(await t.attach(n,m,l,u))for(const a of p)await t.detach(n,m,a)},R=t=>{const n=t.headers.origin;if(!n)return!1;try{return new URL(n).host!==t.headers.host}catch{return!0}};function xt({root:t,options:n,routes:m,open:l=()=>ot(t),crossOrigin:u=!1}){const p=gt(t),a=(r,d=200)=>({status:d,type:"application/json",body:JSON.stringify(r)}),c=(r,d)=>({status:r,type:"text/plain",body:d}),j=async r=>{const d=await r.body();if(d.length>45e5)throw Object.assign(new Error("too large"),{status:413});try{return d.length?JSON.parse(d.toString("utf8")):{}}catch{throw Object.assign(new Error("not JSON"),{status:400})}},k=async(r,d)=>{const s=async o=>{const e=await d(o);if(e.status>=400)throw Object.assign(new Error("not written"),{out:e});return e};try{if(r.cloud)return await st(r,s);const o=r.load(),e=await s(o);return r.save(o),e}catch(o){if(o.out)return o.out;throw o}},L=async(r,d)=>{if(r.method!=="GET"&&!u&&R(r))return c(403,"Cross-origin write refused");const s=await l();if(r.method==="GET"){const i=d.searchParams.get("route"),y=s.version?String(await s.version()):null;if(y&&d.searchParams.get("since")===y)return{status:204,type:"text/plain",body:""};const x=await s.load();return a({version:y,comments:i?x.comments.filter(I=>I.route===i):x.comments,listening:x.listening??null,turbo:x.turbo??null})}let o=null,e=null;const f=s.cloud&&r.method!=="DELETE"?s.people().then(i=>{o=i,e=i.me},i=>{throw i}).catch(i=>i):Promise.resolve(),w=async()=>{const i=await f;if(i instanceof Error)throw i},N=i=>{if(e&&i){i.by=e.email,i.byName=e.name;const y=at(i.text,o.team.filter(x=>x.email!==e.email));y.length&&(i.mentions=y)}return i};if(r.method==="POST"){const{image:i,images:y,before:x,...I}=await j(r),B=wt(I);return B.text.trim()?/^\/(?![\/\\])/.test(B.route)?k(s,async C=>{await w();const O=N(s.add(C,B));for(const P of[].concat(y??i??[]))await s.attach(C,O.id,P);return await Q(s,C,O.id,x,"before"),a(O,201)}):a({error:"route must be a path"},400):a({error:"empty comment"},400)}if(r.method==="PATCH"){const i=await j(r);if(i.turbo==="on"||i.turbo==="off")return k(s,async h=>(h.turbo={paused:i.turbo==="off",at:new Date().toISOString()},a({turbo:h.turbo})));const{id:y,reply:x,image:I,images:B,removeImage:C,edit:O,unsay:P,after:X,...Y}=i,g=Number(y);if(!Number.isInteger(g))return a({error:"bad id"},400);const E=yt(Y);return k(s,async h=>{if(await w(),O){const S=h.comments.find(_=>_.id===Number(g)),$=O.at?S?.replies?.find(_=>_.at===O.at):S;if(e&&$?.by&&$.by!==e.email||!(O.text?.trim?.()&&s.edit(h,g,O.at??null,O.text.trim().slice(0,1e4))))return a({error:`no message of yours to edit in #${g}`},404)}if(typeof P=="string"){const S=h.comments.find($=>$.id===g)?.replies?.find($=>$.at===P);return!S||e&&S.by&&S.by!==e.email||!s.unsay(h,g,P)?a({error:`no reply of yours to delete in #${g}`},404):a(h.comments.find($=>$.id===g))}x?.trim?.()&&N(s.reply(h,g,"you",x.trim().slice(0,1e4))?.replies.at(-1));for(const S of[].concat(B??I??[]))await s.attach(h,g,S);for(const S of[].concat(C||[]))await s.detach(h,g,S);await Q(s,h,g,X,"after"),e&&E.status==="done"&&Object.assign(E,{confirmedBy:e.email,confirmedAt:new Date().toISOString()}),e&&E.status==="open"&&Object.assign(E,{confirmedBy:null,confirmedAt:null});const H=Object.keys(E).length||!x?s.patch(h,g,E):h.comments.find(S=>S.id===Number(g));return H?a(H):a({error:`no comment #${g}`},404)})}if(r.method==="DELETE"){const i=Number(d.searchParams.get("id"));return k(s,async y=>await s.remove(y,i)?a({ok:!0,id:i}):a({error:`no comment #${i}`},404))}return c(405,"Method not allowed")},A=(r,d)=>{const s=d.replace(/^.*[/\\]/,""),o=s.split(".").pop()?.toLowerCase()??"";if(!/^[\w.-]+$/.test(s)||!K[o])return c(400,"Bad name");const e=T(r,s);return F(e)?{status:200,type:K[o],body:z(e)}:c(404,"Not found")};return async r=>{const d=new URL(r.url,"http://devbar"),s=d.pathname.slice(10);if(!u&&!ht(r))return c(403,"Notemend answers local addresses only");try{if(s==="config"){const o=pt({root:t,options:{...await p(),...n},routes:m()}),e=await l();return e.cloud&&Object.assign(o,await e.people().catch(()=>({}))),(e.cloud||await b().catch(()=>null))&&(o.voice=!0),a(o)}if(s==="transcribe"&&r.method==="POST"){if(!u&&R(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await b().catch(()=>null))?.access_token;if(!e)return c(401,"Voice replies need Notemend \u2014 run `npx notemend login`.");const{audio:f}=await j(r),w=/^data:(audio\/(?:webm|mp4))(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(f||""));if(!w)return c(400,"Not a recording");const N=await fetch(`${J}/api/transcribe`,{method:"POST",body:Buffer.from(w[2],"base64"),headers:{authorization:`Bearer ${e}`,"content-type":w[1]}});return{status:N.status,type:"application/json",body:await N.text()}}if(s==="translate"&&r.method==="POST"){if(!u&&R(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await b().catch(()=>null))?.access_token;if(!e)return c(401,"Translating needs Notemend \u2014 run `npx notemend login`.");const{text:f,to:w}=await j(r),N=await fetch(`${J}/api/translate`,{method:"POST",body:JSON.stringify({text:f,to:w}),headers:{authorization:`Bearer ${e}`,"content-type":"application/json"}});return{status:N.status,type:"application/json",body:await N.text()}}if(s==="comments")return await L(r,d);if(s==="image"){const o=await l(),e=(d.searchParams.get("name")||"").replace(/^.*[/\\]/,"");return o.cloud&&/^[\w.-]+$/.test(e)&&await o.fetchImage(e).catch(()=>null),A(o.imageDir,e)}return c(404,"Not found")}catch(o){return o.status===400||o.status===413?c(o.status,o.message):(console.error("[notemend]",o),c(500,"Something went wrong \u2014 the dev server log says what."))}}}function Ct(t){const n=xt(t),m=l=>new Promise((u,p)=>{const a=[];l.on("data",c=>a.push(c)),l.on("end",()=>u(Buffer.concat(a))),l.on("error",p)});return async function(u,p,a){if(!u.url||!u.url.startsWith("/__devbar/"))return a();const c=await n({method:u.method,url:u.url,headers:u.headers,body:()=>m(u)});p.statusCode=c.status,p.setHeader("content-type",c.type),p.setHeader("cache-control","no-store"),p.end(c.body)}}export{pt as buildConfig,xt as notemendHandler,Ct as notemendMiddleware,Bt as scanApp,ft as titleOf,dt as titled};
@@ -1 +1 @@
1
- const o=[{id:"general",label:"General",color:"#0d99ff"},{id:"text",label:"Text",color:"#f5c451"},{id:"bug",label:"Bug",color:"#e5484d"},{id:"motion",label:"Motion",color:"#a475f9"}],t=e=>o.find(l=>l.id===e)||o[0];export{o as CATEGORIES,t as categoryOf};
1
+ const i=[{id:"general",label:"General",color:"#0d99ff",hint:"anything else",icon:'<path d="M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z"/><rect x="3" y="14" width="7" height="7" rx="1"/><circle cx="17.5" cy="17.5" r="3.5"/>'},{id:"bug",label:"Bug",color:"#e5484d",hint:"it is broken",icon:'<path d="m8 2 1.88 1.88M14.12 3.88 16 2M9 7.13v-1a3 3 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6M12 20v-9M6.53 9C4.6 8.8 3 7.1 3 5M6 13H2M3 21c0-2.1 1.7-3.9 3.8-4M20.97 5c0 2.1-1.6 3.8-3.5 4M22 13h-4M17.2 17c2.1.1 3.8 1.9 3.8 4"/>'},{id:"text",label:"Text",color:"#f5c451",hint:"wording, copy",icon:'<path d="M4 7V4h16v3M9 20h6M12 4v16"/>'},{id:"motion",label:"Motion",color:"#a475f9",hint:"animation",icon:'<path d="M17.7 7.7a2.5 2.5 0 1 1 1.8 4.3H2M9.6 4.6A2 2 0 1 1 11 8H2M12.6 19.4A2 2 0 1 0 14 16H2"/>'},{id:"design",label:"Design",color:"#d6409f",hint:"colour, spacing, layout",icon:'<path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.93 0 1.65-.75 1.65-1.69 0-.44-.18-.84-.44-1.13-.29-.29-.44-.65-.44-1.13a1.64 1.64 0 0 1 1.67-1.67h2c3.05 0 5.55-2.5 5.55-5.55C21.97 6.01 17.46 2 12 2z"/><circle cx="13.5" cy="6.5" r="1"/><circle cx="17.5" cy="10.5" r="1"/><circle cx="8.5" cy="7.5" r="1"/><circle cx="6.5" cy="12.5" r="1"/>'},{id:"content",label:"Content",color:"#30a46c",hint:"images, files, data",icon:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4M10 9H8M16 13H8M16 17H8"/>'}],t=(c,o=14)=>`<svg viewBox="0 0 24 24" width="${o}" height="${o}" fill="none" stroke="${c.color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${c.icon}</svg>`,e=c=>i.find(o=>o.id===c)||i[0];export{i as CATEGORIES,t as categoryIcon,e as categoryOf};
@@ -1,3 +1,3 @@
1
- import{readFileSync as O,writeFileSync as g,existsSync as B,mkdirSync as $,rmSync as T}from"node:fs";import{homedir as K}from"node:os";import{dirname as J,join as w}from"node:path";import{createStore as z,add as U,reply as Y,edit as Z,patch as G,shotName as S,mediaOf as R,mediaName as M}from"./comments.mjs";const C=process.env.NOTEMEND_APP||"https://app.notemend.com",x={url:process.env.NOTEMEND_SUPABASE_URL||"https://xzhnjldvkirrydbyrdnm.supabase.co",key:process.env.NOTEMEND_SUPABASE_KEY||"sb_publishable_b8h8jTHZ9KtbPvMuroLhqA_-yBqZwd6"},N=w(process.env.NOTEMEND_HOME||w(K(),".config","notemend"),"session.json"),P=e=>w(e,".notemend.json"),W=e=>{try{return JSON.parse(O(P(e),"utf8")).project||null}catch{return null}},ue=(e,t)=>g(P(e),JSON.stringify({project:t},null,2)+`
2
- `),le=e=>T(P(e),{force:!0}),Q=()=>{try{const e=JSON.parse(O(N,"utf8"));return e.url===x.url?e:null}catch{return null}},V=e=>{$(J(N),{recursive:!0}),g(N,JSON.stringify(e,null,2)+`
3
- `,{mode:384})},fe=()=>T(N,{force:!0});async function y(e,{method:t="GET",token:o,body:s,headers:i={},raw:a=!1}={}){const l=await fetch(`${x.url}${e}`,{method:t,headers:{apikey:x.key,authorization:`Bearer ${o||x.key}`,...s&&!a?{"content-type":"application/json"}:{},...i},body:a?s:s&&JSON.stringify(s)});if(!l.ok){const p=await l.text();let k=p;try{const v=JSON.parse(p);k=v.msg||v.message||v.error_description||v.error||p}catch{}const b=new Error(`${k} (${l.status})`);throw b.status=l.status,b}return l}const D=e=>{const t={url:x.url,email:e.user.email,user:e.user.id,access_token:e.access_token,refresh_token:e.refresh_token,expires_at:e.expires_at??Math.floor(Date.now()/1e3)+e.expires_in};return V(t),t},pe=e=>y("/auth/v1/otp",{method:"POST",body:{email:e,create_user:!0}}),me=async(e,t)=>D(await(await y("/auth/v1/verify",{method:"POST",body:{email:e,token:t,type:"email"}})).json());async function de(e){const t=await fetch(`${C}/api/cli/device`,{method:"POST"}),o=await t.json().catch(()=>({}));if(!t.ok)throw new Error(o.error||`The cabinet said ${t.status}`);console.log(`Your code: ${o.code}`),e(o.url);const s=Date.now()+o.expires_in*1e3;for(;Date.now()<s;){await new Promise(p=>setTimeout(p,o.interval*1e3));const i=await fetch(`${C}/api/cli/device?device=${o.device}`).catch(()=>null);if(!i||i.status===202)continue;const a=await i.json().catch(()=>({}));if(!i.ok)throw new Error(a.error||`The cabinet said ${i.status}`);const l=await(await y("/auth/v1/user",{token:a.access_token})).json();return D({user:l,access_token:a.access_token,refresh_token:a.refresh_token,expires_at:Number(a.expires_at)})}throw new Error("No answer from the browser in 10 minutes.")}async function he(e,t){const o=await E();if(!o)throw new Error("Sign in first: npx notemend login");return(await(await y("/rest/v1/projects",{method:"POST",token:o.access_token,headers:{prefer:"return=representation"},body:{name:e,...t?{site_url:t}:{}}})).json())[0]}async function E(){const e=Q();if(!e)return null;if(e.expires_at-60>Date.now()/1e3)return e;try{const t=await y("/auth/v1/token?grant_type=refresh_token",{method:"POST",body:{refresh_token:e.refresh_token}});return D(await t.json())}catch(t){if(t.status===400||t.status===401)return null;throw t}}async function we(e,t,o){const s=w(J(N),"seen.json");let i={};try{i=JSON.parse(O(s,"utf8"))}catch{}const a=`${e}|${t}|${o}`;if(Date.now()-(i[a]||0)<6*36e5)return;const l=await E();l&&(await y("/rest/v1/rpc/agent_seen",{method:"POST",token:l.access_token,body:{p_agent:e,p_version:t,p_via:o}}),g(s,JSON.stringify({...i,[a]:Date.now()})))}class q extends Error{}function X(e,t,o=null){const s=w(e,"feedback","images"),i=n=>`feedback/images/${n}`,a=new WeakMap,l=o?async()=>o:async()=>{const n=await E();if(!n)throw new Error("Not signed in to Notemend \u2014 run `npx notemend login`.");return n},p=async(n,r={})=>y(`/rest/v1/${n}`,{...r,token:(await l()).access_token}),k=async(n,r={})=>y(`/storage/v1/object/shots/${t}/${n}`,{...r,token:(await l()).access_token}),b=async()=>{const n=await(await p(`stores?project_id=eq.${t}&select=doc,version`)).json();if(!n.length)throw new Error(`Project ${t} is not there, or you are not in it. Check \`npx notemend link\`.`);const r=n[0].doc;return a.set(r,n[0].version),r},v=async()=>(await(await p(`stores?project_id=eq.${t}&select=version`)).json())[0]?.version??null,L=async n=>{const r=a.get(n),c=await(await p(`stores?project_id=eq.${t}&version=eq.${r}`,{method:"PATCH",body:{doc:n},headers:{prefer:"return=representation"}})).json();if(!c.length)throw new q("Someone else wrote first");a.set(n,c[0].version)},F=async(n,r,c,u)=>{const m=n.comments.find(h=>h.id===Number(r)),d=R(c);if(!m||!d)return null;let f=Date.now();for(;B(w(s,M(m.id,f,d,u)));)f++;const _=M(m.id,f,d,u),j=Buffer.from(d.base64,"base64");return await k(_,{method:"POST",body:j,raw:!0,headers:{"content-type":d.type,"x-upsert":"true"}}),$(s,{recursive:!0}),g(w(s,_),j),(m.images||=[]).push(i(_)),m.updatedAt=new Date().toISOString(),i(_)},A=async n=>{S(n)&&(T(w(s,n),{force:!0}),await k(n,{method:"DELETE"}).catch(()=>{}))};return{cloud:!0,project:t,root:e,imageDir:s,load:b,version:v,save:L,attach:F,detach:async(n,r,c)=>{const u=n.comments.find(f=>f.id===Number(r)),m=S(c),d=m&&u?.images?.find(f=>S(f)===m);return d?(await A(m),u.images=u.images.filter(f=>f!==d),u.updatedAt=new Date().toISOString(),!0):!1},remove:async(n,r)=>{const c=n.comments.find(u=>u.id===Number(r));if(!c)return!1;for(const u of c.images||[])await A(S(u));return n.comments=n.comments.filter(u=>u.id!==Number(r)),!0},fetchImage:async n=>{if(!S(n)||S(n)!==n)return null;const r=w(s,n);if(B(r))return r;const c=await k(n).catch(()=>null);return c?($(s,{recursive:!0}),g(r,Buffer.from(await c.arrayBuffer())),r):null},people:async()=>{const n=await l(),r=h=>p(`rpc/${h}`,{method:"POST",body:{p:t}}).then(H=>H.json()).catch(()=>null),[c,u,m,d,f]=await Promise.all([p("profiles?select=email,name,nickname,avatar_url").then(h=>h.json()),r("project_people"),r("is_staff").then(h=>h??!0),r("project_staff"),r("project_lead")]),_=Array.isArray(u)?new Set(u):null,j=_?c.filter(h=>_.has(h.email)):c;return{me:c.find(h=>h.email===n.email)??{email:n.email,name:"",avatar_url:null},team:j,client:m===!1,...Array.isArray(d)?{studio:d}:{},...typeof f=="string"?{lead:f}:{}}},add:U,reply:Y,edit:Z,patch:G,token:async()=>(await l()).access_token}}let I=!1;async function ye(e){const t=W(e);return t&&await E()?X(e,t):(t&&!I&&(I=!0,console.warn("[notemend] this site is linked to a Notemend project, but this computer is not signed in \u2014 comments stay in feedback/ until you run `npx notemend login`.")),z(e))}async function _e(e,t){for(let o=0;;o++){const s=await e.load(),i=await t(s);try{return await e.save(s),i}catch(a){if(!(a instanceof q)||o>=4)throw a}}}export{x as BACKEND,C as CABINET,q as Conflict,X as cloudStore,he as createProject,de as deviceLogin,ue as link,W as linkedProject,fe as logout,ye as openStore,_e as retry,we as seen,pe as sendCode,E as session,le as unlink,me as verifyCode};
1
+ import{readFileSync as E,writeFileSync as S,existsSync as M,mkdirSync as O,rmSync as T}from"node:fs";import{homedir as K}from"node:os";import{dirname as J,join as y}from"node:path";import{createStore as Y,add as Z,reply as G,edit as R,unsay as W,patch as Q,shotName as v,mediaOf as U,mediaName as C}from"./comments.mjs";const q=process.env.NOTEMEND_APP||"https://app.notemend.com",x={url:process.env.NOTEMEND_SUPABASE_URL||"https://xzhnjldvkirrydbyrdnm.supabase.co",key:process.env.NOTEMEND_SUPABASE_KEY||"sb_publishable_b8h8jTHZ9KtbPvMuroLhqA_-yBqZwd6"},N=y(process.env.NOTEMEND_HOME||y(K(),".config","notemend"),"session.json"),P=e=>y(e,".notemend.json"),V=e=>{try{return JSON.parse(E(P(e),"utf8")).project||null}catch{return null}},fe=(e,t)=>S(P(e),JSON.stringify({project:t},null,2)+`
2
+ `),me=e=>T(P(e),{force:!0}),X=()=>{try{const e=JSON.parse(E(N,"utf8"));return e.url===x.url?e:null}catch{return null}},ee=e=>{O(J(N),{recursive:!0}),S(N,JSON.stringify(e,null,2)+`
3
+ `,{mode:384})},pe=()=>T(N,{force:!0});async function _(e,{method:t="GET",token:o,body:s,headers:u={},raw:a=!1}={}){const l=await fetch(`${x.url}${e}`,{method:t,headers:{apikey:x.key,authorization:`Bearer ${o||x.key}`,...s&&!a?{"content-type":"application/json"}:{},...u},body:a?s:s&&JSON.stringify(s)});if(!l.ok){const p=await l.text();let k=p;try{const g=JSON.parse(p);k=g.msg||g.message||g.error_description||g.error||p}catch{}const b=new Error(`${k} (${l.status})`);throw b.status=l.status,b}return l}const D=e=>{const t={url:x.url,email:e.user.email,user:e.user.id,access_token:e.access_token,refresh_token:e.refresh_token,expires_at:e.expires_at??Math.floor(Date.now()/1e3)+e.expires_in};return ee(t),t},he=e=>_("/auth/v1/otp",{method:"POST",body:{email:e,create_user:!0}}),de=async(e,t)=>D(await(await _("/auth/v1/verify",{method:"POST",body:{email:e,token:t,type:"email"}})).json());async function we(e){const t=await fetch(`${q}/api/cli/device`,{method:"POST"}),o=await t.json().catch(()=>({}));if(!t.ok)throw new Error(o.error||`The cabinet said ${t.status}`);console.log(`Your code: ${o.code}`),e(o.url);const s=Date.now()+o.expires_in*1e3;for(;Date.now()<s;){await new Promise(p=>setTimeout(p,o.interval*1e3));const u=await fetch(`${q}/api/cli/device`,{headers:{authorization:`Bearer ${o.device}`}}).catch(()=>null);if(!u||u.status===202)continue;const a=await u.json().catch(()=>({}));if(!u.ok)throw new Error(a.error||`The cabinet said ${u.status}`);const l=await(await _("/auth/v1/user",{token:a.access_token})).json();return D({user:l,access_token:a.access_token,refresh_token:a.refresh_token,expires_at:Number(a.expires_at)})}throw new Error("No answer from the browser in 10 minutes.")}async function ye(e,t){const o=await $();if(!o)throw new Error("Sign in first: npx notemend login");return(await(await _("/rest/v1/projects",{method:"POST",token:o.access_token,headers:{prefer:"return=representation"},body:{name:e,...t?{site_url:t}:{}}})).json())[0]}async function $(){const e=X();if(!e)return null;if(e.expires_at-60>Date.now()/1e3)return e;try{const t=await _("/auth/v1/token?grant_type=refresh_token",{method:"POST",body:{refresh_token:e.refresh_token}});return D(await t.json())}catch(t){if(t.status===400||t.status===401)return null;throw t}}async function _e(e,t,o){const s=y(J(N),"seen.json");let u={};try{u=JSON.parse(E(s,"utf8"))}catch{}const a=`${e}|${t}|${o}`;if(Date.now()-(u[a]||0)<6*36e5)return;const l=await $();l&&(await _("/rest/v1/rpc/agent_seen",{method:"POST",token:l.access_token,body:{p_agent:e,p_version:t,p_via:o}}),S(s,JSON.stringify({...u,[a]:Date.now()})))}class I extends Error{}function te(e,t,o=null){const s=y(e,"feedback","images"),u=n=>`feedback/images/${n}`,a=new WeakMap,l=o?async()=>o:async()=>{const n=await $();if(!n)throw new Error("Not signed in to Notemend \u2014 run `npx notemend login`.");return n},p=async(n,r={})=>_(`/rest/v1/${n}`,{...r,token:(await l()).access_token}),k=async(n,r={})=>_(`/storage/v1/object/shots/${t}/${n}`,{...r,token:(await l()).access_token}),b=async()=>{const n=await(await p(`stores?project_id=eq.${t}&select=doc,version`)).json();if(!n.length)throw new Error(`Project ${t} is not there, or you are not in it. Check \`npx notemend link\`.`);const r=n[0].doc;return a.set(r,n[0].version),r},g=async()=>(await(await p(`stores?project_id=eq.${t}&select=version`)).json())[0]?.version??null,z=async n=>{const r=a.get(n),i=await(await p(`stores?project_id=eq.${t}&version=eq.${r}`,{method:"PATCH",body:{doc:n},headers:{prefer:"return=representation"}})).json();if(!i.length)throw new I("Someone else wrote first");a.set(n,i[0].version)},A=new Map,F=async(n,r,i,c)=>{const m=n.comments.find(f=>f.id===Number(r)),h=U(i);if(!m||!h)return null;const d=`${m.id}:${c??""}:${i.length}:${i.slice(-48)}`;let w=A.get(d);if(!w){let f=Date.now();for(;M(y(s,C(m.id,f,h,c)));)f++;w=C(m.id,f,h,c),A.set(d,w)}const j=Buffer.from(h.base64,"base64");return await k(w,{method:"POST",body:j,raw:!0,headers:{"content-type":h.type,"x-upsert":"true"}}),O(s,{recursive:!0}),S(y(s,w),j),(m.images||=[]).push(u(w)),m.updatedAt=new Date().toISOString(),u(w)},B=async n=>{v(n)&&(T(y(s,n),{force:!0}),await k(n,{method:"DELETE"}).catch(()=>{}))};return{cloud:!0,project:t,root:e,imageDir:s,load:b,version:g,save:z,attach:F,detach:async(n,r,i)=>{const c=n.comments.find(d=>d.id===Number(r)),m=v(i),h=m&&c?.images?.find(d=>v(d)===m);return h?(await B(m),c.images=c.images.filter(d=>d!==h),c.updatedAt=new Date().toISOString(),!0):!1},remove:async(n,r)=>{const i=n.comments.find(c=>c.id===Number(r));if(!i)return!1;for(const c of i.images||[])await B(v(c));return n.comments=n.comments.filter(c=>c.id!==Number(r)),!0},fetchImage:async n=>{if(!v(n)||v(n)!==n)return null;const r=y(s,n);if(M(r))return r;const i=await k(n).catch(()=>null);return i?(O(s,{recursive:!0}),S(r,Buffer.from(await i.arrayBuffer())),r):null},people:async()=>{const n=await l(),r=f=>p(`rpc/${f}`,{method:"POST",body:{p:t}}).then(H=>H.json()).catch(()=>null),[i,c,m,h,d]=await Promise.all([p("profiles?select=email,name,nickname,avatar_url,agent_name,agent_avatar_url").then(f=>f.json()),r("project_people"),r("is_staff").then(f=>f??!0),r("project_staff"),r("project_lead")]),w=Array.isArray(c)?new Set(c):null,j=w?i.filter(f=>w.has(f.email)):i;return{me:i.find(f=>f.email===n.email)??{email:n.email,name:"",avatar_url:null},team:j,client:m===!1,...Array.isArray(h)?{studio:h}:{},...typeof d=="string"?{lead:d}:{}}},add:Z,reply:G,edit:R,unsay:W,patch:Q,token:async()=>(await l()).access_token}}let L=!1;async function ke(e){const t=V(e);return t&&await $()?te(e,t):(t&&!L&&(L=!0,console.warn("[notemend] this site is linked to a Notemend project, but this computer is not signed in \u2014 comments stay in feedback/ until you run `npx notemend login`.")),Y(e))}async function ge(e,t){for(let o=0;;o++){const s=await e.load(),u=await t(s);try{return await e.save(s),u}catch(a){if(!(a instanceof I)||o>=4)throw a}}}export{x as BACKEND,q as CABINET,I as Conflict,te as cloudStore,ye as createProject,we as deviceLogin,fe as link,V as linkedProject,pe as logout,ke as openStore,ge as retry,_e as seen,he as sendCode,$ as session,me as unlink,de as verifyCode};
@@ -1,3 +1,3 @@
1
- import{readFileSync as E,writeFileSync as $,existsSync as O,mkdirSync as I,renameSync as F,rmSync as J}from"node:fs";import{dirname as T,join as l}from"node:path";import{categoryOf as L}from"./categories.mjs";import{FRAMES as R}from"./thread.mjs";import{CATEGORIES as X,categoryOf as Y}from"./categories.mjs";import{stateOf as ee,STATE_LABEL as te}from"./status.mjs";const v=o=>{const t=String(o??"").split(/[/\\]/).pop();return/^[\w-][\w.-]*\.(png|jpe?g|webp|gif|webm|m4a)$/i.test(t)?t:""},C=o=>{const t=/^data:(image|video|audio)\/(png|jpeg|webp|gif|webm|mp4)(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(o||""));if(!t)return null;const[,e,n,s]=t;return(e==="image"?!/^(png|jpeg|webp|gif)$/.test(n):e==="video"?n!=="webm":!/^(webm|mp4)$/.test(n))?null:{base64:s,voice:e==="audio",ext:n==="jpeg"?"jpg":n==="mp4"?"m4a":n,type:`${e}/${n}`}},M=(o,t,e,n)=>`${e.voice?"voice-":R.includes(n)?`${n}-`:""}${o}-${t}.${e.ext}`,N=o=>Math.max(o.nextId||0,o.comments.reduce((t,e)=>Math.max(t,e.id),0)+1);function G(o,{route:t,selector:e,rx:n,ry:s,text:p,label:f,viewport:b,breakpoint:y,browser:D,device:A,tag:j,classes:i,nth:d,category:g,suggest:r,assignee:c,ctx:m,logs:a,host:S,priority:x,shared:u,stage:h}){const w={id:N(o),route:t,selector:e,rx:n,ry:s,text:p,tag:j||"",classes:i||[],nth:Number.isInteger(d)?d:null,label:f||"",ctx:m||"",viewport:b||null,breakpoint:y||"desktop",browser:D||"",device:A||"",category:L(g).id,status:"open",note:"",replies:[],doneBy:null,images:[],...r?{suggest:r}:{},...c?{assignee:c}:{},...x?{priority:x}:{},...h?{stage:h}:{},...u?{shared:!0}:{},...S?{host:S}:{},...a?.length?{logs:a}:{},createdAt:new Date().toISOString(),updatedAt:null};return o.comments.push(w),o.nextId=w.id+1,w}function _(o,t,e,n,s,p){const f=o.comments.find(b=>b.id===Number(t));return f?((f.replies||=[]).push({author:e,text:n,at:new Date().toISOString(),...s&&s!=="claude"?{agent:s}:{},...p?{by:p}:{}}),f.updatedAt=new Date().toISOString(),f):null}function q(o,t,e,n){const s=o.comments.find(f=>f.id===Number(t)),p=e?s?.replies?.find(f=>f.at===e&&f.author==="you"):s;return p?(p.text=n,s.updatedAt=new Date().toISOString(),s):null}function z(o,t,e){const n=o.comments.find(s=>s.id===Number(t));return n?(Object.assign(n,e,{updatedAt:new Date().toISOString()}),n):null}function U(o){const t=l(o,"feedback","comments.json"),e=l(o,"feedback","images"),n=l(o,"feedback","archive"),s=l(n,"images"),p=i=>`feedback/images/${i}`;return{root:o,file:t,imageDir:e,archiveDir:n,archiveImageDir:s,load:()=>O(t)?JSON.parse(E(t,"utf8")):{comments:[]},save:i=>{I(T(t),{recursive:!0}),$(`${t}.tmp`,JSON.stringify(i,null,2)+`
2
- `),F(`${t}.tmp`,t)},attach:(i,d,g,r)=>{const c=i.comments.find(x=>x.id===Number(d)),m=C(g);if(!c||!m)return null;I(e,{recursive:!0});let a=Date.now();for(;O(l(e,M(c.id,a,m,r)));)a++;const S=M(c.id,a,m,r);return $(l(e,S),Buffer.from(m.base64,"base64")),(c.images||=[]).push(p(S)),c.updatedAt=new Date().toISOString(),p(S)},detach:(i,d,g)=>{const r=i.comments.find(a=>a.id===Number(d)),c=v(g),m=c&&r?.images?.find(a=>v(a)===c);return m?(J(l(e,c),{force:!0}),r.images=r.images.filter(a=>a!==m),r.updatedAt=new Date().toISOString(),!0):!1},remove:(i,d)=>{const g=i.comments.find(r=>r.id===Number(d));if(!g)return!1;for(const r of g.images||[])v(r)&&J(l(e,v(r)),{force:!0});return i.comments=i.comments.filter(r=>r.id!==Number(d)),!0},add:G,patch:z,reply:_,edit:q,nextId:N,prune:(i,{dry:d=!1,date:g=new Date().toISOString().slice(0,10)}={})=>{const r=i.comments.filter(u=>u.status==="done"),c=i.comments.filter(u=>u.status!=="done"),m=l(n,`comments-${g}.json`);if(d||!r.length)return{moving:r,keeping:c,archiveFile:m,images:r.flatMap(u=>u.images||[])};I(s,{recursive:!0});const a=[];for(const u of r)u.images=(u.images||[]).map(h=>{const w=v(h);if(!w)return h;const k=l(e,w),B=l(s,w);return O(k)&&F(k,B),a.push(w),`feedback/archive/images/${w}`});const S=O(m)?JSON.parse(E(m,"utf8")).comments||[]:[],x=new Set(S.map(u=>u.id));return $(m,JSON.stringify({comments:[...S,...r.filter(u=>!x.has(u.id))]},null,2)+`
3
- `),i.nextId=N(i),i.comments=c,{moving:r,keeping:c,archiveFile:m,images:a}}}}export{X as CATEGORIES,te as STATE_LABEL,G as add,Y as categoryOf,U as createStore,q as edit,M as mediaName,C as mediaOf,N as nextId,z as patch,_ as reply,v as shotName,ee as stateOf};
1
+ import{readFileSync as E,writeFileSync as y,existsSync as $,mkdirSync as I,renameSync as F,rmSync as J}from"node:fs";import{dirname as C,join as l}from"node:path";import{categoryOf as L}from"./categories.mjs";import{DOCS as M,FRAMES as R,docSlug as G}from"./thread.mjs";import{CATEGORIES as ee,categoryOf as te}from"./categories.mjs";import{stateOf as re,STATE_LABEL as oe}from"./status.mjs";const v=r=>{const e=String(r??"").split(/[/\\]/).pop();return/^[\w-][\w.-]*\.(png|jpe?g|webp|gif|webm|m4a|pdf|docx?)$/i.test(e)?e:""},_=r=>{const e=/^data:(application\/[\w.+-]+)((?:;[\w=.-]+)*);base64,(.+)$/s.exec(String(r||""));if(e){const x=Object.keys(M).find(O=>M[O]===e[1]);return x?{base64:e[3],voice:!1,ext:x,type:e[1],slug:G(/;name=([\w.-]+)/.exec(e[2])?.[1])}:null}const n=/^data:(image|video|audio)\/(png|jpeg|webp|gif|webm|mp4)(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(r||""));if(!n)return null;const[,o,t,c]=n;return(o==="image"?!/^(png|jpeg|webp|gif)$/.test(t):o==="video"?t!=="webm":!/^(webm|mp4)$/.test(t))?null:{base64:c,voice:o==="audio",ext:t==="jpeg"?"jpg":t==="mp4"?"m4a":t,type:`${o}/${t}`}},B=(r,e,n,o)=>`${n.voice?"voice-":R.includes(o)?`${o}-`:""}${r}-${e}${n.slug?`.${n.slug}`:""}.${n.ext}`,N=r=>Math.max(r.nextId||0,r.comments.reduce((e,n)=>Math.max(e,n.id),0)+1);function q(r,{route:e,selector:n,rx:o,ry:t,text:c,label:d,viewport:x,breakpoint:O,browser:D,device:A,tag:j,classes:i,nth:p,category:g,suggest:s,assignee:a,ctx:m,logs:u,host:S,priority:b,shared:f,stage:h}){const w={id:N(r),route:e,selector:n,rx:o,ry:t,text:c,tag:j||"",classes:i||[],nth:Number.isInteger(p)?p:null,label:d||"",ctx:m||"",viewport:x||null,breakpoint:O||"desktop",browser:D||"",device:A||"",category:L(g).id,status:"open",note:"",replies:[],doneBy:null,images:[],...s?{suggest:s}:{},...a?{assignee:a}:{},...b?{priority:b}:{},...h?{stage:h}:{},...f?{shared:!0}:{},...S?{host:S}:{},...u?.length?{logs:u}:{},createdAt:new Date().toISOString(),updatedAt:null};return r.comments.push(w),r.nextId=w.id+1,w}function z(r,e,n,o,t,c){const d=r.comments.find(x=>x.id===Number(e));return d?((d.replies||=[]).push({author:n,text:o,at:new Date().toISOString(),...t&&t!=="claude"?{agent:t}:{},...c?{by:c}:{}}),d.updatedAt=new Date().toISOString(),d):null}function H(r,e,n,o){const t=r.comments.find(d=>d.id===Number(e)),c=n?t?.replies?.find(d=>d.at===n&&d.author==="you"):t;return c?(c.text=o,t.updatedAt=new Date().toISOString(),t):null}function K(r,e,n){const o=r.comments.find(c=>c.id===Number(e)),t=o?.replies?.find(c=>c.at===n&&c.author==="you");return t?(t.text="",t.deleted=!0,delete t.mentions,o.updatedAt=new Date().toISOString(),o):null}function P(r,e,n){const o=r.comments.find(t=>t.id===Number(e));return o?(Object.assign(o,n,{updatedAt:new Date().toISOString()}),o):null}function Y(r){const e=l(r,"feedback","comments.json"),n=l(r,"feedback","images"),o=l(r,"feedback","archive"),t=l(o,"images"),c=i=>`feedback/images/${i}`;return{root:r,file:e,imageDir:n,archiveDir:o,archiveImageDir:t,load:()=>$(e)?JSON.parse(E(e,"utf8")):{comments:[]},save:i=>{I(C(e),{recursive:!0}),y(`${e}.tmp`,JSON.stringify(i,null,2)+`
2
+ `),F(`${e}.tmp`,e)},attach:(i,p,g,s)=>{const a=i.comments.find(b=>b.id===Number(p)),m=_(g);if(!a||!m)return null;I(n,{recursive:!0});let u=Date.now();for(;$(l(n,B(a.id,u,m,s)));)u++;const S=B(a.id,u,m,s);return y(l(n,S),Buffer.from(m.base64,"base64")),(a.images||=[]).push(c(S)),a.updatedAt=new Date().toISOString(),c(S)},detach:(i,p,g)=>{const s=i.comments.find(u=>u.id===Number(p)),a=v(g),m=a&&s?.images?.find(u=>v(u)===a);return m?(J(l(n,a),{force:!0}),s.images=s.images.filter(u=>u!==m),s.updatedAt=new Date().toISOString(),!0):!1},remove:(i,p)=>{const g=i.comments.find(s=>s.id===Number(p));if(!g)return!1;for(const s of g.images||[])v(s)&&J(l(n,v(s)),{force:!0});return i.comments=i.comments.filter(s=>s.id!==Number(p)),!0},add:q,patch:P,reply:z,edit:H,unsay:K,nextId:N,prune:(i,{dry:p=!1,date:g=new Date().toISOString().slice(0,10)}={})=>{const s=i.comments.filter(f=>f.status==="done"),a=i.comments.filter(f=>f.status!=="done"),m=l(o,`comments-${g}.json`);if(p||!s.length)return{moving:s,keeping:a,archiveFile:m,images:s.flatMap(f=>f.images||[])};I(t,{recursive:!0});const u=[];for(const f of s)f.images=(f.images||[]).map(h=>{const w=v(h);if(!w)return h;const k=l(n,w),T=l(t,w);return $(k)&&F(k,T),u.push(w),`feedback/archive/images/${w}`});const S=$(m)?JSON.parse(E(m,"utf8")).comments||[]:[],b=new Set(S.map(f=>f.id));return y(m,JSON.stringify({comments:[...S,...s.filter(f=>!b.has(f.id))]},null,2)+`
3
+ `),i.nextId=N(i),i.comments=a,{moving:s,keeping:a,archiveFile:m,images:u}}}}export{ee as CATEGORIES,oe as STATE_LABEL,q as add,te as categoryOf,Y as createStore,H as edit,B as mediaName,_ as mediaOf,N as nextId,P as patch,z as reply,v as shotName,re as stateOf,K as unsay};
@@ -1 +1 @@
1
- const h=["before","after"],i=e=>/(?:^|\/)(before|after)-[^/]*$/.exec(String(e))?.[1]??null,A=e=>{const t={};for(const n of e?.images||[]){const o=i(n);o&&(t[o]=n)}return t},y=e=>{const t=[{author:"you",text:e.text,at:e.createdAt,by:e.by,byName:e.byName,images:[]},...e.note?[{author:"claude",text:e.note,at:e.updatedAt,images:[]}]:[],...(e.replies||[]).map(n=>({...n,images:[]}))];for(const n of e.images||[]){if(i(n))continue;const o=Number(/-(\d+)\.\w+$/.exec(n)?.[1]);let r=0;t.forEach((s,p)=>{Date.parse(s.at)<=o&&(r=p)}),t[r].images.push(n)}return t},b=e=>e.nickname||e.name||e.email,C=(e,t)=>{const n=String(e||"").toLowerCase();return n.includes("@")?[...new Set(t.filter(o=>[o.name,o.nickname,o.email].some(r=>{if(!r)return!1;const s=n.indexOf("@"+r.toLowerCase());return s!==-1&&!/[\p{L}\p{N}_.-]/u.test(n[s+r.length+1]??"")})).map(o=>o.email))]:[]},l={claude:"Claude",codex:"Codex",gemini:"Gemini",cursor:"Cursor",copilot:"Copilot",windsurf:"Windsurf",amp:"Amp",aider:"Aider",opencode:"OpenCode",agent:"AI agent"},u=e=>l[e]||(e?"AI agent":"Claude"),a=e=>typeof e=="string"&&e.startsWith("agent:")?e.slice(6):null,d=e=>e==="claude"||a(e)!=null,g=/^[^\s@]+@[^\s@]+$/,O=e=>{if(e==="claude")return e;if(typeof e!="string"||e.length>210)return null;const t=e.toLowerCase();return g.test(a(t)??t)?t:null},m=["new","approved","progress","review"],c=e=>m.includes(e?.stage)?e.stage:d(e?.assignee)?"approved":"new",k=(e,t)=>{const n=a(e.assignee);return c(e)==="approved"&&(!e.assignee||e.assignee==="claude"||n!=null&&(t===void 0||n===t))&&!w(e)},S=(e,t,n=o=>o)=>u(e)+(t?` \xB7 ${n(t)}`:""),f=2*36e5,N=(e,t=Date.now())=>e?.working&&e.status!=="done"&&t-Date.parse(e.working.at)<f?e.working:null,x=e=>/@guest\.notemend\.com$/i.test(String(e||"")),w=e=>x(e.by)&&!e.approvedBy,L={plugin:"Claude Code: /plugin \u2192 Installed \u2192 notemend \u2192 Update now, then /reload-plugins",npx:'run it as npx -y notemend@latest (npx keeps an old copy of plain "notemend"), then restart the agent',project:"npm i -D notemend@latest in the site, then restart the agent",desktop:"Claude Desktop: download app.notemend.com/notemend.mcpb again and open it",source:"pull the notemend repository"},D=(e,t)=>{const n=String(e).split(".").map(Number),o=String(t).split(".").map(Number);for(let r=0;r<3;r++)if((n[r]||0)!==(o[r]||0))return(n[r]||0)>(o[r]||0);return!1};export{l as AGENTS,h as FRAMES,m as STAGES,L as UPDATE_HOW,f as WORKING_TTL,S as agentLabel,u as agentName,a as agentOwner,O as cleanAssignee,k as forAgentOf,i as frameOf,A as framesOf,b as handleOf,w as held,x as isGuest,C as mentionsIn,D as newer,c as stageOf,y as threadOf,d as toAgent,N as workingOn};
1
+ const O=["before","after"],u=e=>/(?:^|\/)(before|after)-[^/]*$/.exec(String(e))?.[1]??null,y=e=>{const t={};for(const n of e?.images||[]){const o=u(n);o&&(t[o]=n)}return t},d={pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"},f=Object.fromEntries([..."\u0430\u0431\u0432\u0433\u0491\u0434\u0435\u0454\u0436\u0437\u0438\u0456\u0457\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044C\u044E\u044F\u044B\u044D\u0451\u044A"].map((e,t)=>[e,["a","b","v","h","g","d","e","ie","zh","z","y","i","i","i","k","l","m","n","o","p","r","s","t","u","f","kh","ts","ch","sh","shch","","iu","ia","y","e","io",""][t]])),b=e=>String(e??"").replace(/\.[^.]*$/,"").toLowerCase().replace(/[а-яёєіїґ]/g,t=>f[t]??"").normalize("NFKD").replace(/[^\w-]+/g,"-").replace(/^[-_]+|-+$/g,"").slice(0,60),N=e=>{const t=String(e??"");if(t.startsWith("data:")){const o=/^data:([^;,]+)((?:;[^;,]*)*)[;,]/.exec(t),r=o&&Object.keys(d).find(s=>d[s]===o[1]);return r?`${/;name=([\w-]+)/.exec(o[2])?.[1]||"document"}.${r}`:null}const n=/-\d+(?:\.([\w-]+))?\.(pdf|docx?)(?:\?|$)/i.exec(t.split("/").pop());return n?`${n[1]||"document"}.${n[2].toLowerCase()}`:null},m=e=>{const t=[{author:"you",text:e.text,at:e.createdAt,by:e.by,byName:e.byName,images:[]},...e.note?[{author:"claude",text:e.note,at:e.updatedAt,images:[]}]:[],...(e.replies||[]).map(n=>({...n,images:[]}))];for(const n of e.images||[]){if(u(n))continue;const o=Number(/-(\d+)(?:\.[\w-]+)?\.\w+$/.exec(n)?.[1]);let r=0;t.forEach((s,i)=>{Date.parse(s.at)<=o&&(r=i)}),t[r].images.push(n)}return t.filter(n=>!n.deleted)},I=e=>e.nickname||e.name||e.email,$=(e,t)=>{const n=String(e||"").toLowerCase();return n.includes("@")?[...new Set(t.filter(o=>[o.name,o.nickname,o.email].some(r=>{if(!r)return!1;const s=n.indexOf("@"+r.toLowerCase());return s!==-1&&!/[\p{L}\p{N}_.-]/u.test(n[s+r.length+1]??"")})).map(o=>o.email))]:[]},x={claude:"Claude",codex:"Codex",gemini:"Gemini",cursor:"Cursor",copilot:"Copilot",windsurf:"Windsurf",amp:"Amp",aider:"Aider",opencode:"OpenCode",agent:"AI agent"},h=e=>x[e]||(e?"AI agent":"Claude"),_="3.6 3.6 10.8 10.8",w="M10.116 9H13.883M9.966 9.558L12.222 10.86M9.558 9.966L11.441 13.228M9 10.116V12.72M8.442 9.966L6.559 13.228M8.034 9.558L5.778 10.86M7.884 9H4.118M8.034 8.442L5.778 7.14M8.442 8.034L6.559 4.772M9 7.884V5.28M9.558 8.034L11.441 4.772M9.966 8.442L12.222 7.14",p=e=>typeof e=="string"&&e.startsWith("agent:")?e.slice(6):null,l=e=>e==="claude"||p(e)!=null,A=/^[^\s@]+@[^\s@]+$/,D=e=>{if(e==="claude")return e;if(typeof e!="string"||e.length>210)return null;const t=e.toLowerCase();return A.test(p(t)??t)?t:null},L=["new","approved","progress","review","waiting"],c=e=>L.includes(e?.stage)?e.stage:l(e?.assignee)?"approved":"new",E=(e,t)=>{const n=p(e.assignee);return c(e)==="approved"&&(!e.assignee||e.assignee==="claude"||n!=null&&(t===void 0||n===t))&&!g(e)},k=()=>[{assignee:"claude",handle:"Claude",owner:null}],T=(e,t=[])=>{const n=String(e||"").toLowerCase();let o=null,r=-1;for(const s of k()){const i="@"+s.handle.toLowerCase();for(let a=n.indexOf(i);a!==-1;a=n.indexOf(i,a+1))!/[\p{L}\p{N}_.-]/u.test(n[a+i.length]??"")&&a>r&&(r=a,o=s.assignee)}return o},v=(e,t,n=o=>o)=>h(e)+(t?` \xB7 ${n(t)}`:""),M=2*36e5,S=(e,t=Date.now())=>e?.working&&e.status!=="done"&&t-Date.parse(e.working.at)<M?e.working:null,C=e=>/@guest\.notemend\.com$/i.test(String(e||"")),g=e=>C(e.by)&&!e.approvedBy,W=(e,t=Date.now())=>{if(!e)return null;if(e.status==="done")return e.doneBy==="claude"?"review":l(e.assignee)?"done":null;if(g(e))return"held";if(!l(e.assignee))return null;const n=m(e);return n.length>1&&n[n.length-1].author==="claude"?"asks":S(e,t)?"working":e.working?"stuck":c(e)==="approved"?"queued":null},G={held:0,queued:2,asks:6,working:6,stuck:6,review:10,done:12},H=w.split("M").filter(Boolean).map(e=>{const t=e.match(/[\d.]+/g).map(Number),[n,o]=/H/.test(e)?[t[2],t[1]]:/V/.test(e)?[t[0],t[2]]:[t[2],t[3]];return{d:"M"+e,a:(Math.atan2(n-9,9-o)+2*Math.PI)%(2*Math.PI)}}).sort((e,t)=>e.a-t.a).map(e=>e.d),R={plugin:"Claude Code: /plugin \u2192 Installed \u2192 notemend \u2192 Update now, then /reload-plugins",npx:'run it as npx -y notemend@latest (npx keeps an old copy of plain "notemend"), then restart the agent',project:"npm i -D notemend@latest in the site, then restart the agent",desktop:"Claude Desktop: download app.notemend.com/notemend.mcpb again and open it",source:"pull the notemend repository"},B=(e,t)=>{const n=String(e).split(".").map(Number),o=String(t).split(".").map(Number);for(let r=0;r<3;r++)if((n[r]||0)!==(o[r]||0))return(n[r]||0)>(o[r]||0);return!1};export{x as AGENTS,_ as AI_BOX,w as AI_RAYS,H as AI_RAYS_CW,d as DOCS,O as FRAMES,L as STAGES,G as STEP_RAYS,R as UPDATE_HOW,M as WORKING_TTL,k as agentHandles,v as agentLabel,T as agentMentioned,h as agentName,p as agentOwner,W as agentStep,D as cleanAssignee,N as docOf,b as docSlug,E as forAgentOf,u as frameOf,y as framesOf,I as handleOf,g as held,C as isGuest,$ as mentionsIn,B as newer,c as stageOf,m as threadOf,l as toAgent,S as workingOn};
package/store.d.ts CHANGED
@@ -22,7 +22,9 @@ export interface Comment {
22
22
  export interface Db { comments: Comment[]; nextId?: number }
23
23
  export type NewComment = Partial<Omit<Comment, 'id' | 'status' | 'replies' | 'images' | 'createdAt' | 'updatedAt'>> & Pick<Comment, 'route' | 'selector' | 'rx' | 'ry' | 'text'>;
24
24
 
25
- export interface Category { id: string; label: string; color: string }
25
+ export interface Category { id: string; label: string; color: string; hint: string; icon: string }
26
+ /** A type's icon as an inline <svg>, stroked in its colour */
27
+ export function categoryIcon(k: Category, size?: number): string;
26
28
  export const CATEGORIES: Category[];
27
29
  export function categoryOf(id?: string | null): Category;
28
30
  /** open, done (by a person) or claude (by an agent, waiting for a look) */
package/thread.d.ts CHANGED
@@ -7,15 +7,18 @@ export function mentionsIn(text: string, people: Mentionable[]): string[];
7
7
  export const AGENTS: Record<string, string>;
8
8
  /** The name to show for an agent's message: its `agent`, or Claude when there is none */
9
9
  export function agentName(id?: string | null): string;
10
+ /** The agent mark: twelve rays drawn with a stroke, in viewBox AI_BOX. */
11
+ export const AI_BOX: string;
12
+ export const AI_RAYS: string;
10
13
  /** Whose agent a thread is for: the email in 'agent:<email>', else null */
11
14
  export function agentOwner(assignee?: string | null): string | null;
12
15
  /** Given to an agent: the shared queue ('claude') or a person's own ('agent:<email>') */
13
16
  export function toAgent(assignee?: string | null): boolean;
14
17
  /** A valid assignee, lower-cased — 'claude', an email or 'agent:<email>' — else null */
15
18
  export function cleanAssignee(v: unknown): string | null;
16
- /** Where a thread stands: new, approved for an agent, or waiting for a person's review */
19
+ /** Where a thread stands: new, approved for an agent, in progress (a person on it), waiting for a person's review, or waiting on someone */
17
20
  export const STAGES: string[];
18
- export function stageOf(c: { stage?: string | null; assignee?: string | null } | null | undefined): "new" | "approved" | "review";
21
+ export function stageOf(c: { stage?: string | null; assignee?: string | null } | null | undefined): "new" | "approved" | "progress" | "review" | "waiting";
19
22
  /** A thread for the agent running as `me` (null: a CI key, the shared queue only; undefined: a local store, all) */
20
23
  export function forAgentOf(c: { assignee?: string | null; stage?: string | null; by?: string | null; approvedBy?: string | null }, me?: string | null): boolean;
21
24
  /** "Claude · Ann": the agent, and the person it ran as */
@@ -29,7 +32,24 @@ export function workingOn(c: { working?: Working | null; status?: string } | nul
29
32
  export function isGuest(email?: string | null): boolean;
30
33
  /** A guest's thread the studio has not approved yet: no agent takes it */
31
34
  export function held(c: { by?: string | null; approvedBy?: string | null }): boolean;
35
+ /** The agents a message can @mention: the shared queue, and each person's own */
36
+ export function agentHandles(people?: { email: string; name?: string | null; agent_name?: string | null }[]): { assignee: string; handle: string; owner: string | null }[];
37
+ /** The agent a text hands its thread to: the last one it @mentions, else null */
38
+ export function agentMentioned(text: string, people?: { email: string; name?: string | null; agent_name?: string | null }[]): string | null;
39
+ export type AgentStep = "held" | "queued" | "asks" | "working" | "stuck" | "review" | "done";
40
+ /** Where a thread is on an agent's way; null when no agent is in it */
41
+ export function agentStep(c: Record<string, any> | null | undefined, now?: number): AgentStep | null;
42
+ /** How far along each step is: rays of the agent mark lit, of 12 */
43
+ export const STEP_RAYS: Record<AgentStep, number>;
44
+ /** The agent mark's rays one by one, clockwise from the top (viewBox AI_BOX) */
45
+ export const AI_RAYS_CW: string[];
32
46
  /** How each kind of install is brought up to date: plugin, npx, project, desktop, source */
33
47
  export const UPDATE_HOW: Record<string, string>;
34
48
  /** Is version a newer than b (x.y.z) */
35
49
  export function newer(a: string, b: string): boolean;
50
+ /** The documents a message may carry, by extension: their MIME types */
51
+ export const DOCS: { pdf: string; doc: string; docx: string };
52
+ /** A file's own name made safe for a filed one: lower-case word characters and dashes */
53
+ export function docSlug(name: string): string;
54
+ /** What to call a document — "brief.pdf" — by its path or data: URL; null when it is not one */
55
+ export function docOf(path: string): string | null;