lensmcp 1.23.11 → 1.23.13
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/lib/cli.js +19 -19
- package/lib/gateway-registration.d.ts +22 -0
- package/lib/gateway-registration.js +1 -0
- package/lib/upgrade.d.ts +18 -0
- package/lib/upgrade.js +3 -3
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/lensmcp/.codex-plugin/plugin.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var os=Object.defineProperty;var p=(t,n)=>os(t,"name",{value:n,configurable:!0});var rs=Object.defineProperty,d=p((t,n)=>rs(t,"name",{value:n,configurable:!0}),"d");import{spawn as is,spawnSync as M}from"node:child_process";import{existsSync as S,mkdirSync as Z,openSync as as,readFileSync as V,readdirSync as ce,realpathSync as cs,rmSync as ls,statSync as Re,writeFileSync as q}from"node:fs";import{request as Ae}from"node:http";import{homedir as ds,tmpdir as us}from"node:os";import{basename as le,dirname as _,isAbsolute as ps,join as m,relative as Ie,resolve as L}from"node:path";import{fileURLToPath as gs}from"node:url";import{ensureLensConfig as z,readLensConfig as hs}from"./workspace-scope.js";import{commandUsage as fs,onOutputBroken as ms,wantsHelp as ws}from"./cli-help.js";import{splitLintArgs as ys}from"./lint-args.js";import{decideRecycle as vs,hashConfig as ks}from"./recycle-policy.js";import{planMcpRestart as _e}from"./mcp-restart.js";import{detectDuplicateRegistration as $s,disabledMcpServers as De,mcpServerNames as Fe,pluginEnabledInSettings as Ke}from"./duplicate-registration.js";import{readTrackedPid as bs,stillSameProcess as Cs,writeTrackedPid as Ge}from"./process-identity.js";import{remember as xs,shouldAnnounce as Ss}from"./hook-memory.js";import{isMcpMode as Ve}from"./mcp-mode.js";import{effectiveMcpMode as js,LENS_CONFIG as Ns,probeIdentitySync as He,probeSharedMcp as Be,probeSharedMcpSync as Ps,readMcpWiring as te,wireMcpMode as Es}from"./mcp-wiring.js";import{sweepLensRuntimeFiles as Je}from"./sweep.js";import{candidateSignals as Ts,findingLine as Ms,findingsDigest as Ls,formatContext as Os,hookPayload as We,isHookEvent as Ue,select as Rs}from"./status-policy.js";import{DEFAULT_BUDGET_MS as As,readStatus as Is,withLensSession as _s}from"./status-client.js";import{DISMISS_USAGE as Ds,parseDismissArgs as Fs,runDismissCommand as Ks}from"./dismiss-command.js";import{otherCheckoutLines as qe,refusalMessage as de,registrationState as ze}from"./gateway-registration.js";import{detectSkew as Gs,formatSkewContext as Ye,readInstalledPlugin as Xe,readInstalledPlugins as Ze,readVersions as Qe,spawnRunner as Vs,syncPlugin as Hs,updateCommands as Bs}from"./plugin-version.js";import{AGENTS as et,agentById as Js,codexInstalledVersion as Ws,installAgentPlugin as Us,MARKETPLACE as qs,PLUGIN_ID as Q,readPluginManifestVersion as zs,resolvePluginRoot as tt,spawnAgentRunner as st}from"./agent-plugins.js";import{detectGlobalInstall as Ys,daemonVerdict as Xs,detectPackageManager as Zs,installLanded as nt,lensPackagesIn as Qs,missingFromRegistry as en,needsInstall as tn,planRestart as sn,readConnectedWorkspaces as nn,registryAnswer as on,rewriteLensmcpDeps as rn,setupReminder as an}from"./upgrade.js";const ue=`lensmcp \u2014 CLI for LensMCP (FrontMCP-based observability for coding agents)
|
|
2
2
|
|
|
3
3
|
Usage:
|
|
4
4
|
lensmcp <command> [options]
|
|
@@ -193,37 +193,37 @@ Commands:
|
|
|
193
193
|
listening" link in \`lensmcp logs <service>\`.
|
|
194
194
|
--version Print the lensmcp version.
|
|
195
195
|
--help Show this help.
|
|
196
|
-
`;export async function runCli(t){const n=t.out??(r=>console.log(r)),e=t.err??(r=>console.error(r)),[s,...o]=t.argv;if(!s||s==="--help"||s==="-h")return n(
|
|
196
|
+
`;export async function runCli(t){const n=t.out??(r=>console.log(r)),e=t.err??(r=>console.error(r)),[s,...o]=t.argv;if(!s||s==="--help"||s==="-h")return n(ue),{exitCode:0};if(s==="--version"||s==="-V")return n(X()),{exitCode:0};if(ws(o,s))return n(fs(ue,s)??ue),{exitCode:0};switch(s){case"setup":return xt(t,o,n,e);case"mcp":return it(t,o,n,e);case"dashboard":return at(t,o,n,e);case"gateway":return we(t,o,n,e);case"bridge":return yt(t,o,n,e);case"install":return be(t,o,n,e);case"plugin":case"plugins":return _t(t,o,n,e);case"upgrade":return Gt(t,o,n,e);case"trust":return Ce(t,o,n,e);case"status":return St(t,o,n);case"version-check":return jt(t,o,n);case"doctor":return Nt(t,o,n);case"prune":return ot(t,o,n,e);case"rollout":return Bt(t,o,e);case"logs":return ts(t,o,n,e);case"dismiss":return vt(t,o,n,e);case"lint":return kt(t,o,e);case"debug":return ss(t,o,n,e);default:return e(`Unknown command: ${s}`),e(ue),{exitCode:2,message:`Unknown command: ${s}`}}}p(runCli,"runCli"),d(runCli,"runCli");function ot(t,n,e,s){const o=I(n,{string:["--cwd"],boolean:["--force"]}),r=L(b(o.flags["--cwd"])??t.cwd),i=m(r,".lensmcp"),c=m(i,"gateway.log"),l=d(()=>{try{return ce(i).reduce((f,w)=>{try{return f+Re(m(i,w)).size}catch{return f}},0)}catch{return 0}},"dirBytes"),a=d(f=>`${(f/1048576).toFixed(1)} MB`,"mb"),u=l();if(u===0)return e(`nothing to prune \u2014 no .lensmcp runtime files at ${i}`),{exitCode:0};if(o.flags["--force"]!==!0&&rt(i))return s("a gateway is running for this workspace \u2014 pruning now can drop a generation a live"),s("writer is still counting (issues/foodguard/13). Stop it first:"),s(" lensmcp gateway stop"),s("\u2026or pass --force if you accept losing recent history."),{exitCode:1,message:"gateway running"};Je(r,c);const h=l();return e(`pruned ${i}`),e(` ${a(u)} \u2192 ${a(h)} (reclaimed ${a(Math.max(0,u-h))})`),{exitCode:0}}p(ot,"at"),d(ot,"runPrune");function rt(t){try{return ve(m(t,"gateway.pid"))!==void 0}catch{return!1}}p(rt,"ct"),d(rt,"gatewayPidAlive");function it(t,n,e,s){const o=I(n,{string:["--cwd","--transport","--port","--mcp"]}),r=L(b(o.flags["--cwd"])??t.cwd),i=z(r),c=b(o.flags["--transport"])??t.env?.LENSMCP_TRANSPORT??"stdio",l=b(o.flags["--port"])??t.env?.LENSMCP_PORT??String(i.ports.mcpHttp),a=js(r,b(o.flags["--mcp"]),{...process.env,...t.env??{}})==="shared"&&c==="stdio",u=a?Wt(r)??ge(r):ge(r);if(!u)return s(`Could not locate the lensmcp-mcp server bundle.
|
|
197
197
|
Looked in (in order):
|
|
198
198
|
\u2022 <cli-package>/bundled/main.js (published bin)
|
|
199
199
|
\u2022 <workspace>/apps/lensmcp-mcp/dist/main.js (dev build)
|
|
200
|
-
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};ae(r);const h=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl"),f={...process.env,...t.env??{},LENSMCP_TRANSPORT:c,LENSMCP_PORT:
|
|
200
|
+
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};ae(r);const h=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl"),f={...process.env,...t.env??{},LENSMCP_TRANSPORT:c,LENSMCP_PORT:l,LENSMCP_EVENT_FILE:h},w=a?[u,"--cwd",r]:[u];return{exitCode:M(process.execPath,w,{cwd:r,stdio:"inherit",env:f}).status??1}}p(it,"dt"),d(it,"runMcp");function at(t,n,e,s){const o=I(n,{string:["--cwd","--port","--base"]}),r=L(b(o.flags["--cwd"])??t.cwd),i=z(r),c=b(o.flags["--port"])??t.env?.LENSMCP_DASHBOARD_PORT??String(i.ports.dashboard),l=b(o.flags["--base"])??t.env?.LENSMCP_DASHBOARD_BASE??"",a=he(r,"dashboard.js");if(!a)return s(`Could not locate the lensmcp dashboard bundle.
|
|
201
201
|
Looked in (in order):
|
|
202
202
|
\u2022 <cli-package>/bundled/dashboard.js (published bin)
|
|
203
203
|
\u2022 <workspace>/servers/lensmcp-mcp/dist/dashboard.js (dev build)
|
|
204
|
-
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};ae(r);const u=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl");return e(`lensmcp dashboard \u2192 http://localhost:${c}${
|
|
205
|
-
%{http_code}`,"--unix-socket",s,"-X",t,`http://localhost${n}`];e!==void 0&&o.push("-H","content-type: application/json","-d",JSON.stringify(e));const r=
|
|
206
|
-
`),c=Number(i.pop());let
|
|
207
|
-
`).trim();
|
|
208
|
-
Free it first (stop that process), then \`lensmcp gateway start\`.`),{exitCode:1}}const $=ct(c,b(o.flags["--project"]),b(o.flags["--target"]));if(!$)return s(`This workspace ('${d.key}') has no gateway target \u2014 no project declares the`),s("`@lensmcp/cluster:gateway` executor, so there is nothing here to launch on :443."),s(""),s(" \u2022 Joining a shared gateway? Start it in the workspace that OWNS it, then run"),s(" `lensmcp gateway start` here \u2014 this workspace registers into it (no local target needed)."),s(" \u2022 Should this workspace host its own gateway? Scaffold it: `lensmcp install`"),s(" (or `lensmcp setup` for the full install + trust bootstrap)."),s(" \u2022 Already have a differently-named target? `lensmcp gateway start --project <p> --target <t>`."),{exitCode:1};const j=ie(c);if(!j)return s("Could not find the `nx` binary in the workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};Be(c,u);const P=ns(u,"a"),_=ss(j,["run",`${$.project}:${$.target}`],{cwd:c,detached:!0,stdio:["ignore",P,P],env:{...process.env,...t.env??{}}});return _.unref(),_.pid&&Ke(a,_.pid),e(`gateway starting \u2192 ${$.project}:${$.target} (pid ${_.pid??"?"})`),e(` dashboard \u2192 ${f}`),e(` logs \u2192 ${u}`),e(" note: binding :443 needs privilege \u2014 if it fails, run the gateway target with sudo,"),e(" and run `nx run gateway:trust` once for the *.local hosts + TLS."),{exitCode:0}},"start"),v=l(()=>{if(x(h)&&V(c)===void 0){let j=d.key;try{j=JSON.parse(K(h,"utf8")).wsKey??d.key}catch{}const P=R("POST","/unregister",{wsKey:j});return J(h),e(P&&P.status===200?`unregistered '${j}' from the shared gateway daemon.`:"unregister sent (the daemon may already be gone)."),{exitCode:0}}J(h);const{pid:y,healed:N}=oe(a,c);if(y===void 0)return e("gateway not running."),J(a),{exitCode:0};N&&e(`healed: found an orphaned gateway (pid ${y}) the pid file had lost \u2014 stopping it.`),re(y);let g=!1;if(!ke(6e3)){g=!0,re(y,"SIGKILL");const j=V(c);if(j!==void 0)try{process.kill(j,"SIGKILL")}catch{}else G().length>0&&e(":443 is still held by a process that is not this workspace's gateway \u2014 leaving it alone.");ke(3e3)}const $=V(c);return $!==void 0&&$!==y&&(re($,"SIGKILL"),g=!0),J(a),g&&se(c,t.env,()=>{}),e(`gateway stopped (pid ${y})${g?" \u2014 forced (a child ignored SIGTERM)":""}.`),{exitCode:0}},"stop"),k=l(()=>{const{pid:y,healed:N}=oe(a,c),g=y!==void 0&&ne(y)?classifyAliveGateway({oursOn443:V(c)!==void 0,port443Held:G().length>0,pidFileAgeMs:ve(a)}):void 0,$=g==="serving"||g==="booting";if(i){const S=R("GET","/status"),L=S?.status===200&&S.json&&typeof S.json=="object"?S.json:null,B=x(h),Qt=$?"daemon":L&&B?"guest":L?"other":"stopped";return e(JSON.stringify({thisWorkspace:d.key,role:Qt,dashboardUrl:f,chooserUrl:"https://lensmcp.local/",logFile:u,daemonLogFile:(()=>{const fe=Se();return fe&&fe!==c?m(fe,".lensmcp","gateway.log"):u})(),mcp:je(c,t.env??process.env),daemon:L?.daemon??null,workspaces:L?.workspaces??[],services:L?.services??[]})),{exitCode:$||L&&B?0:1}}const j=R("GET","/list"),P=j?.status===200&&j.json&&typeof j.json=="object"?j.json.workspaces??[]:[],_=l(()=>{if(P.length!==0){e(` workspaces (${P.length} registered):`);for(const S of P)e(` \u2022 ${S.key} (${S.routes??0} routes, ${S.services??0} services)${S.key===d.key?" \u2190 this workspace":""}`)}},"printWorkspaces"),O=l(()=>{const S=je(c,t.env??process.env);e(S.mode==="shared"?` mcp \u2192 shared ${S.url} ${S.healthy?"(up)":`(DOWN \u2014 ${S.error??"no answer"})`}`:" mcp \u2192 stdio (one server per agent session)")},"printMcp"),D=l(()=>{const S=R("GET","/status"),L=S?.status===200&&S.json&&typeof S.json=="object"?S.json.daemon:void 0,B=Y(c);L?.version&&B&&L.version!==B&&e(` version \u2192 the daemon runs ${L.version} but this workspace depends on ${B} \u2014 \`lensmcp upgrade\` reconciles everything (or restart the daemon workspace's gateway).`)},"printVersionSkew");if($)return e(g==="booting"?`gateway: starting (pid ${y}) \u2014 :443 not bound yet`:`gateway: running (pid ${y}) \u2014 DAEMON on :443${N?" \u2014 recovered a stale pid file":""}`),e(` workspace \u2192 ${d.key}`),e(` dashboard \u2192 ${f}`),e(" chooser \u2192 https://lensmcp.local/"),e(` logs \u2192 ${u}`),O(),D(),_(),{exitCode:0};if(x(h)&&j?.status===200){const S=G()[0];e(`gateway: registered into a shared daemon${S!==void 0?` (pid ${S})`:""} \u2014 this workspace is a guest`),e(` workspace \u2192 ${d.key}`),e(` dashboard \u2192 ${f}`),e(` logs \u2192 ${u} (this workspace's pods)`);const L=Se();return L&&L!==c&&e(` ${m(L,".lensmcp","gateway.log")} (the daemon's own log \u2014 gateway-level lines land there)`),e(" attach \u2192 `lensmcp logs <service>` (live, from any workspace)"),e(" stop \u2192 `lensmcp gateway stop` (unregisters; the daemon keeps running)"),O(),D(),_(),{exitCode:0}}return g==="zombie"?(e(`gateway: NOT serving \u2014 tracked pid ${y} is alive but nothing holds :443 for this workspace`),e(" (a crashed gateway under a wedged nx wrapper) \u2014 run `lensmcp gateway restart` to recover."),e(` workspace \u2192 ${d.key}`),e(` logs \u2192 ${u}`),O(),_(),{exitCode:1}):(e("gateway: stopped"),e(` workspace \u2192 ${d.key}`),e(` dashboard \u2192 ${f}`),O(),{exitCode:1})},"status"),C=l(()=>{const y=R("GET","/status");if(y?.status!==200||!y.json||typeof y.json!="object")return e(i?JSON.stringify({daemon:null,workspaces:[],services:[]}):"gateway: no daemon answers on the control socket \u2014 nothing is hosted."),{exitCode:1};const N=y.json;if(i)return e(JSON.stringify(N)),{exitCode:0};e(`daemon: pid ${N.daemon?.pid??"?"} \xB7 owner ${N.daemon?.wsKey??"?"}${N.daemon?.version?` \xB7 lensmcp ${N.daemon.version}`:""}`);for(const g of N.workspaces??[]){e(` ${g.isDaemon?"\u2605":"\xB7"} ${g.key.padEnd(16)} ${String(g.routes??0).padStart(3)} routes ${String(g.services??0).padStart(3)} services ${g.root??""}`);for(const $ of(N.services??[]).filter(j=>(j.wsKey??N.daemon?.wsKey)===g.key))e(` ${$.project.padEnd(16)} ${($.state??"unknown").padEnd(9)} ${$.host??""}`)}return{exitCode:0}},"list");switch(r){case"start":return w();case"stop":return v();case"list":return C();case"restart":return v(),se(c,t.env,e),w();case"status":return k();default:return s(`Unknown gateway subcommand: ${r} (use start | stop | status | restart | list)`),{exitCode:2}}}p(me,"_e"),l(me,"runGateway");function se(t,n,e){const s=ie(t);if(!s){e(" (graph refresh skipped \u2014 no nx binary found in the workspace)");return}const o={...process.env,...n??{}},r=l(i=>T(s,i,{cwd:t,env:o,stdio:"ignore"}).status===0,"tryNx");if(r(["reset","--only-daemon"])||r(["daemon","--stop"])){e(" nx project graph refreshed \u2014 a lib/app added since boot will now resolve.");return}e(" (graph refresh best-effort failed \u2014 if a new project does not resolve, run `nx reset`)")}p(se,"re"),l(se,"refreshNxGraph");function we(t,n,e,s){if(e&&s)return{project:e,target:s};const o=W(t,r=>r==="project.json");for(const r of o){let i;try{i=JSON.parse(F(r))}catch{continue}const c=i.name??de(I(r));for(const[d,a]of Object.entries(i.targets??{}))if(a.executor===n)return{project:e??c,target:s??d}}}p(we,"Ie"),l(we,"scanExecutorTarget");function ct(t,n,e){return we(t,"@lensmcp/cluster:gateway",n,e)||(n||e?{project:n??"gateway",target:e??"serve"}:void 0)}p(ct,"dt"),l(ct,"findGatewayTarget");function dt(t,n,e){return we(t,"@lensmcp/cluster:trust",n,e)||(n?{project:n,target:e??"trust"}:lt(t,"gateway")?{project:"gateway",target:e??"trust"}:void 0)}p(dt,"lt"),l(dt,"findTrustTarget");function lt(t,n){for(const e of W(t,s=>s==="project.json"))try{if((JSON.parse(F(e)).name??de(I(e)))===n)return!0}catch{}return!1}p(lt,"pt"),l(lt,"projectExists");function ye(t){const n=ys(t);if(n)return vs(n.pid,n.stamp)?n.pid:void 0}p(ye,"De"),l(ye,"readPid");function ne(t){try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}p(ne,"oe"),l(ne,"isAlive");function G(){try{const t=T("lsof",["-nP","-iTCP:443","-sTCP:LISTEN","-t"],{encoding:"utf8"});return t.status!==0||!t.stdout?[]:[...new Set(t.stdout.split(/\s+/).map(Number).filter(n=>Number.isInteger(n)&&n>0))]}catch{return[]}}p(G,"H"),l(G,"pidsOnPort443");function ut(t){try{return(T("ps",["-o","command=","-p",String(t)],{encoding:"utf8"}).stdout??"").trim()}catch{return""}}p(ut,"ut"),l(ut,"processCmd");function V(t){const n=m(t,"node_modules","nx","dist","bin","run-executor.js"),e=m(t,"node_modules","@lensmcp","cluster");for(const s of G()){const o=ut(s);if(o.includes(n)||o.includes(e))return s}}p(V,"V"),l(V,"gatewayOnPort443");function ve(t){try{return Date.now()-Oe(t).mtimeMs}catch{return}}p(ve,"Fe"),l(ve,"pidFileAgeMs");const tn=18e4;export function classifyAliveGateway(t){if(t.oursOn443)return"serving";const n=t.pidFileAgeMs!==void 0&&t.pidFileAgeMs<(t.bootGraceMs??tn);return!t.port443Held&&n?"booting":"zombie"}p(classifyAliveGateway,"classifyAliveGateway"),l(classifyAliveGateway,"classifyAliveGateway");function oe(t,n){const e=ye(t);if(e!==void 0&&ne(e))return{pid:e,healed:!1};const s=V(n);if(s!==void 0){try{Ke(t,s)}catch{}return{pid:s,healed:!0}}return{healed:!1}}p(oe,"ie"),l(oe,"reconcileGateway");function re(t,n="SIGTERM"){try{process.kill(-t,n)}catch{try{process.kill(t,n)}catch{}}}p(re,"ae"),l(re,"killGatewayTree");function ke(t){const n=Date.now()+t;for(;;){if(G().length===0)return!0;if(Date.now()>=n)return!1;T("sleep",["0.15"])}}p(ke,"Ke"),l(ke,"waitForPortFree");function pt(t){const n=T("curl",["-s","-o","/dev/null","-m","8","-w","%{ssl_verify_result}",`https://${t}/`],{encoding:"utf8"}),e=(n.stdout??"").trim();return n.status===0&&e==="0"?"trusted":e&&e!=="0"?"untrusted":"unknown"}p(pt,"gt"),l(pt,"probeHostTrust");function gt(t){for(const n of W(t,e=>e==="project.json"))try{const e=JSON.parse(K(n,"utf8")),s=(e.cluster??e.davnx)?.host;if(s&&!s.includes("*"))return s}catch{}}p(gt,"ht"),l(gt,"firstClusterHost");function J(t){try{rs(t,{force:!0})}catch{}}p(J,"W"),l(J,"rmFile");function ht(t,n,e,s){const o=A(n,{string:["--cwd","--host","--port"]}),r=M(b(o.flags["--cwd"])??t.cwd),i=q(r),c=b(o.flags["--host"])??t.env?.LENSMCP_WS_HOST??process.env.LENSMCP_WS_HOST,d=b(o.flags["--port"])??t.env?.LENSMCP_WS_PORT??process.env.LENSMCP_WS_PORT??String(i.ports.bridge),a=Ht(r);if(!a)return s(`Could not locate the lensmcp bridge bundle.
|
|
204
|
+
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};ae(r);const u=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl");return e(`lensmcp dashboard \u2192 http://localhost:${c}${l||"/"} (reading ${u})`),{exitCode:M(process.execPath,[a],{cwd:r,stdio:"inherit",env:{...process.env,...t.env??{},LENSMCP_DASHBOARD_PORT:c,LENSMCP_DASHBOARD_BASE:l,LENSMCP_EVENT_FILE:u}}).status??1}}p(at,"lt"),d(at,"runDashboard");function ct(){return m(process.env.LENSMCP_HOME||ds(),".lensmcp","control.sock")}p(ct,"pt"),d(ct,"controlSocketPath");function A(t,n,e){const s=ct();if(!S(s))return null;const o=["-s","-o","-","-w",`
|
|
205
|
+
%{http_code}`,"--unix-socket",s,"-X",t,`http://localhost${n}`];e!==void 0&&o.push("-H","content-type: application/json","-d",JSON.stringify(e));const r=M("curl",o,{encoding:"utf8",timeout:5e3});if(r.status!==0||typeof r.stdout!="string"||r.stdout.length===0)return null;const i=r.stdout.split(`
|
|
206
|
+
`),c=Number(i.pop());let l=null;try{const a=i.join(`
|
|
207
|
+
`).trim();l=a?JSON.parse(a):null}catch{}return Number.isFinite(c)?{status:c,json:l}:null}p(A,"A"),d(A,"daemonRequest");function lt(){const t=A("GET","/status");if(t?.status!==200||!t.json||typeof t.json!="object")return;const n=t.json.daemon;return typeof n?.wsKey=="string"&&n.wsKey.length>0?n.wsKey:void 0}p(lt,"ut"),d(lt,"daemonWsKey");function dt(t){const n={};for(const e of U(t,s=>s==="project.json"))try{const s=JSON.parse(V(e,"utf8")),o=_(e);n[s.name??le(o)]={root:Ie(t,o)||"."}}catch{}return n}p(dt,"ft"),d(dt,"buildProjectsMap");function ut(t){const n=m(t,"node_modules",".bin",process.platform==="win32"?"nx.cmd":"nx");if(!S(n))return;const e=M(n,["graph","--print"],{cwd:t,encoding:"utf8",timeout:15e3,maxBuffer:32*1024*1024});if(!(e.status!==0||typeof e.stdout!="string"))try{const s=JSON.parse(e.stdout).graph?.dependencies;return s?Object.fromEntries(Object.entries(s).map(([o,r])=>[o,r.flatMap(i=>typeof i.target=="string"?[i.target]:[])])):void 0}catch{return}}p(ut,"gt"),d(ut,"buildProjectDependencies");function pe(t,n){const e=ut(t);return{wsKey:n,root:t,projects:dt(t),...e?{projectDependencies:e}:{}}}p(pe,"ue"),d(pe,"gatewayRegistrationBody");function we(t,n,e,s){const o=I(n,{string:["--cwd","--project","--target"]}),r=(o.positional[0]??"status").toLowerCase(),i=n.includes("--json"),c=L(b(o.flags["--cwd"])??t.cwd),l=z(c),a=m(c,".lensmcp","gateway.pid"),u=m(c,".lensmcp","gateway.log"),h=m(c,".lensmcp","registered.json"),f=`https://lensmcp.local${l.dashboardBasePath}/`,w=d(()=>{const{pid:v,healed:E}=oe(a,c);if(v!==void 0&&ne(v)){const O=classifyAliveGateway({oursOn443:B(c)!==void 0,port443Held:H().length>0,pidFileAgeMs:ke(a)});if(O==="serving")return E&&e(`healed: adopted a running gateway (pid ${v}) the pid file had lost \u2014 no duplicate started.`),e(`gateway already running (pid ${v}).`),e(` dashboard \u2192 ${f}`),{exitCode:0};if(O==="booting")return e(`gateway starting (pid ${v}) \u2014 :443 not bound yet.`),e(` dashboard \u2192 ${f}`),e(` logs \u2192 ${u}`),{exitCode:0};re(v,"SIGKILL"),W(a),se(c,t.env,()=>{}),e(`reaped a dead gateway (pid ${v} was alive but nothing served :443 for this workspace).`)}const g=H()[0];if(g!==void 0){const O=A("GET","/list");if(O!==null){const F=O.status===200&&O.json&&typeof O.json=="object"?O.json.workspaces??[]:[],j=ze(F,l.key,c);if(j.kind==="other-checkout"){for(const K of qe(l.key,j.root,c))s(K);return{exitCode:1}}if(j.kind==="mine")return Z(_(h),{recursive:!0}),q(h,JSON.stringify({wsKey:l.key})),e(`already registered into the shared gateway daemon (pid ${g}).`),e(` dashboard \u2192 ${f}`),{exitCode:0};const P=A("POST","/register",pe(c,l.key));return P&&P.status===200?(Z(_(h),{recursive:!0}),q(h,JSON.stringify({wsKey:l.key})),e(`registered '${l.key}' into the shared gateway daemon (pid ${g}).`),e(` dashboard \u2192 ${f}`),e(" the daemon hosts this workspace's services + dashboard; `lensmcp gateway stop` unregisters."),{exitCode:0}):(s(`failed to register into the gateway daemon: ${de(P)??(P?JSON.stringify(P.json):"no response from the control socket")}`),{exitCode:1})}return s(`port :443 is held by pid ${g}, which is not this workspace's gateway.
|
|
208
|
+
Free it first (stop that process), then \`lensmcp gateway start\`.`),{exitCode:1}}const y=pt(c,b(o.flags["--project"]),b(o.flags["--target"]));if(!y)return s(`This workspace ('${l.key}') has no gateway target \u2014 no project declares the`),s("`@lensmcp/cluster:gateway` executor, so there is nothing here to launch on :443."),s(""),s(" \u2022 Joining a shared gateway? Start it in the workspace that OWNS it, then run"),s(" `lensmcp gateway start` here \u2014 this workspace registers into it (no local target needed)."),s(" \u2022 Should this workspace host its own gateway? Scaffold it: `lensmcp install`"),s(" (or `lensmcp setup` for the full install + trust bootstrap)."),s(" \u2022 Already have a differently-named target? `lensmcp gateway start --project <p> --target <t>`."),{exitCode:1};const x=ie(c);if(!x)return s("Could not find the `nx` binary in the workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};Je(c,u);const N=as(u,"a"),R=is(x,["run",`${y.project}:${y.target}`],{cwd:c,detached:!0,stdio:["ignore",N,N],env:{...process.env,...t.env??{}}});return R.unref(),R.pid&&Ge(a,R.pid),e(`gateway starting \u2192 ${y.project}:${y.target} (pid ${R.pid??"?"})`),e(` dashboard \u2192 ${f}`),e(` logs \u2192 ${u}`),e(" note: binding :443 needs privilege \u2014 if it fails, run the gateway target with sudo,"),e(" and run `nx run gateway:trust` once for the *.local hosts + TLS."),{exitCode:0}},"start"),k=d(()=>{if(S(h)&&B(c)===void 0){let x=l.key;try{x=JSON.parse(V(h,"utf8")).wsKey??l.key}catch{}const N=A("POST","/unregister",{wsKey:x,root:c});W(h);const R=de(N);return e(R??(N&&N.status===200?`unregistered '${x}' from the shared gateway daemon.`:"unregister sent (the daemon may already be gone).")),{exitCode:0}}W(h);const{pid:v,healed:E}=oe(a,c);if(v===void 0)return e("gateway not running."),W(a),{exitCode:0};E&&e(`healed: found an orphaned gateway (pid ${v}) the pid file had lost \u2014 stopping it.`),re(v);let g=!1;if(!$e(6e3)){g=!0,re(v,"SIGKILL");const x=B(c);if(x!==void 0)try{process.kill(x,"SIGKILL")}catch{}else H().length>0&&e(":443 is still held by a process that is not this workspace's gateway \u2014 leaving it alone.");$e(3e3)}const y=B(c);return y!==void 0&&y!==v&&(re(y,"SIGKILL"),g=!0),W(a),g&&se(c,t.env,()=>{}),e(`gateway stopped (pid ${v})${g?" \u2014 forced (a child ignored SIGTERM)":""}.`),{exitCode:0}},"stop"),$=d(()=>{const{pid:v,healed:E}=oe(a,c),g=v!==void 0&&ne(v)?classifyAliveGateway({oursOn443:B(c)!==void 0,port443Held:H().length>0,pidFileAgeMs:ke(a)}):void 0,y=g==="serving"||g==="booting";if(i){const j=A("GET","/status"),P=j?.status===200&&j.json&&typeof j.json=="object"?j.json:null,K=S(h),ns=y?"daemon":P&&K?"guest":P?"other":"stopped";return e(JSON.stringify({thisWorkspace:l.key,role:ns,dashboardUrl:f,chooserUrl:"https://lensmcp.local/",logFile:u,daemonLogFile:(()=>{const me=je();return me&&me!==c?m(me,".lensmcp","gateway.log"):u})(),mcp:Ne(c,t.env??process.env),daemon:P?.daemon??null,workspaces:P?.workspaces??[],services:P?.services??[]})),{exitCode:y||P&&K?0:1}}const x=A("GET","/list"),N=x?.status===200&&x.json&&typeof x.json=="object"?x.json.workspaces??[]:[],R=d(()=>{if(N.length!==0){e(` workspaces (${N.length} registered):`);for(const j of N)e(` \u2022 ${j.key} (${j.routes??0} routes, ${j.services??0} services)${j.key===l.key?" \u2190 this workspace":""}`)}},"printWorkspaces"),O=d(()=>{const j=Ne(c,t.env??process.env);e(j.mode==="shared"?` mcp \u2192 shared ${j.url} ${j.healthy?"(up)":`(DOWN \u2014 ${j.error??"no answer"})`}`:" mcp \u2192 stdio (one server per agent session)")},"printMcp"),F=d(()=>{const j=A("GET","/status"),P=j?.status===200&&j.json&&typeof j.json=="object"?j.json.daemon:void 0,K=G(c);P?.version&&K&&P.version!==K&&e(` version \u2192 the daemon runs ${P.version} but this workspace depends on ${K} \u2014 \`lensmcp upgrade\` reconciles everything (or restart the daemon workspace's gateway).`)},"printVersionSkew");if(y)return e(g==="booting"?`gateway: starting (pid ${v}) \u2014 :443 not bound yet`:`gateway: running (pid ${v}) \u2014 DAEMON on :443${E?" \u2014 recovered a stale pid file":""}`),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${f}`),e(" chooser \u2192 https://lensmcp.local/"),e(` logs \u2192 ${u}`),O(),F(),R(),{exitCode:0};if(S(h)&&x?.status===200){const j=H()[0];e(`gateway: registered into a shared daemon${j!==void 0?` (pid ${j})`:""} \u2014 this workspace is a guest`),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${f}`),e(` logs \u2192 ${u} (this workspace's pods)`);const P=je();return P&&P!==c&&e(` ${m(P,".lensmcp","gateway.log")} (the daemon's own log \u2014 gateway-level lines land there)`),e(" attach \u2192 `lensmcp logs <service>` (live, from any workspace)"),e(" stop \u2192 `lensmcp gateway stop` (unregisters; the daemon keeps running)"),O(),F(),R(),{exitCode:0}}return g==="zombie"?(e(`gateway: NOT serving \u2014 tracked pid ${v} is alive but nothing holds :443 for this workspace`),e(" (a crashed gateway under a wedged nx wrapper) \u2014 run `lensmcp gateway restart` to recover."),e(` workspace \u2192 ${l.key}`),e(` logs \u2192 ${u}`),O(),R(),{exitCode:1}):(e("gateway: stopped"),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${f}`),O(),{exitCode:1})},"status"),C=d(()=>{const v=A("GET","/status");if(v?.status!==200||!v.json||typeof v.json!="object")return e(i?JSON.stringify({daemon:null,workspaces:[],services:[]}):"gateway: no daemon answers on the control socket \u2014 nothing is hosted."),{exitCode:1};const E=v.json;if(i)return e(JSON.stringify(E)),{exitCode:0};e(`daemon: pid ${E.daemon?.pid??"?"} \xB7 owner ${E.daemon?.wsKey??"?"}${E.daemon?.version?` \xB7 lensmcp ${E.daemon.version}`:""}`);for(const g of E.workspaces??[]){e(` ${g.isDaemon?"\u2605":"\xB7"} ${g.key.padEnd(16)} ${String(g.routes??0).padStart(3)} routes ${String(g.services??0).padStart(3)} services ${g.root??""}`);for(const y of(E.services??[]).filter(x=>(x.wsKey??E.daemon?.wsKey)===g.key))e(` ${y.project.padEnd(16)} ${(y.state??"unknown").padEnd(9)} ${y.host??""}`)}return{exitCode:0}},"list");switch(r){case"start":return w();case"stop":return k();case"list":return C();case"restart":return k(),se(c,t.env,e),w();case"status":return $();default:return s(`Unknown gateway subcommand: ${r} (use start | stop | status | restart | list)`),{exitCode:2}}}p(we,"Ke"),d(we,"runGateway");function se(t,n,e){const s=ie(t);if(!s){e(" (graph refresh skipped \u2014 no nx binary found in the workspace)");return}const o={...process.env,...n??{}},r=d(i=>M(s,i,{cwd:t,env:o,stdio:"ignore"}).status===0,"tryNx");if(r(["reset","--only-daemon"])||r(["daemon","--stop"])){e(" nx project graph refreshed \u2014 a lib/app added since boot will now resolve.");return}e(" (graph refresh best-effort failed \u2014 if a new project does not resolve, run `nx reset`)")}p(se,"oe"),d(se,"refreshNxGraph");function ye(t,n,e,s){if(e&&s)return{project:e,target:s};const o=U(t,r=>r==="project.json");for(const r of o){let i;try{i=JSON.parse(D(r))}catch{continue}const c=i.name??le(_(r));for(const[l,a]of Object.entries(i.targets??{}))if(a.executor===n)return{project:e??c,target:s??l}}}p(ye,"Ge"),d(ye,"scanExecutorTarget");function pt(t,n,e){return ye(t,"@lensmcp/cluster:gateway",n,e)||(n||e?{project:n??"gateway",target:e??"serve"}:void 0)}p(pt,"ht"),d(pt,"findGatewayTarget");function gt(t,n,e){return ye(t,"@lensmcp/cluster:trust",n,e)||(n?{project:n,target:e??"trust"}:ht(t,"gateway")?{project:"gateway",target:e??"trust"}:void 0)}p(gt,"mt"),d(gt,"findTrustTarget");function ht(t,n){for(const e of U(t,s=>s==="project.json"))try{if((JSON.parse(D(e)).name??le(_(e)))===n)return!0}catch{}return!1}p(ht,"wt"),d(ht,"projectExists");function ve(t){const n=bs(t);if(n)return Cs(n.pid,n.stamp)?n.pid:void 0}p(ve,"He"),d(ve,"readPid");function ne(t){try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}p(ne,"ie"),d(ne,"isAlive");function H(){try{const t=M("lsof",["-nP","-iTCP:443","-sTCP:LISTEN","-t"],{encoding:"utf8"});return t.status!==0||!t.stdout?[]:[...new Set(t.stdout.split(/\s+/).map(Number).filter(n=>Number.isInteger(n)&&n>0))]}catch{return[]}}p(H,"V"),d(H,"pidsOnPort443");function ft(t){try{return(M("ps",["-o","command=","-p",String(t)],{encoding:"utf8"}).stdout??"").trim()}catch{return""}}p(ft,"yt"),d(ft,"processCmd");function B(t){const n=m(t,"node_modules","nx","dist","bin","run-executor.js"),e=m(t,"node_modules","@lensmcp","cluster");for(const s of H()){const o=ft(s);if(o.includes(n)||o.includes(e))return s}}p(B,"B"),d(B,"gatewayOnPort443");function ke(t){try{return Date.now()-Re(t).mtimeMs}catch{return}}p(ke,"Ve"),d(ke,"pidFileAgeMs");const cn=18e4;export function classifyAliveGateway(t){if(t.oursOn443)return"serving";const n=t.pidFileAgeMs!==void 0&&t.pidFileAgeMs<(t.bootGraceMs??cn);return!t.port443Held&&n?"booting":"zombie"}p(classifyAliveGateway,"classifyAliveGateway"),d(classifyAliveGateway,"classifyAliveGateway");function oe(t,n){const e=ve(t);if(e!==void 0&&ne(e))return{pid:e,healed:!1};const s=B(n);if(s!==void 0){try{Ge(t,s)}catch{}return{pid:s,healed:!0}}return{healed:!1}}p(oe,"ae"),d(oe,"reconcileGateway");function re(t,n="SIGTERM"){try{process.kill(-t,n)}catch{try{process.kill(t,n)}catch{}}}p(re,"ce"),d(re,"killGatewayTree");function $e(t){const n=Date.now()+t;for(;;){if(H().length===0)return!0;if(Date.now()>=n)return!1;M("sleep",["0.15"])}}p($e,"Be"),d($e,"waitForPortFree");function mt(t){const n=M("curl",["-s","-o","/dev/null","-m","8","-w","%{ssl_verify_result}",`https://${t}/`],{encoding:"utf8"}),e=(n.stdout??"").trim();return n.status===0&&e==="0"?"trusted":e&&e!=="0"?"untrusted":"unknown"}p(mt,"kt"),d(mt,"probeHostTrust");function wt(t){for(const n of U(t,e=>e==="project.json"))try{const e=JSON.parse(V(n,"utf8")),s=(e.cluster??e.davnx)?.host;if(s&&!s.includes("*"))return s}catch{}}p(wt,"$t"),d(wt,"firstClusterHost");function W(t){try{ls(t,{force:!0})}catch{}}p(W,"U"),d(W,"rmFile");function yt(t,n,e,s){const o=I(n,{string:["--cwd","--host","--port"]}),r=L(b(o.flags["--cwd"])??t.cwd),i=z(r),c=b(o.flags["--host"])??t.env?.LENSMCP_WS_HOST??process.env.LENSMCP_WS_HOST,l=b(o.flags["--port"])??t.env?.LENSMCP_WS_PORT??process.env.LENSMCP_WS_PORT??String(i.ports.bridge),a=Ut(r);if(!a)return s(`Could not locate the lensmcp bridge bundle.
|
|
209
209
|
Looked in (in order):
|
|
210
210
|
\u2022 <cli-package>/bundled/bridge.js (published bin)
|
|
211
211
|
\u2022 <workspace>/libs/bridge/dist/main.js (dev build)
|
|
212
|
-
For dev: \`yarn nx build @lensmcp/bridge\`.`),{exitCode:1};ae(r);const u=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl"),h={...process.env,...t.env??{},LENSMCP_EVENT_FILE:u};return c&&(h.LENSMCP_WS_HOST=c),
|
|
212
|
+
For dev: \`yarn nx build @lensmcp/bridge\`.`),{exitCode:1};ae(r);const u=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(r,".lensmcp","events.jsonl"),h={...process.env,...t.env??{},LENSMCP_EVENT_FILE:u};return c&&(h.LENSMCP_WS_HOST=c),l&&(h.LENSMCP_WS_PORT=l),e(`lensmcp bridge \u2192 ws://${c??"127.0.0.1"}:${l??"5747"} (forwarding to ${u})`),{exitCode:M(process.execPath,[a],{cwd:r,stdio:"inherit",env:h}).status??1}}p(yt,"bt"),d(yt,"runBridge");async function vt(t,n,e,s){const o=Fs(n);if("error"in o)return s(`lensmcp dismiss: ${o.error}`),s(Ds),{exitCode:2};const r=L(o.cwd??t.cwd),i={...process.env,...t.env??{}},c=await Ks(o,{session:d(l=>_s({cwd:r,env:i,budgetMs:8e3,clientName:"lensmcp-dismiss"},l),"session")});for(const l of c.lines)(c.exitCode===2?s:e)(l);return{exitCode:c.exitCode}}p(vt,"Ct"),d(vt,"runDismiss");function kt(t,n,e){const s=ys(n),o=L(s.cwd??t.cwd),r=qt(o);if(!r)return e(`Could not locate the lensmcp lint runner.
|
|
213
213
|
Looked in (in order):
|
|
214
214
|
\u2022 <cli-package>/bundled/lint-runner.js (published bin)
|
|
215
215
|
\u2022 <workspace>/libs/session/dist/lint-runner.js (dev build)
|
|
216
|
-
For dev: \`yarn nx build @lensmcp/session\`.`),{exitCode:2};const i=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(o,".lensmcp","events.jsonl");return{exitCode:
|
|
217
|
-
`)}catch{}}p(wt,"vt"),l(wt,"writeSetupState");async function yt(t,n,e,s){const o=Ge(n)?n:te(t,e).mode,r=Ss(t,o);if(s(""),s(`[mcp] mode \u2192 ${o}`),r.wrote&&s(` wrote ${Cs}`),o==="embedded"){s(" every agent session builds its OWN MCP server, and keeps serving"),s(" the bundle it started with until that session exits."),s(" one shared server for the workspace: `lensmcp setup --mcp shared`");return}s(` sessions proxy into ONE shared server at ${r.url}`),s(" .mcp.json is unchanged \u2014 `lensmcp mcp` becomes a thin stdio shim.");const i=await He(r.url);if(!i.ok){s(` \xB7 not up yet (${i.error??"unknown"}) \u2014 the next session starts it on demand`);return}const c=Y(t)??X(),d=Ie({identity:Ve(r.port),targetVersion:c,expectedRoot:Pe(t),expectedKey:q(t).key,selfPid:process.pid});if(!d.kill){s(` \u2713 already up \u2014 ${i.server??"MCP"} (protocol ${i.protocolVersion??"?"}) \u2014 ${d.reason}`);return}try{process.kill(d.pid,"SIGTERM"),s(` \u21BA restarted the shared server \u2014 it was ${d.reason}; the next session brings it up on ${c}`)}catch(a){s(` ! the shared server is ${d.reason} and could not be stopped (pid ${d.pid}): ${a.message}`)}}p(yt,"kt"),l(yt,"applyMcpModeStep");function vt(t,n,e){const s=Ye({cwd:t,cliVersion:X()}),o=Fs({run:Ds(n),facts:s});if(!(o.outcome==="current"||o.outcome==="unknown")){if(e(""),o.outcome==="updated"){e(`[plugin] ${o.from} \u2192 ${o.to}`),e(" restart Claude Code for the new plugin to load.");return}e(`[plugin] the Claude Code plugin is ${o.from}, this lensmcp is ${o.to}.`),e(` could not update it automatically (${o.detail??"unknown reason"}). Run:`);for(const r of o.commands??[])e(` ${r}`);e(" \u2026then restart Claude Code.")}}p(vt,"bt"),l(vt,"applyPluginSyncStep");async function kt(t,n,e,s){const o=A(n,{string:["--cwd","--mcp"],boolean:["--no-recycle"]}),r=M(b(o.flags["--cwd"])??t.cwd),i={...t,cwd:r},c=b(o.flags["--mcp"]);if(c!==void 0&&!Ge(c))return s(`setup: --mcp must be "embedded" or "shared" (got "${c}").`),{exitCode:1};e("lensmcp setup \u2014 first-time bootstrap (install \u2192 trust \u2192 pods)"),e(""),e("[1/3] install \u2014 plugin, .mcp.json, nx config, vite/nest wiring");const d=$e(i,n,e,s);if(d.exitCode!==0)return s(""),s("setup: the install step failed \u2014 fix the above and re-run `lensmcp setup`."),d;e(""),e("[2/3] trust \u2014 dev CA \u2192 System keychain, /etc/hosts, DNS flush (sudo)");const a=be(i,n,e,s);if(a.exitCode!==0)return s(""),s("setup: the trust step failed \u2014 run `lensmcp setup` directly in a terminal so sudo can prompt."),a;e(""),e("[3/3] pods \u2014 recycle this workspace's devservers, reconcile the gateway");const u=q(r).key,h=fs({previous:xe(r),current:Ce(r),disabled:o.flags["--no-recycle"]===!0}),f=h.recycle?zt(r,u,e,h.reason):(e(` \xB7 pods left running \u2014 ${h.reason}`),{killed:0,stale:0});Yt(i,r,u,e),await yt(r,c,t.env??process.env,e);try{vt(r,{...process.env,...t.env??{}},e)}catch{}return wt(r,h.recycle),e(""),e("\u2713 setup complete."),(f.killed>0||f.stale>0)&&e(` recycled ${f.killed} pod${f.killed===1?"":"s"}`+(f.stale>0?` (+${f.stale} stale socket${f.stale===1?"":"s"} cleared)`:"")+" \u2014 they come back on the new wiring."),e(" next: lensmcp gateway start (the :443 front door \u2014 needs sudo)"),e(" verify: lensmcp doctor"),{exitCode:0}}p(kt,"$t"),l(kt,"runSetup");async function $t(t,n,e){const s=A(n,{string:["--cwd","--hook","--timeout","--session"],boolean:["--json","--quiet"]}),o=M(b(s.flags["--cwd"])??t.cwd),r=b(s.flags["--hook"]),i=We(r)?r:void 0,c=b(s.flags["--session"]);if(r!==void 0&&i===void 0)return{exitCode:0};const d=s.flags["--json"]===!0,a=s.flags["--quiet"]===!0||r!==void 0,u=Number(b(s.flags["--timeout"])??""),h=Number.isFinite(u)&&u>0?u:Ms,f={...process.env,...t.env??{}};try{const w=await Ls({cwd:o,env:f,budgetMs:h,verify:l(C=>js(C).map(y=>y.resource),"verify")});if(!w.available)return d&&!a?e(JSON.stringify({available:!1,workspace:w.source.workspace,mode:w.source.mode,reason:w.reason,elapsedMs:w.elapsedMs})):a||e(`lensmcp status \u2014 ${w.source.workspace}: unavailable (${w.reason})`),{exitCode:0};const v=Ts(w.status,w.evidence,Date.now()),k=Es(v,{workspace:w.source.workspace,includeUnmonitored:i==="SessionStart"||!a});if(d)return a&&k===void 0?{exitCode:0}:(e(JSON.stringify({available:!0,workspace:w.source.workspace,mode:w.source.mode,url:w.source.url,aggregate:w.status.status??"unknown",elapsedMs:w.elapsedMs,findings:v.findings,suppressed:v.suppressed,unmonitored:v.unmonitored})),{exitCode:0});if(i){const C=Ps(v.findings);return $s(c,C)?(k!==void 0&&e(Je(i,k)),c&&ks(c,C),{exitCode:0}):{exitCode:0}}if(a)return k!==void 0&&e(k),{exitCode:0};if(e(`lensmcp status \u2014 ${w.source.workspace} (${w.source.mode}, ${w.source.url})`),e(` aggregate says: ${w.status.status??"unknown"} (read in ${w.elapsedMs}ms)`),v.findings.length===0)e(" nothing actionable that this command can vouch for.");else for(const C of v.findings)e(` \u2022 ${Ns(C)}`);for(const C of v.suppressed)e(` \xB7 not reported \u2014 ${C.kind}: ${C.reason}`);return v.unmonitored.length>0&&e(` \xB7 unmonitored (unknown, NOT clean): ${v.unmonitored.join(", ")}`),{exitCode:0}}catch(w){return a||e(`lensmcp status: unavailable (${w instanceof Error?w.message:String(w)})`),{exitCode:0}}}p($t,"Ct"),l($t,"runStatus");function bt(t,n,e){const s=A(n,{string:["--cwd","--hook","--plugin-root"],boolean:["--json","--quiet"]}),o=M(b(s.flags["--cwd"])??t.cwd),r=b(s.flags["--hook"]),i=We(r)?r:void 0;if(r!==void 0&&i===void 0)return{exitCode:0};const c=s.flags["--json"]===!0,d=s.flags["--quiet"]===!0||r!==void 0,a=b(s.flags["--plugin-root"]);try{const u=Ye({cwd:o,cliVersion:X(),...a?{pluginRoot:a}:{}}),h=_s(u);if(c)return d&&!h?{exitCode:0}:(e(JSON.stringify({...u,skew:h??null})),{exitCode:0});if(i)return h&&e(Je(i,Ue(h))),{exitCode:0};if(d)return h&&e(Ue(h)),{exitCode:0};if(e(`lensmcp version-check \u2014 ${u.pluginId??"lensmcp plugin"}`),e(` plugin ${u.plugin??"unknown"}${u.pluginSource?` (${u.pluginSource})`:""}`),e(` project ${u.project??"unknown"} (node_modules/lensmcp)`),e(` cli ${u.cli??"unknown"} (the binary running now)`),!h)return e(u.plugin&&(u.project??u.cli)?" \u2713 in step.":" ? cannot compare \u2014 one of the versions is unreadable (staying silent)."),{exitCode:0};e(` \u2717 the plugin is ${h.direction} \u2014 update it, then restart Claude Code:`);for(const f of Ks(h))e(` ${f}`);return{exitCode:0}}catch(u){return d||e(`lensmcp version-check: unavailable (${u instanceof Error?u.message:String(u)})`),{exitCode:0}}}p(bt,"St"),l(bt,"runVersionCheck");async function Ct(t,n,e){const s=A(n,{string:["--cwd"],boolean:["--json"]}),o=M(b(s.flags["--cwd"])??t.cwd),r=s.flags["--json"]===!0,i=[];xt(i),St(o,i),jt(o,i),Nt(o,t.env??process.env,i),await Pt(o,t.env??process.env,i),Et(o,i),Tt(o,i),Mt(o,i),Lt(i);const c=i.some(a=>a.status==="fail"),d=i.some(a=>a.status==="warn");if(r)return e(JSON.stringify({ok:!c,summary:{total:i.length,failed:i.filter(a=>a.status==="fail").length,warnings:i.filter(a=>a.status==="warn").length},checks:i},null,2)),{exitCode:c?1:0};for(const a of i){const u=a.status==="pass"?"\u2713":a.status==="warn"?"!":"\u2717";e(`${u} ${a.label}${a.detail?` \u2014 ${a.detail}`:""}`),a.status!=="pass"&&a.hint&&e(` \u21B3 ${a.hint}`)}return e(""),e(c?"doctor: issues found (see \u2717 above).":d?"doctor: ok, with warnings (!).":"doctor: all checks passed."),{exitCode:c?1:0}}p(Ct,"jt"),l(Ct,"runDoctor");function E(t,n,e,s,o){t.push({status:n,label:e,detail:s,hint:o})}p(E,"M"),l(E,"add");function xt(t){const n=Number(process.versions.node.split(".")[0]);n>=20?E(t,"pass",`Node ${process.versions.node}`):n>=18?E(t,"warn",`Node ${process.versions.node}`,"older than recommended","upgrade to Node 20+ for best results"):E(t,"fail",`Node ${process.versions.node}`,"too old","LensMCP needs Node 18+ (20+ recommended)")}p(xt,"xt"),l(xt,"checkNode");function St(t,n){const e=m(t,"nx.json");if(!x(e)){E(n,"fail","nx.json at workspace root","missing","run `lensmcp` from inside a Nx workspace");return}let s;try{s=JSON.parse(K(e,"utf8"))}catch(r){E(n,"fail","nx.json parses",r.message,"fix the JSON syntax in nx.json");return}const o=(s.plugins??[]).some(r=>typeof r=="string"?r==="@lensmcp/nx-plugin":!!r&&typeof r=="object"&&r.plugin==="@lensmcp/nx-plugin");E(n,o?"pass":"fail","@lensmcp/nx-plugin registered in nx.json#plugins",o?void 0:"not registered",o?void 0:"run `lensmcp install`"),E(n,s.lensmcp?.schemaVersion===1?"pass":"warn","lensmcp config block in nx.json",s.lensmcp?.schemaVersion===1?void 0:"missing",s.lensmcp?.schemaVersion===1?void 0:"run `lensmcp install` to write the config defaults")}p(St,"Nt"),l(St,"checkWorkspace");function jt(t,n){const e=m(t,".mcp.json");if(!x(e)){E(n,"warn",".mcp.json with a lensmcp server","missing","run `lensmcp install` so agents auto-discover the MCP server");return}try{const s=JSON.parse(K(e,"utf8")),o=!!s.mcpServers&&!!s.mcpServers.lensmcp;E(n,o?"pass":"warn",".mcp.json registers the lensmcp MCP server",o?void 0:"no lensmcp entry",o?void 0:"run `lensmcp install`")}catch(s){E(n,"warn",".mcp.json parses",s.message,"fix the JSON syntax in .mcp.json")}}p(jt,"Pt"),l(jt,"checkMcpConfig");function Nt(t,n,e){const s=z(m(t,".claude","settings.json")),o=z(m(t,".claude","settings.local.json")),r=Ze({cwd:t}),i=r?z(m(r.root,"plugin",".mcp.json")):void 0,c=De(i),d=ze(),a=Fe(s,Q)||Fe(o,Q)||d.some(h=>h.scope==="user"||h.projectPath===t),u=ws({workspaceServers:De(z(m(t,".mcp.json"))),pluginServers:c,pluginEnabled:a,pluginReadable:i!==void 0,disabledServers:[..._e(s),..._e(o)],sharedMcp:te(t,n).mode==="shared"});E(e,u.duplicated||u.indeterminate?"warn":"pass","the MCP server is registered exactly once",u.duplicated||u.indeterminate?u.detail:void 0,u.duplicated||u.indeterminate?u.hint:void 0)}p(Nt,"Et"),l(Nt,"checkDuplicateRegistration");function Se(){const t=R("GET","/status");if(!t||t.status!==200)return;const n=t.json?.daemon,e=t.json?.workspaces;if(!(!n?.wsKey||!Array.isArray(e)))return e.find(s=>s.key===n.wsKey)?.root}p(Se,"Je"),l(Se,"daemonOwnerRoot");function z(t){try{return JSON.parse(K(t,"utf8"))}catch{return}}p(z,"Y"),l(z,"readJsonFile");async function Pt(t,n,e){const s=te(t,n);if(E(e,"pass","MCP mode",s.mode==="shared"?`shared \u2014 sessions proxy into ${s.url}`:"embedded \u2014 one MCP server per agent session",s.mode==="shared"?void 0:"one shared server: `lensmcp setup --mcp shared`"),s.mode!=="shared")return;const o=await He(s.url);E(e,o.ok?"pass":"warn","shared MCP server",o.ok?`${o.server??"MCP"} @ ${s.url} (protocol ${o.protocolVersion??"?"})`:`not running at ${s.url} \u2014 ${o.error??"no answer"}`,o.ok?void 0:"the next agent session starts it on demand; `lensmcp gateway start` starts it now")}p(Pt,"Tt"),l(Pt,"checkMcpMode");function je(t,n){const e=te(t,n);if(e.mode!=="shared")return{mode:e.mode,url:e.url,port:e.port,healthy:!1};const s=xs(e.url);return{mode:e.mode,url:e.url,port:e.port,healthy:s.ok,...s.server?{server:s.server}:{},...s.error?{error:s.error}:{}}}p(je,"We"),l(je,"mcpStatusBlock");function Et(t,n){const e=pe(t);E(n,e?"pass":"fail","lensmcp-mcp server bundle reachable",e??"missing",e?void 0:"dev: `yarn nx build @lensmcp/lensmcp-mcp`")}p(Et,"Mt"),l(Et,"checkServerBundle");function Tt(t,n){const e=m(t,".lensmcp");E(n,x(e)?"pass":"warn",".lensmcp/ runtime directory",x(e)?void 0:"not created yet",x(e)?void 0:"created automatically on first `lensmcp mcp` run");const s=m(t,".gitignore"),o=(x(s)?F(s):"").split(`
|
|
218
|
-
`).some(r=>r.trim()===".lensmcp/"||r.trim()===".lensmcp");
|
|
219
|
-
${
|
|
220
|
-
`).filter(Boolean).pop():void 0;e(`lensmcp ${i} is not on the npm registry${
|
|
221
|
-
`).filter(Boolean).pop():void 0;if(!r||!/^\d+\.\d+\.\d+/.test(r)){e("Could not resolve the latest lensmcp version from the npm registry \u2014 pass one explicitly: `lensmcp upgrade 1.20.1`.");return}return r}p(
|
|
216
|
+
For dev: \`yarn nx build @lensmcp/session\`.`),{exitCode:2};const i=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(o,".lensmcp","events.jsonl");return{exitCode:M(process.execPath,[r,...s.runnerArgs],{cwd:o,stdio:"inherit",env:{...process.env,...t.env??{},LENSMCP_EVENT_FILE:i}}).status??2}}p(kt,"St"),d(kt,"runLint");function be(t,n,e,s){const o=I(n,{string:["--cwd","--register-host-config"],boolean:["--skip-format","--yes"]}),r=L(b(o.flags["--cwd"])??t.cwd);if(!S(m(r,"nx.json")))return s(`No nx.json found at ${r}.`),s("Run `lensmcp install` from inside a Nx workspace."),{exitCode:1};const i=ie(r);if(!i)return s("Could not find the `nx` binary in the host workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};const c=["g","@lensmcp/nx-plugin:init","--no-interactive"];return o.flags["--skip-format"]===!0&&c.push("--skipFormat"),o.flags["--register-host-config"]&&c.push(`--registerHostConfig=${String(o.flags["--register-host-config"])}`),e(`> ${i} ${c.join(" ")}`),{exitCode:M(i,c,{cwd:r,stdio:"inherit",env:{...process.env,...t.env??{}}}).status??1}}p(be,"Je"),d(be,"runInstall");function Ce(t,n,e,s){const o=I(n,{string:["--cwd","--project","--target"]}),r=L(b(o.flags["--cwd"])??t.cwd);if(!S(m(r,"nx.json")))return s(`No nx.json found at ${r}.`),s("Run `lensmcp trust` from inside a Nx workspace (after `lensmcp install`)."),{exitCode:1};const i=ie(r);if(!i)return s("Could not find the `nx` binary in the workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};const c=gt(r,b(o.flags["--project"]),b(o.flags["--target"])),l=A("GET","/list")?.status===200&&B(r)===void 0;if(!c){if(s("This workspace has no trust target \u2014 no project declares the `@lensmcp/cluster:trust` executor."),s(""),l){const u=lt();s(` A shared gateway daemon${u?` (owned by '${u}')`:""} already serves this workspace, and`),s(" TLS rides ITS certificate authority. Run `lensmcp trust` in THAT workspace \u2014 it owns the CA \u2014"),s(" and this workspace is trusted too (restart the browser once if it cached a cert error).")}else s(" \u2022 Should this workspace own its gateway (and its CA)? Scaffold it first: `lensmcp install`,"),s(" then re-run `lensmcp trust`."),s(" \u2022 Joining a shared gateway? Run `lensmcp trust` in the workspace that owns the daemon.");return s(" \u2022 Already have a differently-named target? `lensmcp trust --project <p> --target <t>`."),{exitCode:1}}zt()||e(" note: trust runs `sudo` for the CA + /etc/hosts \u2014 run it in a real terminal if a step is needed."),l&&(e(" a shared gateway daemon serves this workspace \u2014 TLS rides ITS (already-trusted) CA, not a separate"),e(" one here. Setting up /etc/hosts only (trusting the CA is the DAEMON workspace's job).")),e(`> ${i} run ${c.project}:${c.target} (sudo prompts inline for ${l?"/etc/hosts":"the CA + /etc/hosts"})`);const a=M(i,["run",`${c.project}:${c.target}`],{cwd:r,stdio:"inherit",env:{...process.env,...t.env??{},...l?{LENSMCP_TRUST_HOSTS_ONLY:"1"}:{}}});if(l&&a.status===0){const u=wt(r);if(u){const h=mt(u);e(""),e(h==="trusted"?` \u2713 ${u} \u2192 served by the daemon with a TRUSTED cert \u2014 you're set (restart the browser once if it cached an error).`:h==="untrusted"?` \u2717 ${u} \u2192 the daemon's cert is NOT trusted yet. Run \`lensmcp trust\` in the DAEMON workspace (it owns the CA), then restart your browser.`:` ? ${u} \u2192 couldn't reach it to verify (is the daemon running?). /etc/hosts is set; TLS rides the daemon's CA.`)}}return{exitCode:a.status??1}}p(Ce,"We"),d(Ce,"runTrust");function xe(t){const n=G(t)??X(),e=ks(D(m(t,".lensmcp","config.json")));return{version:n,...e?{configHash:e}:{}}}p(xe,"Ue"),d(xe,"currentRecycleStamp");function Se(t){const n=Y(m(t,".lensmcp","setup-state.json"))?.recycled;return n&&typeof n=="object"?n:void 0}p(Se,"qe"),d(Se,"readRecycleStamp");function $t(t,n){ae(t);const e={version:X(),completedAt:new Date().toISOString(),steps:{install:!0,trust:!0},recycled:n?xe(t):Se(t)??{}};try{q(m(t,".lensmcp","setup-state.json"),`${JSON.stringify(e,null,2)}
|
|
217
|
+
`)}catch{}}p($t,"jt"),d($t,"writeSetupState");async function bt(t,n,e,s){const o=Ve(n)?n:te(t,e).mode,r=Es(t,o);if(s(""),s(`[mcp] mode \u2192 ${o}`),r.wrote&&s(` wrote ${Ns}`),o==="embedded"){s(" every agent session builds its OWN MCP server, and keeps serving"),s(" the bundle it started with until that session exits."),s(" one shared server for the workspace: `lensmcp setup --mcp shared`");return}s(` sessions proxy into ONE shared server at ${r.url}`),s(" .mcp.json is unchanged \u2014 `lensmcp mcp` becomes a thin stdio shim.");const i=await Be(r.url);if(!i.ok){s(` \xB7 not up yet (${i.error??"unknown"}) \u2014 the next session starts it on demand`);return}const c=G(t)??X(),l=_e({identity:He(r.port),targetVersion:c,expectedRoot:Ee(t),expectedKey:z(t).key,selfPid:process.pid});if(!l.kill){s(` \u2713 already up \u2014 ${i.server??"MCP"} (protocol ${i.protocolVersion??"?"}) \u2014 ${l.reason}`);return}try{process.kill(l.pid,"SIGTERM"),s(` \u21BA restarted the shared server \u2014 it was ${l.reason}; the next session brings it up on ${c}`)}catch(a){s(` ! the shared server is ${l.reason} and could not be stopped (pid ${l.pid}): ${a.message}`)}}p(bt,"xt"),d(bt,"applyMcpModeStep");function Ct(t,n,e){const s=Qe({cwd:t,cliVersion:X()}),o=Hs({run:Vs(n),facts:s});if(!(o.outcome==="current"||o.outcome==="unknown")){if(e(""),o.outcome==="updated"){e(`[plugin] ${o.from} \u2192 ${o.to}`),e(" restart Claude Code for the new plugin to load.");return}e(`[plugin] the Claude Code plugin is ${o.from}, this lensmcp is ${o.to}.`),e(` could not update it automatically (${o.detail??"unknown reason"}). Run:`);for(const r of o.commands??[])e(` ${r}`);e(" \u2026then restart Claude Code.")}}p(Ct,"Nt"),d(Ct,"applyPluginSyncStep");async function xt(t,n,e,s){const o=I(n,{string:["--cwd","--mcp"],boolean:["--no-recycle"]}),r=L(b(o.flags["--cwd"])??t.cwd),i={...t,cwd:r},c=b(o.flags["--mcp"]);if(c!==void 0&&!Ve(c))return s(`setup: --mcp must be "embedded" or "shared" (got "${c}").`),{exitCode:1};e("lensmcp setup \u2014 first-time bootstrap (install \u2192 trust \u2192 pods)"),e(""),e("[1/3] install \u2014 plugin, .mcp.json, nx config, vite/nest wiring");const l=be(i,n,e,s);if(l.exitCode!==0)return s(""),s("setup: the install step failed \u2014 fix the above and re-run `lensmcp setup`."),l;e(""),e("[2/3] trust \u2014 dev CA \u2192 System keychain, /etc/hosts, DNS flush (sudo)");const a=Ce(i,n,e,s);if(a.exitCode!==0)return s(""),s("setup: the trust step failed \u2014 run `lensmcp setup` directly in a terminal so sudo can prompt."),a;e(""),e("[3/3] pods \u2014 recycle this workspace's devservers, reconcile the gateway");const u=z(r).key,h=vs({previous:Se(r),current:xe(r),disabled:o.flags["--no-recycle"]===!0}),f=h.recycle?Qt(r,u,e,h.reason):(e(` \xB7 pods left running \u2014 ${h.reason}`),{killed:0,stale:0});es(i,r,u,e),await bt(r,c,t.env??process.env,e);try{Ct(r,{...process.env,...t.env??{}},e)}catch{}return $t(r,h.recycle),e(""),e("\u2713 setup complete."),(f.killed>0||f.stale>0)&&e(` recycled ${f.killed} pod${f.killed===1?"":"s"}`+(f.stale>0?` (+${f.stale} stale socket${f.stale===1?"":"s"} cleared)`:"")+" \u2014 they come back on the new wiring."),e(" next: lensmcp gateway start (the :443 front door \u2014 needs sudo)"),e(" verify: lensmcp doctor"),{exitCode:0}}p(xt,"Pt"),d(xt,"runSetup");async function St(t,n,e){const s=I(n,{string:["--cwd","--hook","--timeout","--session"],boolean:["--json","--quiet"]}),o=L(b(s.flags["--cwd"])??t.cwd),r=b(s.flags["--hook"]),i=Ue(r)?r:void 0,c=b(s.flags["--session"]);if(r!==void 0&&i===void 0)return{exitCode:0};const l=s.flags["--json"]===!0,a=s.flags["--quiet"]===!0||r!==void 0,u=Number(b(s.flags["--timeout"])??""),h=Number.isFinite(u)&&u>0?u:As,f={...process.env,...t.env??{}};try{const w=await Is({cwd:o,env:f,budgetMs:h,verify:d(C=>Ts(C).map(v=>v.resource),"verify")});if(!w.available)return l&&!a?e(JSON.stringify({available:!1,workspace:w.source.workspace,mode:w.source.mode,reason:w.reason,elapsedMs:w.elapsedMs})):a||e(`lensmcp status \u2014 ${w.source.workspace}: unavailable (${w.reason})`),{exitCode:0};const k=Rs(w.status,w.evidence,Date.now()),$=Os(k,{workspace:w.source.workspace,includeUnmonitored:i==="SessionStart"||!a});if(l)return a&&$===void 0?{exitCode:0}:(e(JSON.stringify({available:!0,workspace:w.source.workspace,mode:w.source.mode,url:w.source.url,aggregate:w.status.status??"unknown",elapsedMs:w.elapsedMs,findings:k.findings,suppressed:k.suppressed,unmonitored:k.unmonitored})),{exitCode:0});if(i){const C=Ls(k.findings);return Ss(c,C)?($!==void 0&&e(We(i,$)),c&&xs(c,C),{exitCode:0}):{exitCode:0}}if(a)return $!==void 0&&e($),{exitCode:0};if(e(`lensmcp status \u2014 ${w.source.workspace} (${w.source.mode}, ${w.source.url})`),e(` aggregate says: ${w.status.status??"unknown"} (read in ${w.elapsedMs}ms)`),k.findings.length===0)e(" nothing actionable that this command can vouch for.");else for(const C of k.findings)e(` \u2022 ${Ms(C)}`);for(const C of k.suppressed)e(` \xB7 not reported \u2014 ${C.kind}: ${C.reason}`);return k.unmonitored.length>0&&e(` \xB7 unmonitored (unknown, NOT clean): ${k.unmonitored.join(", ")}`),{exitCode:0}}catch(w){return a||e(`lensmcp status: unavailable (${w instanceof Error?w.message:String(w)})`),{exitCode:0}}}p(St,"Et"),d(St,"runStatus");function jt(t,n,e){const s=I(n,{string:["--cwd","--hook","--plugin-root"],boolean:["--json","--quiet"]}),o=L(b(s.flags["--cwd"])??t.cwd),r=b(s.flags["--hook"]),i=Ue(r)?r:void 0;if(r!==void 0&&i===void 0)return{exitCode:0};const c=s.flags["--json"]===!0,l=s.flags["--quiet"]===!0||r!==void 0,a=b(s.flags["--plugin-root"]);try{const u=Qe({cwd:o,cliVersion:X(),...a?{pluginRoot:a}:{}}),h=Gs(u);if(c)return l&&!h?{exitCode:0}:(e(JSON.stringify({...u,skew:h??null})),{exitCode:0});if(i)return h&&e(We(i,Ye(h))),{exitCode:0};if(l)return h&&e(Ye(h)),{exitCode:0};if(e(`lensmcp version-check \u2014 ${u.pluginId??"lensmcp plugin"}`),e(` plugin ${u.plugin??"unknown"}${u.pluginSource?` (${u.pluginSource})`:""}`),e(` project ${u.project??"unknown"} (node_modules/lensmcp)`),e(` cli ${u.cli??"unknown"} (the binary running now)`),!h)return e(u.plugin&&(u.project??u.cli)?" \u2713 in step.":" ? cannot compare \u2014 one of the versions is unreadable (staying silent)."),{exitCode:0};e(` \u2717 the plugin is ${h.direction} \u2014 update it, then restart Claude Code:`);for(const f of Bs(h))e(` ${f}`);return{exitCode:0}}catch(u){return l||e(`lensmcp version-check: unavailable (${u instanceof Error?u.message:String(u)})`),{exitCode:0}}}p(jt,"Mt"),d(jt,"runVersionCheck");async function Nt(t,n,e){const s=I(n,{string:["--cwd"],boolean:["--json"]}),o=L(b(s.flags["--cwd"])??t.cwd),r=s.flags["--json"]===!0,i=[];Pt(i),Et(o,i),Tt(o,i),Mt(o,t.env??process.env,i),await Lt(o,t.env??process.env,i),Ot(o,i),Rt(o,i),At(o,i),It(i);const c=i.some(a=>a.status==="fail"),l=i.some(a=>a.status==="warn");if(r)return e(JSON.stringify({ok:!c,summary:{total:i.length,failed:i.filter(a=>a.status==="fail").length,warnings:i.filter(a=>a.status==="warn").length},checks:i},null,2)),{exitCode:c?1:0};for(const a of i){const u=a.status==="pass"?"\u2713":a.status==="warn"?"!":"\u2717";e(`${u} ${a.label}${a.detail?` \u2014 ${a.detail}`:""}`),a.status!=="pass"&&a.hint&&e(` \u21B3 ${a.hint}`)}return e(""),e(c?"doctor: issues found (see \u2717 above).":l?"doctor: ok, with warnings (!).":"doctor: all checks passed."),{exitCode:c?1:0}}p(Nt,"Tt"),d(Nt,"runDoctor");function T(t,n,e,s,o){t.push({status:n,label:e,detail:s,hint:o})}p(T,"T"),d(T,"add");function Pt(t){const n=Number(process.versions.node.split(".")[0]);n>=20?T(t,"pass",`Node ${process.versions.node}`):n>=18?T(t,"warn",`Node ${process.versions.node}`,"older than recommended","upgrade to Node 20+ for best results"):T(t,"fail",`Node ${process.versions.node}`,"too old","LensMCP needs Node 18+ (20+ recommended)")}p(Pt,"Lt"),d(Pt,"checkNode");function Et(t,n){const e=m(t,"nx.json");if(!S(e)){T(n,"fail","nx.json at workspace root","missing","run `lensmcp` from inside a Nx workspace");return}let s;try{s=JSON.parse(V(e,"utf8"))}catch(r){T(n,"fail","nx.json parses",r.message,"fix the JSON syntax in nx.json");return}const o=(s.plugins??[]).some(r=>typeof r=="string"?r==="@lensmcp/nx-plugin":!!r&&typeof r=="object"&&r.plugin==="@lensmcp/nx-plugin");T(n,o?"pass":"fail","@lensmcp/nx-plugin registered in nx.json#plugins",o?void 0:"not registered",o?void 0:"run `lensmcp install`"),T(n,s.lensmcp?.schemaVersion===1?"pass":"warn","lensmcp config block in nx.json",s.lensmcp?.schemaVersion===1?void 0:"missing",s.lensmcp?.schemaVersion===1?void 0:"run `lensmcp install` to write the config defaults")}p(Et,"Rt"),d(Et,"checkWorkspace");function Tt(t,n){const e=m(t,".mcp.json");if(!S(e)){T(n,"warn",".mcp.json with a lensmcp server","missing","run `lensmcp install` so agents auto-discover the MCP server");return}try{const s=JSON.parse(V(e,"utf8")),o=!!s.mcpServers&&!!s.mcpServers.lensmcp;T(n,o?"pass":"warn",".mcp.json registers the lensmcp MCP server",o?void 0:"no lensmcp entry",o?void 0:"run `lensmcp install`")}catch(s){T(n,"warn",".mcp.json parses",s.message,"fix the JSON syntax in .mcp.json")}}p(Tt,"Ot"),d(Tt,"checkMcpConfig");function Mt(t,n,e){const s=Y(m(t,".claude","settings.json")),o=Y(m(t,".claude","settings.local.json")),r=tt({cwd:t}),i=r?Y(m(r.root,"plugin",".mcp.json")):void 0,c=Fe(i),l=Ze(),a=Ke(s,Q)||Ke(o,Q)||l.some(h=>h.scope==="user"||h.projectPath===t),u=$s({workspaceServers:Fe(Y(m(t,".mcp.json"))),pluginServers:c,pluginEnabled:a,pluginReadable:i!==void 0,disabledServers:[...De(s),...De(o)],sharedMcp:te(t,n).mode==="shared"});T(e,u.duplicated||u.indeterminate?"warn":"pass","the MCP server is registered exactly once",u.duplicated||u.indeterminate?u.detail:void 0,u.duplicated||u.indeterminate?u.hint:void 0)}p(Mt,"At"),d(Mt,"checkDuplicateRegistration");function je(){const t=A("GET","/status");if(!t||t.status!==200)return;const n=t.json?.daemon,e=t.json?.workspaces;if(!(!n?.wsKey||!Array.isArray(e)))return e.find(s=>s.key===n.wsKey)?.root}p(je,"ze"),d(je,"daemonOwnerRoot");function Y(t){try{return JSON.parse(V(t,"utf8"))}catch{return}}p(Y,"X"),d(Y,"readJsonFile");async function Lt(t,n,e){const s=te(t,n);if(T(e,"pass","MCP mode",s.mode==="shared"?`shared \u2014 sessions proxy into ${s.url}`:"embedded \u2014 one MCP server per agent session",s.mode==="shared"?void 0:"one shared server: `lensmcp setup --mcp shared`"),s.mode!=="shared")return;const o=await Be(s.url);T(e,o.ok?"pass":"warn","shared MCP server",o.ok?`${o.server??"MCP"} @ ${s.url} (protocol ${o.protocolVersion??"?"})`:`not running at ${s.url} \u2014 ${o.error??"no answer"}`,o.ok?void 0:"the next agent session starts it on demand; `lensmcp gateway start` starts it now")}p(Lt,"_t"),d(Lt,"checkMcpMode");function Ne(t,n){const e=te(t,n);if(e.mode!=="shared")return{mode:e.mode,url:e.url,port:e.port,healthy:!1};const s=Ps(e.url);return{mode:e.mode,url:e.url,port:e.port,healthy:s.ok,...s.server?{server:s.server}:{},...s.error?{error:s.error}:{}}}p(Ne,"Ye"),d(Ne,"mcpStatusBlock");function Ot(t,n){const e=ge(t);T(n,e?"pass":"fail","lensmcp-mcp server bundle reachable",e??"missing",e?void 0:"dev: `yarn nx build @lensmcp/lensmcp-mcp`")}p(Ot,"It"),d(Ot,"checkServerBundle");function Rt(t,n){const e=m(t,".lensmcp");T(n,S(e)?"pass":"warn",".lensmcp/ runtime directory",S(e)?void 0:"not created yet",S(e)?void 0:"created automatically on first `lensmcp mcp` run");const s=m(t,".gitignore"),o=(S(s)?D(s):"").split(`
|
|
218
|
+
`).some(r=>r.trim()===".lensmcp/"||r.trim()===".lensmcp");T(n,o?"pass":"warn",".gitignore excludes .lensmcp/",o?void 0:"not ignored",o?void 0:"add `.lensmcp/` to .gitignore (lensmcp install does this)")}p(Rt,"Dt"),d(Rt,"checkRuntimeDir");function At(t,n){const e=U(t,l=>/^vite\.config\.[cm]?[jt]s$/.test(l)),s=e.filter(l=>/lensmcpVitePlugin|@lensmcp\/vite-plugin/.test(D(l)));if(e.length>0){const l=s.length===e.length;T(n,l?"pass":"warn",`Vite wiring: ${s.length}/${e.length} config(s) use the LensMCP plugin`,void 0,l?void 0:"wire each: `nx g @lensmcp/nx-plugin:setup-vite <project>`")}const o=U(t,l=>l==="main.ts").filter(l=>/NestFactory\.create|createLensmcpNestApp/.test(D(l))),r=o.filter(l=>/createLensmcpNestApp/.test(D(l)));if(o.length>0){const l=r.length===o.length;T(n,l?"pass":"warn",`Nest wiring: ${r.length}/${o.length} bootstrap(s) use createLensmcpNestApp`,void 0,l?void 0:"wire each: `nx g @lensmcp/nx-plugin:setup-nest <project>`")}const i=U(t,l=>l==="project.json"||l==="package.json").map(l=>D(l)),c=i.filter(l=>/"agent-dev"/.test(l));i.some(l=>/@lensmcp\/cluster:gateway/.test(l))?T(n,"pass","dev lifecycle: cluster gateway owns it (agent-dev not required)",c.length>0?`${c.length} project(s) ALSO declare agent-dev \u2014 that races the gateway`:void 0,c.length>0?"remove agent-dev from gateway-managed projects; the gateway already serves them":void 0):T(n,c.length>0?"pass":"warn",`agent-dev targets: ${c.length} project(s)`,void 0,c.length>0?void 0:"no project wired \u2014 run setup-vite / setup-nest")}p(At,"Ft"),d(At,"checkProjectWiring");function It(t){const n=process.env.CHROME_PATH,e=process.platform==="darwin"?["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium"]:process.platform==="win32"?["C:/Program Files/Google/Chrome/Application/chrome.exe","C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"]:["/usr/bin/google-chrome","/usr/bin/chromium-browser","/usr/bin/chromium","/usr/bin/google-chrome-stable"],s=(n&&S(n)?n:void 0)??e.find(o=>S(o));T(t,s?"pass":"warn","Chrome for browser:// capture",s?le(s):"not found",s?void 0:"install Chrome or set CHROME_PATH (only needed for browser capture)")}p(It,"Kt"),d(It,"checkChrome");function D(t){try{return V(t,"utf8")}catch{return""}}p(D,"D"),d(D,"safeRead");function U(t,n,e=6,s=6e3){const o=new Set(["node_modules","dist","build",".git",".nx",".lensmcp","coverage","tmp",".cache",".yarn"]),r=[],i=[{dir:t,depth:0}];let c=0;for(;i.length>0;){const{dir:l,depth:a}=i.pop();let u;try{u=ce(l,{withFileTypes:!0})}catch{continue}for(const h of u){if(c++>s)return r;if(h.isDirectory()){if(o.has(h.name)||h.name.startsWith("."))continue;a<e&&i.push({dir:m(l,h.name),depth:a+1})}else h.isFile()&&n(h.name)&&r.push(m(l,h.name))}}return r}p(U,"q"),d(U,"walkProjectFiles");function _t(t,n,e,s){const o=I(n,{string:["--cwd","--from","--scope"]}),r=(o.positional[0]??"").toLowerCase();if(r!=="install"&&r!=="status")return s("Usage: lensmcp plugin <install|status> [claude|codex] [--from <dir>] [--scope <user|project|local>] [--cwd <dir>]"),{exitCode:2};const i=L(b(o.flags["--cwd"])??t.cwd),c=o.positional[1]?.toLowerCase(),l=c?Js(c):void 0;if(c&&!l)return s(`Unknown agent: ${c} (use claude | codex)`),{exitCode:2};const a=l?[l]:[...et],u=b(o.flags["--from"]),h=tt({cwd:i,...u?{from:u}:{},selfRoot:ee()});if(!h)return s("Could not find a lensmcp package to install the plugins from."),s("Run inside a workspace with lensmcp installed, or pass --from <package-root>."),{exitCode:1};e(`plugin package: ${h.root}${h.version?` (lensmcp ${h.version})`:""}`+(h.source==="self"?" \u2014 the running CLI itself (no workspace install found; prefer a workspace)":""));const f=st({...process.env,...t.env??{}});if(r==="status"){for(const $ of a){const C=zs(h.root,$),v=$.id==="claude"?Xe(i)?.version:Ws(f),E=v?C?v===C?`installed ${v} \u2014 current`:`installed ${v}, the package ships ${C} \u2014 \`lensmcp plugin install ${$.id}\``:`installed ${v} (this package ships no ${$.label} plugin \u2014 it arrived in ${$.since})`:`not installed \u2014 \`lensmcp plugin install ${$.id}\``;e(` ${$.label.padEnd(11)} \u2192 ${E}`)}return{exitCode:0}}const w=b(o.flags["--scope"]);let k=!1;for(const $ of a){const C=$.id==="claude"?w??Xe(i)?.scope:void 0,v=Us($,{root:h.root,...C?{scope:C}:{}},{run:f});switch(v.outcome){case"installed":e(` ${$.label.padEnd(11)} \u2192 installed${v.version?` ${v.version}`:""} \u2014 ${v.restartHint}`);break;case"skipped-no-cli":l&&(k=!0),e(` ${$.label.padEnd(11)} \u2192 skipped (${v.detail})`);break;case"skipped-not-packaged":l&&(k=!0),e(` ${$.label.padEnd(11)} \u2192 skipped \u2014 ${v.detail}`);break;case"failed":k=!0,s(` ${$.label.padEnd(11)} \u2192 FAILED \u2014 ${v.detail}`),s(` run by hand:${v.commands.map(E=>`
|
|
219
|
+
${E}`).join("")}`);break}}return{exitCode:k?1:0}}p(_t,"Gt"),d(_t,"runPlugin");function Pe(){const t=A("GET","/status");if(t?.status!==200||!t.json||typeof t.json!="object")return{registeredKeys:[]};const n=t.json;return{...typeof n.daemon?.wsKey=="string"?{wsKey:n.daemon.wsKey}:{},...typeof n.daemon?.version=="string"?{version:n.daemon.version}:{},registeredKeys:(n.workspaces??[]).flatMap(e=>typeof e.key=="string"?[e.key]:[])}}p(Pe,"Xe"),d(Pe,"snapshotDaemon");function Dt(t){let n=L(t);for(let e=0;e<8;e++){const s=m(n,"package.json");if(S(s)&&/"(?:lensmcp|@lensmcp\/[^"]+)"\s*:/.test(D(s)))return{key:hs(n).key,root:n};const o=_(n);if(o===n)break;n=o}}p(Dt,"Ht"),d(Dt,"findLensmcpWorkspace");function Ft(t,n,e,s=!1){if(t){const i=t.replace(/^v/,"");if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(i)){e(`Not a version: ${t} (expected e.g. 1.20.1)`);return}if(!s&&on(n("npm",["view",`lensmcp@${i}`,"version"]),i)==="absent"){const c=n("npm",["view","lensmcp","version"]),l=c&&c.code===0?(c.stdout??"").trim().split(`
|
|
220
|
+
`).filter(Boolean).pop():void 0;e(`lensmcp ${i} is not on the npm registry${l?` (the newest there is ${l})`:""} \u2014 nothing was changed.`),e("If it was published a moment ago, run this again in a minute. `--no-registry-check` skips the question.");return}return i}const o=n("npm",["view","lensmcp","version"]),r=o&&o.code===0?(o.stdout??"").trim().split(`
|
|
221
|
+
`).filter(Boolean).pop():void 0;if(!r||!/^\d+\.\d+\.\d+/.test(r)){e("Could not resolve the latest lensmcp version from the npm registry \u2014 pass one explicitly: `lensmcp upgrade 1.20.1`.");return}return r}p(Ft,"Vt"),d(Ft,"resolveTargetVersion");function Kt(t,n,e,s){for(const o of t){let r;try{r=te(o.root,process.env)}catch{continue}if(r.mode!=="shared")continue;const i=_e({identity:He(r.port),targetVersion:n,expectedRoot:Ee(o.root),expectedKey:o.key,selfPid:process.pid});if(!i.kill){s(` mcp \u2192 '${o.key}' :${r.port} \u2014 ${i.reason}`);continue}if(e){s(` mcp \u2192 would restart '${o.key}' :${r.port} (pid ${i.pid}) \u2014 ${i.reason}`);continue}try{process.kill(i.pid,"SIGTERM"),s(` mcp \u2192 restarted '${o.key}' :${r.port} \u2014 was ${i.reason}; the next session respawns it on ${n}`)}catch(c){s(` mcp \u2192 could not stop '${o.key}' :${r.port} (pid ${i.pid}): ${c.message}`)}}}p(Kt,"Bt"),d(Kt,"restartSharedMcpServers");function Ee(t){try{return cs(t)}catch{return t}}p(Ee,"Ze"),d(Ee,"canonicalRootPath");async function Gt(t,n,e,s){const o=I(n,{string:["--cwd"],boolean:["--dry-run","--no-install","--no-plugins","--no-global","--no-restart","--no-registry-check"]}),r=L(b(o.flags["--cwd"])??t.cwd),i=o.flags["--dry-run"]===!0,c={...process.env,...t.env??{}},l=st(c),a=Ft(o.positional[0],l,s,o.flags["--no-registry-check"]===!0);if(!a)return{exitCode:1};const u=nn(),h=Dt(r),f=[],w=new Set;for(const g of[...h?[h]:[],...u])w.has(g.root)||(w.add(g.root),f.push(g));if(f.length===0)return s("No LensMCP workspace found: ~/.lensmcp/workspaces.json is empty and no package.json above the current directory depends on lensmcp."),{exitCode:1};const k=Pe();if(e(`upgrade \u2192 lensmcp ${a}${i?" (dry run \u2014 nothing will be changed)":""}`),k.wsKey&&e(` daemon \u2192 '${k.wsKey}' on :443${k.version?`, running ${k.version}`:""}, hosting ${k.registeredKeys.length} workspace${k.registeredKeys.length===1?"":"s"}`),e(` will change \u2192 ${f.length} workspace${f.length===1?"":"s"} (${f.map(g=>g.key).join(", ")})${o.flags["--no-install"]===!0?"":" + install"}${o.flags["--no-global"]===!0?"":" + the global CLI"}${o.flags["--no-plugins"]===!0?"":" + the Claude/Codex plugins"}${o.flags["--no-restart"]===!0?"":" + the :443 daemon"}`),o.flags["--no-registry-check"]!==!0){const g=Qs(f.flatMap(x=>["package.json","yarn.lock","package-lock.json","pnpm-lock.yaml"].map(N=>D(m(x.root,N))))),y=en(g,a,x=>l("npm",["view",`${x}@${a}`,"version"]));if(y.length===0&&e(` registry \u2192 all ${g.length} packages these workspaces install are published at ${a}`),y.length>0)return s(`lensmcp ${a} is not fully published yet \u2014 ${y.length} of the ${g.length} packages these workspaces install are not on the npm registry at ${a}:`),s(` ${y.join(", ")}`),s("A release publishes its packages one by one; run this again in a minute. Nothing was changed. (`--no-registry-check` skips the question.)"),{exitCode:1}}const $=[];let C=0;for(const g of f){const y=m(g.root,"package.json"),x=D(y);if(!x){C++,s(` ${g.key}: cannot read ${y} \u2014 skipped`);continue}const N=rn(x,a);for(const P of N.skipped.filter(K=>K.reason==="non-version-spec"))e(` ${g.key}: left ${P.section}.${P.name} at '${P.spec}' (not a plain version \u2014 a link:/workspace: pin is deliberate)`);const R=N.changes.length>0,O=G(g.root);if(!tn({rewritten:R,...O?{installedVersion:O}:{},targetVersion:a})){e(` ${g.key}: already at ${a}`);continue}if(e(R?` ${g.key}: ${N.changes.length} dep${N.changes.length===1?"":"s"} \u2192 ${a} (${N.changes.map(P=>P.name).join(", ")})`:` ${g.key}: package.json is at ${a} but node_modules holds ${O??"no lensmcp"} \u2014 an earlier install did not land`),i){$.push(g);continue}if(R&&q(y,N.text),o.flags["--no-install"]===!0){$.push(g),e(" install skipped (--no-install) \u2014 run it before restarting anything.");continue}const F=Zs(g.root);e(` ${F.name} ${F.install.join(" ")} (${g.root})`);const j=M(F.name,F.install,{cwd:g.root,stdio:"inherit",env:c});if((j.status??1)!==0){C++,s(` ${g.key}: \`${F.name} ${F.install.join(" ")}\` exited ${j.status??"by signal"} \u2014 fix it and re-run \`lensmcp upgrade ${a}\` (the rewrite is already in place).`);continue}$.push(g)}if(o.flags["--no-global"]!==!0){const g=Ys(l);g&&g.version!==a?i?e(` global \u2192 ${g.version} \u2192 ${a} (npm i -g lensmcp@${a})`):(e(` global \u2192 ${g.version} \u2192 ${a}`),(M("npm",["install","-g",`lensmcp@${a}`],{stdio:"inherit",env:c,timeout:3e5}).status??1)!==0&&(C++,s(` the global install failed \u2014 run by hand: npm i -g lensmcp@${a}`))):g&&e(` global \u2192 already ${g.version}`)}if(o.flags["--no-plugins"]!==!0){const g=[k.wsKey?f.find(y=>y.key===k.wsKey):void 0,...$,...f].find(y=>!!y&&S(m(y.root,"node_modules","lensmcp","package.json")));g?!i&&o.flags["--no-install"]!==!0&&!nt(G(g.root),a)?e(` plugins \u2192 skipped (${g.key} still holds ${G(g.root)??"no lensmcp"} \u2014 there is no ${a} package on disk to install them from)`):i?e(` plugins \u2192 would re-install Claude Code + Codex from ${m(g.root,"node_modules","lensmcp")}`):Ht(m(g.root,"node_modules","lensmcp"),r,c,e,s):e(" plugins \u2192 skipped (no workspace has lensmcp installed to point the marketplaces at)")}const v=d(()=>{if(!i)for(const g of f){const y=Y(m(g.root,".lensmcp","setup-state.json"))?.version,x=G(g.root),N=an({key:g.key,root:g.root,...typeof y=="string"?{setupVersion:y}:{},...x?{installedVersion:x}:{}});N&&e(N)}return{exitCode:C>0?1:0}},"finish");if(o.flags["--no-restart"]===!0)return e(" restart \u2192 skipped (--no-restart) \u2014 the daemon keeps serving the OLD code until `lensmcp gateway restart` runs in its workspace."),v();const E=sn({...k.wsKey?{daemonWsKey:k.wsKey}:{},...k.version?{daemonVersion:k.version}:{},targetVersion:a,registeredKeys:k.registeredKeys,known:u,upgraded:$});if(o.flags["--no-install"]!==!0){const g=i?f:f.filter(y=>nt(G(y.root),a));for(const y of f)g.includes(y)||e(` mcp \u2192 '${y.key}' left alone \u2014 its install did not land, so there is no ${a} bundle to restart it onto`);Kt(g,a,i,e)}if(E.steps.length===0)return e(` restart \u2192 nothing to do${E.note?` (${E.note})`:""}`),v();for(const g of E.steps){if(i){e(` restart \u2192 would ${g.action==="restart"?`restart the daemon ('${g.key}')`:`re-register '${g.key}'`}${g.reason==="rehost"?" (not upgraded \u2014 re-hosted so the daemon restart does not drop it)":g.reason==="stale-daemon"?" (its files are current but the process still runs the old bundle)":""}`);continue}if(g.action==="restart"){if(e(` restart \u2192 gateway daemon ('${g.key}') \u2026`),we({...t,cwd:g.root},["restart"],e,s).exitCode!==0){C++,s(` the daemon restart ('${g.key}') failed \u2014 fix it, then \`lensmcp gateway start\` in each guest workspace.`);break}if(!await Vt(18e4)){C++,s(" the restarted daemon did not answer within 3 minutes \u2014 check `lensmcp gateway status`; guests need `lensmcp gateway start` once it is up.");break}}else{const y=A("POST","/register",pe(g.root,g.key));if(y&&y.status===200){try{Z(m(g.root,".lensmcp"),{recursive:!0}),q(m(g.root,".lensmcp","registered.json"),JSON.stringify({wsKey:g.key}))}catch{}e(` restart \u2192 re-registered '${g.key}'${g.reason==="rehost"?" (not upgraded \u2014 re-hosted after the daemon restart)":""}`)}else C++,s(` re-registering '${g.key}' failed \u2014 ${de(y)??`run \`lensmcp gateway start\` in ${g.root}`}.`)}}if(!i){const g=Pe();if(g.version){const y=g.wsKey?f.find(R=>R.key===g.wsKey)?.root:void 0,x=y?G(y):void 0,N=Xs({reported:g.version,target:a,...x?{ownerInstalled:x}:{},...y?{ownerRoot:y}:{}});N.ok?e(N.line):(C++,s(N.line))}}return v()}p(Gt,"Jt"),d(Gt,"runUpgrade");async function Vt(t){const n=Date.now()+t;for(;;){if(A("GET","/list")?.status===200)return!0;if(Date.now()>=n)return!1;await new Promise(e=>setTimeout(e,2e3))}}p(Vt,"Wt"),d(Vt,"waitForDaemon");function Ht(t,n,e,s,o){const r=d((i,c,l)=>{try{const a=M(i,c,{encoding:"utf8",timeout:12e4,env:e,stdio:["ignore","pipe","pipe"],...l?{cwd:l}:{}});return a.error&&a.error.code==="ENOENT"?{ok:!1,detail:`\`${i}\` is not on PATH`}:(a.status??1)!==0?{ok:!1,detail:`${a.stderr??""}
|
|
222
222
|
${a.stdout??""}`.trim().split(`
|
|
223
|
-
`).filter(Boolean).pop()||`exited ${a.status}`}:{ok:!0}}catch(a){return{ok:!1,detail:a.message}}},"exec");for(const i of
|
|
223
|
+
`).filter(Boolean).pop()||`exited ${a.status}`}:{ok:!0}}catch(a){return{ok:!1,detail:a.message}}},"exec");for(const i of et){if(!S(m(t,i.manifest))){s(` plugins \u2192 ${i.label} skipped \u2014 ${t} ships no ${i.manifest} (the plugin arrived in ${i.since})`);continue}const c=r(i.bin,["plugin","marketplace","add",t]);if(!c.ok){s(` plugins \u2192 ${i.label} skipped (${c.detail})`);continue}if(i.id==="codex"){const a=r(i.bin,["plugin","add",Q]);s(a.ok?` plugins \u2192 Codex installed \u2014 ${i.restartHint}`:` plugins \u2192 Codex install failed (${a.detail}) \u2014 run: codex plugin add ${Q}`);continue}r(i.bin,["plugin","marketplace","update",qs]);const l=Ze();if(l.length===0){const a=r(i.bin,["plugin","install",Q,"--yes"]);s(a.ok?` plugins \u2192 Claude Code installed \u2014 ${i.restartHint}`:` plugins \u2192 Claude Code install failed (${a.detail}) \u2014 run: claude plugin install ${Q} --yes`);continue}for(const a of l){const u=a.scope&&a.scope!=="user"?["--scope",a.scope]:[],h=r(i.bin,["plugin","update",a.id,...u],a.projectPath??n),f=a.projectPath?` (${a.projectPath})`:"";h.ok?s(` plugins \u2192 Claude Code updated${f} \u2014 ${i.restartHint}`):(o(` plugins \u2192 Claude Code update failed${f}: ${h.detail}`),o(` run by hand${a.projectPath?` from ${a.projectPath}`:""}: claude plugin update ${a.id}${u.length>0?` --scope ${a.scope}`:""}`))}}}p(Ht,"Ut"),d(Ht,"syncAgentPlugins");function ee(){let t=_(gs(import.meta.url));for(let n=0;n<4;n++){if(S(m(t,"package.json")))return t;const e=_(t);if(e===t)break;t=e}return t}p(ee,"ee"),d(ee,"cliPackageRoot");function G(t){try{const n=JSON.parse(V(m(t,"node_modules","lensmcp","package.json"),"utf8"));return typeof n.version=="string"?n.version:void 0}catch{return}}p(G,"G"),d(G,"readProjectLensmcpVersion");function X(){try{return JSON.parse(V(m(ee(),"package.json"),"utf8")).version}catch{return"0.0.0"}}p(X,"Z"),d(X,"readCliVersion");function Bt(t,n,e){const s=L(t.cwd),o=Jt(s);return o?{exitCode:M(process.execPath,[o,...n],{stdio:"inherit",cwd:s,env:{...process.env,...t.env}}).status??1}:(e(`Could not locate the lensmcp rollout helper (@lensmcp/cluster).
|
|
224
224
|
Looked for main.rollout.js (walking up from cwd):
|
|
225
225
|
\u2022 <dir>/node_modules/@lensmcp/cluster/executors/gateway/main.rollout.js
|
|
226
226
|
\u2022 <dir>/dist/libs/cluster/executors/gateway/main.rollout.js
|
|
227
|
-
Install @lensmcp/cluster, or \`yarn nx build @lensmcp/cluster\` in the workspace.`),{exitCode:1})}p(
|
|
228
|
-
`)[0]?.trim());return Number.isInteger(e)&&e>0?e:void 0}catch{return}}p(
|
|
229
|
-
`).find(e=>e.startsWith("n"));return n&&n.slice(1).trim()||void 0}catch{return}}p(
|
|
227
|
+
Install @lensmcp/cluster, or \`yarn nx build @lensmcp/cluster\` in the workspace.`),{exitCode:1})}p(Bt,"qt"),d(Bt,"runRollout");function Jt(t){let n=t;for(let e=0;e<6;e++){for(const o of[m(n,"node_modules","@lensmcp","cluster","executors","gateway","main.rollout.js"),m(n,"dist","libs","cluster","executors","gateway","main.rollout.js")])if(S(o))return o;const s=_(n);if(s===n)break;n=s}}p(Jt,"zt"),d(Jt,"findRolloutBundle");function ge(t){return he(t,"main.js")}p(ge,"fe"),d(ge,"findMcpBinary");function Wt(t){return he(t,"shim.js")}p(Wt,"Yt"),d(Wt,"findShimBinary");function he(t,n){const e=m(ee(),"bundled",n);if(S(e))return e;const s=m(t,"servers","lensmcp-mcp","dist",n);if(S(s))return s;let o=t;for(let r=0;r<5;r++){const i=m(o,"servers","lensmcp-mcp","dist",n);if(S(i))return i;const c=_(o);if(c===o)break;o=c}}p(he,"ge"),d(he,"findServerBundle");function Ut(t){const n=m(ee(),"bundled","bridge.js");if(S(n))return n;let e=t;for(let s=0;s<5;s++){const o=m(e,"libs","bridge","dist","main.js");if(S(o))return o;const r=_(e);if(r===e)break;e=r}}p(Ut,"Xt"),d(Ut,"findBridgeBundle");function qt(t){const n=m(ee(),"bundled","lint-runner.js");if(S(n))return n;let e=t;for(let s=0;s<5;s++){const o=m(e,"libs","session","dist","lint-runner.js");if(S(o))return o;const r=_(e);if(r===e)break;e=r}}p(qt,"Zt"),d(qt,"findLintRunner");function ie(t){let n=t;for(let e=0;e<5;e++){const s=m(n,"node_modules",".bin","nx");if(S(s))return s;const o=_(n);if(o===n)break;n=o}}p(ie,"de"),d(ie,"findNxBinary");function ae(t){const n=m(t,".lensmcp");S(n)||Z(n,{recursive:!0})}p(ae,"le"),d(ae,"ensureLensmcpDir");function zt(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}p(zt,"Qt"),d(zt,"isInteractive");function fe(){const t=us(),n=[],e=d((s,o)=>{try{for(const r of ce(s,{withFileTypes:!0})){if(!r.isDirectory()||!r.name.endsWith("-devserver"))continue;const i=m(s,r.name,"parent.sock");S(i)&&n.push({service:r.name.slice(0,-10),wsKey:o,sock:i})}}catch{}},"scan");e(t,"");try{for(const s of ce(t,{withFileTypes:!0}))s.isDirectory()&&/^[a-z0-9][a-z0-9-]*$/.test(s.name)&&!s.name.endsWith("-devserver")&&e(m(t,s.name),s.name)}catch{}return n.sort((s,o)=>`${s.wsKey}/${s.service}`.localeCompare(`${o.wsKey}/${o.service}`))}p(fe,"he"),d(fe,"discoverDevserverSocks");const J=d(t=>t.wsKey?`${t.wsKey}/${t.service}`:t.service,"fullServiceName");function Te(t){try{const n=M("lsof",["-t",t],{encoding:"utf8"}),e=Number((n.stdout??"").split(`
|
|
228
|
+
`)[0]?.trim());return Number.isInteger(e)&&e>0?e:void 0}catch{return}}p(Te,"Qe"),d(Te,"pidOnSocket");function Me(t){try{const n=M("ps",["-o","pgid=","-p",String(t)],{encoding:"utf8"}),e=Number((n.stdout??"").trim());return Number.isInteger(e)&&e>1?e:void 0}catch{return}}p(Me,"en"),d(Me,"pgidOf");function Yt(t){try{const n=(M("lsof",["-a","-p",String(t),"-d","cwd","-Fn"],{encoding:"utf8"}).stdout??"").split(`
|
|
229
|
+
`).find(e=>e.startsWith("n"));return n&&n.slice(1).trim()||void 0}catch{return}}p(Yt,"es"),d(Yt,"cwdOfPid");function Xt(t,n){const e=Ie(L(t),L(n));return e===""||!e.startsWith("..")&&!ps(e)}p(Xt,"ns"),d(Xt,"isInside");function Zt(t,n){return fe().filter(e=>{if(e.wsKey)return e.wsKey===n;const s=Te(e.sock),o=s!==void 0?Yt(s):void 0;return o!==void 0&&Xt(t,o)})}p(Zt,"ts"),d(Zt,"workspaceDevservers");function Qt(t,n,e,s){const o=Zt(t,n);if(o.length===0)return e(" no devserver pods running for this workspace \u2014 nothing to recycle."),{killed:0,stale:0};s&&e(` \xB7 recycling ${o.length} pod${o.length===1?"":"s"} because ${s}`);const r=new Set;for(const l of[process.pid,...H()]){const a=Me(l);a!==void 0&&r.add(a)}let i=0,c=0;for(const l of o){const a=J(l),u=Te(l.sock);if(u===void 0){W(l.sock),e(` \u2713 ${a} \u2014 stale socket removed (no process held it)`),c++;continue}const h=Me(u),f=h!==void 0&&!r.has(h),w=d(k=>{try{f?process.kill(-h,k):process.kill(u,k)}catch{}},"signal");w("SIGTERM"),Le(u,5e3)||(w("SIGKILL"),Le(u,2e3)),W(l.sock),e(` \u2713 ${a} \u2014 stopped (pid ${u}${f?`, group ${h}`:", parent only"})`),i++}return{killed:i,stale:c}}p(Qt,"ss"),d(Qt,"reapWorkspacePods");function Le(t,n){const e=Date.now()+n;for(;;){if(!ne(t))return!0;if(Date.now()>=e)return!1;M("sleep",["0.15"])}}p(Le,"nn"),d(Le,"waitForPidGone");function es(t,n,e,s){const o=m(n,".lensmcp","gateway.pid"),r=m(n,".lensmcp","registered.json"),{pid:i,healed:c}=oe(o,n);if(c&&s(` healed: adopted a running gateway (pid ${i}) the pid file had lost.`),se(n,t.env,f=>s(` ${f}`)),B(n)!==void 0){s(` gateway: this workspace owns the :443 daemon (pid ${i??"?"}) \u2014 left running, pods respawn fresh.`);return}const l=A("GET","/list");if(l?.status!==200){s(" gateway: not running. Start it when you are ready: lensmcp gateway start");return}const a=l.json&&typeof l.json=="object"?l.json.workspaces??[]:[],u=ze(a,e,n);if(u.kind==="other-checkout"){for(const f of qe(e,u.root,n))s(` gateway: ${f}`);return}if(u.kind==="mine"){Z(_(r),{recursive:!0}),q(r,JSON.stringify({wsKey:e})),s(` gateway: '${e}' is already registered into the shared daemon \u2014 left serving.`);return}const h=A("POST","/register",pe(n,e));if(h&&h.status===200){Z(_(r),{recursive:!0}),q(r,JSON.stringify({wsKey:e})),s(` gateway: registered '${e}' into the shared daemon \u2014 it now hosts this workspace.`);return}s(` gateway: a shared daemon is up but registering this workspace failed \u2014 ${de(h)??"run `lensmcp gateway start`"}.`)}p(es,"rs"),d(es,"reconcileGatewayAfterSetup");function Oe(t,n,e,s){let o=n.filter(r=>r.service===t||J(r)===t);if(o.length>1)try{const r=z(e).key,i=o.filter(c=>c.wsKey===r);i.length===1&&(o=i)}catch{}return o.length===0?(s(`No running service named "${t}".`),n.length>0&&s(`Running: ${n.map(J).join(", ")}`),null):o.length>1?(s(`"${t}" is ambiguous \u2014 use one of: ${o.map(J).join(", ")}`),null):o[0]}p(Oe,"tn"),d(Oe,"resolveServiceSock");async function ts(t,n,e,s){const o=I(n,{string:["--tail","--cwd"],boolean:["--no-follow","--plain","--color"]}),r=o.positional[0],i=fe();if(!r){if(i.length===0)e("No running services found (no devserver control sockets under $TMPDIR)."),e("Start one with `yarn nx serve <project>` or `lensmcp gateway start`.");else{e("Running services \u2014 attach with `lensmcp logs <service>`:");for(const w of i)e(` ${J(w)}`)}return{exitCode:0}}const c=Oe(r,i,L(b(o.flags["--cwd"])??t.cwd),s);if(!c)return{exitCode:1};const l=o.flags["--no-follow"]!==!0,a=Number(b(o.flags["--tail"])??NaN),u=Number.isInteger(a)&&a>=0?a:100,h=o.flags["--plain"]===!0||o.flags["--color"]!==!0&&!process.stdout.isTTY,f=`/webpack/logs?tail=${u}&follow=${l?1:0}${h?"&plain=1":""}`;return new Promise(w=>{const k=Ae({socketPath:c.sock,path:f,method:"GET"},$=>{$.on("data",C=>process.stdout.write(C)),ms(()=>{$.destroy(),w({exitCode:0})}),$.on("end",()=>w({exitCode:0})),$.on("error",()=>w({exitCode:1}))});k.on("error",$=>{s(`Cannot attach to ${J(c)}: ${$.message}`),s("The devserver may have crashed leaving a stale socket \u2014 restart the service and retry."),w({exitCode:1})}),k.end()})}p(ts,"os"),d(ts,"runLogs");async function ss(t,n,e,s){const o=I(n,{string:["--port","--cwd"]}),r=o.positional[0],i=fe();if(!r)return s("Usage: lensmcp debug <service> [--port <base>]"),i.length>0&&s(`Running: ${i.map(J).join(", ")}`),{exitCode:2};const c=Oe(r,i,L(b(o.flags["--cwd"])??t.cwd),s);if(!c)return{exitCode:1};const l=Number(b(o.flags["--port"])??"")||void 0,a=`/webpack/debug${l?`?port=${l}`:""}`,u=await new Promise(f=>{const w=Ae({socketPath:c.sock,path:a,method:"POST"},k=>{let $="";k.on("data",C=>$+=C),k.on("end",()=>f($)),k.on("error",()=>f(null))});w.on("error",()=>f(null)),w.end()});if(u===null)return s(`Cannot reach ${J(c)} \u2014 the devserver may have crashed leaving a stale socket.`),{exitCode:1};let h;try{h=JSON.parse(u)}catch{return s(`Unexpected response from the devserver: ${u.slice(0,200)}`),{exitCode:1}}e(`Inspectors open on ${J(c)} \u2014 in place, no restart:`);for(const f of h.pods??[])e(` pod #${f.id} ${f.inspectorUrl??"(no url reported \u2014 check lensmcp logs)"}`);for(const f of h.workers??[])e(` worker ${f.name} 127.0.0.1:${f.port}`);return e(h.fixedPorts&&h.basePort?`Attach WebStorm (Run \u2192 Attach to Node.js/Chrome) to 127.0.0.1:${h.basePort} \u2014 or click the "Debugger listening" link in \`lensmcp logs ${r}\`.`:"Attach WebStorm (Run \u2192 Attach to Node.js/Chrome) using one of the URLs above \u2014 the ports are ephemeral, so there is no fixed address to configure. Set LENSMCP_DEBUG_FIXED_PORTS=1 if you need a stable one."),{exitCode:0}}p(ss,"is"),d(ss,"runDebug");function b(t){if(t!==void 0)return typeof t=="string"?t:void 0}p(b,"b"),d(b,"stringFlag");function I(t,n={}){const e=new Set(n.string??[]),s=new Set(n.boolean??[]),o={},r=[];for(let i=0;i<t.length;i++){const c=t[i];if(c.startsWith("--")){const l=c.indexOf("="),a=l===-1?c:c.slice(0,l);if(s.has(a))o[a]=!0;else if(e.has(a))if(l!==-1)o[a]=c.slice(l+1);else{const u=t[i+1];u===void 0||u.startsWith("--")?o[a]="":(o[a]=u,i++)}else o[a]=l===-1?!0:c.slice(l+1)}else r.push(c)}return{flags:o,positional:r}}p(I,"_"),d(I,"parseFlags");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface RegisteredWorkspace {
|
|
2
|
+
key: string;
|
|
3
|
+
/** Absent from a daemon older than the `/list` that reports it. */
|
|
4
|
+
root?: string;
|
|
5
|
+
}
|
|
6
|
+
export type RegistrationState = {
|
|
7
|
+
kind: 'free';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'mine';
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'other-checkout';
|
|
12
|
+
root: string;
|
|
13
|
+
};
|
|
14
|
+
/** Is this key free, held by THIS checkout, or held by another one? */
|
|
15
|
+
export declare function registrationState(workspaces: readonly RegisteredWorkspace[], key: string, cwd: string): RegistrationState;
|
|
16
|
+
/** What to tell someone who ran `gateway start` in a second checkout. */
|
|
17
|
+
export declare function otherCheckoutLines(key: string, otherRoot: string, cwd: string): string[];
|
|
18
|
+
/** The daemon's own sentence for a refused request (409 with a `message`), if it gave one. */
|
|
19
|
+
export declare function refusalMessage(res: {
|
|
20
|
+
status: number;
|
|
21
|
+
json?: unknown;
|
|
22
|
+
} | null | undefined): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var o=(e,t)=>c(e,"name",{value:t,configurable:!0});var u=Object.defineProperty,s=o((e,t)=>u(e,"name",{value:t,configurable:!0}),"t");import{realpathSync as f}from"node:fs";import{join as h,resolve as d}from"node:path";const i=s(e=>{try{return f(e)}catch{return d(e)}},"canonical");export function registrationState(e,t,r){const n=e.find(a=>a.key===t);return n?n.root===void 0||i(n.root)===i(r)?{kind:"mine"}:{kind:"other-checkout",root:n.root}:{kind:"free"}}o(registrationState,"registrationState"),s(registrationState,"registrationState");export function otherCheckoutLines(e,t,r){return[`'${e}' is already served from ${t}.`,`This checkout (${r}) derives the same key, and two checkouts cannot share a key or hosts behind one gateway \u2014 nothing was registered.`,`Give this one its own \`key\` in ${h(r,".lensmcp","config.json")} and its own hosts, or run \`lensmcp gateway stop\` in ${t} first.`]}o(otherCheckoutLines,"otherCheckoutLines"),s(otherCheckoutLines,"otherCheckoutLines");export function refusalMessage(e){if(!e||e.status!==409||!e.json||typeof e.json!="object")return;const t=e.json.message;return typeof t=="string"&&t.trim()?t:void 0}o(refusalMessage,"refusalMessage"),s(refusalMessage,"refusalMessage");
|
package/lib/upgrade.d.ts
CHANGED
|
@@ -99,6 +99,24 @@ export declare function registryAnswer(res: {
|
|
|
99
99
|
stdout?: string;
|
|
100
100
|
stderr?: string;
|
|
101
101
|
} | undefined, version: string): RegistryAnswer;
|
|
102
|
+
/**
|
|
103
|
+
* Every `lensmcp` / `@lensmcp/*` package a workspace installs, read from its manifest and lockfile
|
|
104
|
+
* text — the names whose target version must ALL be on the registry before anything is rewritten.
|
|
105
|
+
*
|
|
106
|
+
* A release publishes its packages one by one. On 2026-10-07 `lensmcp@1.23.12` was on the registry
|
|
107
|
+
* at 01:13:31 and `@lensmcp/protocol-types@1.23.12` at about 01:17; an upgrade in between passed
|
|
108
|
+
* the "is `lensmcp` there" check, rewrote package.json, and failed its install on
|
|
109
|
+
* "@lensmcp/vite-plugin: No candidates found". The lockfile is where the transitive ones are named.
|
|
110
|
+
*/
|
|
111
|
+
export declare function lensPackagesIn(texts: readonly string[]): string[];
|
|
112
|
+
/** The packages whose target version the registry positively does NOT have. Unknown answers are not listed. */
|
|
113
|
+
export declare function missingFromRegistry(names: readonly string[], version: string, ask: (name: string) => {
|
|
114
|
+
code: number;
|
|
115
|
+
stdout?: string;
|
|
116
|
+
stderr?: string;
|
|
117
|
+
} | undefined): string[];
|
|
118
|
+
/** Is the target version what is on disk in this workspace? Only then is there a NEW package to act on. */
|
|
119
|
+
export declare function installLanded(installedVersion: string | undefined, targetVersion: string): boolean;
|
|
102
120
|
/**
|
|
103
121
|
* Does this workspace still need its package manager run?
|
|
104
122
|
*
|
package/lib/upgrade.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var
|
|
2
|
-
`).some(
|
|
3
|
-
${
|
|
1
|
+
"use strict";var h=Object.defineProperty;var c=(e,t)=>h(e,"name",{value:t,configurable:!0});var w=Object.defineProperty,d=c((e,t)=>w(e,"name",{value:t,configurable:!0}),"d");import{existsSync as k,readFileSync as f}from"node:fs";import{homedir as $}from"node:os";import{join as l}from"node:path";export const UPGRADE_SECTIONS=["dependencies","devDependencies","optionalDependencies","resolutions","overrides"];export function isLensmcpPackage(e){return e==="lensmcp"||e.startsWith("@lensmcp/")}c(isLensmcpPackage,"isLensmcpPackage"),d(isLensmcpPackage,"isLensmcpPackage");export function readConnectedWorkspaces(e={}){const t=e.home??process.env.LENSMCP_HOME??$(),r=e.exists??k,n=e.readFile??(i=>f(i,"utf8"));let s;try{s=JSON.parse(n(l(t,".lensmcp","workspaces.json")))}catch{return[]}if(!Array.isArray(s))return[];const a=new Set,u=[];for(const i of s){if(!i||typeof i!="object")continue;const{key:o,root:p}=i;typeof o!="string"||typeof p!="string"||p.length===0||a.has(p)||r(l(p,"package.json"))&&(a.add(p),u.push({key:o,root:p}))}return u}c(readConnectedWorkspaces,"readConnectedWorkspaces"),d(readConnectedWorkspaces,"readConnectedWorkspaces");export function versionPrefix(e){const t=/^([~^]?)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(e.trim());return t?t[1]:void 0}c(versionPrefix,"versionPrefix"),d(versionPrefix,"versionPrefix");function m(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}c(m,"y"),d(m,"escapeRegExp");export function rewriteLensmcpDeps(e,t){let r;try{r=JSON.parse(e)}catch{return{text:e,changes:[],skipped:[]}}const n=[],s=[];for(const u of UPGRADE_SECTIONS){const i=r[u];if(!(!i||typeof i!="object"))for(const[o,p]of Object.entries(i)){if(typeof p!="string"||!isLensmcpPackage(o))continue;const g=versionPrefix(p);if(g===void 0){s.push({name:o,section:u,spec:p,reason:"non-version-spec"});continue}const y=`${g}${t}`;if(y===p){s.push({name:o,section:u,spec:p,reason:"already-current"});continue}n.push({name:o,section:u,from:p,to:y})}}let a=e;for(const u of n){const i=new RegExp(`("${m(u.name)}"\\s*:\\s*)"${m(u.from)}"`,"g");a=a.replace(i,`$1"${u.to}"`)}return{text:a,changes:n,skipped:s}}c(rewriteLensmcpDeps,"rewriteLensmcpDeps"),d(rewriteLensmcpDeps,"rewriteLensmcpDeps");export function detectPackageManager(e,t=k,r=n=>f(n,"utf8")){let n;try{const a=JSON.parse(r(l(e,"package.json")));typeof a.packageManager=="string"&&(n=a.packageManager.split("@")[0])}catch{}const s=d(a=>({name:a,install:["install"]}),"manager");return n==="yarn"||n==="npm"||n==="pnpm"||n==="bun"?s(n):t(l(e,"yarn.lock"))?s("yarn"):t(l(e,"pnpm-lock.yaml"))?s("pnpm"):t(l(e,"bun.lockb"))?s("bun"):s("npm")}c(detectPackageManager,"detectPackageManager"),d(detectPackageManager,"detectPackageManager");export function detectGlobalInstall(e,t=r=>f(r,"utf8")){const r=e("npm",["root","-g"]);if(!r||r.code!==0||!r.stdout)return;const n=r.stdout.trim();if(n)try{const s=JSON.parse(t(l(n,"lensmcp","package.json")));return typeof s.version=="string"?{version:s.version,root:n}:void 0}catch{return}}c(detectGlobalInstall,"detectGlobalInstall"),d(detectGlobalInstall,"detectGlobalInstall");export function registryAnswer(e,t){if(!e)return"unknown";const r=(e.stdout??"").trim();return e.code===0?r.split(`
|
|
2
|
+
`).some(n=>n.trim()===t)?"published":r===""?"absent":"unknown":/\bE404\b|\bETARGET\b|No match found/i.test(`${e.stderr??""}
|
|
3
|
+
${r}`)?"absent":"unknown"}c(registryAnswer,"registryAnswer"),d(registryAnswer,"registryAnswer");export function lensPackagesIn(e){const t=new Set,r=/(?<![\w-])(@lensmcp\/[a-z0-9][a-z0-9-]*)(?=["'@:\s/])/g,n=/(?:(?<=node_modules\/)|(?<![\w@/.-]))(lensmcp)(?=["'@:\s])/g;for(const s of e){for(const a of s.matchAll(r))t.add(a[1]);for(const a of s.matchAll(n))t.add(a[1])}return[...t].sort()}c(lensPackagesIn,"lensPackagesIn"),d(lensPackagesIn,"lensPackagesIn");export function missingFromRegistry(e,t,r){return e.filter(n=>registryAnswer(r(n),t)==="absent")}c(missingFromRegistry,"missingFromRegistry"),d(missingFromRegistry,"missingFromRegistry");export function installLanded(e,t){return e===t}c(installLanded,"installLanded"),d(installLanded,"installLanded");export function needsInstall(e){return e.rewritten||e.installedVersion!==e.targetVersion}c(needsInstall,"needsInstall"),d(needsInstall,"needsInstall");export function daemonVerdict(e){if(e.reported===e.target)return{ok:!0,line:` daemon \u2192 now running ${e.reported} \u2713`};const t=e.ownerInstalled!==void 0&&e.ownerInstalled!==e.target?`its workspace's node_modules holds ${e.ownerInstalled}, so the install did not land \u2014 run it${e.ownerRoot?` in ${e.ownerRoot}`:""}, then \`lensmcp upgrade ${e.target}\` again`:"it restarted onto files that are not the target \u2014 check `lensmcp gateway status`";return{ok:!1,line:` daemon \u2192 runs ${e.reported}, not ${e.target}: ${t}.`}}c(daemonVerdict,"daemonVerdict"),d(daemonVerdict,"daemonVerdict");export function setupReminder(e){if(!e.installedVersion||e.setupVersion===e.installedVersion)return;const t=e.setupVersion?`last set up for ${e.setupVersion}`:"not set up yet";return` setup \u2192 '${e.key}' is ${t}, and ${e.installedVersion} is installed: run \`lensmcp setup\` in ${e.root} \u2014 the lens tools are gated until it does.`}c(setupReminder,"setupReminder"),d(setupReminder,"setupReminder");export function planRestart(e){const t=new Map(e.known.map(o=>[o.key,o.root]));for(const o of e.upgraded)t.set(o.key,o.root);const r=new Set(e.upgraded.map(o=>o.key)),n=new Set(e.registeredKeys),s=e.daemonWsKey!==void 0&&e.daemonVersion!==void 0&&e.targetVersion!==void 0&&e.daemonVersion!==e.targetVersion;if(e.upgraded.length===0&&!s)return{steps:[],note:"nothing was upgraded"};if(!e.daemonWsKey)return{steps:[],note:"no gateway daemon is running \u2014 the next `lensmcp gateway start` picks up the new version"};const a=e.upgraded.find(o=>o.key===e.daemonWsKey),u=a?.root??t.get(e.daemonWsKey),i=[];if(a||s&&u){i.push({key:e.daemonWsKey,root:u,action:"restart",reason:a?"upgraded":"stale-daemon"});for(const o of e.registeredKeys){if(o===e.daemonWsKey)continue;const p=t.get(o);p&&i.push({key:o,root:p,action:"reregister",reason:r.has(o)?"upgraded":"rehost"})}return{steps:i}}if(s&&!u)return{steps:[],note:`the daemon ('${e.daemonWsKey}') runs ${e.daemonVersion} but its root is unknown \u2014 restart it with \`lensmcp gateway restart\` in its workspace`};for(const o of e.upgraded)n.has(o.key)&&i.push({key:o.key,root:o.root,action:"reregister",reason:"upgraded"});return i.length===0?{steps:[],note:`the running daemon ('${e.daemonWsKey}') hosts none of the upgraded workspaces`}:{steps:i}}c(planRestart,"planRestart"),d(planRestart,"planRestart");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lensmcp",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@frontmcp/sdk": "^1.9.1",
|
|
21
|
-
"@lensmcp/cluster": "1.23.
|
|
22
|
-
"@lensmcp/nx-plugin": "1.23.
|
|
21
|
+
"@lensmcp/cluster": "1.23.13",
|
|
22
|
+
"@lensmcp/nx-plugin": "1.23.13",
|
|
23
23
|
"reflect-metadata": "^0.2.2",
|
|
24
24
|
"tslib": "^2.3.0",
|
|
25
25
|
"vectoriadb": "^2.2.0"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "lensmcp",
|
|
3
3
|
"displayName": "LensMCP",
|
|
4
4
|
"description": "The observability lens for coding agents. One command brings up the dev cluster gateway (every project.json `cluster` decl → its host on :443), the per-project lens dashboard at https://lensmcp.local/<project>/, and the MCP server your agent connects to — scoped automatically to whatever project you opened Claude Code in.",
|
|
5
|
-
"version": "1.23.
|
|
5
|
+
"version": "1.23.13",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Antoon",
|
|
8
8
|
"email": "davidmantoon@gmail.com"
|