notemend 0.1.16 → 0.1.18
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/bin/notemend.mjs +8 -8
- package/package.json +1 -1
- package/src/client/markup.js +1 -1
- package/src/client/notemend.css +1 -1
- package/src/client/panel.js +25 -21
- package/src/client/review.js +3 -4
- package/src/client/run.js +52 -51
- package/src/server/middleware.mjs +1 -1
- package/src/store/thread.mjs +1 -1
- package/thread.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
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 I,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 D}from"../store/cloud.mjs";import{mentionsIn as at,cleanAssignee as R,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:I(t,n),"utf8").match(/title="([^"]+)"|\btitle:\s*["'`]([^"'`]+)["'`]/);return(l?.[1]??l?.[2])?.split("\u2014").pop()?.trim()||null}catch{return null}};function At(t){const n=["app","src/app"].map(u=>I(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(I(u,c),/^\(.+\)$/.test(c)?p:[...p,c])}else/^page\.(jsx?|tsx?|mdx?)$/.test(c)&&m.push({origin:"project",type:"page",pattern:"/"+p.join("/"),entrypoint:I(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,P=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",...P.map(e=>e.group).sort()])],d=P.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=I(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,...R(t.assignee)?{assignee:R(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),t.status==="open"&&(n.reopenedAt=new Date().toISOString()),"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=R(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)},b=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&&b(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(T=>T.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,...T}=await j(r),A=wt(T);return A.text.trim()?/^\/(?![\/\\])/.test(A.route)?k(s,async B=>{await w();const O=N(s.add(B,A));for(const C of[].concat(y??i??[]))await s.attach(B,O.id,C);return await Q(s,B,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:T,images:A,removeImage:B,edit:O,unsay:C,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 C=="string"){const S=h.comments.find($=>$.id===g)?.replies?.find($=>$.at===C);return!S||e&&S.by&&S.by!==e.email||!s.unsay(h,g,C)?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(A??T??[]))await s.attach(h,g,S);for(const S of[].concat(B||[]))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")},P=(r,d)=>{const s=d.replace(/^.*[/\\]/,""),o=s.split(".").pop()?.toLowerCase()??"";if(!/^[\w.-]+$/.test(s)||!K[o])return c(400,"Bad name");const e=I(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 D().catch(()=>null))&&(o.voice=!0),a(o)}if(s==="transcribe"&&r.method==="POST"){if(!u&&b(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await D().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&&b(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await D().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),P(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 Bt(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,Bt as notemendMiddleware,At as scanApp,ft as titleOf,dt as titled};
|
|
1
|
+
import{readFileSync as z,existsSync as D,statSync as q,readdirSync as tt}from"node:fs";import{mask as et}from"../store/mask.mjs";import{join as I,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 F}from"../store/cloud.mjs";import{mentionsIn as at,cleanAssignee as R,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:I(t,n),"utf8").match(/title="([^"]+)"|\btitle:\s*["'`]([^"'`]+)["'`]/);return(l?.[1]??l?.[2])?.split("\u2014").pop()?.trim()||null}catch{return null}};function At(t){const n=["app","src/app"].map(u=>I(t,u)).find(D),m=[],l=(u,p)=>{for(const a of tt(u,{withFileTypes:!0})){const c=a.name;if(a.isDirectory()){if(/^[_@]|^\(\./.test(c))continue;l(I(u,c),/^\(.+\)$/.test(c)?p:[...p,c])}else/^page\.(jsx?|tsx?|mdx?)$/.test(c)&&m.push({origin:"project",type:"page",pattern:"/"+p.join("/"),entrypoint:I(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,P=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",...P.map(e=>e.group).sort()])],d=P.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=I(t,"notemend.config.mjs");let m=0,l={};return async()=>{if(!D(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,...R(t.assignee)?{assignee:R(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),t.status==="open"&&(n.reopenedAt=new Date().toISOString()),"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=R(t.assignee)),"stage"in t&&(n.stage=M.includes(t.stage)?t.stage:null),t.stage==="accepted"&&(n.acceptedAt=new Date().toISOString()),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)},H=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&&H(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(T=>T.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,...T}=await j(r),A=wt(T);return A.text.trim()?/^\/(?![\/\\])/.test(A.route)?k(s,async B=>{await w();const O=N(s.add(B,A));for(const C of[].concat(y??i??[]))await s.attach(B,O.id,C);return await Q(s,B,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:T,images:A,removeImage:B,edit:O,unsay:C,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 C=="string"){const S=h.comments.find($=>$.id===g)?.replies?.find($=>$.at===C);return!S||e&&S.by&&S.by!==e.email||!s.unsay(h,g,C)?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(A??T??[]))await s.attach(h,g,S);for(const S of[].concat(B||[]))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 b=Object.keys(E).length||!x?s.patch(h,g,E):h.comments.find(S=>S.id===Number(g));return b?a(b):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")},P=(r,d)=>{const s=d.replace(/^.*[/\\]/,""),o=s.split(".").pop()?.toLowerCase()??"";if(!/^[\w.-]+$/.test(s)||!K[o])return c(400,"Bad name");const e=I(r,s);return D(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 F().catch(()=>null))&&(o.voice=!0),a(o)}if(s==="transcribe"&&r.method==="POST"){if(!u&&H(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await F().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&&H(r))return c(403,"Cross-origin write refused");const o=await l(),e=o.cloud?await o.token():(await F().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),P(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 Bt(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,Bt as notemendMiddleware,At as scanApp,ft as titleOf,dt as titled};
|
package/src/store/thread.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const O=["before","after"],d=e=>/(?:^|\/)(before|after)-[^/]*$/.exec(String(e))?.[1]??null,y=e=>{const t={};for(const n of e?.images||[]){const o=d(n);o&&(t[o]=n)}return t},u={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(u).find(s=>u[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(d(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"),D="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",
|
|
1
|
+
const O=["before","after"],d=e=>/(?:^|\/)(before|after)-[^/]*$/.exec(String(e))?.[1]??null,y=e=>{const t={};for(const n of e?.images||[]){const o=d(n);o&&(t[o]=n)}return t},u={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(u).find(s=>u[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(d(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"),D="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",l=e=>typeof e=="string"&&e.startsWith("agent:")?e.slice(6):null,p=e=>e==="claude"||l(e)!=null,A=/^[^\s@]+@[^\s@]+$/,_=e=>{if(e==="claude")return e;if(typeof e!="string"||e.length>210)return null;const t=e.toLowerCase();return A.test(l(t)??t)?t:null},L=["new","approved","progress","review","waiting","accepted"],c=e=>L.includes(e?.stage)?e.stage:p(e?.assignee)?"approved":"new",E=(e,t)=>{const n=l(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":p(e.assignee)?"done":null;if(e.stage==="accepted")return p(e.assignee)?"done":null;if(g(e))return"held";if(!p(e.assignee))return null;const n=m(e),o=n[n.length-1];return n.length>1&&o.author==="claude"&&!(e.reopenedAt&&Date.parse(e.reopenedAt)>=Date.parse(o.at))?"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,D as AI_BOX,w as AI_RAYS,H as AI_RAYS_CW,u 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,l as agentOwner,W as agentStep,_ as cleanAssignee,N as docOf,b as docSlug,E as forAgentOf,d 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,p as toAgent,S as workingOn};
|
package/thread.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export function toAgent(assignee?: string | null): boolean;
|
|
|
18
18
|
export function cleanAssignee(v: unknown): string | null;
|
|
19
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 */
|
|
20
20
|
export const STAGES: string[];
|
|
21
|
-
export function stageOf(c: { stage?: string | null; assignee?: string | null } | null | undefined): "new" | "approved" | "progress" | "review" | "waiting";
|
|
21
|
+
export function stageOf(c: { stage?: string | null; assignee?: string | null } | null | undefined): "new" | "approved" | "progress" | "review" | "waiting" | "accepted";
|
|
22
22
|
/** A thread for the agent running as `me` (null: a CI key, the shared queue only; undefined: a local store, all) */
|
|
23
23
|
export function forAgentOf(c: { assignee?: string | null; stage?: string | null; by?: string | null; approvedBy?: string | null }, me?: string | null): boolean;
|
|
24
24
|
/** "Claude · Ann": the agent, and the person it ran as */
|