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