notemend 0.1.12 → 0.1.14
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/.claude-plugin/plugin.json +1 -1
- package/README.md +29 -18
- package/bin/notemend.mjs +10 -10
- package/package.json +1 -1
- package/src/client/anchor.js +1 -1
- package/src/client/config.js +1 -1
- package/src/client/field-menu.js +1 -1
- package/src/client/markup.js +2 -2
- package/src/client/notemend.css +1 -1
- package/src/client/run.js +78 -77
- package/src/hosting.mjs +1 -1
- package/src/server/middleware.mjs +1 -1
- package/src/store/cloud.mjs +3 -3
- package/src/store/comments.mjs +3 -3
- package/src/store/thread.mjs +1 -1
- package/thread.d.ts +5 -2
package/src/hosting.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tmpdir as
|
|
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 H,existsSync as _,statSync as Y,readdirSync as q}from"node:fs";import{mask as tt}from"../store/mask.mjs";import{join as I,isAbsolute as et}from"node:path";import{isIP as b}from"node:net";import{pathToFileURL as rt}from"node:url";import{openStore as nt,retry as ot,CABINET as st,session as G}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 z,SHELLS as J,BROWSERS as U}from"../presets.mjs";const W={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,l)=>r*100+(Number.isNaN(l)?9999:l),0),ft=(t,r)=>{try{const m=H(et(r)?r:I(t,r),"utf8").match(/title="([^"]+)"|\btitle:\s*["'`]([^"'`]+)["'`]/);return(m?.[1]??m?.[2])?.split("\u2014").pop()?.trim()||null}catch{return null}};function Bt(t){const r=["app","src/app"].map(c=>I(t,c)).find(_),l=[],m=(c,g)=>{for(const a of q(c,{withFileTypes:!0})){const u=a.name;if(a.isDirectory()){if(/^[_@]|^\(\./.test(u))continue;m(I(c,u),/^\(.+\)$/.test(u)?g:[...g,u])}else/^page\.(jsx?|tsx?|mdx?)$/.test(u)&&l.push({origin:"project",type:"page",pattern:"/"+g.join("/"),entrypoint:I(c,u)})}};return r&&m(r,[]),l}const dt=t=>t[0].toUpperCase()+t.slice(1).replace(/[-_]+/g," ");function gt({root:t,options:r,routes:l}){const m=r.pages??{},c=(e,f,v)=>({route:e,name:f,label:f.replace(/^[\d.]+[A-Z]?\.\s*/,""),group:v}),g=l.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)),u=[...g,...Object.keys(m).filter(e=>!a.has(e)).map(e=>({route:e}))],j={};for(const{route:e}of u){const f=e.split("/")[1];f&&(j[f]=(j[f]||0)+1)}const $=e=>{const f=e.split("/")[1];return f&&j[f]>1?dt(f):"Pages"},L=r.groups?()=>r.groups[r.groups.length-1]:$,P=u.map(({route:e,entrypoint:f})=>{const[v,E]=m[e]??[];return c(e,v??(f&&ft(t,f))??e,E??L(e))}),o=r.groups??[...new Set([...Object.values(m).map(([,e])=>e).filter(Boolean),"Pages",...P.map(e=>e.group).sort()])],d=P.sort((e,f)=>o.indexOf(e.group)-o.indexOf(f.group)||V(e.name)-V(f.name)||e.route.localeCompare(f.route)),n=(r.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??z[e.id]??z.desktop})),s=(r.devices??mt).filter(e=>e.w>0&&e.h>0&&J.includes(e.shell)&&U.includes(e.browser)?!0:(console.warn(`[notemend] device "${e.id}" skipped: it needs w and h, shell (${J.join(", ")}) and browser (${U.join(", ")})${e.frame?"; `frame` pictures were replaced by shell + browser in 0.3":""}`),!1));return{pages:d,groups:o.filter(e=>d.some(f=>f.group===e)),breakpoints:n,devices:s,categories:ct,sanity:!!r.sanity,shortcuts:r.shortcuts!==!1,ignore:r.ignore??[],grid:{container:"container",grid:"grid",columns:12,...r.grid},zIndex:r.zIndex??2000000020}}const pt=t=>{const r=I(t,"notemend.config.mjs");let l=0,m={};return async()=>{if(!_(r))return{};const c=Y(r).mtimeMs;if(c===l)return m;l=c;try{const{default:g,...a}=await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ `${rt(r).href}?t=${c}`);m={...a,...g}}catch(g){console.warn(`[notemend] notemend.config.mjs: ${g.message}`)}return m}},ht=t=>{const r=String(t.headers.host||"").toLowerCase(),l=r.startsWith("[")?r.slice(1,r.indexOf("]")):r.replace(/:\d+$/,"");return l.includes(":")?b(l)===6:!l||!l.includes(".")||b(l)===4||/\.(localhost|local|test|internal|lan|home\.arpa)$/.test(l)},S=(t,r)=>String(t??"").replace(/[\u0000-\u001f\u007f]+/g," ").trim().slice(0,r),yt=t=>({route:S(t.route,500),text:String(t.text??"").slice(0,1e4),selector:S(t.selector,2e3),rx:Number.isFinite(t.rx)?t.rx:0,ry:Number.isFinite(t.ry)?t.ry:0,label:S(t.label,200),ctx:S(t.ctx,120),breakpoint:S(t.breakpoint,40),browser:S(t.browser,80),device:S(t.device,80),tag:S(t.tag,40),classes:Array.isArray(t.classes)?t.classes.slice(0,20).map(r=>S(r,80)):[],nth:Number.isInteger(t.nth)?t.nth:null,category:S(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(r=>({at:S(r?.at,30),kind:["console","error","rejection","network"].includes(r?.kind)?r.kind:"console",text:tt(S(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)}}:{}}),wt=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=ut(t.category).id),"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=D(t.assignee)),"stage"in t&&(r.stage=M.includes(t.stage)?t.stage:null),r},K=async(t,r,l,m,c)=>{if(typeof m!="string")return;const g=r.comments.find(a=>a.id===Number(l))?.images?.filter(a=>it(a)===c)??[];if(await t.attach(r,l,m,c))for(const a of g)await t.detach(r,l,a)},Z=t=>{const r=t.headers.origin;if(!r)return!1;try{return new URL(r).host!==t.headers.host}catch{return!0}};function xt({root:t,options:r,routes:l,open:m=()=>nt(t),crossOrigin:c=!1}){const g=pt(t),a=(o,d=200)=>({status:d,type:"application/json",body:JSON.stringify(o)}),u=(o,d)=>({status:o,type:"text/plain",body:d}),j=async o=>{const d=await o.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})}},$=async(o,d)=>{const n=async s=>{const e=await d(s);if(e.status>=400)throw Object.assign(new Error("not written"),{out:e});return e};try{if(o.cloud)return await ot(o,n);const s=o.load(),e=await n(s);return o.save(s),e}catch(s){if(s.out)return s.out;throw s}},L=async(o,d)=>{if(o.method!=="GET"&&!c&&Z(o))return u(403,"Cross-origin write refused");const n=await m();if(o.method==="GET"){const i=d.searchParams.get("route"),y=n.version?String(await n.version()):null;if(y&&d.searchParams.get("since")===y)return{status:204,type:"text/plain",body:""};const w=await n.load();return a({version:y,comments:i?w.comments.filter(A=>A.route===i):w.comments,listening:w.listening??null,turbo:w.turbo??null})}let s=null,e=null;const f=n.cloud&&o.method!=="DELETE"?n.people().then(i=>{s=i,e=i.me},i=>{throw i}).catch(i=>i):Promise.resolve(),v=async()=>{const i=await f;if(i instanceof Error)throw i},E=i=>{if(e&&i){i.by=e.email,i.byName=e.name;const y=at(i.text,s.team.filter(w=>w.email!==e.email));y.length&&(i.mentions=y)}return i};if(o.method==="POST"){const{image:i,images:y,before:w,...A}=await j(o),B=yt(A);return B.text.trim()?/^\/(?![\/\\])/.test(B.route)?$(n,async C=>{await v();const N=E(n.add(C,B));for(const T of[].concat(y??i??[]))await n.attach(C,N.id,T);return await K(n,C,N.id,w,"before"),a(N,201)}):a({error:"route must be a path"},400):a({error:"empty comment"},400)}if(o.method==="PATCH"){const i=await j(o);if(i.turbo==="on"||i.turbo==="off")return $(n,async h=>(h.turbo={paused:i.turbo==="off",at:new Date().toISOString()},a({turbo:h.turbo})));const{id:y,reply:w,image:A,images:B,removeImage:C,edit:N,unsay:T,after:Q,...X}=i,p=Number(y);if(!Number.isInteger(p))return a({error:"bad id"},400);const k=wt(X);return $(n,async h=>{if(await v(),N){const x=h.comments.find(F=>F.id===Number(p)),O=N.at?x?.replies?.find(F=>F.at===N.at):x;if(e&&O?.by&&O.by!==e.email||!(N.text?.trim?.()&&n.edit(h,p,N.at??null,N.text.trim().slice(0,1e4))))return a({error:`no message of yours to edit in #${p}`},404)}if(typeof T=="string"){const x=h.comments.find(O=>O.id===p)?.replies?.find(O=>O.at===T);return!x||e&&x.by&&x.by!==e.email||!n.unsay(h,p,T)?a({error:`no reply of yours to delete in #${p}`},404):a(h.comments.find(O=>O.id===p))}w?.trim?.()&&E(n.reply(h,p,"you",w.trim().slice(0,1e4))?.replies.at(-1));for(const x of[].concat(B??A??[]))await n.attach(h,p,x);for(const x of[].concat(C||[]))await n.detach(h,p,x);await K(n,h,p,Q,"after"),e&&k.status==="done"&&Object.assign(k,{confirmedBy:e.email,confirmedAt:new Date().toISOString()}),e&&k.status==="open"&&Object.assign(k,{confirmedBy:null,confirmedAt:null});const R=Object.keys(k).length||!w?n.patch(h,p,k):h.comments.find(x=>x.id===Number(p));return R?a(R):a({error:`no comment #${p}`},404)})}if(o.method==="DELETE"){const i=Number(d.searchParams.get("id"));return $(n,async y=>await n.remove(y,i)?a({ok:!0,id:i}):a({error:`no comment #${i}`},404))}return u(405,"Method not allowed")},P=(o,d)=>{const n=d.replace(/^.*[/\\]/,""),s=n.split(".").pop()?.toLowerCase()??"";if(!/^[\w.-]+$/.test(n)||!W[s])return u(400,"Bad name");const e=I(o,n);return _(e)?{status:200,type:W[s],body:H(e)}:u(404,"Not found")};return async o=>{const d=new URL(o.url,"http://devbar"),n=d.pathname.slice(10);if(!c&&!ht(o))return u(403,"Notemend answers local addresses only");try{if(n==="config"){const s=gt({root:t,options:{...await g(),...r},routes:l()}),e=await m();return e.cloud&&Object.assign(s,await e.people().catch(()=>({}))),(e.cloud||await G().catch(()=>null))&&(s.voice=!0),a(s)}if(n==="transcribe"&&o.method==="POST"){if(!c&&Z(o))return u(403,"Cross-origin write refused");const s=await m(),e=s.cloud?await s.token():(await G().catch(()=>null))?.access_token;if(!e)return u(401,"Voice replies need Notemend \u2014 run `npx notemend login`.");const{audio:f}=await j(o),v=/^data:(audio\/(?:webm|mp4))(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(f||""));if(!v)return u(400,"Not a recording");const E=await fetch(`${st}/api/transcribe`,{method:"POST",body:Buffer.from(v[2],"base64"),headers:{authorization:`Bearer ${e}`,"content-type":v[1]}});return{status:E.status,type:"application/json",body:await E.text()}}if(n==="comments")return await L(o,d);if(n==="image"){const s=await m(),e=(d.searchParams.get("name")||"").replace(/^.*[/\\]/,"");return s.cloud&&/^[\w.-]+$/.test(e)&&await s.fetchImage(e).catch(()=>null),P(s.imageDir,e)}return u(404,"Not found")}catch(s){return s.status===400||s.status===413?u(s.status,s.message):(console.error("[notemend]",s),u(500,"Something went wrong \u2014 the dev server log says what."))}}}function Ct(t){const r=xt(t),l=m=>new Promise((c,g)=>{const a=[];m.on("data",u=>a.push(u)),m.on("end",()=>c(Buffer.concat(a))),m.on("error",g)});return async function(c,g,a){if(!c.url||!c.url.startsWith("/__devbar/"))return a();const u=await r({method:c.method,url:c.url,headers:c.headers,body:()=>l(c)});g.statusCode=u.status,g.setHeader("content-type",u.type),g.setHeader("cache-control","no-store"),g.end(u.body)}}export{gt as buildConfig,xt as notemendHandler,Ct as notemendMiddleware,Bt as scanApp,ft as titleOf,dt as titled};
|
package/src/store/cloud.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{readFileSync as
|
|
2
|
-
`),
|
|
3
|
-
`,{mode:384})},
|
|
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};
|
package/src/store/comments.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{readFileSync as E,writeFileSync as
|
|
2
|
-
`),F(`${
|
|
3
|
-
`),
|
|
1
|
+
import{readFileSync as E,writeFileSync as I,existsSync as O,mkdirSync as $,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 Y,categoryOf as Z}from"./categories.mjs";import{stateOf as te,STATE_LABEL as ne}from"./status.mjs";const b=r=>{const n=String(r??"").split(/[/\\]/).pop();return/^[\w-][\w.-]*\.(png|jpe?g|webp|gif|webm|m4a)$/i.test(n)?n:""},C=r=>{const n=/^data:(image|video|audio)\/(png|jpeg|webp|gif|webm|mp4)(?:;[\w=.-]+)*;base64,(.+)$/s.exec(String(r||""));if(!n)return null;const[,e,t,i]=n;return(e==="image"?!/^(png|jpeg|webp|gif)$/.test(t):e==="video"?t!=="webm":!/^(webm|mp4)$/.test(t))?null:{base64:i,voice:e==="audio",ext:t==="jpeg"?"jpg":t==="mp4"?"m4a":t,type:`${e}/${t}`}},M=(r,n,e,t)=>`${e.voice?"voice-":R.includes(t)?`${t}-`:""}${r}-${n}.${e.ext}`,y=r=>Math.max(r.nextId||0,r.comments.reduce((n,e)=>Math.max(n,e.id),0)+1);function G(r,{route:n,selector:e,rx:t,ry:i,text:c,label:d,viewport:v,breakpoint:N,browser:D,device:A,tag:j,classes:s,nth:p,category:g,suggest:o,assignee:m,ctx:a,logs:u,host:S,priority:x,shared:f,stage:h}){const w={id:y(r),route:n,selector:e,rx:t,ry:i,text:c,tag:j||"",classes:s||[],nth:Number.isInteger(p)?p:null,label:d||"",ctx:a||"",viewport:v||null,breakpoint:N||"desktop",browser:D||"",device:A||"",category:L(g).id,status:"open",note:"",replies:[],doneBy:null,images:[],...o?{suggest:o}:{},...m?{assignee:m}:{},...x?{priority:x}:{},...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 _(r,n,e,t,i,c){const d=r.comments.find(v=>v.id===Number(n));return d?((d.replies||=[]).push({author:e,text:t,at:new Date().toISOString(),...i&&i!=="claude"?{agent:i}:{},...c?{by:c}:{}}),d.updatedAt=new Date().toISOString(),d):null}function q(r,n,e,t){const i=r.comments.find(d=>d.id===Number(n)),c=e?i?.replies?.find(d=>d.at===e&&d.author==="you"):i;return c?(c.text=t,i.updatedAt=new Date().toISOString(),i):null}function z(r,n,e){const t=r.comments.find(c=>c.id===Number(n)),i=t?.replies?.find(c=>c.at===e&&c.author==="you");return i?(i.text="",i.deleted=!0,delete i.mentions,t.updatedAt=new Date().toISOString(),t):null}function H(r,n,e){const t=r.comments.find(i=>i.id===Number(n));return t?(Object.assign(t,e,{updatedAt:new Date().toISOString()}),t):null}function V(r){const n=l(r,"feedback","comments.json"),e=l(r,"feedback","images"),t=l(r,"feedback","archive"),i=l(t,"images"),c=s=>`feedback/images/${s}`;return{root:r,file:n,imageDir:e,archiveDir:t,archiveImageDir:i,load:()=>O(n)?JSON.parse(E(n,"utf8")):{comments:[]},save:s=>{$(T(n),{recursive:!0}),I(`${n}.tmp`,JSON.stringify(s,null,2)+`
|
|
2
|
+
`),F(`${n}.tmp`,n)},attach:(s,p,g,o)=>{const m=s.comments.find(x=>x.id===Number(p)),a=C(g);if(!m||!a)return null;$(e,{recursive:!0});let u=Date.now();for(;O(l(e,M(m.id,u,a,o)));)u++;const S=M(m.id,u,a,o);return I(l(e,S),Buffer.from(a.base64,"base64")),(m.images||=[]).push(c(S)),m.updatedAt=new Date().toISOString(),c(S)},detach:(s,p,g)=>{const o=s.comments.find(u=>u.id===Number(p)),m=b(g),a=m&&o?.images?.find(u=>b(u)===m);return a?(J(l(e,m),{force:!0}),o.images=o.images.filter(u=>u!==a),o.updatedAt=new Date().toISOString(),!0):!1},remove:(s,p)=>{const g=s.comments.find(o=>o.id===Number(p));if(!g)return!1;for(const o of g.images||[])b(o)&&J(l(e,b(o)),{force:!0});return s.comments=s.comments.filter(o=>o.id!==Number(p)),!0},add:G,patch:H,reply:_,edit:q,unsay:z,nextId:y,prune:(s,{dry:p=!1,date:g=new Date().toISOString().slice(0,10)}={})=>{const o=s.comments.filter(f=>f.status==="done"),m=s.comments.filter(f=>f.status!=="done"),a=l(t,`comments-${g}.json`);if(p||!o.length)return{moving:o,keeping:m,archiveFile:a,images:o.flatMap(f=>f.images||[])};$(i,{recursive:!0});const u=[];for(const f of o)f.images=(f.images||[]).map(h=>{const w=b(h);if(!w)return h;const k=l(e,w),B=l(i,w);return O(k)&&F(k,B),u.push(w),`feedback/archive/images/${w}`});const S=O(a)?JSON.parse(E(a,"utf8")).comments||[]:[],x=new Set(S.map(f=>f.id));return I(a,JSON.stringify({comments:[...S,...o.filter(f=>!x.has(f.id))]},null,2)+`
|
|
3
|
+
`),s.nextId=y(s),s.comments=m,{moving:o,keeping:m,archiveFile:a,images:u}}}}export{Y as CATEGORIES,ne as STATE_LABEL,G as add,Z as categoryOf,V as createStore,q as edit,M as mediaName,C as mediaOf,y as nextId,H as patch,_ as reply,b as shotName,te as stateOf,z as unsay};
|
package/src/store/thread.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const A=["before","after"],i=e=>/(?:^|\/)(before|after)-[^/]*$/.exec(String(e))?.[1]??null,h=e=>{const t={};for(const n of e?.images||[]){const o=i(n);o&&(t[o]=n)}return t},L=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.filter(n=>!n.deleted)},M=e=>e.nickname||e.name||e.email,y=(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"),O="3.6 3.6 10.8 10.8",b="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",a=e=>typeof e=="string"&&e.startsWith("agent:")?e.slice(6):null,d=e=>e==="claude"||a(e)!=null,g=/^[^\s@]+@[^\s@]+$/,C=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},c=["new","approved","progress","review","waiting"],m=e=>c.includes(e?.stage)?e.stage:d(e?.assignee)?"approved":"new",S=(e,t)=>{const n=a(e.assignee);return m(e)==="approved"&&(!e.assignee||e.assignee==="claude"||n!=null&&(t===void 0||n===t))&&!w(e)},k=(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,I={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,O as AI_BOX,b as AI_RAYS,A as FRAMES,c as STAGES,I as UPDATE_HOW,f as WORKING_TTL,k as agentLabel,u as agentName,a as agentOwner,C as cleanAssignee,S as forAgentOf,i as frameOf,h as framesOf,M as handleOf,w as held,x as isGuest,y as mentionsIn,D as newer,m as stageOf,L as threadOf,d as toAgent,N as workingOn};
|
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,
|
|
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 */
|