lensmcp 1.26.3 → 1.26.4
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/bundled/dashboard.js +1 -1
- package/bundled/main.js +543 -542
- package/bundled/migrations.js +146 -145
- package/bundled/project.js +1 -1
- package/lib/bridge-origins.d.ts +1 -1
- package/lib/bridge-origins.js +1 -1
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/lensmcp/.codex-plugin/plugin.json +1 -1
package/bundled/dashboard.js
CHANGED
|
@@ -20269,7 +20269,7 @@ LensMCP changes nothing and sends nothing to the app's model provider. The devel
|
|
|
20269
20269
|
`,t)].filter(r=>r>=0);return e.slice(s,n.length?Math.min(...n)+1:e.length).trim()},"sentenceOf"),rLs=l(e=>`\xAB${e.length>160?`${e.slice(0,160)}\u2026`:e}\xBB`,"quote");function Nje(e){if(/\bonce (?:per|a|each) request/i.test(e))return 1;let t=/(?:\bat most|\bdown to|(?<!\bup )\bto|\bunder|≤|<=)\s*(?:about\s*)?(?:×|x)?\s*(\d+)(?!\d|[.,]\d)(?:\s*(?:[–-]|or)\s*(?:×|x)?\s*(\d+)(?!\d|[.,]\d))?(?!\s*(?:ms|s|%|min)\b)/i.exec(e);if(t)return Math.max(Number(t[1]),Number(t[2]??t[1]));let s=/×\s*(\d+)\s*(?:or\s*×?\s*\d+\s*)?(?:\([^)]*\)\s*)?per request/i.exec(e);if(s)return Number(s[1]);if(/\bonce\b|\bto one\b|\bone per\b/i.test(e))return 1;if(/\ba few\b(?!\s+dozen)/i.test(e))return 3}h(Nje,"Lkt"),l(Nje,"countBound");function UFt(e,t,s={}){let n=[],r=[],a=l((g,w)=>{n.length>=4||n.some(y=>y.on.kind===g.on.kind&&y.on.id===g.on.id&&y.metric===g.metric&&(y.finding??"")===(g.finding??""))||(n.push(g),r.includes(w)||r.push(w))},"add"),i=["sql","route","page","error","queue","external","db","dbtable"].includes(e.target.kind)?{kind:e.target.kind,id:e.target.id}:void 0,o=(e.refs??[]).filter(g=>g.kind==="sql"&&g.why!=="target"),d=e.target.kind==="page"?s.pageNow?.(e.target.id)??e.target.id:e.target.id,c=l(g=>{for(let b of g.matchAll(/(per[- ]request|in one request|within one request|per request|once per request|per call|times one request|one request runs)/gi)){let v=eR(g,b.index??0),$=v.slice(Math.max(0,v.toLowerCase().indexOf(b[1].toLowerCase()))),k=Nje($)??Nje(v);if(k===void 0||k>20)continue;let x=o.filter(A=>v.includes(A.label));e.target.kind==="sql"&&a({on:{kind:"sql",id:e.target.id},metric:"perRequestMax",op:"<=",value:k},v);let S=/\b(?:no|each|every|any) (?:statement|shape|query)/i.test(v);for(let A of(x.length?x:S&&e.target.kind!=="sql"?o:[]).slice(0,3))a({on:{kind:"sql",id:A.id},metric:"perRequestMax",op:"<=",value:k},v)}let w=/statements per run[^.]*?(?:to|order of|under|below)[^\d]*(\d+)(?:\s*[–-]\s*(\d+))?/i.exec(g);w&&e.target.kind==="route"&&a({on:{kind:"route",id:e.target.id},metric:"sqlPerRun",op:"<=",value:Number(w[2]??w[1])},eR(g,w.index));let y=/(?:about\s*)?(\d+)\s*SQL(?: statements)? (?:per|a) visit|SQL (?:statements )?per visit[^.]*?(?:to|under|below)\s*(?:about\s*)?(\d+)/i.exec(g);y&&e.target.kind==="page"&&a({on:{kind:"page",id:d},metric:"sqlPerVisit",op:"<=",value:Number(y[1]??y[2])},eR(g,y.index));for(let b of g.matchAll(/(?:\bp95\b|\bp50\b|\bmax\b|finish(?:es)?|answers?|takes?|ready|run(?:s)? under)[^.\n]{0,80}?(?:under|below|less than|<)\s*(?:the\s*)?(\d+(?:[.,]\d+)?)\s*(ms|s)\b/gi)){let v=nLs(b[1],b[2]),$=eR(g,b.index??0);if(e.target.kind==="page"){let k=g.slice(Math.max(0,(b.index??0)-24),b.index??0)+b[0];/\b(?:ready|loads?|loaded|visits?|page(?:'s)?)\b/i.test(k)&&!/\b(?:templates?|requests?|reads?|calls?|routes?|endpoints?|statements?|quer(?:y|ies)|both)\b/i.test(b[0])&&a({on:{kind:"page",id:d},metric:"loadMs",op:"<",value:v},$)}else(e.target.kind==="route"||e.target.kind==="sql"||e.target.kind==="external")&&a({on:{kind:e.target.kind,id:e.target.id},metric:"p95Ms",op:"<",value:v},$)}},"read");c(e.finding.verify??"");let u=!1;!n.length&&e.finding.title&&(c(e.finding.title),u=n.length>0);let p=[e.finding.verify,e.finding.title].join(`
|
|
20270
20270
|
`);e.target.kind==="error"&&i&&a({on:i,metric:"occurrences",op:"==",value:0},"the error itself \u2014 not seen again");let m=/\b(?:no (?:new )?5\d\d|5\d\d (?:count )?(?:should )?(?:fall|stop|drop)|no new 503s)/i.exec(p);if(m&&e.target.kind==="route"&&a({on:{kind:"route",id:e.target.id},metric:"errors",op:"==",value:0},eR(p,m.index)),(e.target.kind==="dbtable"||e.target.kind==="db")&&i){let g=`${e.finding.title} ${e.finding.verify}`,w=/duplicat/i.test(g)?"duplicate-index":/foreign key/i.test(g)&&/index/i.test(g)?"unindexed-foreign-key":/unused/i.test(g)&&/index/i.test(g)?"unused-index":/seq(?:uential)?[ _]scan/i.test(g)?"seq-scan":/dead rows|vacuum/i.test(g)?"dead-rows":/invalid/i.test(g)&&/index/i.test(g)?"invalid-index":void 0;w&&a({on:i,metric:"findings",finding:w,op:"==",value:0},`the lens's ${w} finding${e.target.kind==="dbtable"?" on the table":""} gone`)}let f=d!==e.target.id&&n.some(g=>g.on.kind==="page")?` \u2014 on ${d}, the name the lens knows the page by now (the review saw ${e.target.id})`:"";return n.length?{measures:n,from:`Read from its ${u?"title":"verify line"}: ${r.map(rLs).join("; ")}${f}`}:t?{review:!0,from:"Its verify line names no number the lens records \u2014 its review run anew"}:void 0}h(UFt,"jkt"),l(UFt,"proposeCheck"),Wr(),km();import{readFileSync as aLs}from"node:fs";import{basename as iLs,join as zFt}from"node:path";function Dje(e){try{return JSON.parse(aLs(e,"utf8"))}catch{return}}h(Dje,"Dkt"),l(Dje,"readJson");function tR(e){return e.toLowerCase().replace(/^@[^/]+\//,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")||"workspace"}h(tR,"tX"),l(tR,"slugify");function sR(e){let t=Dje(zFt(e,"nx.json")),s=ru(e).key;if(typeof s=="string"&&s)return tR(s);let n=Dje(zFt(e,"package.json"));return n?.name?tR(n.name):t?.name?tR(t.name):tR(iLs(e))}h(sR,"gx"),l(sR,"resolveWorkspaceKey");import{readFileSync as oLs,statSync as lLs}from"node:fs";import{join as dLs}from"node:path";function lS(e,t=e){let s=qje(e);if(t===e)return s;let n=qje(t),r={};for(let[a,i]of Object.entries(s))WFt.get(a)!=="work"&&(r[a]=i);for(let[a,i]of Object.entries(n))WFt.get(a)==="work"&&(r[a]=i);return r}h(lS,"lv"),l(lS,"repositorySwitches");var WFt=new Map(cr.flatMap(e=>e.channels.map(t=>[t.key,e.area]))),eV=new Map;function qje(e){let t=dLs(e,sa),s;try{let a=lLs(t);s=`${a.size}:${a.mtimeMs}`}catch{return eV.delete(t),{}}let n=eV.get(t);if(n?.stamp===s)return n.switches;let r={};try{r=Ab(oLs(t,"utf8"),cr).file?.switches??{}}catch{}return eV.set(t,{stamp:s,switches:r}),r}h(qje,"Fkt"),l(qje,"fileSwitches");function HFt(){eV.clear()}h(HFt,"Ukt"),l(HFt,"forgetRepositorySwitches");import{readFileSync as cLs,statSync as uLs}from"node:fs";import{join as GFt,resolve as hLs}from"node:path";var tV=l(e=>new Map(cr.flatMap(t=>e(t).map(s=>[s,{card:t}]))),"index"),sV=tV(e=>e.brings.tools),pLs=tV(e=>e.brings.resources),mLs=tV(e=>e.brings.templates),KFt=tV(e=>e.brings.screens),fLs=new Set(["lens","environment"]);function JFt(e,t){let s=Ab(e,cr).file;if(t===e)return s;let n=Ab(t,cr).file;if(!s&&!n)return;let r={...s??{schemaVersion:1}};return delete r.work,n?.work!==void 0&&(r.work=n.work),r}h(JFt,"l1n"),l(JFt,"surfaceFile");function Lje(e,t={}){let s=qB(cr,e),n=kJ(t),r=dPt(cr,s),a=new Set(r),i=l(o=>{if(!o)return;let d=s.get(o.card.id);if(!(!d||d.on))return{feature:o.card.id,title:o.card.title,area:o.card.area,why:kPt({why:d.why,...d.by?{by:d.by}:{}})}},"offOf");return{key:cr.filter(o=>s.get(o.id)?.on).map(o=>o.id).join(" "),tool:l(o=>i(sV.get(o)??sV.get(o.replace(/\./g,"_"))),"tool"),resource:l(o=>i(pLs.get(o)),"resource"),template:l(o=>i(mLs.get(o)),"template"),screen:l(o=>i(KFt.get(o)),"screen"),screensOff:Object.fromEntries([...KFt].flatMap(([o,d])=>{let c=i(d);return c?[[o,c]]:[]})),needsSetup:l(o=>{let d=sV.get(o)??sV.get(o.replace(/\./g,"_"));return!d||fLs.has(d.card.area)},"needsSetup"),on:l(o=>s.get(o)?.on!==!1,"on"),recordsOff:r,recordOff:l((o,d)=>a.size>0&&cPt(a,o,d),"recordOff"),switchesOff:hPt(cr,s),partsOff:n,partOff:l((o,d)=>n[o]?.includes(d)===!0,"partOff")}}h(Lje,"Bkt"),l(Lje,"surfaceOf");var VFt=l(e=>{try{let t=uLs(e);return`${t.size}:${t.mtimeMs}`}catch{return"none"}},"stampOf"),QFt=l(e=>{try{return cLs(e,"utf8")}catch{return}},"textOf"),nV=new Map;function Pje(e,t){let s=GFt(e,sa),n=GFt(t,sa),r=`${s}:${VFt(s)}|${n===s?"":`${n}:${VFt(n)}`}`,a=`${e}
|
|
20271
20271
|
${t}`,i=nV.get(a);if(i?.stamp===r)return i.surface;let o;try{let d=QFt(s);o={...Lje(JFt(d,n===s?d:QFt(n)),Ab(d,cr).parts),stamp:r}}catch{o={...Lje(void 0),stamp:r}}return nV.size>=8&&nV.clear(),nV.set(a,{stamp:r,surface:o}),o}h(Pje,"QRe"),l(Pje,"currentSurface");var YFt=new Map;function ZFt(e=process.env){try{let t=hLs(e.LENSMCP_WORKSPACE_ROOT??process.cwd()),s=YFt.get(t);return s||YFt.set(t,s=pp(t)),Pje(t,s)}catch{return}}h(ZFt,"Vkt"),l(ZFt,"projectSurface");var XFt=6e4,gLs=3e4,wLs=2e3,Ln,eUt=6e4,nR;function xd(){return Ln?.store}h(xd,"nd"),l(xd,"activeEventStore");function Bu(){return Ln?{workspace:Ln.workspace,checkout:Ln.checkout}:void 0}h(Bu,"Qd"),l(Bu,"activeHistoryScope");function tUt(){return!!Ln&&Ln.keepsFile()}h(tUt,"Zkt"),l(tUt,"historyKeepsFile");function dS(){let e=Ln;if(e)return{appendLedger:l(t=>{e.store.records().appendLedger(t,e.checkout)},"appendLedger")}}h(dS,"yx"),l(dS,"historyLedgerSink");function rV(){let e=Ln;if(e)return{putRun:l(t=>e.store.records().putRun(t,e.checkout),"putRun"),runs:l(t=>e.store.records().runs({checkout:e.checkout,limit:t}),"runs"),find:l((t,s)=>e.store.records().runs({target:t,limit:s}),"find"),run:l(t=>e.store.records().run(t),"run")}}h(rV,"Kq"),l(rV,"historyRunSink");function sUt(e){let t=Ln;if(t)return t.store.records().runs({checkout:t.checkout,limit:e,omit:EFt})}h(sUt,"ebt"),l(sUt,"historyRunHeads");function nUt(){return Ln?.store.records().runsMark()}h(nUt,"tbt"),l(nUt,"historyRunsMark");function rUt(e,t){let s=Ln;return s?s.store.records().runs({targetKind:e,limit:t,omit:ZB}):void 0}h(rUt,"nbt"),l(rUt,"historyRunsOfKind");function Fje(){let e=Ln;return e?e.store.records():void 0}h(Fje,"iX"),l(Fje,"historyJobRows");function aV(){let e=Ln;if(!e)return;let t=l(()=>e.store.records(),"records");return gqt({notes:l(s=>t().notes(s),"notes"),putNote:l(s=>t().putNote(s),"putNote"),removeNote:l(s=>t().removeNote(s),"removeNote")},e.checkout)}h(aV,"Vq"),l(aV,"historyAnalyzerNotes");function iV(){let e=Ln;if(e)return{get:l(()=>eLt(e.store.getMeta("ai.review-choices")),"get"),put:l(t=>e.store.setMeta("ai.review-choices",JSON.stringify(t)),"put")}}h(iV,"Yq"),l(iV,"historyReviewChoices");function Bi(){let e=Ln;if(e)return{get:l(()=>{let t=e.store.getMeta("features"),s=lS(e.root,e.mainRoot);if(!Object.keys(s).length)return F4(t);let n={};try{n=t?JSON.parse(t):{}}catch{}return F4(JSON.stringify({...n,...s}))},"get"),put:l(t=>e.store.setMeta("features",JSON.stringify(t)),"put"),keptInFile:l(t=>Object.prototype.hasOwnProperty.call(lS(e.root,e.mainRoot),t),"keptInFile")}}h(Bi,"Di"),l(Bi,"historyFeatures");function hf(){let e=Ln;try{return e?Pje(e.root,e.mainRoot):ZFt()}catch{return}}h(hf,"Jm"),l(hf,"runtimeSurface");function El(){let e=Bi()?.get()??ls,t=hf()?.switchesOff;return t&&Object.keys(t).length?{...e,...t}:e}h(El,"sd"),l(El,"runtimeFeatures");var aUt=l(e=>{try{let t=JSON.parse(e);return t&&typeof t.id=="string"&&typeof t.key=="string"?t:void 0}catch{return}},"readCheck");function Mb(){let e=Ln;if(!e)return;let t=l(s=>e.store.records().suggestionChecks(s).flatMap(n=>aUt(n.body)??[]),"rows");return{due:l(s=>t({states:["waiting"],checkout:e.checkout,dueBy:s,limit:50}),"due"),running:l(()=>t({states:["running"],checkout:e.checkout,limit:50}),"running"),of:l((s,n)=>t({key:s,...n?{states:n}:{},limit:50}),"of"),get:l(s=>{let n=e.store.records().suggestionCheck(s);return n?aUt(n.body):void 0},"get"),put:l(s=>e.store.records().putSuggestionCheck({id:s.id,key:s.key,state:s.state,...s.state==="waiting"&&s.nextAt!==void 0?{nextAt:s.nextAt}:{},checkout:e.checkout,at:s.at,body:JSON.stringify(s)}),"put")}}h(Mb,"kx"),l(Mb,"historyChecks"),Tqt(()=>El().reviewCode!=="off"),$Ke(()=>!CPt(process.env.LENSMCP_WORKSPACE_ROOT??process.cwd())),Clt(()=>{let e=El();return{teamLaunch:e.teamLaunch,goalWorktrees:e.goalWorktrees,teamLaunchFallback:e.teamLaunchFallback,terminals:e.terminals,goalWorktreeServices:e.goalWorktreeServices,teamLaunchMax:e.teamLaunchMax,...e.teamLaunchCheckersMax!==void 0?{teamLaunchCheckersMax:e.teamLaunchCheckersMax}:{}}});function iUt(){let e=aV(),t=Ln;if(!e||!t){$Ie(void 0);return}let s=LMe(process.env.LENSMCP_WORKSPACE_ROOT??process.cwd()),n=ub(process.env.LENSMCP_EVENT_FILE??nf(s,".lensmcp","events.jsonl")),r=l(f=>t.store.records().runs({target:f,limit:20}),"runsOf"),a=process.env.LENSMCP_PROCESS_ROLE??"mcp",i=l(()=>{let f=rV(),g=dS();return{workspace:process.env.LENSMCP_WS_KEY||r3t(s),root:s,ledgerDir:nf(n,"decisions"),diagnoseDir:nf(n,"diagnose"),trigger:"agent",dailyCapUsd:Fw(s,Bi()?.get()).agent,notes:e,tokens:Hs(),...f?{runSink:f}:{},...g?{ledgerSink:g}:{},checkout:t.checkout,jobRows:t.store.records(),role:a,choices:iV()}},"reviewCtx"),o=new Map,d=l(f=>{let g=t.store.records(),w=g.doneMark(f),y=Date.now(),b=o.get(f);if(b&&b.mark===w&&y-b.at<eUt)return[...b.value];let v=new Set,$=[];for(let k of g.runs({targetKind:f,status:"done",limit:1e3,omit:ZB})){if(v.has(k.target.id))continue;v.add(k.target.id);let x=yB(k);x&&$.push(x)}return o.set(f,{mark:w,at:y,value:$}),[...$]},"newestReviews"),c=Mb(),u,p=l(()=>{let f=Date.now(),g=t.store.records(),w=g.doneMark();(!u||u.mark!==w||f-u.at>=eUt)&&(u={at:f,mark:w,runs:g.runs({status:"done",limit:400,omit:ZB})});let y=new Map;for(let b of g.suggestionChecks({states:["waiting","running"],limit:1e3}))y.set(b.key,(y.get(b.key)??0)+1);return SFt(u.runs,g.suggestionStates(),Gqt(s),f,y)},"suggestionsNow"),m=l(async(f,g,w,y)=>{let b=await w();if(b.review&&Ln===t){let S=f.indexOf(":");yNt(f.slice(0,S),f.slice(S+1),b.review.runId,b)}let v=zw(of({root:s,jobRows:t.store.records(),role:a})),$=[...v.running.map(S=>({...S,ahead:0})),...v.queued].find(S=>S.target===f),k=$?{state:$.state,runId:$.runId,ahead:$.ahead,max:v.max,owner:$.owner}:void 0;if(b.holds||!g?.run)return{...b,...k?{inProgress:k}:{}};let x=await(await y()).wait();return x.status!=="done"?{holds:!1,why:`the review failed: ${x.error??x.step}`,run:x}:{review:yB(x,r(f)),holds:!0,why:`reviewed now \u2014 ${x.costUsd?`$${x.costUsd.toFixed(4)} est.`:"no cost recorded"}`,run:x}},"follow");$Ie({notes:l(f=>e.list(f),"notes"),remember:l(f=>e.remember(f),"remember"),forget:l(f=>e.forget(f),"forget"),reviews:l(()=>d("sql"),"reviews"),routeReviews:l(()=>d("route"),"routeReviews"),reviewsOf:l(f=>d(f),"reviewsOf"),kinds:l(()=>{let f=new Set,g=[];for(let w of af())f.has(w.target)||(f.add(w.target),g.push({kind:w.target,analyzer:w.analyzer.id,name:w.analyzer.name,question:w.analyzer.question}));return g},"kinds"),newest:l((f,g)=>t.store.records().runs({target:`${f}:${g}`,status:"done",limit:1})[0],"newest"),queue:l(()=>zw(of({root:s,jobRows:t.store.records(),role:a})),"queue"),sql:l((f,g)=>m(`sql:${f}`,g,()=>K4(f,{root:s,workspace:t.workspace,notes:e,runs:r(`sql:${f}`)}),()=>SB(f,i())),"sql"),route:l((f,g)=>m(`route:${f}`,g,()=>MB(f,{root:s,workspace:t.workspace,notes:e,runs:r(`route:${f}`),sqlRuns:l(w=>r(`sql:${w}`),"sqlRuns")}),()=>hJ(f,i())),"route"),suggestions:l(()=>p(),"suggestions"),suggestion:l(f=>{let g=p().suggestions.find($=>Rje($,f));if(!g)return;let w=ja(),y=xu(),b=CFt(g,{run:t.store.records().run(g.runId),statements:Mw(Date.now(),5e3)?.templates??[],routes:w?nb(w).routes:[],page:l($=>y?.detail($),"page")}),v=UFt({...g,refs:b},af().some($=>$.target===g.target.kind),{pageNow:l($=>{let k=$.slice($.indexOf(" ")+1);return y?.payload(Date.now()).pages.filter(x=>x.pattern===k).sort((x,S)=>S.lastSeenAt-x.lastSeenAt)[0]?.id},"pageNow")});return{...g,refs:b,checks:c.of(g.key),...v?{proposedCheck:v}:{}}},"suggestion"),setSuggestion:l((f,g,w,y)=>{let b=p().suggestions.find(k=>Rje(k,f));if(!b)throw new Error(`no suggestion ${f} \u2014 the suggestions are the findings of each target's newest review (suggestion_list)`);let v=y?Fa(y).trim().slice(0,600):void 0,$=Date.now();return t.store.records().putSuggestionState({key:b.key,analyzer:b.analyzer,target:`${b.target.kind}:${b.target.id}`,state:g,by:w.slice(0,120),...v?{note:v}:{},runId:b.runId,checkout:t.checkout,at:$,snapshot:_je(b)}),JG(),{...b,state:g,stateAt:$,by:w.slice(0,120),...v?{note:v}:{}}},"setSuggestion"),scheduleCheck:l((f,g,w,y)=>{let b=p().suggestions.find(k=>Rje(k,f));if(!b)throw new Error(`no suggestion ${f} \u2014 suggestion_list names them`);let v=af().some(k=>k.target===b.target.kind),$=qFt(b,{...g,...g.note?{note:Fa(g.note)}:{}},{by:w.slice(0,120),trigger:y,now:Date.now(),reviewable:v});return t.store.records().putSuggestionState({key:b.key,analyzer:b.analyzer,target:`${b.target.kind}:${b.target.id}`,state:b.state,by:b.by??w.slice(0,120),...b.note?{note:b.note}:{},runId:b.runId,checkout:t.checkout,at:b.stateAt??Date.now(),snapshot:_je(b)}),c.put($),JG(),$},"scheduleCheck"),cancelCheck:l((f,g)=>{let w=c.get(f.trim());if(!w)throw new Error(`no check ${f.slice(0,40)}`);if(w.state!=="waiting"&&w.state!=="running")throw new Error(`check ${w.id} is ${w.state} already`);let y=Date.now(),{nextAt:b,...v}=w,$={...v,state:"cancelled",endedAt:y,last:{at:y,outcome:"error",text:`cancelled by ${g.slice(0,120)}`}};return c.put($),JG(),$},"cancelCheck"),aiAgent:l(f=>iFt(s,f),"aiAgent"),review:l((f,g,w)=>{let y=af().find(v=>v.target===f&&v.now);if(!y?.now)return Promise.reject(new Error(`no analyzer reviews a ${f}`));if(y.id(g)===void 0)return Promise.reject(new Error(`"${g.slice(0,80)}" is not an id ${y.analyzer.id} reviews`));let b=y.now;return m(`${f}:${g}`,w,()=>b(g,{root:s,workspace:t.workspace,notes:e,runs:r(`${f}:${g}`),runsOf:r}),()=>y.start(g,i()))},"review")})}h(iUt,"sbt"),l(iUt,"installReviewDesk");function oUt(){let e=Ln;if(e)return{get:l(t=>e.store.records().getSnapshot(e.checkout,t),"get"),put:l((t,s,n)=>e.store.withoutWaiting(()=>e.store.records().putSnapshot(e.checkout,t,s,n)),"put"),pack:l(t=>MHe(t),"pack"),putPacked:l((t,s,n)=>{if(Ln!==e)throw new Error("the event history was closed");e.store.withoutWaiting(()=>e.store.records().putSnapshotPacked(e.checkout,t,s,n))},"putPacked"),work:l(t=>gu.begin(t),"work")}}h(oUt,"obt"),l(oUt,"historyCatalogSnapshots");function lUt(e){let t=Ln;if(t)return{get:l(s=>t.store.records().getSnapshot(t.checkout,s),"get"),put:l((s,n,r)=>{if(Ln!==t)throw new Error("the event history was closed");t.store.withoutWaiting(()=>t.store.records().putSnapshot(t.checkout,s,n,r))},"put"),main:l(s=>t.checkout==="main"?void 0:t.store.records().getSnapshot("main",s),"main"),writer:e,work:l(s=>gu.begin(s),"work")}}h(lUt,"rbt"),l(lUt,"historyLintSnapshots");function dUt(e,t,s){let n=`imported:${s}`,r={ledger:0,runs:0};if(e.getMeta(n))return r;let a=l(c=>{try{return lRs(c,"utf8").split(`
|
|
20272
|
-
`).flatMap(u=>{if(!u.trim())return[];try{return[JSON.parse(u)]}catch{return[]}})}catch{return[]}},"lines"),i=e.records(),o=nf(t,"decisions");if(iRs(o))for(let c of oRs(o).filter(u=>/^ledger-\d{4}-\d{2}\.jsonl$/.test(u)).sort())for(let u of a(nf(o,c))){let p=u;typeof p?.id=="string"&&typeof p.at=="number"&&i.appendLedger(p,s)&&r.ledger++}let d=new Set;for(let c of a(nf(t,"diagnose","runs.jsonl"))){let u=c;typeof u?.id!="string"||typeof u.startedAt!="number"||!u.target||(i.putRun(u,s),d.add(u.id))}return r.runs=d.size,e.setMeta(n,String(Date.now())),r}h(dUt,"w1n"),l(dUt,"importLegacyRecords");function Uje(){return nR}h(Uje,"eOe"),l(Uje,"eventHistoryUnavailable");var yLs=16;function cUt(e,t=process.env){let s=LMe(ub(ub(e))),n=pp(s);return{mainRoot:n,checkout:n===s?"main":t.LENSMCP_INSTANCE||r3t(s)}}h(cUt,"k1n"),l(cUt,"historyScope");function uUt(e){if(process.env.LENSMCP_EVENT_HISTORY==="0"){nR="the event history is off (LENSMCP_EVENT_HISTORY=0)";return}let{mainRoot:t,checkout:s}=cUt(e.eventFile),n=sR(t),r=nf(process.env.LENSMCP_HOME||dRs(),".lensmcp","history"),a=sy.open(nf(r,`${n}.db`),{cacheMb:16});if(!(a instanceof sy)){nR=a.unavailable,console.error(`[lensmcp] ${nR}`);return}try{let g=a.fileState();!g.incremental&&g.freeBytes>=2**30&&g.freeBytes>=g.fileBytes/4&&console.error(`[lensmcp] event history: ${(g.freeBytes/1e9).toFixed(1)} GB of its ${(g.fileBytes/1e9).toFixed(1)} GB file are free pages it cannot give back \u2014 \`lensmcp gateway stop\` compacts it, or \`lensmcp history compact\` while the lens is stopped`)}catch{}try{let g=dUt(a,ub(e.eventFile),s);(g.ledger||g.runs)&&console.error(`[lensmcp] event history: took in ${g.ledger} ledger entries and ${g.runs} analyzer runs from ${ub(e.eventFile)}`)}catch(g){console.error(`[lensmcp] event history: the earlier ledger and runs were not taken in \u2014 ${g instanceof Error?g.message:String(g)}`)}let i=Number(process.env.LENSMCP_EVENT_HISTORY_DAYS??30),o=Number(process.env.LENSMCP_EVENT_HISTORY_MAX_GB??yLs),d=new mGe({store:a,dir:nf(r,n),role:e.role,checkout:s,eventFile:e.eventFile,prepare:e.prepare,retentionDays:Number.isFinite(i)&&i>0?i:36500,...Number.isFinite(o)&&o>0?{maxBytes:Math.round(o*2**30)}:{},work:l(g=>gu.begin(g),"work")}),c=e.subscribe(g=>d.push(g));a.records().keepRunViews(Kqs);let u,p=!1,m=l(()=>{let g=!1,w=gu.begin("timer run views");try{g=a.withoutWaiting(()=>a.records().fillRunViews(Date.now())).more}catch(y){!Zo(y)&&!p&&(p=!0,console.error(`[lensmcp] event history: the runs' views were not made \u2014 ${y instanceof Error?y.message:String(y)}`))}finally{w()}u=setTimeout(m,g?wLs:gLs),u.unref?.()},"fillViews");u=setTimeout(m,XFt),u.unref?.();let f=setTimeout(()=>{d.backfill().catch(g=>console.error(`[lensmcp] event history backfill: ${g instanceof Error?g.message:String(g)}`))},XFt);return f.unref?.(),Ln={store:a,workspace:n,checkout:s,root:LMe(ub(ub(e.eventFile))),mainRoot:t,keepsFile:l(()=>d.isWriter()&&d.keepsFile(),"keepsFile")},nR=void 0,i_e(g=>a.query({flowId:g,kinds:CDs,limit:4e3})),K_e(g=>a.query({since:g,kinds:D3s,limit:5e3})),{stop:l(()=>{c(),clearTimeout(f),clearTimeout(u),d.stop(),a.close(),Ln?.store===a&&(Ln=void 0,i_e(void 0),K_e(void 0))},"stop")}}h(uUt,"ibt"),l(uUt,"installEventHistory"),Ls();import{basename as vLs,dirname as bLs,join as zje,resolve as kLs}from"node:path";Ao();import{execFile as $Ls}from"node:child_process";import{basename as xLs,join as ALs}from"node:path";ze(),ze(),Ht();var SLs=64*1024,hUt=500,Wje=l(()=>[...new Set(cr.flatMap(e=>e.brings.tools))],"servedTools");function Hje(e){try{return Qt(e).repoId}catch{return"project"}}h(Hje,"cbt"),l(Hje,"repoIdOf");var ELs=1e4,cS=new Map;function uS(e,t={}){let s=e.now?.()??Date.now(),n=`${e.root}\0${e.home??""}`,r=cS.get(n);if(!t.fresh&&r&&s-r.at<ELs&&s>=r.at)return r.checkup;let a=vo(e.root),i=Hje(e.root),o=e.tools?e.tools():Wje(),d=(()=>{try{return Art(nu(e.home?{home:e.home}:{}).findings,i)}catch{return}})(),c=(()=>{try{return rfe(e.home,i)}catch{return{}}})(),u=(()=>{try{return mL({projectRoot:a,...e.home?{home:e.home}:{}})}catch{return}})(),p=Srt(Crt(a,zs(a),{...u?{catalog:u}:{},...o?{tools:o}:{},...d?{proposals:d}:{},dismissed:c,now:s}));return d||p.notes.push("The open proposals could not be read on this machine: they are not listed."),cS.size>=16&&cS.clear(),cS.set(n,{at:s,checkup:p}),p}h(uS,"GM"),l(uS,"teamCheckupNow");function Gje(e,t){if(t.safe)return{items:e.items.filter(a=>a.patch?.safe),problems:[]};let s=new Map(e.items.map(a=>[a.id,a])),n=[],r=[];for(let a of[...new Set(t.ids??[])]){let i=s.get(a);i?n.push(i):r.push(`${a} is not an item of the check-up as it reads now \u2014 the files changed, or it was dismissed`)}return{items:n,problems:r}}h(Gje,"dbt"),l(Gje,"picked");function pUt(e){let t=e.ids;if(t!==void 0&&(!Array.isArray(t)||t.length>hUt||!t.every(n=>typeof n=="string"&&n.length<=80)))throw new z(400,`ids is a list of at most ${hUt} check-up item ids`);let s=e.requestId;if(s!==void 0&&(typeof s!="string"||!s||s.length>160))throw new z(400,"requestId is a string of 1\u2013160 characters");if(e.safe!==!0&&!t?.length)throw new z(400,"name the items to apply: { ids: [...] }, or { safe: true } for every safe fix");return{...t?{ids:t}:{},...e.safe===!0?{safe:!0}:{},...typeof s=="string"?{requestId:s}:{}}}h(pUt,"$1n"),l(pUt,"pickOf");function mUt(e,t){let{items:s,problems:n}=Gje(uS(e,{fresh:!0}),t),r=Brt(vo(e.root),s);return{files:r.files,problems:[...n,...r.problems]}}h(mUt,"S1n"),l(mUt,"previewCheckup");var ILs=new Set(["base-unrecorded","base-moved"]);function fUt(e,t){let s=vo(e.root),{items:n,problems:r}=Gje(uS(e,{fresh:!0}),t),a=Rrt(s,n);cS.clear();let i=n.filter(d=>a.applied.includes(d.id)&&!ILs.has(d.kind)),o=!1;if(t.requestId&&i.length){let d=[...new Set(i.map(u=>u.patch.file))],c=Sh(s,`${t.requestId}:team-changed`,`the team's check-up fixes were applied (${d.join(", ")})`,e.home?{home:e.home}:{});o=c.notified,c.problem&&a.problems.push(c.problem)}return{written:a.written,applied:a.applied,problems:[...r,...a.problems],notified:o}}h(fUt,"A1n"),l(fUt,"applyCheckup");function gUt(e,t){let s=t.id;if(typeof s!="string"||!s||s.length>80)throw new z(400,"name the item: { id }");let n=t.why;if(n!==void 0&&(typeof n!="string"||n.length>400))throw new z(400,"why is text of at most 400 characters");let r=t.restore===!0,a=uS(e,{fresh:!0}),i=[...a.items,...a.dismissed].find(o=>o.id===s);if(!i)throw new z(404,"no such item in the check-up as it reads now");try{Ort(e.home,Hje(e.root),s,{dismissed:!r,...typeof n=="string"?{why:n}:{},text:i.text,...e.now?{now:e.now()}:{}})}catch(o){throw new z(400,o instanceof Error?o.message:String(o))}return cS.clear(),{id:s,dismissed:!r}}h(gUt,"_1n"),l(gUt,"dismissCheckup");function wUt(e,t,s,n,r,a){if(e!=="/api/team/checkup"&&e!=="/api/team/checkup/preview"&&e!=="/api/team/checkup/apply"&&e!=="/api/team/checkup/dismiss")return!1;let i=l(d=>{n.headersSent||a(n,d instanceof z?d.status:500,{error:d instanceof Error?d.message:String(d)})},"fail");if(e==="/api/team/checkup"){if(s.method!=="GET"&&s.method!=="HEAD")return a(n,405,{error:"the check-up is read with GET \u2014 it writes nothing"}),!0;try{let d=uS(r,{fresh:t.searchParams.get("fresh")==="1"});a(n,200,t.searchParams.get("count")==="1"?{at:d.at,team:d.team,items:[],dismissed:[],counts:d.counts,moved:d.moved,notes:[]}:d)}catch(d){i(d)}return!0}let o=Zt(s.method,s.headers);return o.ok?(Xt(s,SLs).then(d=>{let c={};if(d.trim())try{c=JSON.parse(d)}catch{throw new z(400,"the body is not JSON")}if(!c||typeof c!="object"||Array.isArray(c))throw new z(400,"the body is not a JSON object");let u=c;if(e==="/api/team/checkup/dismiss")return gUt(r,u);let p=pUt(u);return e==="/api/team/checkup/preview"?mUt(r,p):fUt(r,p)}).then(d=>a(n,200,d)).catch(i),!0):(a(n,o.status,{error:o.error}),!0)}h(wUt,"lbt"),l(wUt,"handleTeamCheckup"),he(),Ht();import{closeSync as TLs,existsSync as MLs,openSync as CLs,readSync as _Ls,statSync as jLs}from"node:fs";import{readFileSync as BLs}from"node:fs";import{join as RLs}from"node:path";function oV(e){try{let t=JSON.parse(BLs(RLs(e,"lensmcp.json"),"utf8")).services;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}}h(oV,"KM"),l(oV,"lensmcpServices");function lV(e,t,s){let n=e[t];if(n===!1)return;if(n&&typeof n=="object"&&!Array.isArray(n))return n;let r=s;return r?.cluster??r?.davnx}h(lV,"VM"),l(lV,"declFor"),Wr(),ze();import{homedir as OLs}from"node:os";import{join as yUt}from"node:path";import{performance as vUt}from"node:perf_hooks";Fm(),ze();var hS={tester:"test",reviewer:"review",qa:"qa",docs:"docs"},pS=l(e=>Object.prototype.hasOwnProperty.call(hS,e),"isFlowRole"),bUt="LensMCP keeps the roles its flow hands to \u2014 tester, reviewer, qa and docs (TH-D2); refine it instead (its paths, rules, model, effort)";function rR(e){let t=e.on.after==="build"?" after a build":e.on.after==="bug"?" after a fix":"",s=e.create.to?", back to whoever did it":"";return`${e.on.kind} ${e.on.outcome}${t} \u2192 ${e.create.kind}${s}`}h(rR,"Xq"),l(rR,"stepWords");var Kje={"build done \u2192 test":"A change gets its automated tests right after it is built, from another agent (the tester), on its branch, against what its task says done means \u2014 so the review sees the code and its tests together (OP-D4). Parallel work comes from many changes in flight, not from splitting one change\u2019s steps.","test passed after a build \u2192 review":"The review checks the code AND the tests written for it, once both exist: a review before its tests approves half a change, and tests written after approval go unreviewed (OP-D4).","test failed after a build \u2192 build, back to whoever did it":"Tests that show the change wrong send it back to whoever built it, on the same branch, until they pass.","bug done \u2192 review":"A fix carries its own regression test (the fixer writes it, so there is no test task), and goes straight to review as a change: the cause it names, the fix, the test that fails without it.","review changes-requested after a build \u2192 build, back to whoever did it":"Changes go back to whoever did the work, on the same branch, with what the review asked; the re-review checks those items against the new diff (OP-D3).","review changes-requested after a fix \u2192 bug, back to whoever did it":"The same for a fix: back to its fixer, on its branch.","review approved \u2192 qa":"Once every change under a goal is written, tested and approved, ONE QA run for the goal (join: goal; one at a time per repository, OP-D5): the suites and e2e of what it changed, then its acceptance checks in the running app. While it runs LensMCP measures the goal\u2019s worktree against the workspace\u2019s performance limits \u2014 slow routes and queries, N+1, DB calls in a loop, slow pages \u2014 and a breach refuses a passed QA: the QA files it as a bug (planning/team/07 GA-D1). A failed QA files one bug per failed change itself, so no hand-off follows it.","qa passed \u2192 docs":"Docs once per goal, after its QA passed, covering every change of the milestone (OP-D6) \u2014 not one docs task per change."};function kUt(){return Wl.map(e=>{let t=rR(e);return{step:t,...Kje[t]?{why:Kje[t]}:{}}})}h(kUt,"pbt"),l(kUt,"defaultSteps");var NLs=l((e,t)=>e.kind===t.kind&&e.outcome===t.outcome&&(e.after??void 0)===(t.after??void 0)&&!e.paths?.length&&!t.paths?.length,"sameOn"),$Ut=l(e=>e==="builder"?"owner":e,"owner");function Jje(e,t=Wl){let s=t.find(n=>NLs(n.on,e.on)&&n.create.kind===e.create.kind&&$Ut(n.create.to)===$Ut(e.create.to));if(s)return{verdict:"same",step:rR(s)};if(e.create.kind==="qa")return{verdict:"refused",why:"LensMCP makes ONE QA run per goal (review approved \u2192 qa, once nothing under the goal is still to do) \u2014 where it measures the goal\u2019s worktree against the performance limits; another hand-off to qa would run it per change"};if(e.create.kind==="docs")return{verdict:"refused",why:"docs follow the goal\u2019s QA run, once per goal (qa passed \u2192 docs) \u2014 not a docs task per change"};if(e.on.kind==="qa"&&e.on.outcome==="failed")return{verdict:"refused",why:"a failed QA run files one bug per failed change itself \u2014 a hand-off after it would file them twice"};if(!e.on.paths?.length){let n=t.find(r=>r.on.kind===e.on.kind&&r.on.outcome===e.on.outcome&&(!r.on.after||!e.on.after||r.on.after===e.on.after));if(n){let r=rR(n);return{verdict:"refused",why:`it would replace or reorder LensMCP's step \xAB${r}\xBB \u2014 ${Kje[r]??"the default steps are kept"} A specialist joins at this moment with on.paths (the paths it watches)`}}}return{verdict:"add"}}h(Jje,"nOe"),l(Jje,"againstDefaults");function xUt(e){let t=[],s=[];return e.forEach((n,r)=>{let a=Jje(n);a.verdict==="add"?t.push(n):a.verdict==="same"?s.push({level:"changed",index:r,why:`restates LensMCP's step \xAB${a.step}\xBB \u2014 the default is kept as it is`}):s.push({level:"dropped",index:r,why:a.why})}),{added:t,notes:s}}h(xUt,"fbt"),l(xUt,"flowAdditions");var DLs=l(e=>[...Wl,...e],"designFlow"),qLs=/(?:^|[/_-])(?:agents?[_-]?sync|sync|hand[_-]?offs?|handover|status|coordination|locks?|reservations?|claims?|work[_-]?log|progress|board)(?:[_-][\w-]*)?\.mdx?$/i,LLs=/(?:^|[/_-])(?:agents?[_-]?sync|hand[_-]?offs?|handover|locks?|reservations?|work[_-]?log)(?:[_-][\w-]*)?\.mdx?$/i,PLs=/[\w./-]*[\w-]\.mdx?\b/g,AUt=String.raw`(?:hand-?offs?|handovers?)`,FLs=new RegExp(String.raw`\b(?:reserv\w*|lock(?:s|ed|ing)?\s+(?:the\s+|your\s+)?(?:files?|paths?)|coordinat\w*`+String.raw`|(?:writ\w*|wrote|leav\w*|left|updat\w*|record\w*|add|adds|added|post\w*|append\w*|keep|kept|fill\w*|log|logs|logged|note|notes|noted)(?:\s+\S+){0,3}?\s+${AUt}\b`+String.raw`|${AUt}\s+(?:notes?|entr(?:y|ies)|logs?|tables?|files?)\b`+String.raw`|who(?:'s| is) (?:working|editing)|check (?:in|out)\b|sign (?:in|out|up)\b|claim(?:s|ed)? (?:the |your )?(?:files?|paths?|work))`,"i"),Vje="a manual coordination ritual of the repository \u2014 LensMCP\u2019s tasks, their paths, reservations (agent_task_reserve on the task you hold), messages and the board replace it (TH-D7)";function SUt(e){let t=/^file:\s*(\S+?)(?::\d+(?:-\d+)?)?$/.exec(e.trim());return!!t&&LLs.test(t[1])}h(SUt,"gbt"),l(SUt,"isLedgerCitation");function EUt(e){let t=e.match(PLs)??[];return t.length?t.some(s=>qLs.test(s))||FLs.test(e):!1}h(EUt,"N1n"),l(EUt,"isCoordinationRitual");function Qje(e){let t=[],s=[];for(let n of e.split(`
|
|
20272
|
+
`).flatMap(u=>{if(!u.trim())return[];try{return[JSON.parse(u)]}catch{return[]}})}catch{return[]}},"lines"),i=e.records(),o=nf(t,"decisions");if(iRs(o))for(let c of oRs(o).filter(u=>/^ledger-\d{4}-\d{2}\.jsonl$/.test(u)).sort())for(let u of a(nf(o,c))){let p=u;typeof p?.id=="string"&&typeof p.at=="number"&&i.appendLedger(p,s)&&r.ledger++}let d=new Set;for(let c of a(nf(t,"diagnose","runs.jsonl"))){let u=c;typeof u?.id!="string"||typeof u.startedAt!="number"||!u.target||(i.putRun(u,s),d.add(u.id))}return r.runs=d.size,e.setMeta(n,String(Date.now())),r}h(dUt,"w1n"),l(dUt,"importLegacyRecords");function Uje(){return nR}h(Uje,"eOe"),l(Uje,"eventHistoryUnavailable");var yLs=16;function cUt(e,t=process.env){let s=LMe(ub(ub(e))),n=pp(s);return{mainRoot:n,checkout:n===s?"main":t.LENSMCP_INSTANCE||r3t(s)}}h(cUt,"k1n"),l(cUt,"historyScope");function uUt(e){if(process.env.LENSMCP_EVENT_HISTORY==="0"){nR="the event history is off (LENSMCP_EVENT_HISTORY=0)";return}let{mainRoot:t,checkout:s}=cUt(e.eventFile),n=sR(t),r=nf(process.env.LENSMCP_HOME||dRs(),".lensmcp","history"),a=sy.open(nf(r,`${n}.db`),{cacheMb:16});if(!(a instanceof sy)){nR=a.unavailable,console.error(`[lensmcp] ${nR}`);return}try{let g=a.fileState();!g.incremental&&g.freeBytes>=2**30&&g.freeBytes>=g.fileBytes/4&&console.error(`[lensmcp] event history: ${(g.freeBytes/1e9).toFixed(1)} GB of its ${(g.fileBytes/1e9).toFixed(1)} GB file are free pages it cannot give back \u2014 \`lensmcp gateway stop\` compacts it, or \`lensmcp history compact\` while the lens is stopped`)}catch{}try{let g=dUt(a,ub(e.eventFile),s);(g.ledger||g.runs)&&console.error(`[lensmcp] event history: took in ${g.ledger} ledger entries and ${g.runs} analyzer runs from ${ub(e.eventFile)}`)}catch(g){console.error(`[lensmcp] event history: the earlier ledger and runs were not taken in \u2014 ${g instanceof Error?g.message:String(g)}`)}let i=Number(process.env.LENSMCP_EVENT_HISTORY_DAYS??30),o=Number(process.env.LENSMCP_EVENT_HISTORY_MAX_GB??yLs),d=new mGe({store:a,dir:nf(r,n),role:e.role,checkout:s,eventFile:e.eventFile,prepare:e.prepare,retentionDays:Number.isFinite(i)&&i>0?i:36500,...Number.isFinite(o)&&o>0?{maxBytes:Math.round(o*2**30)}:{},work:l(g=>gu.begin(g),"work")}),c=e.subscribe(g=>d.push(g));a.records().keepRunViews(Kqs);let u,p=!1,m=l(()=>{let g=!1,w=gu.begin("timer run views");try{g=a.withoutWaiting(()=>a.records().fillRunViews(Date.now())).more}catch(y){!Zo(y)&&!p&&(p=!0,console.error(`[lensmcp] event history: the runs' views were not made \u2014 ${y instanceof Error?y.message:String(y)}`))}finally{w()}u=setTimeout(m,g?wLs:gLs),u.unref?.()},"fillViews");u=setTimeout(m,XFt),u.unref?.();let f=setTimeout(()=>{d.backfill().catch(g=>console.error(`[lensmcp] event history backfill: ${g instanceof Error?g.message:String(g)}`))},XFt);return f.unref?.(),Ln={store:a,workspace:n,checkout:s,root:LMe(ub(ub(e.eventFile))),mainRoot:t,keepsFile:l(()=>d.isWriter()&&d.keepsFile(),"keepsFile")},nR=void 0,i_e(g=>a.query({flowId:g,kinds:CDs,limit:4e3})),K_e(g=>a.query({since:g,kinds:D3s,limit:5e3})),{stop:l(()=>{c(),clearTimeout(f),clearTimeout(u),d.stop(),a.close(),Ln?.store===a&&(Ln=void 0,i_e(void 0),K_e(void 0))},"stop")}}h(uUt,"ibt"),l(uUt,"installEventHistory"),Ls();import{basename as vLs,dirname as bLs,join as zje,resolve as kLs}from"node:path";Ao();import{execFile as $Ls}from"node:child_process";import{basename as xLs,join as ALs}from"node:path";ze(),ze(),Ht();var SLs=64*1024,hUt=500,Wje=l(()=>[...new Set(cr.flatMap(e=>e.brings.tools))],"servedTools");function Hje(e){try{return Qt(e).repoId}catch{return"project"}}h(Hje,"cbt"),l(Hje,"repoIdOf");var ELs=1e4,cS=new Map;function uS(e,t={}){let s=e.now?.()??Date.now(),n=`${e.root}\0${e.home??""}`,r=cS.get(n);if(!t.fresh&&r&&s-r.at<ELs&&s>=r.at)return r.checkup;let a=vo(e.root),i=Hje(e.root),o=e.tools?e.tools():Wje(),d=(()=>{try{return Art(nu(e.home?{home:e.home}:{}).findings,i)}catch{return}})(),c=(()=>{try{return rfe(e.home,i)}catch{return{}}})(),u=(()=>{try{return mL({projectRoot:a,...e.home?{home:e.home}:{}})}catch{return}})(),p=Srt(Crt(a,zs(a),{...u?{catalog:u}:{},...o?{tools:o}:{},...d?{proposals:d}:{},dismissed:c,now:s}));return d||p.notes.push("The open proposals could not be read on this machine: they are not listed."),cS.size>=16&&cS.clear(),cS.set(n,{at:s,checkup:p}),p}h(uS,"GM"),l(uS,"teamCheckupNow");function Gje(e,t){if(t.safe)return{items:e.items.filter(a=>a.patch?.safe),problems:[]};let s=new Map(e.items.map(a=>[a.id,a])),n=[],r=[];for(let a of[...new Set(t.ids??[])]){let i=s.get(a);i?n.push(i):r.push(`${a} is not an item of the check-up as it reads now \u2014 the files changed, or it was dismissed`)}return{items:n,problems:r}}h(Gje,"dbt"),l(Gje,"picked");function pUt(e){let t=e.ids;if(t!==void 0&&(!Array.isArray(t)||t.length>hUt||!t.every(n=>typeof n=="string"&&n.length<=80)))throw new z(400,`ids is a list of at most ${hUt} check-up item ids`);let s=e.requestId;if(s!==void 0&&(typeof s!="string"||!s||s.length>160))throw new z(400,"requestId is a string of 1\u2013160 characters");if(e.safe!==!0&&!t?.length)throw new z(400,"name the items to apply: { ids: [...] }, or { safe: true } for every safe fix");return{...t?{ids:t}:{},...e.safe===!0?{safe:!0}:{},...typeof s=="string"?{requestId:s}:{}}}h(pUt,"$1n"),l(pUt,"pickOf");function mUt(e,t){let{items:s,problems:n}=Gje(uS(e,{fresh:!0}),t),r=Brt(vo(e.root),s);return{files:r.files,problems:[...n,...r.problems]}}h(mUt,"S1n"),l(mUt,"previewCheckup");var ILs=new Set(["base-unrecorded","base-moved"]);function fUt(e,t){let s=vo(e.root),{items:n,problems:r}=Gje(uS(e,{fresh:!0}),t),a=Rrt(s,n);cS.clear();let i=n.filter(d=>a.applied.includes(d.id)&&!ILs.has(d.kind)),o=!1;if(t.requestId&&i.length){let d=[...new Set(i.map(u=>u.patch.file))],c=Sh(s,`${t.requestId}:team-changed`,`the team's check-up fixes were applied (${d.join(", ")})`,e.home?{home:e.home}:{});o=c.notified,c.problem&&a.problems.push(c.problem)}return{written:a.written,applied:a.applied,problems:[...r,...a.problems],notified:o}}h(fUt,"A1n"),l(fUt,"applyCheckup");function gUt(e,t){let s=t.id;if(typeof s!="string"||!s||s.length>80)throw new z(400,"name the item: { id }");let n=t.why;if(n!==void 0&&(typeof n!="string"||n.length>400))throw new z(400,"why is text of at most 400 characters");let r=t.restore===!0,a=uS(e,{fresh:!0}),i=[...a.items,...a.dismissed].find(o=>o.id===s);if(!i)throw new z(404,"no such item in the check-up as it reads now");try{Ort(e.home,Hje(e.root),s,{dismissed:!r,...typeof n=="string"?{why:n}:{},text:i.text,...e.now?{now:e.now()}:{}})}catch(o){throw new z(400,o instanceof Error?o.message:String(o))}return cS.clear(),{id:s,dismissed:!r}}h(gUt,"_1n"),l(gUt,"dismissCheckup");function wUt(e,t,s,n,r,a){if(e!=="/api/team/checkup"&&e!=="/api/team/checkup/preview"&&e!=="/api/team/checkup/apply"&&e!=="/api/team/checkup/dismiss")return!1;let i=l(d=>{n.headersSent||a(n,d instanceof z?d.status:500,{error:d instanceof Error?d.message:String(d)})},"fail");if(e==="/api/team/checkup"){if(s.method!=="GET"&&s.method!=="HEAD")return a(n,405,{error:"the check-up is read with GET \u2014 it writes nothing"}),!0;try{let d=uS(r,{fresh:t.searchParams.get("fresh")==="1"});a(n,200,t.searchParams.get("count")==="1"?{at:d.at,team:d.team,items:[],dismissed:[],counts:d.counts,moved:d.moved,notes:[]}:d)}catch(d){i(d)}return!0}let o=Zt(s.method,s.headers);return o.ok?(Xt(s,SLs).then(d=>{let c={};if(d.trim())try{c=JSON.parse(d)}catch{throw new z(400,"the body is not JSON")}if(!c||typeof c!="object"||Array.isArray(c))throw new z(400,"the body is not a JSON object");let u=c;if(e==="/api/team/checkup/dismiss")return gUt(r,u);let p=pUt(u);return e==="/api/team/checkup/preview"?mUt(r,p):fUt(r,p)}).then(d=>a(n,200,d)).catch(i),!0):(a(n,o.status,{error:o.error}),!0)}h(wUt,"lbt"),l(wUt,"handleTeamCheckup"),he(),Ht();import{closeSync as TLs,existsSync as MLs,openSync as CLs,readSync as _Ls,statSync as jLs}from"node:fs";import{readFileSync as BLs}from"node:fs";import{join as RLs}from"node:path";function oV(e){try{let t=JSON.parse(BLs(RLs(e,"lensmcp.json"),"utf8")).services;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}}h(oV,"KM"),l(oV,"lensmcpServices");function lV(e,t,s){let n=e[t];if(n===!1)return;let r=s,a=r?.cluster??r?.davnx;return n&&typeof n=="object"&&!Array.isArray(n)?{...a,...n}:a}h(lV,"VM"),l(lV,"declFor"),Wr(),ze();import{homedir as OLs}from"node:os";import{join as yUt}from"node:path";import{performance as vUt}from"node:perf_hooks";Fm(),ze();var hS={tester:"test",reviewer:"review",qa:"qa",docs:"docs"},pS=l(e=>Object.prototype.hasOwnProperty.call(hS,e),"isFlowRole"),bUt="LensMCP keeps the roles its flow hands to \u2014 tester, reviewer, qa and docs (TH-D2); refine it instead (its paths, rules, model, effort)";function rR(e){let t=e.on.after==="build"?" after a build":e.on.after==="bug"?" after a fix":"",s=e.create.to?", back to whoever did it":"";return`${e.on.kind} ${e.on.outcome}${t} \u2192 ${e.create.kind}${s}`}h(rR,"Xq"),l(rR,"stepWords");var Kje={"build done \u2192 test":"A change gets its automated tests right after it is built, from another agent (the tester), on its branch, against what its task says done means \u2014 so the review sees the code and its tests together (OP-D4). Parallel work comes from many changes in flight, not from splitting one change\u2019s steps.","test passed after a build \u2192 review":"The review checks the code AND the tests written for it, once both exist: a review before its tests approves half a change, and tests written after approval go unreviewed (OP-D4).","test failed after a build \u2192 build, back to whoever did it":"Tests that show the change wrong send it back to whoever built it, on the same branch, until they pass.","bug done \u2192 review":"A fix carries its own regression test (the fixer writes it, so there is no test task), and goes straight to review as a change: the cause it names, the fix, the test that fails without it.","review changes-requested after a build \u2192 build, back to whoever did it":"Changes go back to whoever did the work, on the same branch, with what the review asked; the re-review checks those items against the new diff (OP-D3).","review changes-requested after a fix \u2192 bug, back to whoever did it":"The same for a fix: back to its fixer, on its branch.","review approved \u2192 qa":"Once every change under a goal is written, tested and approved, ONE QA run for the goal (join: goal; one at a time per repository, OP-D5): the suites and e2e of what it changed, then its acceptance checks in the running app. While it runs LensMCP measures the goal\u2019s worktree against the workspace\u2019s performance limits \u2014 slow routes and queries, N+1, DB calls in a loop, slow pages \u2014 and a breach refuses a passed QA: the QA files it as a bug (planning/team/07 GA-D1). A failed QA files one bug per failed change itself, so no hand-off follows it.","qa passed \u2192 docs":"Docs once per goal, after its QA passed, covering every change of the milestone (OP-D6) \u2014 not one docs task per change."};function kUt(){return Wl.map(e=>{let t=rR(e);return{step:t,...Kje[t]?{why:Kje[t]}:{}}})}h(kUt,"pbt"),l(kUt,"defaultSteps");var NLs=l((e,t)=>e.kind===t.kind&&e.outcome===t.outcome&&(e.after??void 0)===(t.after??void 0)&&!e.paths?.length&&!t.paths?.length,"sameOn"),$Ut=l(e=>e==="builder"?"owner":e,"owner");function Jje(e,t=Wl){let s=t.find(n=>NLs(n.on,e.on)&&n.create.kind===e.create.kind&&$Ut(n.create.to)===$Ut(e.create.to));if(s)return{verdict:"same",step:rR(s)};if(e.create.kind==="qa")return{verdict:"refused",why:"LensMCP makes ONE QA run per goal (review approved \u2192 qa, once nothing under the goal is still to do) \u2014 where it measures the goal\u2019s worktree against the performance limits; another hand-off to qa would run it per change"};if(e.create.kind==="docs")return{verdict:"refused",why:"docs follow the goal\u2019s QA run, once per goal (qa passed \u2192 docs) \u2014 not a docs task per change"};if(e.on.kind==="qa"&&e.on.outcome==="failed")return{verdict:"refused",why:"a failed QA run files one bug per failed change itself \u2014 a hand-off after it would file them twice"};if(!e.on.paths?.length){let n=t.find(r=>r.on.kind===e.on.kind&&r.on.outcome===e.on.outcome&&(!r.on.after||!e.on.after||r.on.after===e.on.after));if(n){let r=rR(n);return{verdict:"refused",why:`it would replace or reorder LensMCP's step \xAB${r}\xBB \u2014 ${Kje[r]??"the default steps are kept"} A specialist joins at this moment with on.paths (the paths it watches)`}}}return{verdict:"add"}}h(Jje,"nOe"),l(Jje,"againstDefaults");function xUt(e){let t=[],s=[];return e.forEach((n,r)=>{let a=Jje(n);a.verdict==="add"?t.push(n):a.verdict==="same"?s.push({level:"changed",index:r,why:`restates LensMCP's step \xAB${a.step}\xBB \u2014 the default is kept as it is`}):s.push({level:"dropped",index:r,why:a.why})}),{added:t,notes:s}}h(xUt,"fbt"),l(xUt,"flowAdditions");var DLs=l(e=>[...Wl,...e],"designFlow"),qLs=/(?:^|[/_-])(?:agents?[_-]?sync|sync|hand[_-]?offs?|handover|status|coordination|locks?|reservations?|claims?|work[_-]?log|progress|board)(?:[_-][\w-]*)?\.mdx?$/i,LLs=/(?:^|[/_-])(?:agents?[_-]?sync|hand[_-]?offs?|handover|locks?|reservations?|work[_-]?log)(?:[_-][\w-]*)?\.mdx?$/i,PLs=/[\w./-]*[\w-]\.mdx?\b/g,AUt=String.raw`(?:hand-?offs?|handovers?)`,FLs=new RegExp(String.raw`\b(?:reserv\w*|lock(?:s|ed|ing)?\s+(?:the\s+|your\s+)?(?:files?|paths?)|coordinat\w*`+String.raw`|(?:writ\w*|wrote|leav\w*|left|updat\w*|record\w*|add|adds|added|post\w*|append\w*|keep|kept|fill\w*|log|logs|logged|note|notes|noted)(?:\s+\S+){0,3}?\s+${AUt}\b`+String.raw`|${AUt}\s+(?:notes?|entr(?:y|ies)|logs?|tables?|files?)\b`+String.raw`|who(?:'s| is) (?:working|editing)|check (?:in|out)\b|sign (?:in|out|up)\b|claim(?:s|ed)? (?:the |your )?(?:files?|paths?|work))`,"i"),Vje="a manual coordination ritual of the repository \u2014 LensMCP\u2019s tasks, their paths, reservations (agent_task_reserve on the task you hold), messages and the board replace it (TH-D7)";function SUt(e){let t=/^file:\s*(\S+?)(?::\d+(?:-\d+)?)?$/.exec(e.trim());return!!t&&LLs.test(t[1])}h(SUt,"gbt"),l(SUt,"isLedgerCitation");function EUt(e){let t=e.match(PLs)??[];return t.length?t.some(s=>qLs.test(s))||FLs.test(e):!1}h(EUt,"N1n"),l(EUt,"isCoordinationRitual");function Qje(e){let t=[],s=[];for(let n of e.split(`
|
|
20273
20273
|
`)){let r=/^(\s*(?:[-*+]|\d+[.)])\s+)?([\s\S]*)$/.exec(n),a=r[1]??"",i=r[2].split(/(?<=[.!?])\s+(?=\S)/),o=i.filter(d=>EUt(d)?(t.push(d.trim()),!1):!0);o.length===i.length?s.push(n):o.join(" ").trim()&&s.push(`${a}${o.join(" ")}`)}return{text:t.length?s.join(`
|
|
20274
20274
|
`):e,dropped:t}}h(Qje,"cX"),l(Qje,"withoutRituals"),Wr(),Fm();import{execFile as ULs}from"node:child_process";import{createHash as zLs}from"node:crypto";import{performance as dV}from"node:perf_hooks";var Yje="90 days ago",IUt=2e3,WLs=2e4,TUt=12,HLs=32<<20,GLs=64<<20,KLs=15e3,JLs=8e3,MUt=2e3,VLs=200,QLs=/(?:^|\/)(?:\.git|\.lensmcp)(?:\/|$)/,YLs=/(?:^|\/)(?:package\.json|CHANGELOG\.mdx?|changelog\.mdx?|Cargo\.toml|pyproject\.toml|pom\.xml|build\.gradle(?:\.kts)?|version\.txt|VERSION)$/,ZLs=/(?:^|\/)(?:yarn\.lock|package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|bun\.lockb?|Cargo\.lock|poetry\.lock|uv\.lock|Pipfile\.lock|Gemfile\.lock|go\.sum|composer\.lock|flake\.lock)$/,aR=l(e=>!QLs.test(e)&&!Kh(e),"showable");function mS(e=WLs){let t=dV.now()+e;return{left:l(()=>Math.max(0,Math.floor(t-dV.now())),"left")}}h(mS,"YM"),l(mS,"gitBudget");var XLs=l(e=>e.trim().split(`
|
|
20275
20275
|
`)[0].slice(0,200),"firstLine");function iR(e,t,s,n){let r=Math.min(n.timeoutMs,s.left());return r<50?Promise.resolve({ok:!1,out:"",why:"the git time budget was spent"}):new Promise(a=>{ULs("git",["-C",e,"-c","core.quotepath=off",...t],{encoding:"utf8",timeout:r,maxBuffer:n.maxBuffer,windowsHide:!0,env:{...process.env,GIT_OPTIONAL_LOCKS:"0",GIT_TERMINAL_PROMPT:"0",LC_ALL:"C"}},(i,o,d)=>{let c=String(o??"");if(!i)return a({ok:!0,out:c});let u=i;if(u.code==="ERR_CHILD_PROCESS_STDIO_MAXBUFFER")return a({ok:!0,out:c,cut:"buffer",why:`its output passed ${n.maxBuffer>=1<<20?`${Math.round(n.maxBuffer/(1<<20))} MB`:`${Math.ceil(n.maxBuffer/1024)} KB`}`});if(u.killed||u.signal)return a({ok:c.length>0,out:c,cut:"timeout",why:`it took over ${(r/1e3).toFixed(1)} s`});a({ok:!1,out:c,why:XLs(String(d??""))||u.message.slice(0,200)})})})}h(iR,"uX"),l(iR,"runGit");function CUt(e){if(!(e.length>=2&&e.startsWith('"')&&e.endsWith('"')))return e;try{let t=JSON.parse(e);if(typeof t=="string")return t}catch{}return e.slice(1,-1)}h(CUt,"K1n"),l(CUt,"unquote");async function cV(e,t=mS()){let s=await iR(e,["ls-files","-z"],t,{timeoutMs:JLs,maxBuffer:GLs});if(!s.ok)return{ok:!1,files:[],why:s.why??"git ls-files failed"};let n=s.out.split("\0");s.cut&&n.pop();let r=n.filter(Boolean).sort();return{ok:!0,files:r,...s.cut?{cut:`the tracked-file list was cut at ${r.length.toLocaleString("en-US")} names: ${s.why}`}:{}}}h(cV,"Zq"),l(cV,"trackedFiles");async function _Ut(e,t=mS()){let[s,n]=await Promise.all([iR(e,["rev-parse","--verify","--quiet","HEAD"],t,{timeoutMs:MUt,maxBuffer:65536}),iR(e,["symbolic-ref","--quiet","--short","HEAD"],t,{timeoutMs:MUt,maxBuffer:65536})]);return{head:s.ok&&s.out.trim()?s.out.trim():null,branch:n.ok&&n.out.trim()?n.out.trim():null}}h(_Ut,"kbt"),l(_Ut,"headOf");var jUt="",uV="",e6s=l(e=>zLs("sha256").update(e.trim().toLowerCase()).digest("hex").slice(0,10),"authorKey");function BUt(e){let t=[];for(let s of e.split(jUt)){if(!s.trim())continue;let n=s.split(`
|