lensmcp 1.18.14 → 1.19.0
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/bin.js +1 -1
- package/lib/cli.js +13 -13
- package/lib/hook-memory.js +1 -1
- package/lib/mcp-mode.js +2 -2
- package/lib/mcp-wiring.js +2 -2
- package/lib/plugin-version.js +3 -3
- package/lib/status-client.js +2 -2
- package/lib/status-policy.js +2 -2
- package/lib/sweep.js +1 -1
- package/lib/workspace-scope.js +2 -2
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
package/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";import{runCli as
|
|
2
|
+
"use strict";import{runCli as r}from"./lib/cli.js";r({cwd:process.cwd(),argv:process.argv.slice(2)}).then(e=>{process.exit(e.exitCode)},e=>{console.error(e instanceof Error?e.stack??e.message:String(e)),process.exit(1)});
|
package/lib/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var gt=Object.defineProperty;var d=(t,n)=>gt(t,"name",{value:n,configurable:!0});var mt=Object.defineProperty,u=d((t,n)=>mt(t,"name",{value:n,configurable:!0}),"d");import{spawn as wt,spawnSync as $}from"node:child_process";import{existsSync as y,mkdirSync as B,openSync as vt,readFileSync as D,readdirSync as oe,rmSync as yt,statSync as kt,writeFileSync as K}from"node:fs";import{request as ye}from"node:http";import{homedir as bt,tmpdir as Ct}from"node:os";import{basename as ee,dirname as M,isAbsolute as St,join as m,relative as ke,resolve as x}from"node:path";import{fileURLToPath as $t}from"node:url";import{ensureLensConfig as V}from"./workspace-scope.js";import{remember as xt,shouldAnnounce as jt}from"./hook-memory.js";import{isMcpMode as be}from"./mcp-mode.js";import{effectiveMcpMode as Nt,LENS_CONFIG as Pt,probeSharedMcp as Ce,probeSharedMcpSync as Et,readMcpWiring as ie,wireMcpMode as Mt}from"./mcp-wiring.js";import{sweepLensRuntimeFiles as Tt}from"./sweep.js";import{candidateSignals as Ot,findingLine as Lt,findingsDigest as _t,formatContext as At,hookPayload as Se,isHookEvent as $e,select as Rt}from"./status-policy.js";import{DEFAULT_BUDGET_MS as It,readStatus as Dt}from"./status-client.js";import{detectSkew as Ft,formatSkewContext as xe,readVersions as je,spawnRunner as Gt,syncPlugin as Ht,updateCommands as Wt}from"./plugin-version.js";const Ne=`lensmcp \u2014 CLI for LensMCP (FrontMCP-based observability for coding agents)
|
|
2
2
|
|
|
3
3
|
Usage:
|
|
4
4
|
lensmcp <command> [options]
|
|
@@ -122,28 +122,28 @@ Commands:
|
|
|
122
122
|
listening" link in \`lensmcp logs <service>\`.
|
|
123
123
|
--version Print the lensmcp version.
|
|
124
124
|
--help Show this help.
|
|
125
|
-
`;export async function runCli(t){const n=t.out??(o=>console.log(o)),e=t.err??(o=>console.error(o)),[s,...r]=t.argv;if(!s||s==="--help"||s==="-h")return n(
|
|
125
|
+
`;export async function runCli(t){const n=t.out??(o=>console.log(o)),e=t.err??(o=>console.error(o)),[s,...r]=t.argv;if(!s||s==="--help"||s==="-h")return n(Ne),{exitCode:0};if(s==="--version"||s==="-V")return n(X()),{exitCode:0};switch(s){case"setup":return Ke(t,r,n,e);case"mcp":return Pe(t,r,n,e);case"dashboard":return Ee(t,r,n,e);case"gateway":return Oe(t,r,n,e);case"bridge":return Ge(t,r,n,e);case"install":return le(t,r,n,e);case"trust":return pe(t,r,n,e);case"status":return Ve(t,r,n);case"version-check":return Be(t,r,n);case"doctor":return Ue(t,r,n);case"rollout":return st(t,r,e);case"logs":return pt(t,r,n,e);case"debug":return ht(t,r,n,e);default:return e(`Unknown command: ${s}`),e(Ne),{exitCode:2,message:`Unknown command: ${s}`}}}d(runCli,"runCli"),u(runCli,"runCli");function Pe(t,n,e,s){const r=T(n,{string:["--cwd","--transport","--port","--mcp"]}),o=x(w(r.flags["--cwd"])??t.cwd),a=V(o),i=w(r.flags["--transport"])??t.env?.LENSMCP_TRANSPORT??"stdio",l=w(r.flags["--port"])??t.env?.LENSMCP_PORT??String(a.ports.mcpHttp),c=Nt(o,w(r.flags["--mcp"]),{...process.env,...t.env??{}})==="shared"&&i==="stdio",p=c?rt(o)??se(o):se(o);if(!p)return s(`Could not locate the lensmcp-mcp server bundle.
|
|
126
126
|
Looked in (in order):
|
|
127
127
|
\u2022 <cli-package>/bundled/main.js (published bin)
|
|
128
128
|
\u2022 <workspace>/apps/lensmcp-mcp/dist/main.js (dev build)
|
|
129
|
-
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};Z(o);const
|
|
129
|
+
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};Z(o);const h=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(o,".lensmcp","events.jsonl"),v={...process.env,...t.env??{},LENSMCP_TRANSPORT:i,LENSMCP_PORT:l,LENSMCP_EVENT_FILE:h},f=c?[p,"--cwd",o]:[p];return{exitCode:$(process.execPath,f,{cwd:o,stdio:"inherit",env:v}).status??1}}d(Pe,"tt"),u(Pe,"runMcp");function Ee(t,n,e,s){const r=T(n,{string:["--cwd","--port","--base"]}),o=x(w(r.flags["--cwd"])??t.cwd),a=V(o),i=w(r.flags["--port"])??t.env?.LENSMCP_DASHBOARD_PORT??String(a.ports.dashboard),l=w(r.flags["--base"])??t.env?.LENSMCP_DASHBOARD_BASE??"",c=ne(o,"dashboard.js");if(!c)return s(`Could not locate the lensmcp dashboard bundle.
|
|
130
130
|
Looked in (in order):
|
|
131
131
|
\u2022 <cli-package>/bundled/dashboard.js (published bin)
|
|
132
132
|
\u2022 <workspace>/servers/lensmcp-mcp/dist/dashboard.js (dev build)
|
|
133
|
-
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};Z(o);const
|
|
134
|
-
%{http_code}`,"--unix-socket",s,"-X",t,`http://localhost${n}`];e!==void 0&&r.push("-H","content-type: application/json","-d",JSON.stringify(e));const o
|
|
133
|
+
For dev: \`yarn nx build @lensmcp/lensmcp-mcp\`.`),{exitCode:1};Z(o);const p=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(o,".lensmcp","events.jsonl");return e(`lensmcp dashboard \u2192 http://localhost:${i}${l||"/"} (reading ${p})`),{exitCode:$(process.execPath,[c],{cwd:o,stdio:"inherit",env:{...process.env,...t.env??{},LENSMCP_DASHBOARD_PORT:i,LENSMCP_DASHBOARD_BASE:l,LENSMCP_EVENT_FILE:p}}).status??1}}d(Ee,"nt"),u(Ee,"runDashboard");function Me(){return m(process.env.LENSMCP_HOME||bt(),".lensmcp","control.sock")}d(Me,"st"),u(Me,"controlSocketPath");function O(t,n,e){const s=Me();if(!y(s))return null;const r=["-s","-o","-","-w",`
|
|
134
|
+
%{http_code}`,"--unix-socket",s,"-X",t,`http://localhost${n}`];e!==void 0&&r.push("-H","content-type: application/json","-d",JSON.stringify(e));const o=$("curl",r,{encoding:"utf8",timeout:5e3});if(o.status!==0||typeof o.stdout!="string"||o.stdout.length===0)return null;const a=o.stdout.split(`
|
|
135
135
|
`),i=Number(a.pop());let l=null;try{const c=a.join(`
|
|
136
|
-
`).trim();l=c?JSON.parse(c):null}catch{}return Number.isFinite(i)?{status:i,json:l}:null}
|
|
137
|
-
Free it first (stop that process), then \`lensmcp gateway start\`.`),{exitCode:1}}const
|
|
136
|
+
`).trim();l=c?JSON.parse(c):null}catch{}return Number.isFinite(i)?{status:i,json:l}:null}d(O,"L"),u(O,"daemonRequest");function Te(){const t=O("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}d(Te,"rt"),u(Te,"daemonWsKey");function ae(t){const n={};for(const e of W(t,s=>s==="project.json"))try{const s=JSON.parse(D(e,"utf8")),r=M(e);n[s.name??ee(r)]={root:ke(t,r)||"."}}catch{}return n}d(ae,"me"),u(ae,"buildProjectsMap");function Oe(t,n,e,s){const r=T(n,{string:["--cwd","--project","--target"]}),o=(r.positional[0]??"status").toLowerCase(),a=n.includes("--json"),i=x(w(r.flags["--cwd"])??t.cwd),l=V(i),c=m(i,".lensmcp","gateway.pid"),p=m(i,".lensmcp","gateway.log"),h=m(i,".lensmcp","registered.json"),v=`https://lensmcp.local${l.dashboardBasePath}/`,f=u(()=>{const{pid:g,healed:J}=z(c,i);if(g!==void 0&&q(g)){const E=classifyAliveGateway({oursOn443:F(i)!==void 0,port443Held:_().length>0,pidFileAgeMs:ue(c)});if(E==="serving")return J&&e(`healed: adopted a running gateway (pid ${g}) the pid file had lost \u2014 no duplicate started.`),e(`gateway already running (pid ${g}).`),e(` dashboard \u2192 ${v}`),{exitCode:0};if(E==="booting")return e(`gateway starting (pid ${g}) \u2014 :443 not bound yet.`),e(` dashboard \u2192 ${v}`),e(` logs \u2192 ${p}`),{exitCode:0};Y(g,"SIGKILL"),G(c),U(i,t.env,()=>{}),e(`reaped a dead gateway (pid ${g} was alive but nothing served :443 for this workspace).`)}const j=_()[0];if(j!==void 0){const E=O("GET","/list");if(E!==null){if(E.status===200&&E.json&&typeof E.json=="object"&&(E.json.workspaces??[]).some(I=>I.key===l.key))return B(M(h),{recursive:!0}),K(h,JSON.stringify({wsKey:l.key})),e(`already registered into the shared gateway daemon (pid ${j}).`),e(` dashboard \u2192 ${v}`),{exitCode:0};const k=O("POST","/register",{wsKey:l.key,root:i,projects:ae(i)});return k&&k.status===200?(B(M(h),{recursive:!0}),K(h,JSON.stringify({wsKey:l.key})),e(`registered '${l.key}' into the shared gateway daemon (pid ${j}).`),e(` dashboard \u2192 ${v}`),e(" the daemon hosts this workspace's services + dashboard; `lensmcp gateway stop` unregisters."),{exitCode:0}):(s(`failed to register into the gateway daemon: ${k?JSON.stringify(k.json):"no response from the control socket"}`),{exitCode:1})}return s(`port :443 is held by pid ${j}, which is not this workspace's gateway.
|
|
137
|
+
Free it first (stop that process), then \`lensmcp gateway start\`.`),{exitCode:1}}const P=Le(i,w(r.flags["--project"]),w(r.flags["--target"]));if(!P)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 N=Q(i);if(!N)return s("Could not find the `nx` binary in the workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};Tt(i,p);const L=vt(p,"a"),R=wt(N,["run",`${P.project}:${P.target}`],{cwd:i,detached:!0,stdio:["ignore",L,L],env:{...process.env,...t.env??{}}});return R.unref(),R.pid&&K(c,String(R.pid)),e(`gateway starting \u2192 ${P.project}:${P.target} (pid ${R.pid??"?"})`),e(` dashboard \u2192 ${v}`),e(` logs \u2192 ${p}`),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"),b=u(()=>{if(y(h)&&F(i)===void 0){let N=l.key;try{N=JSON.parse(D(h,"utf8")).wsKey??l.key}catch{}const L=O("POST","/unregister",{wsKey:N});return G(h),e(L&&L.status===200?`unregistered '${N}' from the shared gateway daemon.`:"unregister sent (the daemon may already be gone)."),{exitCode:0}}G(h);const{pid:g,healed:J}=z(c,i);if(g===void 0)return e("gateway not running."),G(c),{exitCode:0};J&&e(`healed: found an orphaned gateway (pid ${g}) the pid file had lost \u2014 stopping it.`),Y(g);let j=!1;if(!de(6e3)){j=!0,Y(g,"SIGKILL");for(const N of _())try{process.kill(N,"SIGKILL")}catch{}de(3e3)}const P=F(i);return P!==void 0&&P!==g&&(Y(P,"SIGKILL"),j=!0),G(c),j&&U(i,t.env,()=>{}),e(`gateway stopped (pid ${g})${j?" \u2014 forced (a child ignored SIGTERM)":""}.`),{exitCode:0}},"stop"),S=u(()=>{const{pid:g,healed:J}=z(c,i),j=g!==void 0&&q(g)?classifyAliveGateway({oursOn443:F(i)!==void 0,port443Held:_().length>0,pidFileAgeMs:ue(c)}):void 0,P=j==="serving"||j==="booting";if(a){const k=O("GET","/status"),I=k?.status===200&&k.json&&typeof k.json=="object"?k.json:null,ve=y(h),ft=P?"daemon":I&&ve?"guest":I?"other":"stopped";return e(JSON.stringify({thisWorkspace:l.key,role:ft,dashboardUrl:v,chooserUrl:"https://lensmcp.local/",logFile:p,mcp:he(i,t.env??process.env),daemon:I?.daemon??null,workspaces:I?.workspaces??[],services:I?.services??[]})),{exitCode:P||I&&ve?0:1}}const N=O("GET","/list"),L=N?.status===200&&N.json&&typeof N.json=="object"?N.json.workspaces??[]:[],R=u(()=>{if(L.length!==0){e(` workspaces (${L.length} registered):`);for(const k of L)e(` \u2022 ${k.key} (${k.routes??0} routes, ${k.services??0} services)${k.key===l.key?" \u2190 this workspace":""}`)}},"printWorkspaces"),E=u(()=>{const k=he(i,t.env??process.env);e(k.mode==="shared"?` mcp \u2192 shared ${k.url} ${k.healthy?"(up)":`(DOWN \u2014 ${k.error??"no answer"})`}`:" mcp \u2192 stdio (one server per agent session)")},"printMcp");if(P)return e(j==="booting"?`gateway: starting (pid ${g}) \u2014 :443 not bound yet`:`gateway: running (pid ${g}) \u2014 DAEMON on :443${J?" \u2014 recovered a stale pid file":""}`),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${v}`),e(" chooser \u2192 https://lensmcp.local/"),e(` logs \u2192 ${p}`),E(),R(),{exitCode:0};if(y(h)&&N?.status===200){const k=_()[0];return e(`gateway: registered into a shared daemon${k!==void 0?` (pid ${k})`:""} \u2014 this workspace is a guest`),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${v}`),e(" stop \u2192 `lensmcp gateway stop` (unregisters; the daemon keeps running)"),E(),R(),{exitCode:0}}return j==="zombie"?(e(`gateway: NOT serving \u2014 tracked pid ${g} 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 ${p}`),E(),R(),{exitCode:1}):(e("gateway: stopped"),e(` workspace \u2192 ${l.key}`),e(` dashboard \u2192 ${v}`),E(),{exitCode:1})},"status");switch(o){case"start":return f();case"stop":return b();case"restart":return b(),U(i,t.env,e),f();case"status":return S();default:return s(`Unknown gateway subcommand: ${o} (use start | stop | status | restart)`),{exitCode:2}}}d(Oe,"ot"),u(Oe,"runGateway");function U(t,n,e){const s=Q(t);if(!s){e(" (graph refresh skipped \u2014 no nx binary found in the workspace)");return}const r={...process.env,...n??{}},o=u(a=>$(s,a,{cwd:t,env:r,stdio:"ignore"}).status===0,"tryNx");if(o(["reset","--only-daemon"])||o(["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`)")}d(U,"q"),u(U,"refreshNxGraph");function ce(t,n,e,s){if(e&&s)return{project:e,target:s};const r=W(t,o=>o==="project.json");for(const o of r){let a;try{a=JSON.parse(H(o))}catch{continue}const i=a.name??ee(M(o));for(const[l,c]of Object.entries(a.targets??{}))if(c.executor===n)return{project:e??i,target:s??l}}}d(ce,"we"),u(ce,"scanExecutorTarget");function Le(t,n,e){return ce(t,"@lensmcp/cluster:gateway",n,e)||(n||e?{project:n??"gateway",target:e??"serve"}:void 0)}d(Le,"it"),u(Le,"findGatewayTarget");function _e(t,n,e){return ce(t,"@lensmcp/cluster:trust",n,e)||(n?{project:n,target:e??"trust"}:Ae(t,"gateway")?{project:"gateway",target:e??"trust"}:void 0)}d(_e,"at"),u(_e,"findTrustTarget");function Ae(t,n){for(const e of W(t,s=>s==="project.json"))try{if((JSON.parse(H(e)).name??ee(M(e)))===n)return!0}catch{}return!1}d(Ae,"ct"),u(Ae,"projectExists");function Re(t){try{const n=Number(D(t,"utf8").trim());return Number.isInteger(n)&&n>0?n:void 0}catch{return}}d(Re,"dt"),u(Re,"readPid");function q(t){try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}d(q,"z"),u(q,"isAlive");function _(){try{const 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[]}}d(_,"I"),u(_,"pidsOnPort443");function Ie(t){try{return($("ps",["-o","command=","-p",String(t)],{encoding:"utf8"}).stdout??"").trim()}catch{return""}}d(Ie,"lt"),u(Ie,"processCmd");function F(t){const n=m(t,"node_modules","nx","dist","bin","run-executor.js"),e=m(t,"node_modules","@lensmcp","cluster");for(const s of _()){const r=Ie(s);if(r.includes(n)||r.includes(e))return s}}d(F,"G"),u(F,"gatewayOnPort443");function ue(t){try{return Date.now()-kt(t).mtimeMs}catch{return}}d(ue,"ye"),u(ue,"pidFileAgeMs");const Jt=18e4;export function classifyAliveGateway(t){if(t.oursOn443)return"serving";const n=t.pidFileAgeMs!==void 0&&t.pidFileAgeMs<(t.bootGraceMs??Jt);return!t.port443Held&&n?"booting":"zombie"}d(classifyAliveGateway,"classifyAliveGateway"),u(classifyAliveGateway,"classifyAliveGateway");function z(t,n){const e=Re(t);if(e!==void 0&&q(e))return{pid:e,healed:!1};const s=F(n);if(s!==void 0){try{K(t,String(s))}catch{}return{pid:s,healed:!0}}return{healed:!1}}d(z,"Y"),u(z,"reconcileGateway");function Y(t,n="SIGTERM"){try{process.kill(-t,n)}catch{try{process.kill(t,n)}catch{}}}d(Y,"X"),u(Y,"killGatewayTree");function de(t){const n=Date.now()+t;for(;;){if(_().length===0)return!0;if(Date.now()>=n)return!1;$("sleep",["0.15"])}}d(de,"ve"),u(de,"waitForPortFree");function De(t){const n=$("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"}d(De,"pt"),u(De,"probeHostTrust");function Fe(t){for(const n of W(t,e=>e==="project.json"))try{const e=JSON.parse(D(n,"utf8")),s=(e.cluster??e.davnx)?.host;if(s&&!s.includes("*"))return s}catch{}}d(Fe,"ft"),u(Fe,"firstClusterHost");function G(t){try{yt(t,{force:!0})}catch{}}d(G,"H"),u(G,"rmFile");function Ge(t,n,e,s){const r=T(n,{string:["--cwd","--host","--port"]}),o=x(w(r.flags["--cwd"])??t.cwd),a=V(o),i=w(r.flags["--host"])??t.env?.LENSMCP_WS_HOST??process.env.LENSMCP_WS_HOST,l=w(r.flags["--port"])??t.env?.LENSMCP_WS_PORT??process.env.LENSMCP_WS_PORT??String(a.ports.bridge),c=ot(o);if(!c)return s(`Could not locate the lensmcp bridge bundle.
|
|
138
138
|
Looked in (in order):
|
|
139
139
|
\u2022 <cli-package>/bundled/bridge.js (published bin)
|
|
140
140
|
\u2022 <workspace>/libs/bridge/dist/main.js (dev build)
|
|
141
|
-
For dev: \`yarn nx build @lensmcp/bridge\`.`),{exitCode:1};Z(o);const
|
|
142
|
-
`)}catch{}}u(Le,"He"),p(Le,"gt"),d(Le,"writeSetupState");async function Oe(t,n,e,s){const r=ct(n)?n:ve(t,e).mode,o=Lt(t,r);if(s(""),s(`[mcp] mode \u2192 ${r}`),o.wrote&&s(` wrote ${Mt}`),r==="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 ${o.url}`),s(" .mcp.json is unchanged \u2014 `lensmcp mcp` becomes a thin stdio shim.");const a=await dt(o.url);s(a.ok?` \u2713 already up \u2014 ${a.server??"MCP"} (protocol ${a.protocolVersion??"?"})`:` \xB7 not up yet (${a.error??"unknown"}) \u2014 the next session starts it on demand`)}u(Oe,"We"),p(Oe,"mt"),d(Oe,"applyMcpModeStep");function Ae(t,n,e){const s=ht({cwd:t,cliVersion:X()}),r=Wt({run:Jt(n),facts:s});if(!(r.outcome==="current"||r.outcome==="unknown")){if(e(""),r.outcome==="updated"){e(`[plugin] ${r.from} \u2192 ${r.to}`),e(" restart Claude Code for the new plugin to load.");return}e(`[plugin] the Claude Code plugin is ${r.from}, this lensmcp is ${r.to}.`),e(` could not update it automatically (${r.detail??"unknown reason"}). Run:`);for(const o of r.commands??[])e(` ${o}`);e(" \u2026then restart Claude Code.")}}u(Ae,"Je"),p(Ae,"wt"),d(Ae,"applyPluginSyncStep");async function _e(t,n,e,s){const r=E(n,{string:["--cwd","--mcp"]}),o=j(v(r.flags["--cwd"])??t.cwd),a={...t,cwd:o},i=v(r.flags["--mcp"]);if(i!==void 0&&!ct(i))return s(`setup: --mcp must be "embedded" or "shared" (got "${i}").`),{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=ue(a,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 c=le(a,n,e,s);if(c.exitCode!==0)return s(""),s("setup: the trust step failed \u2014 run `lensmcp setup` directly in a terminal so sudo can prompt."),c;e(""),e("[3/3] pods \u2014 recycle this workspace's devservers, reconcile the gateway");const h=B(o).key,f=tt(o,h,e);st(a,o,h,e),await Oe(o,i,t.env??process.env,e);try{Ae(o,{...process.env,...t.env??{}},e)}catch{}return Le(o),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}}u(_e,"Ke"),p(_e,"yt"),d(_e,"runSetup");async function Re(t,n,e){const s=E(n,{string:["--cwd","--hook","--timeout","--session"],boolean:["--json","--quiet"]}),r=j(v(s.flags["--cwd"])??t.cwd),o=v(s.flags["--hook"]),a=lt(o)?o:void 0,i=v(s.flags["--session"]);if(o!==void 0&&a===void 0)return{exitCode:0};const l=s.flags["--json"]===!0,c=s.flags["--quiet"]===!0||o!==void 0,h=Number(v(s.flags["--timeout"])??""),f=Number.isFinite(h)&&h>0?h:Ft,y={...process.env,...t.env??{}};try{const g=await Gt({cwd:r,env:y,budgetMs:f,verify:d(m=>At(m).map(K=>K.resource),"verify")});if(!g.available)return l&&!c?e(JSON.stringify({available:!1,workspace:g.source.workspace,mode:g.source.mode,reason:g.reason,elapsedMs:g.elapsedMs})):c||e(`lensmcp status \u2014 ${g.source.workspace}: unavailable (${g.reason})`),{exitCode:0};const S=Dt(g.status,g.evidence,Date.now()),$=It(S,{workspace:g.source.workspace,includeUnmonitored:a==="SessionStart"||!c});if(l)return c&&$===void 0?{exitCode:0}:(e(JSON.stringify({available:!0,workspace:g.source.workspace,mode:g.source.mode,url:g.source.url,aggregate:g.status.status??"unknown",elapsedMs:g.elapsedMs,findings:S.findings,suppressed:S.suppressed,unmonitored:S.unmonitored})),{exitCode:0});if(a){const m=Rt(S.findings);return Pt(i,m)?($!==void 0&&e(ut(a,$)),i&&Nt(i,m),{exitCode:0}):{exitCode:0}}if(c)return $!==void 0&&e($),{exitCode:0};if(e(`lensmcp status \u2014 ${g.source.workspace} (${g.source.mode}, ${g.source.url})`),e(` aggregate says: ${g.status.status??"unknown"} (read in ${g.elapsedMs}ms)`),S.findings.length===0)e(" nothing actionable that this command can vouch for.");else for(const m of S.findings)e(` \u2022 ${_t(m)}`);for(const m of S.suppressed)e(` \xB7 not reported \u2014 ${m.kind}: ${m.reason}`);return S.unmonitored.length>0&&e(` \xB7 unmonitored (unknown, NOT clean): ${S.unmonitored.join(", ")}`),{exitCode:0}}catch(g){return c||e(`lensmcp status: unavailable (${g instanceof Error?g.message:String(g)})`),{exitCode:0}}}u(Re,"Ve"),p(Re,"vt"),d(Re,"runStatus");function Ie(t,n,e){const s=E(n,{string:["--cwd","--hook","--plugin-root"],boolean:["--json","--quiet"]}),r=j(v(s.flags["--cwd"])??t.cwd),o=v(s.flags["--hook"]),a=lt(o)?o:void 0;if(o!==void 0&&a===void 0)return{exitCode:0};const i=s.flags["--json"]===!0,l=s.flags["--quiet"]===!0||o!==void 0,c=v(s.flags["--plugin-root"]);try{const h=ht({cwd:r,cliVersion:X(),...c?{pluginRoot:c}:{}}),f=Ht(h);if(i)return l&&!f?{exitCode:0}:(e(JSON.stringify({...h,skew:f??null})),{exitCode:0});if(a)return f&&e(ut(a,pt(f))),{exitCode:0};if(l)return f&&e(pt(f)),{exitCode:0};if(e(`lensmcp version-check \u2014 ${h.pluginId??"lensmcp plugin"}`),e(` plugin ${h.plugin??"unknown"}${h.pluginSource?` (${h.pluginSource})`:""}`),e(` project ${h.project??"unknown"} (node_modules/lensmcp)`),e(` cli ${h.cli??"unknown"} (the binary running now)`),!f)return e(h.plugin&&(h.project??h.cli)?" \u2713 in step.":" ? cannot compare \u2014 one of the versions is unreadable (staying silent)."),{exitCode:0};e(` \u2717 the plugin is ${f.direction} \u2014 update it, then restart Claude Code:`);for(const y of Kt(f))e(` ${y}`);return{exitCode:0}}catch(h){return l||e(`lensmcp version-check: unavailable (${h instanceof Error?h.message:String(h)})`),{exitCode:0}}}u(Ie,"Be"),p(Ie,"bt"),d(Ie,"runVersionCheck");async function De(t,n,e){const s=E(n,{string:["--cwd"],boolean:["--json"]}),r=j(v(s.flags["--cwd"])??t.cwd),o=s.flags["--json"]===!0,a=[];Fe(a),Ge(r,a),He(r,a),await Je(r,t.env??process.env,a),We(r,a),Ke(r,a),Ve(r,a),Be(a);const i=a.some(c=>c.status==="fail"),l=a.some(c=>c.status==="warn");if(o)return e(JSON.stringify({ok:!i,summary:{total:a.length,failed:a.filter(c=>c.status==="fail").length,warnings:a.filter(c=>c.status==="warn").length},checks:a},null,2)),{exitCode:i?1:0};for(const c of a){const h=c.status==="pass"?"\u2713":c.status==="warn"?"!":"\u2717";e(`${h} ${c.label}${c.detail?` \u2014 ${c.detail}`:""}`),c.status!=="pass"&&c.hint&&e(` \u21B3 ${c.hint}`)}return e(""),e(i?"doctor: issues found (see \u2717 above).":l?"doctor: ok, with warnings (!).":"doctor: all checks passed."),{exitCode:i?1:0}}u(De,"Ue"),p(De,"kt"),d(De,"runDoctor");function C(t,n,e,s,r){t.push({status:n,label:e,detail:s,hint:r})}u(C,"C"),p(C,"b"),d(C,"add");function Fe(t){const n=Number(process.versions.node.split(".")[0]);n>=20?C(t,"pass",`Node ${process.versions.node}`):n>=18?C(t,"warn",`Node ${process.versions.node}`,"older than recommended","upgrade to Node 20+ for best results"):C(t,"fail",`Node ${process.versions.node}`,"too old","LensMCP needs Node 18+ (20+ recommended)")}u(Fe,"qe"),p(Fe,"St"),d(Fe,"checkNode");function Ge(t,n){const e=w(t,"nx.json");if(!k(e)){C(n,"fail","nx.json at workspace root","missing","run `lensmcp` from inside a Nx workspace");return}let s;try{s=JSON.parse(W(e,"utf8"))}catch(o){C(n,"fail","nx.json parses",o.message,"fix the JSON syntax in nx.json");return}const r=(s.plugins??[]).some(o=>typeof o=="string"?o==="@lensmcp/nx-plugin":!!o&&typeof o=="object"&&o.plugin==="@lensmcp/nx-plugin");C(n,r?"pass":"fail","@lensmcp/nx-plugin registered in nx.json#plugins",r?void 0:"not registered",r?void 0:"run `lensmcp install`"),C(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")}u(Ge,"ze"),p(Ge,"Ct"),d(Ge,"checkWorkspace");function He(t,n){const e=w(t,".mcp.json");if(!k(e)){C(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(W(e,"utf8")),r=!!s.mcpServers&&!!s.mcpServers.lensmcp;C(n,r?"pass":"warn",".mcp.json registers the lensmcp MCP server",r?void 0:"no lensmcp entry",r?void 0:"run `lensmcp install`")}catch(s){C(n,"warn",".mcp.json parses",s.message,"fix the JSON syntax in .mcp.json")}}u(He,"Ye"),p(He,"$t"),d(He,"checkMcpConfig");async function Je(t,n,e){const s=ve(t,n);if(C(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 r=await dt(s.url);C(e,r.ok?"pass":"warn","shared MCP server",r.ok?`${r.server??"MCP"} @ ${s.url} (protocol ${r.protocolVersion??"?"})`:`not running at ${s.url} \u2014 ${r.error??"no answer"}`,r.ok?void 0:"the next agent session starts it on demand; `lensmcp gateway start` starts it now")}u(Je,"Xe"),p(Je,"Nt"),d(Je,"checkMcpMode");function pe(t,n){const e=ve(t,n);if(e.mode!=="shared")return{mode:e.mode,url:e.url,port:e.port,healthy:!1};const s=Tt(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}:{}}}u(pe,"he"),p(pe,"Se"),d(pe,"mcpStatusBlock");function We(t,n){const e=se(t);C(n,e?"pass":"fail","lensmcp-mcp server bundle reachable",e??"missing",e?void 0:"dev: `yarn nx build @lensmcp/lensmcp-mcp`")}u(We,"Qe"),p(We,"jt"),d(We,"checkServerBundle");function Ke(t,n){const e=w(t,".lensmcp");C(n,k(e)?"pass":"warn",".lensmcp/ runtime directory",k(e)?void 0:"not created yet",k(e)?void 0:"created automatically on first `lensmcp mcp` run");const s=w(t,".gitignore"),r=(k(s)?D(s):"").split(`
|
|
143
|
-
`).some(o=>o.trim()===".lensmcp/"||o.trim()===".lensmcp");C(n,r?"pass":"warn",".gitignore excludes .lensmcp/",r?void 0:"not ignored",r?void 0:"add `.lensmcp/` to .gitignore (lensmcp install does this)")}
|
|
141
|
+
For dev: \`yarn nx build @lensmcp/bridge\`.`),{exitCode:1};Z(o);const p=t.env?.LENSMCP_EVENT_FILE??process.env.LENSMCP_EVENT_FILE??m(o,".lensmcp","events.jsonl"),h={...process.env,...t.env??{},LENSMCP_EVENT_FILE:p};return i&&(h.LENSMCP_WS_HOST=i),l&&(h.LENSMCP_WS_PORT=l),e(`lensmcp bridge \u2192 ws://${i??"127.0.0.1"}:${l??"5747"} (forwarding to ${p})`),{exitCode:$(process.execPath,[c],{cwd:o,stdio:"inherit",env:h}).status??1}}d(Ge,"ht"),u(Ge,"runBridge");function le(t,n,e,s){const r=T(n,{string:["--cwd","--register-host-config"],boolean:["--skip-format","--yes"]}),o=x(w(r.flags["--cwd"])??t.cwd);if(!y(m(o,"nx.json")))return s(`No nx.json found at ${o}.`),s("Run `lensmcp install` from inside a Nx workspace."),{exitCode:1};const a=Q(o);if(!a)return s("Could not find the `nx` binary in the host workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};const i=["g","@lensmcp/nx-plugin:init","--no-interactive"];return r.flags["--skip-format"]===!0&&i.push("--skipFormat"),r.flags["--register-host-config"]&&i.push(`--registerHostConfig=${String(r.flags["--register-host-config"])}`),e(`> ${a} ${i.join(" ")}`),{exitCode:$(a,i,{cwd:o,stdio:"inherit",env:{...process.env,...t.env??{}}}).status??1}}d(le,"be"),u(le,"runInstall");function pe(t,n,e,s){const r=T(n,{string:["--cwd","--project","--target"]}),o=x(w(r.flags["--cwd"])??t.cwd);if(!y(m(o,"nx.json")))return s(`No nx.json found at ${o}.`),s("Run `lensmcp trust` from inside a Nx workspace (after `lensmcp install`)."),{exitCode:1};const a=Q(o);if(!a)return s("Could not find the `nx` binary in the workspace. Install Nx first: `yarn add -D nx`."),{exitCode:1};const i=_e(o,w(r.flags["--project"]),w(r.flags["--target"])),l=O("GET","/list")?.status===200&&F(o)===void 0;if(!i){if(s("This workspace has no trust target \u2014 no project declares the `@lensmcp/cluster:trust` executor."),s(""),l){const p=Te();s(` A shared gateway daemon${p?` (owned by '${p}')`:""} 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}}it()||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(`> ${a} run ${i.project}:${i.target} (sudo prompts inline for ${l?"/etc/hosts":"the CA + /etc/hosts"})`);const c=$(a,["run",`${i.project}:${i.target}`],{cwd:o,stdio:"inherit",env:{...process.env,...t.env??{},...l?{LENSMCP_TRUST_HOSTS_ONLY:"1"}:{}}});if(l&&c.status===0){const p=Fe(o);if(p){const h=De(p);e(""),e(h==="trusted"?` \u2713 ${p} \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 ${p} \u2192 the daemon's cert is NOT trusted yet. Run \`lensmcp trust\` in the DAEMON workspace (it owns the CA), then restart your browser.`:` ? ${p} \u2192 couldn't reach it to verify (is the daemon running?). /etc/hosts is set; TLS rides the daemon's CA.`)}}return{exitCode:c.status??1}}d(pe,"ke"),u(pe,"runTrust");function He(t){Z(t);const n={version:X(),completedAt:new Date().toISOString(),steps:{install:!0,trust:!0}};try{K(m(t,".lensmcp","setup-state.json"),`${JSON.stringify(n,null,2)}
|
|
142
|
+
`)}catch{}}d(He,"gt"),u(He,"writeSetupState");async function We(t,n,e,s){const r=be(n)?n:ie(t,e).mode,o=Mt(t,r);if(s(""),s(`[mcp] mode \u2192 ${r}`),o.wrote&&s(` wrote ${Pt}`),r==="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 ${o.url}`),s(" .mcp.json is unchanged \u2014 `lensmcp mcp` becomes a thin stdio shim.");const a=await Ce(o.url);s(a.ok?` \u2713 already up \u2014 ${a.server??"MCP"} (protocol ${a.protocolVersion??"?"})`:` \xB7 not up yet (${a.error??"unknown"}) \u2014 the next session starts it on demand`)}d(We,"mt"),u(We,"applyMcpModeStep");function Je(t,n,e){const s=je({cwd:t,cliVersion:X()}),r=Ht({run:Gt(n),facts:s});if(!(r.outcome==="current"||r.outcome==="unknown")){if(e(""),r.outcome==="updated"){e(`[plugin] ${r.from} \u2192 ${r.to}`),e(" restart Claude Code for the new plugin to load.");return}e(`[plugin] the Claude Code plugin is ${r.from}, this lensmcp is ${r.to}.`),e(` could not update it automatically (${r.detail??"unknown reason"}). Run:`);for(const o of r.commands??[])e(` ${o}`);e(" \u2026then restart Claude Code.")}}d(Je,"wt"),u(Je,"applyPluginSyncStep");async function Ke(t,n,e,s){const r=T(n,{string:["--cwd","--mcp"]}),o=x(w(r.flags["--cwd"])??t.cwd),a={...t,cwd:o},i=w(r.flags["--mcp"]);if(i!==void 0&&!be(i))return s(`setup: --mcp must be "embedded" or "shared" (got "${i}").`),{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=le(a,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 c=pe(a,n,e,s);if(c.exitCode!==0)return s(""),s("setup: the trust step failed \u2014 run `lensmcp setup` directly in a terminal so sudo can prompt."),c;e(""),e("[3/3] pods \u2014 recycle this workspace's devservers, reconcile the gateway");const p=V(o).key,h=dt(o,p,e);lt(a,o,p,e),await We(o,i,t.env??process.env,e);try{Je(o,{...process.env,...t.env??{}},e)}catch{}return He(o),e(""),e("\u2713 setup complete."),(h.killed>0||h.stale>0)&&e(` recycled ${h.killed} pod${h.killed===1?"":"s"}`+(h.stale>0?` (+${h.stale} stale socket${h.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}}d(Ke,"yt"),u(Ke,"runSetup");async function Ve(t,n,e){const s=T(n,{string:["--cwd","--hook","--timeout","--session"],boolean:["--json","--quiet"]}),r=x(w(s.flags["--cwd"])??t.cwd),o=w(s.flags["--hook"]),a=$e(o)?o:void 0,i=w(s.flags["--session"]);if(o!==void 0&&a===void 0)return{exitCode:0};const l=s.flags["--json"]===!0,c=s.flags["--quiet"]===!0||o!==void 0,p=Number(w(s.flags["--timeout"])??""),h=Number.isFinite(p)&&p>0?p:It,v={...process.env,...t.env??{}};try{const f=await Dt({cwd:r,env:v,budgetMs:h,verify:u(g=>Ot(g).map(J=>J.resource),"verify")});if(!f.available)return l&&!c?e(JSON.stringify({available:!1,workspace:f.source.workspace,mode:f.source.mode,reason:f.reason,elapsedMs:f.elapsedMs})):c||e(`lensmcp status \u2014 ${f.source.workspace}: unavailable (${f.reason})`),{exitCode:0};const b=Rt(f.status,f.evidence,Date.now()),S=At(b,{workspace:f.source.workspace,includeUnmonitored:a==="SessionStart"||!c});if(l)return c&&S===void 0?{exitCode:0}:(e(JSON.stringify({available:!0,workspace:f.source.workspace,mode:f.source.mode,url:f.source.url,aggregate:f.status.status??"unknown",elapsedMs:f.elapsedMs,findings:b.findings,suppressed:b.suppressed,unmonitored:b.unmonitored})),{exitCode:0});if(a){const g=_t(b.findings);return jt(i,g)?(S!==void 0&&e(Se(a,S)),i&&xt(i,g),{exitCode:0}):{exitCode:0}}if(c)return S!==void 0&&e(S),{exitCode:0};if(e(`lensmcp status \u2014 ${f.source.workspace} (${f.source.mode}, ${f.source.url})`),e(` aggregate says: ${f.status.status??"unknown"} (read in ${f.elapsedMs}ms)`),b.findings.length===0)e(" nothing actionable that this command can vouch for.");else for(const g of b.findings)e(` \u2022 ${Lt(g)}`);for(const g of b.suppressed)e(` \xB7 not reported \u2014 ${g.kind}: ${g.reason}`);return b.unmonitored.length>0&&e(` \xB7 unmonitored (unknown, NOT clean): ${b.unmonitored.join(", ")}`),{exitCode:0}}catch(f){return c||e(`lensmcp status: unavailable (${f instanceof Error?f.message:String(f)})`),{exitCode:0}}}d(Ve,"vt"),u(Ve,"runStatus");function Be(t,n,e){const s=T(n,{string:["--cwd","--hook","--plugin-root"],boolean:["--json","--quiet"]}),r=x(w(s.flags["--cwd"])??t.cwd),o=w(s.flags["--hook"]),a=$e(o)?o:void 0;if(o!==void 0&&a===void 0)return{exitCode:0};const i=s.flags["--json"]===!0,l=s.flags["--quiet"]===!0||o!==void 0,c=w(s.flags["--plugin-root"]);try{const p=je({cwd:r,cliVersion:X(),...c?{pluginRoot:c}:{}}),h=Ft(p);if(i)return l&&!h?{exitCode:0}:(e(JSON.stringify({...p,skew:h??null})),{exitCode:0});if(a)return h&&e(Se(a,xe(h))),{exitCode:0};if(l)return h&&e(xe(h)),{exitCode:0};if(e(`lensmcp version-check \u2014 ${p.pluginId??"lensmcp plugin"}`),e(` plugin ${p.plugin??"unknown"}${p.pluginSource?` (${p.pluginSource})`:""}`),e(` project ${p.project??"unknown"} (node_modules/lensmcp)`),e(` cli ${p.cli??"unknown"} (the binary running now)`),!h)return e(p.plugin&&(p.project??p.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 v of Wt(h))e(` ${v}`);return{exitCode:0}}catch(p){return l||e(`lensmcp version-check: unavailable (${p instanceof Error?p.message:String(p)})`),{exitCode:0}}}d(Be,"bt"),u(Be,"runVersionCheck");async function Ue(t,n,e){const s=T(n,{string:["--cwd"],boolean:["--json"]}),r=x(w(s.flags["--cwd"])??t.cwd),o=s.flags["--json"]===!0,a=[];qe(a),ze(r,a),Ye(r,a),await Xe(r,t.env??process.env,a),Qe(r,a),Ze(r,a),et(r,a),tt(a);const i=a.some(c=>c.status==="fail"),l=a.some(c=>c.status==="warn");if(o)return e(JSON.stringify({ok:!i,summary:{total:a.length,failed:a.filter(c=>c.status==="fail").length,warnings:a.filter(c=>c.status==="warn").length},checks:a},null,2)),{exitCode:i?1:0};for(const c of a){const p=c.status==="pass"?"\u2713":c.status==="warn"?"!":"\u2717";e(`${p} ${c.label}${c.detail?` \u2014 ${c.detail}`:""}`),c.status!=="pass"&&c.hint&&e(` \u21B3 ${c.hint}`)}return e(""),e(i?"doctor: issues found (see \u2717 above).":l?"doctor: ok, with warnings (!).":"doctor: all checks passed."),{exitCode:i?1:0}}d(Ue,"kt"),u(Ue,"runDoctor");function C(t,n,e,s,r){t.push({status:n,label:e,detail:s,hint:r})}d(C,"b"),u(C,"add");function qe(t){const n=Number(process.versions.node.split(".")[0]);n>=20?C(t,"pass",`Node ${process.versions.node}`):n>=18?C(t,"warn",`Node ${process.versions.node}`,"older than recommended","upgrade to Node 20+ for best results"):C(t,"fail",`Node ${process.versions.node}`,"too old","LensMCP needs Node 18+ (20+ recommended)")}d(qe,"St"),u(qe,"checkNode");function ze(t,n){const e=m(t,"nx.json");if(!y(e)){C(n,"fail","nx.json at workspace root","missing","run `lensmcp` from inside a Nx workspace");return}let s;try{s=JSON.parse(D(e,"utf8"))}catch(o){C(n,"fail","nx.json parses",o.message,"fix the JSON syntax in nx.json");return}const r=(s.plugins??[]).some(o=>typeof o=="string"?o==="@lensmcp/nx-plugin":!!o&&typeof o=="object"&&o.plugin==="@lensmcp/nx-plugin");C(n,r?"pass":"fail","@lensmcp/nx-plugin registered in nx.json#plugins",r?void 0:"not registered",r?void 0:"run `lensmcp install`"),C(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")}d(ze,"Ct"),u(ze,"checkWorkspace");function Ye(t,n){const e=m(t,".mcp.json");if(!y(e)){C(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(D(e,"utf8")),r=!!s.mcpServers&&!!s.mcpServers.lensmcp;C(n,r?"pass":"warn",".mcp.json registers the lensmcp MCP server",r?void 0:"no lensmcp entry",r?void 0:"run `lensmcp install`")}catch(s){C(n,"warn",".mcp.json parses",s.message,"fix the JSON syntax in .mcp.json")}}d(Ye,"$t"),u(Ye,"checkMcpConfig");async function Xe(t,n,e){const s=ie(t,n);if(C(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 r=await Ce(s.url);C(e,r.ok?"pass":"warn","shared MCP server",r.ok?`${r.server??"MCP"} @ ${s.url} (protocol ${r.protocolVersion??"?"})`:`not running at ${s.url} \u2014 ${r.error??"no answer"}`,r.ok?void 0:"the next agent session starts it on demand; `lensmcp gateway start` starts it now")}d(Xe,"Nt"),u(Xe,"checkMcpMode");function he(t,n){const e=ie(t,n);if(e.mode!=="shared")return{mode:e.mode,url:e.url,port:e.port,healthy:!1};const s=Et(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}:{}}}d(he,"Se"),u(he,"mcpStatusBlock");function Qe(t,n){const e=se(t);C(n,e?"pass":"fail","lensmcp-mcp server bundle reachable",e??"missing",e?void 0:"dev: `yarn nx build @lensmcp/lensmcp-mcp`")}d(Qe,"jt"),u(Qe,"checkServerBundle");function Ze(t,n){const e=m(t,".lensmcp");C(n,y(e)?"pass":"warn",".lensmcp/ runtime directory",y(e)?void 0:"not created yet",y(e)?void 0:"created automatically on first `lensmcp mcp` run");const s=m(t,".gitignore"),r=(y(s)?H(s):"").split(`
|
|
143
|
+
`).some(o=>o.trim()===".lensmcp/"||o.trim()===".lensmcp");C(n,r?"pass":"warn",".gitignore excludes .lensmcp/",r?void 0:"not ignored",r?void 0:"add `.lensmcp/` to .gitignore (lensmcp install does this)")}d(Ze,"xt"),u(Ze,"checkRuntimeDir");function et(t,n){const e=W(t,i=>/^vite\.config\.[cm]?[jt]s$/.test(i)),s=e.filter(i=>/lensmcpVitePlugin|@lensmcp\/vite-plugin/.test(H(i)));if(e.length>0){const i=s.length===e.length;C(n,i?"pass":"warn",`Vite wiring: ${s.length}/${e.length} config(s) use the LensMCP plugin`,void 0,i?void 0:"wire each: `nx g @lensmcp/nx-plugin:setup-vite <project>`")}const r=W(t,i=>i==="main.ts").filter(i=>/NestFactory\.create|createLensmcpNestApp/.test(H(i))),o=r.filter(i=>/createLensmcpNestApp/.test(H(i)));if(r.length>0){const i=o.length===r.length;C(n,i?"pass":"warn",`Nest wiring: ${o.length}/${r.length} bootstrap(s) use createLensmcpNestApp`,void 0,i?void 0:"wire each: `nx g @lensmcp/nx-plugin:setup-nest <project>`")}const a=W(t,i=>i==="project.json"||i==="package.json").filter(i=>/"agent-dev"/.test(H(i)));C(n,a.length>0?"pass":"warn",`agent-dev targets: ${a.length} project(s)`,void 0,a.length>0?void 0:"no project wired \u2014 run setup-vite / setup-nest")}d(et,"Pt"),u(et,"checkProjectWiring");function tt(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&&y(n)?n:void 0)??e.find(r=>y(r));C(t,s?"pass":"warn","Chrome for browser:// capture",s?ee(s):"not found",s?void 0:"install Chrome or set CHROME_PATH (only needed for browser capture)")}d(tt,"Et"),u(tt,"checkChrome");function H(t){try{return D(t,"utf8")}catch{return""}}d(H,"J"),u(H,"safeRead");function W(t,n,e=6,s=6e3){const r=new Set(["node_modules","dist","build",".git",".nx",".lensmcp","coverage","tmp",".cache",".yarn"]),o=[],a=[{dir:t,depth:0}];let i=0;for(;a.length>0;){const{dir:l,depth:c}=a.pop();let p;try{p=oe(l,{withFileTypes:!0})}catch{continue}for(const h of p){if(i++>s)return o;if(h.isDirectory()){if(r.has(h.name)||h.name.startsWith("."))continue;c<e&&a.push({dir:m(l,h.name),depth:c+1})}else h.isFile()&&n(h.name)&&o.push(m(l,h.name))}}return o}d(W,"W"),u(W,"walkProjectFiles");function te(){let t=M($t(import.meta.url));for(let n=0;n<4;n++){if(y(m(t,"package.json")))return t;const e=M(t);if(e===t)break;t=e}return t}d(te,"se"),u(te,"cliPackageRoot");function X(){try{return JSON.parse(D(m(te(),"package.json"),"utf8")).version}catch{return"0.0.0"}}d(X,"Q"),u(X,"readCliVersion");function st(t,n,e){const s=x(t.cwd),r=nt(s);return r?{exitCode:$(process.execPath,[r,...n],{stdio:"inherit",cwd:s,env:{...process.env,...t.env}}).status??1}:(e(`Could not locate the lensmcp rollout helper (@lensmcp/cluster).
|
|
144
144
|
Looked for main.rollout.js (walking up from cwd):
|
|
145
145
|
\u2022 <dir>/node_modules/@lensmcp/cluster/executors/gateway/main.rollout.js
|
|
146
146
|
\u2022 <dir>/dist/libs/cluster/executors/gateway/main.rollout.js
|
|
147
|
-
Install @lensmcp/cluster, or \`yarn nx build @lensmcp/cluster\` in the workspace.`),{exitCode:1})}
|
|
148
|
-
`)[0]?.trim());return Number.isInteger(e)&&e>0?e:void 0}catch{return}}
|
|
149
|
-
`).find(e=>e.startsWith("n"));return n&&n.slice(1).trim()||void 0}catch{return}}
|
|
147
|
+
Install @lensmcp/cluster, or \`yarn nx build @lensmcp/cluster\` in the workspace.`),{exitCode:1})}d(st,"Mt"),u(st,"runRollout");function nt(t){let n=t;for(let e=0;e<6;e++){for(const r of[m(n,"node_modules","@lensmcp","cluster","executors","gateway","main.rollout.js"),m(n,"dist","libs","cluster","executors","gateway","main.rollout.js")])if(y(r))return r;const s=M(n);if(s===n)break;n=s}}d(nt,"Tt"),u(nt,"findRolloutBundle");function se(t){return ne(t,"main.js")}d(se,"re"),u(se,"findMcpBinary");function rt(t){return ne(t,"shim.js")}d(rt,"Ot"),u(rt,"findShimBinary");function ne(t,n){const e=m(te(),"bundled",n);if(y(e))return e;const s=m(t,"servers","lensmcp-mcp","dist",n);if(y(s))return s;let r=t;for(let o=0;o<5;o++){const a=m(r,"servers","lensmcp-mcp","dist",n);if(y(a))return a;const i=M(r);if(i===r)break;r=i}}d(ne,"oe"),u(ne,"findServerBundle");function ot(t){const n=m(te(),"bundled","bridge.js");if(y(n))return n;let e=t;for(let s=0;s<5;s++){const r=m(e,"libs","bridge","dist","main.js");if(y(r))return r;const o=M(e);if(o===e)break;e=o}}d(ot,"Lt"),u(ot,"findBridgeBundle");function Q(t){let n=t;for(let e=0;e<5;e++){const s=m(n,"node_modules",".bin","nx");if(y(s))return s;const r=M(n);if(r===n)break;n=r}}d(Q,"Z"),u(Q,"findNxBinary");function Z(t){const n=m(t,".lensmcp");y(n)||B(n,{recursive:!0})}d(Z,"ee"),u(Z,"ensureLensmcpDir");function it(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}d(it,"Rt"),u(it,"isInteractive");function re(){const t=Ct(),n=[],e=u((s,r)=>{try{for(const o of oe(s,{withFileTypes:!0})){if(!o.isDirectory()||!o.name.endsWith("-devserver"))continue;const a=m(s,o.name,"parent.sock");y(a)&&n.push({service:o.name.slice(0,-10),wsKey:r,sock:a})}}catch{}},"scan");e(t,"");try{for(const s of oe(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,r)=>`${s.wsKey}/${s.service}`.localeCompare(`${r.wsKey}/${r.service}`))}d(re,"ie"),u(re,"discoverDevserverSocks");const A=u(t=>t.wsKey?`${t.wsKey}/${t.service}`:t.service,"fullServiceName");function fe(t){try{const n=$("lsof",["-t",t],{encoding:"utf8"}),e=Number((n.stdout??"").split(`
|
|
148
|
+
`)[0]?.trim());return Number.isInteger(e)&&e>0?e:void 0}catch{return}}d(fe,"Ce"),u(fe,"pidOnSocket");function ge(t){try{const n=$("ps",["-o","pgid=","-p",String(t)],{encoding:"utf8"}),e=Number((n.stdout??"").trim());return Number.isInteger(e)&&e>1?e:void 0}catch{return}}d(ge,"$e"),u(ge,"pgidOf");function at(t){try{const n=($("lsof",["-a","-p",String(t),"-d","cwd","-Fn"],{encoding:"utf8"}).stdout??"").split(`
|
|
149
|
+
`).find(e=>e.startsWith("n"));return n&&n.slice(1).trim()||void 0}catch{return}}d(at,"_t"),u(at,"cwdOfPid");function ct(t,n){const e=ke(x(t),x(n));return e===""||!e.startsWith("..")&&!St(e)}d(ct,"At"),u(ct,"isInside");function ut(t,n){return re().filter(e=>{if(e.wsKey)return e.wsKey===n;const s=fe(e.sock),r=s!==void 0?at(s):void 0;return r!==void 0&&ct(t,r)})}d(ut,"It"),u(ut,"workspaceDevservers");function dt(t,n,e){const s=ut(t,n);if(s.length===0)return e(" no devserver pods running for this workspace \u2014 nothing to recycle."),{killed:0,stale:0};const r=new Set;for(const i of[process.pid,..._()]){const l=ge(i);l!==void 0&&r.add(l)}let o=0,a=0;for(const i of s){const l=A(i),c=fe(i.sock);if(c===void 0){G(i.sock),e(` \u2713 ${l} \u2014 stale socket removed (no process held it)`),a++;continue}const p=ge(c),h=p!==void 0&&!r.has(p),v=u(f=>{try{h?process.kill(-p,f):process.kill(c,f)}catch{}},"signal");v("SIGTERM"),me(c,5e3)||(v("SIGKILL"),me(c,2e3)),G(i.sock),e(` \u2713 ${l} \u2014 stopped (pid ${c}${h?`, group ${p}`:", parent only"})`),o++}return{killed:o,stale:a}}d(dt,"Dt"),u(dt,"reapWorkspacePods");function me(t,n){const e=Date.now()+n;for(;;){if(!q(t))return!0;if(Date.now()>=e)return!1;$("sleep",["0.15"])}}d(me,"Ne"),u(me,"waitForPidGone");function lt(t,n,e,s){const r=m(n,".lensmcp","gateway.pid"),o=m(n,".lensmcp","registered.json"),{pid:a,healed:i}=z(r,n);if(i&&s(` healed: adopted a running gateway (pid ${a}) the pid file had lost.`),U(n,t.env,p=>s(` ${p}`)),F(n)!==void 0){s(` gateway: this workspace owns the :443 daemon (pid ${a??"?"}) \u2014 left running, pods respawn fresh.`);return}const l=O("GET","/list");if(l?.status!==200){s(" gateway: not running. Start it when you are ready: lensmcp gateway start");return}if(l.json&&typeof l.json=="object"&&(l.json.workspaces??[]).some(p=>p.key===e)){B(M(o),{recursive:!0}),K(o,JSON.stringify({wsKey:e})),s(` gateway: '${e}' is already registered into the shared daemon \u2014 left serving.`);return}const c=O("POST","/register",{wsKey:e,root:n,projects:ae(n)});if(c&&c.status===200){B(M(o),{recursive:!0}),K(o,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 run `lensmcp gateway start`.")}d(lt,"Ft"),u(lt,"reconcileGatewayAfterSetup");function we(t,n,e,s){let r=n.filter(o=>o.service===t||A(o)===t);if(r.length>1)try{const o=V(e).key,a=r.filter(i=>i.wsKey===o);a.length===1&&(r=a)}catch{}return r.length===0?(s(`No running service named "${t}".`),n.length>0&&s(`Running: ${n.map(A).join(", ")}`),null):r.length>1?(s(`"${t}" is ambiguous \u2014 use one of: ${r.map(A).join(", ")}`),null):r[0]}d(we,"je"),u(we,"resolveServiceSock");async function pt(t,n,e,s){const r=T(n,{string:["--tail","--cwd"],boolean:["--no-follow","--plain","--color"]}),o=r.positional[0],a=re();if(!o){if(a.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 f of a)e(` ${A(f)}`)}return{exitCode:0}}const i=we(o,a,x(w(r.flags["--cwd"])??t.cwd),s);if(!i)return{exitCode:1};const l=r.flags["--no-follow"]!==!0,c=Number(w(r.flags["--tail"])??NaN),p=Number.isInteger(c)&&c>=0?c:100,h=r.flags["--plain"]===!0||r.flags["--color"]!==!0&&!process.stdout.isTTY,v=`/webpack/logs?tail=${p}&follow=${l?1:0}${h?"&plain=1":""}`;return new Promise(f=>{const b=ye({socketPath:i.sock,path:v,method:"GET"},S=>{S.on("data",g=>process.stdout.write(g)),S.on("end",()=>f({exitCode:0})),S.on("error",()=>f({exitCode:1}))});b.on("error",S=>{s(`Cannot attach to ${A(i)}: ${S.message}`),s("The devserver may have crashed leaving a stale socket \u2014 restart the service and retry."),f({exitCode:1})}),b.end()})}d(pt,"Gt"),u(pt,"runLogs");async function ht(t,n,e,s){const r=T(n,{string:["--port","--cwd"]}),o=r.positional[0],a=re();if(!o)return s("Usage: lensmcp debug <service> [--port <base>]"),a.length>0&&s(`Running: ${a.map(A).join(", ")}`),{exitCode:2};const i=we(o,a,x(w(r.flags["--cwd"])??t.cwd),s);if(!i)return{exitCode:1};const l=Number(w(r.flags["--port"])??"")||void 0,c=`/webpack/debug${l?`?port=${l}`:""}`,p=await new Promise(v=>{const f=ye({socketPath:i.sock,path:c,method:"POST"},b=>{let S="";b.on("data",g=>S+=g),b.on("end",()=>v(S)),b.on("error",()=>v(null))});f.on("error",()=>v(null)),f.end()});if(p===null)return s(`Cannot reach ${A(i)} \u2014 the devserver may have crashed leaving a stale socket.`),{exitCode:1};let h;try{h=JSON.parse(p)}catch{return s(`Unexpected response from the devserver: ${p.slice(0,200)}`),{exitCode:1}}e(`Inspectors open on ${A(i)} \u2014 in place, no restart:`);for(const v of h.pods??[])e(` pod #${v.id} ${v.inspectorUrl??"(no url reported \u2014 check lensmcp logs)"}`);for(const v of h.workers??[])e(` worker ${v.name} 127.0.0.1:${v.port}`);return e(`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 ${o}\`.`),{exitCode:0}}d(ht,"Ht"),u(ht,"runDebug");function w(t){if(t!==void 0)return typeof t=="string"?t:void 0}d(w,"w"),u(w,"stringFlag");function T(t,n={}){const e=new Set(n.string??[]),s=new Set(n.boolean??[]),r={},o=[];for(let a=0;a<t.length;a++){const i=t[a];if(i.startsWith("--")){const l=i.indexOf("="),c=l===-1?i:i.slice(0,l);if(s.has(c))r[c]=!0;else if(e.has(c))if(l!==-1)r[c]=i.slice(l+1);else{const p=t[a+1];p===void 0||p.startsWith("--")?r[c]="":(r[c]=p,a++)}else r[c]=l===-1?!0:i.slice(l+1)}else o.push(i)}return{flags:r,positional:o}}d(T,"M"),u(T,"parseFlags");
|
package/lib/hook-memory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var n=(r,e)=>i(r,"name",{value:e,configurable:!0});var m=Object.defineProperty,o=n((r,e)=>m(r,"name",{value:e,configurable:!0}),"n");import{mkdirSync as s,readFileSync as u,rmSync as f,writeFileSync as l}from"node:fs";import{tmpdir as p}from"node:os";import{join as a}from"node:path";const y=o(r=>r.replace(/[^A-Za-z0-9._-]/g,"_").slice(0,100)||"unknown","safeKey");export const memoryPathFor=o((r,e=p())=>a(e,"lensmcp-hook",`${y(r)}.digest`),"memoryPathFor");export function lastAnnounced(r,e){try{return u(memoryPathFor(r,e),"utf8")}catch{return}}n(lastAnnounced,"lastAnnounced"),o(lastAnnounced,"lastAnnounced");export function remember(r,e,t){const c=memoryPathFor(r,t);try{if(!e){f(c,{force:!0});return}s(a(c,".."),{recursive:!0}),l(c,e)}catch{}}n(remember,"remember"),o(remember,"remember");export function shouldAnnounce(r,e,t){return e?r?lastAnnounced(r,t)!==e:!0:!1}n(shouldAnnounce,"shouldAnnounce"),o(shouldAnnounce,"shouldAnnounce");
|
package/lib/mcp-mode.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`;return{json:
|
|
1
|
+
"use strict";var a=Object.defineProperty;var o=(e,r)=>a(e,"name",{value:r,configurable:!0});var d=Object.defineProperty,n=o((e,r)=>d(e,"name",{value:r,configurable:!0}),"e");export const DEFAULT_MCP_MODE="embedded",SHARED_MCP_ENTRY_PATH="/mcp",SHARED_MCP_BIND_ADDRESS="127.0.0.1";export function isMcpMode(e){return e==="embedded"||e==="shared"}o(isMcpMode,"isMcpMode"),n(isMcpMode,"isMcpMode");export function sharedMcpUrl(e,r=SHARED_MCP_BIND_ADDRESS){return`http://${r}:${e}${SHARED_MCP_ENTRY_PATH}`}o(sharedMcpUrl,"sharedMcpUrl"),n(sharedMcpUrl,"sharedMcpUrl");export function resolveMcpMode(e={}){for(const r of[e.flag,e.env,e.config])if(isMcpMode(r))return r;return DEFAULT_MCP_MODE}o(resolveMcpMode,"resolveMcpMode"),n(resolveMcpMode,"resolveMcpMode");function i(e){if(!e||!e.trim())return{};try{const r=JSON.parse(e);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}o(i,"i"),n(i,"parseObject");export function applyConfigMcpMode(e,r){const t=i(e),c=t.mcp,s=c&&typeof c=="object"&&!Array.isArray(c)?{...c,mode:r}:{mode:r},p=JSON.stringify({...t,mcp:s},null,2)+`
|
|
2
|
+
`;return{json:p,changed:p!==e}}o(applyConfigMcpMode,"applyConfigMcpMode"),n(applyConfigMcpMode,"applyConfigMcpMode");
|
package/lib/mcp-wiring.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var i=(e,r)=>y(e,"name",{value:r,configurable:!0});var
|
|
2
|
-
`).find(t=>t.startsWith("data:")),o=r?r.slice(5).trim():e.trim();try{const t=JSON.parse(o);return t.result?{ok:!0,...t.result.serverInfo?.name?{server:t.result.serverInfo.name}:{},...t.result.protocolVersion?{protocolVersion:t.result.protocolVersion}:{}}:{ok:!1,error:"no initialize result"}}catch{return{ok:!1,error:"unreadable initialize response"}}}i(parseInitializeResponse,"parseInitializeResponse"),
|
|
1
|
+
"use strict";var y=Object.defineProperty;var i=(e,r)=>y(e,"name",{value:r,configurable:!0});var S=Object.defineProperty,c=i((e,r)=>S(e,"name",{value:r,configurable:!0}),"s");import{spawnSync as v}from"node:child_process";import{existsSync as x,mkdirSync as k,readFileSync as j,writeFileSync as b}from"node:fs";import{request as C}from"node:http";import{dirname as w,join as f}from"node:path";import{applyConfigMcpMode as E,resolveMcpMode as O,sharedMcpUrl as h}from"./mcp-mode.js";import{readLensConfig as d}from"./workspace-scope.js";export const LENS_CONFIG=f(".lensmcp","config.json");function g(e){try{return j(e,"utf8")}catch{return}}i(g,"E"),c(g,"read");export function effectiveMcpMode(e,r,o=process.env){return O({flag:r,env:o.LENSMCP_MCP_MODE,config:d(e).mcp?.mode})}i(effectiveMcpMode,"effectiveMcpMode"),c(effectiveMcpMode,"effectiveMcpMode");export function wireMcpMode(e,r){const o=d(e).ports.mcpHttp,t=f(e,LENS_CONFIG),s=E(g(t),r);if(s.changed){const a=w(t);x(a)||k(a,{recursive:!0}),b(t,s.json)}return{mode:r,url:h(o),port:o,wrote:s.changed}}i(wireMcpMode,"wireMcpMode"),c(wireMcpMode,"wireMcpMode");export function readMcpWiring(e,r=process.env){const o=d(e).ports.mcpHttp;return{mode:effectiveMcpMode(e,void 0,r),port:o,url:h(o)}}i(readMcpWiring,"readMcpWiring"),c(readMcpWiring,"readMcpWiring");const u=JSON.stringify({jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-06-18",capabilities:{},clientInfo:{name:"lensmcp-doctor",version:"1"}}});export function parseInitializeResponse(e){const r=e.split(`
|
|
2
|
+
`).find(t=>t.startsWith("data:")),o=r?r.slice(5).trim():e.trim();try{const t=JSON.parse(o);return t.result?{ok:!0,...t.result.serverInfo?.name?{server:t.result.serverInfo.name}:{},...t.result.protocolVersion?{protocolVersion:t.result.protocolVersion}:{}}:{ok:!1,error:"no initialize result"}}catch{return{ok:!1,error:"unreadable initialize response"}}}i(parseInitializeResponse,"parseInitializeResponse"),c(parseInitializeResponse,"parseInitializeResponse");export function probeSharedMcpSync(e,r=2){const o=v("curl",["-s","--max-time",String(r),"-X","POST",e,"-H","content-type: application/json","-H","accept: application/json, text/event-stream","-d",u],{encoding:"utf8"});if(o.error||o.status!==0)return{ok:!1,error:"nothing listening"};const t=(o.stdout??"").trim();return t?parseInitializeResponse(t):{ok:!1,error:"empty response"}}i(probeSharedMcpSync,"probeSharedMcpSync"),c(probeSharedMcpSync,"probeSharedMcpSync");export function probeSharedMcp(e,r=2500){return new Promise(o=>{let t=!1;const s=c(n=>{t||(t=!0,o(n))},"finish");let a;try{a=new URL(e)}catch{s({ok:!1,error:`not a URL: ${e}`});return}const p=C({hostname:a.hostname,port:a.port,path:a.pathname,method:"POST",timeout:r,headers:{"content-type":"application/json",accept:"application/json, text/event-stream","content-length":Buffer.byteLength(u)}},n=>{let l="";n.setEncoding("utf8"),n.on("data",M=>{l+=M,(l.includes('"result"')||l.length>64e3)&&n.destroy()});const m=c(()=>{if((n.statusCode??0)>=400){s({ok:!1,error:`HTTP ${n.statusCode}`});return}s(parseInitializeResponse(l))},"settle");n.on("end",m),n.on("close",m)});p.on("timeout",()=>{p.destroy(),s({ok:!1,error:`no response within ${r}ms`})}),p.on("error",n=>{s({ok:!1,error:n.code==="ECONNREFUSED"?"nothing listening":n.message??"request failed"})}),p.end(u)})}i(probeSharedMcp,"probeSharedMcp"),c(probeSharedMcp,"probeSharedMcp");
|
package/lib/plugin-version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}p(formatSkewContext,"formatSkewContext"),
|
|
3
|
-
`)[0]||`\`${
|
|
1
|
+
"use strict";var m=Object.defineProperty;var p=(t,n)=>m(t,"name",{value:n,configurable:!0});var h=Object.defineProperty,i=p((t,n)=>h(t,"name",{value:n,configurable:!0}),"u");import{spawnSync as j}from"node:child_process";import{existsSync as x,readFileSync as k}from"node:fs";import{homedir as v}from"node:os";import{join as d}from"node:path";export const PLUGIN_NAME="lensmcp";function f(t){try{return JSON.parse(k(t,"utf8"))}catch{return}}p(f,"a"),i(f,"readJson");function g(t){const n=f(t)?.version;return typeof n=="string"&&n.length>0?n:void 0}p(g,"g"),i(g,"readVersionField");export function readInstalledPlugin(t,n=v()){const e=f(d(n,".claude","plugins","installed_plugins.json"))?.plugins;if(!e||typeof e!="object")return;const r=[];for(const[o,c]of Object.entries(e)){const[s,a]=o.split("@");if(!(s!==PLUGIN_NAME||!a))for(const l of Array.isArray(c)?c:[c]){if(typeof l!="object"||l===null)continue;const u=l;typeof u.version=="string"&&r.push({id:o,marketplace:a,version:u.version,...typeof u.scope=="string"?{scope:u.scope}:{},...typeof u.projectPath=="string"?{projectPath:u.projectPath}:{}})}}if(r.length!==0)return r.find(o=>o.projectPath===t)??r.find(o=>o.scope==="user")??r[0]}p(readInstalledPlugin,"readInstalledPlugin"),i(readInstalledPlugin,"readInstalledPlugin");export function readVersions(t){const n={};if(t.pluginRoot){const o=g(d(t.pluginRoot,".claude-plugin","plugin.json"));o&&(n.plugin=o,n.pluginSource="plugin-root")}const e=readInstalledPlugin(t.cwd,t.home);e&&(n.pluginId=e.id,n.pluginMarketplace=e.marketplace,e.scope&&(n.pluginScope=e.scope),n.plugin||(n.plugin=e.version,n.pluginSource="install-index"));const r=g(d(t.cwd,"node_modules","lensmcp","package.json"));return r&&(n.project=r),t.cliVersion&&t.cliVersion!=="0.0.0"&&(n.cli=t.cliVersion),n}p(readVersions,"readVersions"),i(readVersions,"readVersions");export function compareVersions(t,n){const e=i(c=>{const s=c.trim().replace(/^v/,"").split(/[-+]/)[0];if(s===void 0)return;const a=s.split(".");if(a.length===0||a.length>3)return;const l=a.map(u=>/^\d+$/.test(u)?Number(u):Number.NaN);return l.some(Number.isNaN)?void 0:[l[0]??0,l[1]??0,l[2]??0]},"parse"),r=e(t),o=e(n);if(!(!r||!o)){for(let c=0;c<3;c++){const s=(r[c]??0)-(o[c]??0);if(s!==0)return s<0?-1:1}return 0}}p(compareVersions,"compareVersions"),i(compareVersions,"compareVersions");export function detectSkew(t){const n=t.plugin,e=t.project??t.cli;if(!n||!e||n===e)return;const r=compareVersions(n,e);if(r===void 0||r===0)return;const o=t.cli&&t.project&&t.cli!==t.project?{cli:t.cli,project:t.project}:void 0;return{mismatch:!0,plugin:n,expected:e,expectedSource:t.project?"project":"cli",direction:r<0?"behind":"ahead",...t.pluginId?{pluginId:t.pluginId}:{},...t.pluginMarketplace?{marketplace:t.pluginMarketplace}:{},...t.pluginScope?{scope:t.pluginScope}:{},...o?{cliSkew:o}:{}}}p(detectSkew,"detectSkew"),i(detectSkew,"detectSkew");export function updateCommands(t){const n=t.pluginId??PLUGIN_NAME,e=t.scope&&t.scope!=="user"?` --scope ${t.scope}`:"";return[...t.marketplace?[`claude plugin marketplace update ${t.marketplace}`]:[],`claude plugin update ${n}${e}`]}p(updateCommands,"updateCommands"),i(updateCommands,"updateCommands");export function formatSkewContext(t){const n=[`LensMCP plugin is out of step: plugin ${t.plugin} vs lensmcp ${t.expected} (${t.expectedSource==="project"?"this project\u2019s node_modules":"the running CLI"}). The plugin\u2019s skills, hooks and wiring are from ${t.plugin} \u2014 update before relying on them:`,...updateCommands(t).map(e=>` ${e}`)," \u2026then restart Claude Code for the new plugin to load."];return t.cliSkew&&n.push(` (also: the lensmcp CLI on PATH is ${t.cliSkew.cli} while this project depends on ${t.cliSkew.project}.)`),n.join(`
|
|
2
|
+
`)}p(formatSkewContext,"formatSkewContext"),i(formatSkewContext,"formatSkewContext");export function syncPlugin(t){const n=detectSkew(t.facts);if(!n)return{outcome:t.facts.plugin!==void 0&&(t.facts.project??t.facts.cli)!==void 0?"current":"unknown",...t.facts.plugin?{from:t.facts.plugin}:{}};const e=updateCommands(n);for(const r of e){const[o,...c]=r.split(" "),s=o===void 0?void 0:t.run(o,c);if(!s)return{outcome:"manual",from:n.plugin,to:n.expected,commands:e,detail:`\`${o??"claude"}\` is not on PATH`};if(s.code!==0)return{outcome:"manual",from:n.plugin,to:n.expected,commands:e,detail:(s.stderr??"").trim().split(`
|
|
3
|
+
`)[0]||`\`${r}\` exited ${s.code}`}}return{outcome:"updated",from:n.plugin,to:n.expected,commands:e}}p(syncPlugin,"syncPlugin"),i(syncPlugin,"syncPlugin");export function spawnRunner(t,n=6e4){return(e,r)=>{try{const o=j(e,r,{encoding:"utf8",timeout:n,env:t,stdio:["ignore","pipe","pipe"]});return o.error&&o.error.code==="ENOENT"?void 0:{code:o.status??1,...o.stderr?{stderr:o.stderr}:{}}}catch{return}}}p(spawnRunner,"spawnRunner"),i(spawnRunner,"spawnRunner");export const pluginManifestPath=i(t=>d(t,".claude-plugin","plugin.json"),"pluginManifestPath"),isPluginRoot=i(t=>x(pluginManifestPath(t)),"isPluginRoot");
|
package/lib/status-client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).find(
|
|
1
|
+
"use strict";var j=Object.defineProperty;var i=(t,r)=>j(t,"name",{value:r,configurable:!0});var x=Object.defineProperty,o=i((t,r)=>x(t,"name",{value:r,configurable:!0}),"i");import{readLensConfig as M}from"./workspace-scope.js";import{sharedMcpUrl as D}from"./mcp-mode.js";import{effectiveMcpMode as k}from"./mcp-wiring.js";import{freshnessOf as T}from"./status-policy.js";export const IDENTITY_PATH="/lensmcp/identity",IDENTITY_KIND="lensmcp-mcp-identity";export function resolveSource(t,r){const n=M(t),e=n.ports.mcpHttp;return{workspace:n.key,mode:k(t,void 0,r),port:e,url:D(e)}}i(resolveSource,"resolveSource"),o(resolveSource,"resolveSource");function w(t){const r=Date.now()+t;return{remaining:o(()=>Math.max(0,r-Date.now()),"remaining"),expired:o(()=>Date.now()>=r,"expired")}}i(w,"M"),o(w,"deadline");async function l(t,r,n){const e=n.remaining();if(e<=0)return;const s=new AbortController,a=setTimeout(()=>s.abort(),e);try{return await fetch(t,{...r,signal:s.signal})}catch{return}finally{clearTimeout(a)}}i(l,"l"),o(l,"fetchWithin");async function f(t,r,n,e){const s=await l(t,{method:"POST",headers:{"content-type":"application/json",accept:"application/json, text/event-stream",...r?{"mcp-session-id":r}:{}},body:JSON.stringify(n)},e);if(!s)return;if(s.status===202)return{res:s};const a=await s.text().catch(()=>"");return{res:s,...parseFrame(a)===void 0?{}:{json:parseFrame(a)}}}i(f,"m"),o(f,"rpc");export function parseFrame(t){const r=t.split(`
|
|
2
|
+
`).find(e=>e.startsWith("data:")),n=(r?r.slice(5):t).trim();if(n)try{const e=JSON.parse(n);return typeof e=="object"&&e!==null?e:void 0}catch{return}}i(parseFrame,"parseFrame"),o(parseFrame,"parseFrame");export function parseResourceResult(t){const r=t?.result;if(typeof r!="object"||r===null)return;const n=r.contents;if(!Array.isArray(n)||n.length===0)return;const e=n[0];if(typeof e!="object"||e===null)return;const s=e.text;if(typeof s=="string")try{return JSON.parse(s)}catch{return}}i(parseResourceResult,"parseResourceResult"),o(parseResourceResult,"parseResourceResult");async function b(t,r,n){const e=await l(`http://127.0.0.1:${t}${IDENTITY_PATH}`,{headers:{accept:"application/json"}},n);if(!e)return"no server on this workspace\u2019s MCP port";if(!e.ok)return await e.text().catch(()=>{}),`the process on :${t} does not serve a lensmcp identity`;const s=await e.json().catch(()=>{});if(typeof s!="object"||s===null)return`unreadable identity on :${t}`;const a=s;if(a.kind!==IDENTITY_KIND)return`the process on :${t} is not a lensmcp server`;if(a.key!==r)return`:${t} serves workspace "${String(a.key)}", not "${r}"`}i(b,"D"),o(b,"verifyIdentity");export const DEFAULT_BUDGET_MS=2e3;export async function readStatus(t){const r=Date.now(),n=resolveSource(t.cwd,t.env),e=w(t.budgetMs??DEFAULT_BUDGET_MS),s=o(u=>({available:!1,source:n,reason:u,elapsedMs:Date.now()-r}),"fail");if(n.mode!=="shared")return s("MCP mode is embedded \u2014 there is no shared server to read (`lensmcp setup --mcp shared`)");const a=await b(n.port,n.workspace,e);if(a)return s(a);const m=await f(n.url,void 0,{jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2025-06-18",capabilities:{},clientInfo:{name:"lensmcp-status",version:"1"}}},e);if(!m||!m.res.ok)return s("the shared MCP server did not accept a session");const c=m.res.headers.get("mcp-session-id")??void 0,g=o(async()=>{c&&await l(n.url,{method:"DELETE",headers:{"mcp-session-id":c}},e)},"close");try{await f(n.url,c,{jsonrpc:"2.0",method:"notifications/initialized"},e);const u=o(async p=>{const d=await f(n.url,c,{jsonrpc:"2.0",id:2,method:"resources/read",params:{uri:p}},e);return parseResourceResult(d?.json)},"read"),h=await u("agent://current-status");if(typeof h!="object"||h===null)return s("the shared MCP server did not return agent://current-status");const y=h,v=new Map;for(const p of t.verify?.(y)??[]){if(e.expired())break;const d=await u(p);d!==void 0&&v.set(p,T(d))}return{available:!0,source:n,status:y,evidence:v,elapsedMs:Date.now()-r}}finally{await g()}}i(readStatus,"readStatus"),o(readStatus,"readStatus");
|
package/lib/status-policy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}i(formatContext,"formatContext"),
|
|
1
|
+
"use strict";var k=Object.defineProperty;var i=(n,t)=>k(n,"name",{value:t,configurable:!0});var v=Object.defineProperty,o=i((n,t)=>v(n,"name",{value:t,configurable:!0}),"r");export const HOOK_SIGNAL_CLASS={typecheck:"check",lint:"check",build:"check",runtime:"observation",cluster:"observation"},OBSERVATION_WINDOW_MS=30*6e4;const p=o(n=>typeof n=="object"&&n!==null&&!Array.isArray(n),"isRecord"),g=o(n=>typeof n=="number"&&Number.isFinite(n)?n:void 0,"asFiniteNumber");function f(n,t){if(!Array.isArray(n))return;let e;for(const s of n){if(!p(s))continue;const r=g(s[t]);r!==void 0&&(e===void 0||r>e)&&(e=r)}return e}i(f,"h"),o(f,"newestIn");export function freshnessOf(n){if(!p(n))return{};const t=typeof n.producer=="string"?n.producer:void 0,e=g(n.lastRunAt)??g(n.lastReportedAt)??f(n.producers,"lastReportedAt")??f(n.producers,"lastRunAt"),s=f(n.entries,"timestamp")??f(n.failures,"timestamp")??f(n.violations,"timestamp");return{...t===void 0?{}:{declaredProducer:t},...n.stale===!0?{declaredStale:!0}:{},...e===void 0?{}:{ranAt:e},...s===void 0?{}:{newestItemAt:s},...g(n.ageMs)===void 0?{}:{ageMs:g(n.ageMs)}}}i(freshnessOf,"freshnessOf"),o(freshnessOf,"freshnessOf");const h=o((n,t)=>n===void 0?void 0:Math.max(0,t-n),"ageFrom");export function candidateSignals(n){return(n.signals??[]).filter(t=>HOOK_SIGNAL_CLASS[t.kind]!==void 0&&(t.state==="failed"||t.state==="warning")&&t.producer==="connected")}i(candidateSignals,"candidateSignals"),o(candidateSignals,"candidateSignals");export function judge(n,t,e,s=OBSERVATION_WINDOW_MS){const r=HOOK_SIGNAL_CLASS[n.kind];if(r===void 0)return{kind:n.kind,reason:"out-of-scope"};if(n.state!=="failed"&&n.state!=="warning")return{kind:n.kind,reason:"not-actionable"};if(n.producer!=="connected"||t?.declaredProducer==="none")return{kind:n.kind,reason:"no-producer"};const c=n.reads?.[0]??n.resource,u={kind:n.kind,state:n.state,...n.count===void 0?{}:{count:n.count},read:c,detail:n.detail};if(n.stale===!0||t?.declaredStale===!0){const l=t?.ageMs??h(t?.ranAt,e);return{...u,stale:!0,...l===void 0?{}:{ageMs:l}}}if(r==="check"){const l=h(t?.ranAt,e);return l===void 0?{kind:n.kind,reason:"no-freshness-evidence"}:{...u,stale:!1,ageMs:l}}const a=t?.newestItemAt;if(a===void 0)return{kind:n.kind,reason:"no-freshness-evidence"};const d=Math.max(0,e-a);return d>s?{kind:n.kind,reason:"stale-observation"}:{...u,stale:!1,ageMs:d}}i(judge,"judge"),o(judge,"judge");const m=o(n=>"state"in n,"isFinding");export function select(n,t,e,s=OBSERVATION_WINDOW_MS){const r=[],c=[],u=[];for(const a of n.signals??[]){a.producer==="none"&&HOOK_SIGNAL_CLASS[a.kind]!==void 0&&u.push(a.kind);const d=judge(a,t.get(a.resource),e,s);m(d)?r.push(d):d.reason!=="out-of-scope"&&d.reason!=="not-actionable"&&c.push(d)}return r.sort((a,d)=>a.state===d.state?(d.count??0)-(a.count??0):a.state==="failed"?-1:1),{findings:r,suppressed:c,unmonitored:u}}i(select,"select"),o(select,"select");export function describeAge(n){return n<6e4?`${Math.max(1,Math.round(n/1e3))}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}i(describeAge,"describeAge"),o(describeAge,"describeAge");export function describeCount(n){const t=n.kind==="runtime"?"browser runtime error":`${n.kind} ${n.state==="failed"?"error":"warning"}`,e=n.count===1?"":"s";return`${n.count===void 0?"":`${n.count} `}${t}${e}`}i(describeCount,"describeCount"),o(describeCount,"describeCount");export function describeWhen(n){return n.stale?`last checked ${n.ageMs===void 0?"a while ago":describeAge(n.ageMs)}, nothing has re-run since`:n.ageMs===void 0?"recency unknown":describeAge(n.ageMs)}i(describeWhen,"describeWhen"),o(describeWhen,"describeWhen");export function findingLine(n){return`${n.kind}: ${describeCount(n)} (${describeWhen(n)}) \u2192 read ${n.read}`}i(findingLine,"findingLine"),o(findingLine,"findingLine");export function formatContext(n,t={}){const{findings:e,unmonitored:s}=n;if(e.length===0)return;const r=[`LensMCP${t.workspace?` (${t.workspace})`:""}: ${e.length===1?"1 signal needs":`${e.length} signals need`} attention.`,...e.map(c=>` \u2022 ${findingLine(c)}`)];return t.includeUnmonitored&&s.length>0&&r.push(` (unmonitored, so unknown rather than clean: ${s.join(", ")})`),r.push(" Verify before acting \u2014 these are observations, not a fresh build."),r.join(`
|
|
2
|
+
`)}i(formatContext,"formatContext"),o(formatContext,"formatContext");export const HOOK_EVENTS=["Stop","SessionStart","SubagentStop"],isHookEvent=o(n=>typeof n=="string"&&HOOK_EVENTS.includes(n),"isHookEvent");export function hookPayload(n,t){return JSON.stringify({hookSpecificOutput:{hookEventName:n,additionalContext:t}})}i(hookPayload,"hookPayload"),o(hookPayload,"hookPayload");export function findingsDigest(n){return n.map(t=>`${t.kind}:${t.state}:${t.count??""}`).sort().join("|")}i(findingsDigest,"findingsDigest"),o(findingsDigest,"findingsDigest");
|
package/lib/sweep.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var r=(t,e)=>v(t,"name",{value:e,configurable:!0});var S=Object.defineProperty,l=r((t,e)=>S(t,"name",{value:e,configurable:!0}),"r");import{readdirSync as N,renameSync as b,rmSync as h,statSync as u}from"node:fs";import{join as i}from"node:path";const c=l(t=>{try{h(t,{force:!0})}catch{}},"removeQuietly");export function sweepLensRuntimeFiles(t,e){const n=i(t,".lensmcp"),f=i(n,"events.jsonl");c(`${f}.old`),c(`${e}.old`);const y=(()=>{const s=Number(process.env.LENSMCP_EVENT_MAX_FILES);return Number.isFinite(s)&&s>=1&&s<=20?Math.floor(s):5})(),p=64*1024*1024;try{for(const s of N(n)){const a=/^events\.jsonl\.(\d+)$/.exec(s);if(!a)continue;const m=Number(a[1]),o=i(n,s);if(m<1||m>y)c(o);else try{u(o).size>p&&c(o)}catch{}}}catch{}const d=16*1024*1024;try{u(e).size>d&&b(e,`${e}.1`)}catch{}}r(sweepLensRuntimeFiles,"sweepLensRuntimeFiles"),l(sweepLensRuntimeFiles,"sweepLensRuntimeFiles");
|
package/lib/workspace-scope.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`;return(!
|
|
1
|
+
"use strict";var m=Object.defineProperty;var o=(r,e)=>m(r,"name",{value:e,configurable:!0});var l=Object.defineProperty,s=o((r,e)=>l(r,"name",{value:e,configurable:!0}),"o");import{existsSync as u,mkdirSync as g,readFileSync as f,writeFileSync as h}from"node:fs";import{basename as y,join as a}from"node:path";function d(r,e){let n=2166136261;for(let t=0;t<r.length;t++)n^=r.charCodeAt(t),n=Math.imul(n,16777619);return Math.abs(n|0)%e}o(d,"l"),s(d,"hashToRange");export function slugify(r){return r.toLowerCase().replace(/^@[^/]+\//,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")||"workspace"}o(slugify,"slugify"),s(slugify,"slugify");export function resolveWorkspaceKey(r){const e=c(a(r,"nx.json"));if(e?.lensmcp?.key)return slugify(e.lensmcp.key);const n=c(a(r,"package.json"));return n?.name?slugify(n.name):e?.name?slugify(e.name):slugify(y(r))}o(resolveWorkspaceKey,"resolveWorkspaceKey"),s(resolveWorkspaceKey,"resolveWorkspaceKey");const i={dashboard:4321,mcpHttp:4500,bridge:5747};export function derivePorts(r){const e=d(r,200);return{dashboard:i.dashboard+e,mcpHttp:i.mcpHttp+e,bridge:i.bridge+e}}o(derivePorts,"derivePorts"),s(derivePorts,"derivePorts");export function deriveConfig(r){const e=resolveWorkspaceKey(r);return{schemaVersion:1,key:e,ports:derivePorts(e),dashboardBasePath:"/"+e}}o(deriveConfig,"deriveConfig"),s(deriveConfig,"deriveConfig");export function readLensConfig(r){const e=deriveConfig(r),n=c(a(r,".lensmcp","config.json"));if(!n)return e;const t=n.key?slugify(n.key):e.key;return{...n,schemaVersion:1,key:t,ports:{...e.ports,...n.ports??{}},dashboardBasePath:n.dashboardBasePath??"/"+t,...n.mcp?{mcp:{...n.mcp}}:{}}}o(readLensConfig,"readLensConfig"),s(readLensConfig,"readLensConfig");export function ensureLensConfig(r){const e=readLensConfig(r),n=a(r,".lensmcp");u(n)||g(n,{recursive:!0});const t=a(n,"config.json"),p=JSON.stringify(e,null,2)+`
|
|
2
|
+
`;return(!u(t)||f(t,"utf8")!==p)&&h(t,p),e}o(ensureLensConfig,"ensureLensConfig"),s(ensureLensConfig,"ensureLensConfig");function c(r){try{return JSON.parse(f(r,"utf8"))}catch{return}}o(c,"a"),s(c,"readJson");
|
package/package.json
CHANGED
|
@@ -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.
|
|
5
|
+
"version": "1.19.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Antoon",
|
|
8
8
|
"email": "davidmantoon@gmail.com"
|