@lensmcp/cluster 1.25.12 → 1.25.14

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.
@@ -105,7 +105,7 @@ export interface ClusterProjectDecl {
105
105
  * }] }`. A `traffic` entry WITHOUT a `path` is push-only: declared, never polled — the lens counts the `inbound` /
106
106
  * `outbound` events the app pushes. The dev gateway reads every other entry from a RUNNING pod every `intervalSec`
107
107
  * (default 10, at least 2) over the pod's socket — never waking a service scaled to zero — and the lens shows it,
108
- * labelled REPORTED (`observe.sources`, `source.get`, `process://sources`, the dashboard's Data views), judged against
108
+ * labelled REPORTED (`observe_sources`, `source_get`, `process://sources`, the dashboard's Data views), judged against
109
109
  * each kind's `thresholds` (every one filled with its default): a queue's `oldestWaitMin` (10) and `stalledMin` (15)
110
110
  * and a loop's `idleMin` (10), in minutes; a store's `quotaPct` (90) and `errorRatePct` (5), percents, and
111
111
  * `orphanMin` (60), minutes; a traffic source's `failurePct` (5), a percent, `p95Ms` (2000), milliseconds, and
@@ -270,7 +270,7 @@ export interface LensFrontendSupervisor {
270
270
  recover(frontend: LensFrontend, reason: string): Promise<boolean>;
271
271
  }
272
272
  /**
273
- * A restart someone asked for — an agent's `service.restart`, `lensmcp restart <service>` — of ONE service of one
273
+ * A restart someone asked for — an agent's `service_restart`, `lensmcp restart <service>` — of ONE service of one
274
274
  * workspace or worktree. A fresh tree re-reads what the service reads when it starts: its config files, its env, its
275
275
  * bundle; a hot swap re-reads only what the new bundle reads again.
276
276
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/cluster",
3
- "version": "1.25.12",
3
+ "version": "1.25.14",
4
4
  "description": "Run your Nx workspace as a local production cluster: pods on unix sockets with true HMR, one https gateway with per-project domains, scale-from-zero, autoscale, idle-kill, local-CA TLS — observed by the LensMCP lens.",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -58,9 +58,9 @@
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
- "@lensmcp/core": "1.25.12",
62
- "@lensmcp/node-instrumentation": "1.25.12",
63
- "@lensmcp/nx-plugin": "1.25.12",
61
+ "@lensmcp/core": "1.25.14",
62
+ "@lensmcp/node-instrumentation": "1.25.14",
63
+ "@lensmcp/nx-plugin": "1.25.14",
64
64
  "fastify": "^5.8.5",
65
65
  "@fastify/reply-from": "^12.6.2",
66
66
  "@typescript/native-preview": "^7.0.0-dev.20260707.2",
@@ -1 +1 @@
1
- "use strict";var H=Object.defineProperty;var M=(e,o)=>H(e,"name",{value:o,configurable:!0});var C=Object.defineProperty,y=M((e,o)=>C(e,"name",{value:o,configurable:!0}),"y");Object.defineProperty(exports,"__esModule",{value:!0}),exports.EXECUTOR_MB_PER_MODULE=exports.DEFAULT_HEAVY_BARREL_THRESHOLDS=exports.HEAVY_BARREL_RULE=void 0,exports.analyzeBarrelImports=analyzeBarrelImports,exports.describeHeavyBarrel=describeHeavyBarrel;const tslib_1=require("tslib"),path=tslib_1.__importStar(require("node:path")),workspace_libraries_1=require("./workspace-libraries"),source_scan_1=require("./source-scan");exports.HEAVY_BARREL_RULE="bundle/heavy-barrel-import",exports.DEFAULT_HEAVY_BARREL_THRESHOLDS={minShare:.5,minModules:100,minBytes:1024*1024,maxNeededShare:.6};const MAX_IMPORTERS_LISTED=8,MAX_SYMBOLS_LISTED=12,MAX_SUBPATHS_LISTED=12,MAX_INTERNAL_LISTED=6,MAX_EXPORT_DEPTH=24,MAX_UNRESOLVED_SHARE=.1;class AliasResolver{static{M(this,"AliasResolver")}static{y(this,"AliasResolver")}constructor(o,r){this.exists=r,this.exact=new Map,this.wildcards=[];for(const s of o){this.exact.set(s.name,s.rootEntry);for(const i of s.aliases)this.exact.set(i,s.rootEntry);for(const i of s.subpaths)this.exact.set(i.specifier,i.entry);for(const i of s.wildcards)this.wildcards.push(i)}this.wildcards.sort((s,i)=>i.prefix.length-s.prefix.length)}resolve(o,r){if(r.startsWith("."))return(0,workspace_libraries_1.resolveSourceFile)(path.resolve(path.dirname(o),r),this.exists);const s=this.exact.get(r);if(s)return s;const i=this.wildcards.find(u=>r.startsWith(u.prefix));return i?(0,workspace_libraries_1.resolveSourceFile)(path.join(i.dir,r.slice(i.prefix.length)),this.exists):void 0}}class ExportReader{static{M(this,"ExportReader")}static{y(this,"ExportReader")}constructor(o,r){this.source=o,this.aliases=r,this.cache=new Map,this.resolved=new Map}index(o){let r=this.cache.get(o);if(r===void 0){const s=this.source.read(o);r=s===void 0?null:(0,source_scan_1.scanExports)(s),this.cache.set(o,r)}return r}resolve(o,r){const s=`${o}\0${r}`;let i=this.resolved.get(s);return i===void 0&&(i=this.follow(o,r,0,new Set)??null,this.resolved.set(s,i)),i??void 0}follow(o,r,s,i){if(s>MAX_EXPORT_DEPTH)return;const u=`${o}\0${r}`;if(i.has(u))return;i.add(u);const a=this.index(o);if(!a)return;if(a.values.has(r))return{file:o,typeOnly:!1};if(a.types.has(r))return{file:o,typeOnly:!0};const l=a.namespaces.get(r);if(l!==void 0){const p=this.aliases.resolve(o,l);return p?{file:p,typeOnly:!1}:void 0}const d=a.reexports.get(r);if(d){const p=this.aliases.resolve(o,d.specifier);if(!p)return;const c=this.follow(p,d.name,s+1,i);return c?{...c,typeOnly:c.typeOnly||d.typeOnly}:void 0}if(r!=="default")for(const p of a.stars){const c=this.aliases.resolve(o,p);if(!c)continue;const h=this.follow(c,r,s+1,i);if(h)return h}}}const rel=y((e,o)=>path.relative(e,o)||o,"rel");function readRootUse(e,o,r,s){const i=y(a=>l=>s.resolve(a,l)===e.rootEntry,"toBarrel"),u=[];for(const a of o){const l=/\.(?:[cm]?[jt]sx?)$/.test(a)?r.source.read(a):void 0;if(l===void 0){u.push({file:a,values:[],typeOnly:0,wholeModule:!0});continue}const d=(0,source_scan_1.scanImports)(l,i(a));if(d.length===0){u.push({file:a,values:[],typeOnly:0,wholeModule:!0});continue}const p=new Set;let c=0,h=!1;for(const x of d){h||=x.wholeModule;for(const f of x.names)f.typeOnly?c++:p.add(f.imported)}u.push({file:a,values:[...p].sort(),typeOnly:c,wholeModule:h})}return{importers:u}}M(readRootUse,"readRootUse"),y(readRootUse,"readRootUse");function closureWithin(e,o,r,s,i){const u=new Set,a=[...o].filter(l=>l!==s&&r.has(l)&&i(l)===e);for(;a.length;){const l=a.pop();if(!u.has(l)){u.add(l);for(const d of r.get(l)?.dependencies??[])d!==s&&!u.has(d)&&i(d)===e&&r.has(d)&&a.push(d)}}return u}M(closureWithin,"closureWithin"),y(closureWithin,"closureWithin");function subpathFor(e,o,r,s,i,u,a=0){if(r===e.rootEntry)return;const l=u(r);if(l!==e)return l&&a<2?subpathFor(l,o,r,s,i,u,a+1):void 0;const d=e.subpaths.filter(f=>r.startsWith(path.dirname(f.entry)+path.sep)||r===f.entry).filter(f=>s.resolve(f.entry,o)?.file===r).sort((f,$)=>$.entry.length-f.entry.length);if(d[0])return{specifier:d[0].specifier,entry:d[0].entry,exists:!0};const p=path.dirname(e.rootEntry);for(const f of e.wildcards){if(!r.startsWith(f.dir))continue;const $=r.slice(f.dir.length).split(path.sep).join("/").replace(/\.(?:[cm]?[jt]sx?)$/,""),w=$.split("/")[0],v=(0,workspace_libraries_1.resolveSourceFile)(path.join(f.dir,w),i.exists);return v&&v!==r&&s.resolve(v,o)?.file===r?{specifier:`${f.prefix}${w}`,entry:v,exists:!0}:{specifier:`${f.prefix}${$.replace(/\/index$/,"")}`,entry:r,exists:!0}}const c=path.relative(p,r).split(path.sep),h=c.length>1?c[0]:c[0].replace(/\.(?:[cm]?[jt]sx?)$/,""),x=c.length>1?(0,workspace_libraries_1.resolveSourceFile)(path.join(p,h),i.exists)??path.join(p,h,"index.ts"):r;return{specifier:`${e.name}/${h}`,entry:x,exists:!1}}M(subpathFor,"subpathFor"),y(subpathFor,"subpathFor");function measure(e,o,r,s,i,u,a){if(!r.has(o.rootEntry))return;const l=y(t=>a(t)===o,"inLib"),d=e.modules.filter(t=>l(t.resource)),p=e.modules.filter(t=>!l(t.resource)&&t.dependencies.includes(o.rootEntry)).map(t=>t.resource).sort();if(p.length===0)return;const c=s.workspaceRoot,h=s.thresholds,x=d.filter(t=>t.resource!==o.rootEntry&&t.dependencies.includes(o.rootEntry)).map(t=>t.resource),f=new Set;for(const t of e.modules)if(!l(t.resource))for(const n of t.dependencies)n!==o.rootEntry&&l(n)&&f.add(n);const $=readRootUse(o,p,s,i),w=new Set(f),v=new Set,S=new Map,R=new Set,_=new Set;for(const t of $.importers)for(const n of t.values){if(_.add(n),S.has(n)||v.has(n)||R.has(n))continue;const m=u.resolve(o.rootEntry,n);m?m.file===o.rootEntry?R.add(n):m.typeOnly||(S.set(n,m.file),w.add(m.file)):v.add(n)}if(R.size>0)for(const t of u.index(o.rootEntry)?.valueImports??[]){const n=i.resolve(o.rootEntry,t);n&&w.add(n)}const L=$.importers.some(t=>t.wholeModule),B=L?new Set(d.map(t=>t.resource)):closureWithin(o,w,r,o.rootEntry,a),T=y(t=>{let n=0;for(const m of t)n+=r.get(m)?.size??0;return n},"sizeOf"),U=d.reduce((t,n)=>t+n.size,0),z=T(B),A=d.filter(t=>!B.has(t.resource)),I=o.files>0?Math.min(1,d.length/o.files):1,O=new Map,D=new Map,k=y((t,n)=>{let m=D.get(t);return m===void 0&&(m=subpathFor(o,t,n,u,s.source,a)??null,D.set(t,m)),m??void 0},"choose"),F=$.importers.map(t=>{const n=new Map;for(const m of t.values){const g=S.get(m);if(!g)continue;const E=k(m,g);if(!E)continue;const j=O.get(E.specifier)??{specifier:E.specifier,entry:rel(c,E.entry),symbols:[],exists:E.exists};j.symbols.includes(m)||j.symbols.push(m),O.set(E.specifier,j),n.set(E.specifier,[...n.get(E.specifier)??[],m])}return{file:rel(c,t.file),symbols:t.values.slice(0,MAX_SYMBOLS_LISTED),typeOnly:t.typeOnly,wholeModule:t.wholeModule,rewrite:[...n].sort((m,g)=>m[0].localeCompare(g[0])).map(([m,g])=>`import { ${g.join(", ")} } from '${m}';`)}}).sort((t,n)=>Number(n.wholeModule)-Number(t.wholeModule)||n.symbols.length-t.symbols.length||t.file.localeCompare(n.file)),b={project:e.project,library:o.name,libraryRoot:rel(c,o.root),rootEntry:rel(c,o.rootEntry),libraryFiles:o.files,compiledModules:d.length,compiledBytes:U,share:I,rootImporterCount:p.length,rootImporters:F.slice(0,MAX_IMPORTERS_LISTED),internalRootImporters:x.slice(0,MAX_INTERNAL_LISTED).map(t=>rel(c,t)),symbols:_.size,unresolvedSymbols:[...v].sort().slice(0,MAX_SYMBOLS_LISTED),barrelDefines:[...R].sort().slice(0,MAX_SYMBOLS_LISTED),neededModules:B.size,neededBytes:z,avoidableModules:A.length,avoidableBytes:A.reduce((t,n)=>t+n.size,0),subpaths:[...O.values()].map(t=>({...t,symbols:t.symbols.sort().slice(0,MAX_SYMBOLS_LISTED)})).sort((t,n)=>Number(t.exists)-Number(n.exists)||n.symbols.length-t.symbols.length).slice(0,MAX_SUBPATHS_LISTED),fires:!1};return I<h.minShare?b.quiet=`compiles ${pct(I)} of the library (below ${pct(h.minShare)})`:b.compiledModules<h.minModules&&b.compiledBytes<h.minBytes?b.quiet=`compiles ${b.compiledModules} modules / ${mb(b.compiledBytes)} (below ${h.minModules} modules and ${mb(h.minBytes)})`:L?b.quiet="an importer uses the whole module (a namespace passed on, require(), import(), export *) \u2014 it may need all of it":_.size>0&&v.size/_.size>MAX_UNRESOLVED_SHARE?b.quiet=`could not follow ${v.size} of ${_.size} symbols to their files`:b.neededModules>h.maxNeededShare*b.compiledModules?b.quiet=`its importers need ${b.neededModules} of the ${b.compiledModules} compiled modules (above ${pct(h.maxNeededShare)})`:b.fires=!0,b}M(measure,"measure"),y(measure,"measure");const pct=y(e=>`${Math.round(e*100)}%`,"pct"),mb=y(e=>`${(e/(1024*1024)).toFixed(1)} MB`,"mb");function analyzeBarrelImports(e){const o=y(l=>e.source.exists(l),"exists"),r=new AliasResolver(e.libraries,o),s=new ExportReader(e.source,r),i=new Map,u=y(l=>(i.has(l)||i.set(l,(0,workspace_libraries_1.libraryOf)(e.libraries,l)),i.get(l)),"owner"),a=[];for(const l of e.projects){const d=new Map(l.modules.map(p=>[p.resource,p]));for(const p of e.libraries){if(e.expired?.())return{complete:!1,measurements:a};const c=measure(l,p,d,e,r,s,u);c&&a.push(c)}}return{complete:!e.expired?.(),measurements:a}}M(analyzeBarrelImports,"analyzeBarrelImports"),y(analyzeBarrelImports,"analyzeBarrelImports"),exports.EXECUTOR_MB_PER_MODULE=.374;function describeHeavyBarrel(e,o){const r=o&&o.builtModules>=50?o.durationMs/o.builtModules:void 0,s=r!==void 0?Math.round(r*e.avoidableModules):void 0,i=Math.round(exports.EXECUTOR_MB_PER_MODULE*e.avoidableModules),u=e.rootImporters.slice(0,3),a=e.subpaths.filter(c=>!c.exists),l=u.map(c=>`${c.file}: replace its \`${e.library}\` import with ${c.rewrite.length?c.rewrite.join(" "):"imports from the subpaths that export what it uses"}`),d=[`Import ${e.library} by subpath, never by its root barrel (${e.rootEntry}). ${e.rootImporterCount} file(s) of ${e.project}'s build import the root; ${l.length?`start with \u2014 ${l.join(" | ")}`:"see evidence.rootImporters"}${e.rootImporterCount>u.length?` (+${e.rootImporterCount-u.length} more: evidence.rootImporters)`:""}.`];a.length&&d.push(`Add the missing subpath entr${a.length===1?"y":"ies"} to the library: ${a.slice(0,4).map(c=>`"${c.specifier}" \u2192 ${c.entry}`).join(", ")} \u2014 in tsconfig.base.json \`compilerOptions.paths\` and, if the library has a package.json, its \`exports\` ("./<domain>"). Add exact keys (plus "<domain>/*" for single files), never one library-wide "${e.library}/*": a bundler's resolver can rank it above the exact keys and re-route them at runtime while tsc and jest stay green.`),e.barrelDefines.length&&d.push(`${e.rootEntry} defines ${e.barrelDefines.slice(0,4).join(", ")} itself, so importing ${e.barrelDefines.length===1?"it":"them"} runs the whole barrel: move ${e.barrelDefines.length===1?"it":"them"} into a module of ${e.barrelDefines.length===1?"its":"their"} own and import that.`),e.internalRootImporters.length&&d.push(`${e.internalRootImporters.length} file(s) inside ${e.library} import its own root barrel (${e.internalRootImporters.slice(0,3).join(", ")}): make them import the module they need, or every subpath still pulls the whole library in.`),d.push(`Stop the root import from coming back: in ${e.project}'s ESLint config add \`'no-restricted-imports': ['error', { paths: [{ name: '${e.library}', message: 'Import from a domain subpath (${e.library}/<domain>), not the root barrel.' }] }]\`.`);const p=`Save a file of ${e.project} (or restart it) so its dev build recompiles: it should compile about ${e.neededModules} modules of ${e.library} instead of ${e.compiledModules}, and LensMCP retracts this finding \u2014 \`observe_current_status\` no longer lists bundle/heavy-barrel-import for ${e.project}. Then check its pods' live heap (\`memory.pods\`).`;return{subject:e.library,severity:"warning",title:`${e.project} compiles ${e.compiledModules} of the ${e.libraryFiles} files of ${e.library} through its root barrel; its imports need ${e.neededModules}`,summary:`${e.rootImporterCount} file(s) of ${e.project} import ${e.library} through its root entry and take ${e.symbols} symbol(s); those need ${e.neededModules} of the library's modules, but the barrel makes the dev build compile ${e.compiledModules} (${mb(e.compiledBytes)}) \u2014 ${e.avoidableModules} modules (${mb(e.avoidableBytes)}) nothing uses, compiled in every service that does the same and loaded into every pod.`,evidence:{library:e.library,libraryRoot:e.libraryRoot,rootEntry:e.rootEntry,libraryFiles:e.libraryFiles,compiledModules:e.compiledModules,compiledBytes:e.compiledBytes,share:Math.round(e.share*1e3)/1e3,neededModules:e.neededModules,neededBytes:e.neededBytes,avoidableModules:e.avoidableModules,avoidableBytes:e.avoidableBytes,symbols:e.symbols,unresolvedSymbols:e.unresolvedSymbols,barrelDefines:e.barrelDefines,rootImporterCount:e.rootImporterCount,rootImporters:e.rootImporters,internalRootImporters:e.internalRootImporters,subpaths:e.subpaths},cost:{modules:e.avoidableModules,bytes:e.avoidableBytes,...s!==void 0?{compileMs:s}:{},memoryMb:i,basis:`modules/bytes measured in this compilation; memoryMb = ${exports.EXECUTOR_MB_PER_MODULE} MB of webpack-executor heap per compiled module (fitted on FoodGuard's watchers)${s!==void 0?"; compileMs = the last full build's time per built module \xD7 the avoidable modules":""}. Each pod also loads them, at runtime cost the bundle cannot measure.`},fix:d,verify:p}}M(describeHeavyBarrel,"describeHeavyBarrel"),y(describeHeavyBarrel,"describeHeavyBarrel");
1
+ "use strict";var H=Object.defineProperty;var M=(e,o)=>H(e,"name",{value:o,configurable:!0});var C=Object.defineProperty,y=M((e,o)=>C(e,"name",{value:o,configurable:!0}),"y");Object.defineProperty(exports,"__esModule",{value:!0}),exports.EXECUTOR_MB_PER_MODULE=exports.DEFAULT_HEAVY_BARREL_THRESHOLDS=exports.HEAVY_BARREL_RULE=void 0,exports.analyzeBarrelImports=analyzeBarrelImports,exports.describeHeavyBarrel=describeHeavyBarrel;const tslib_1=require("tslib"),path=tslib_1.__importStar(require("node:path")),workspace_libraries_1=require("./workspace-libraries"),source_scan_1=require("./source-scan");exports.HEAVY_BARREL_RULE="bundle/heavy-barrel-import",exports.DEFAULT_HEAVY_BARREL_THRESHOLDS={minShare:.5,minModules:100,minBytes:1024*1024,maxNeededShare:.6};const MAX_IMPORTERS_LISTED=8,MAX_SYMBOLS_LISTED=12,MAX_SUBPATHS_LISTED=12,MAX_INTERNAL_LISTED=6,MAX_EXPORT_DEPTH=24,MAX_UNRESOLVED_SHARE=.1;class AliasResolver{static{M(this,"AliasResolver")}static{y(this,"AliasResolver")}constructor(o,r){this.exists=r,this.exact=new Map,this.wildcards=[];for(const s of o){this.exact.set(s.name,s.rootEntry);for(const i of s.aliases)this.exact.set(i,s.rootEntry);for(const i of s.subpaths)this.exact.set(i.specifier,i.entry);for(const i of s.wildcards)this.wildcards.push(i)}this.wildcards.sort((s,i)=>i.prefix.length-s.prefix.length)}resolve(o,r){if(r.startsWith("."))return(0,workspace_libraries_1.resolveSourceFile)(path.resolve(path.dirname(o),r),this.exists);const s=this.exact.get(r);if(s)return s;const i=this.wildcards.find(u=>r.startsWith(u.prefix));return i?(0,workspace_libraries_1.resolveSourceFile)(path.join(i.dir,r.slice(i.prefix.length)),this.exists):void 0}}class ExportReader{static{M(this,"ExportReader")}static{y(this,"ExportReader")}constructor(o,r){this.source=o,this.aliases=r,this.cache=new Map,this.resolved=new Map}index(o){let r=this.cache.get(o);if(r===void 0){const s=this.source.read(o);r=s===void 0?null:(0,source_scan_1.scanExports)(s),this.cache.set(o,r)}return r}resolve(o,r){const s=`${o}\0${r}`;let i=this.resolved.get(s);return i===void 0&&(i=this.follow(o,r,0,new Set)??null,this.resolved.set(s,i)),i??void 0}follow(o,r,s,i){if(s>MAX_EXPORT_DEPTH)return;const u=`${o}\0${r}`;if(i.has(u))return;i.add(u);const a=this.index(o);if(!a)return;if(a.values.has(r))return{file:o,typeOnly:!1};if(a.types.has(r))return{file:o,typeOnly:!0};const l=a.namespaces.get(r);if(l!==void 0){const p=this.aliases.resolve(o,l);return p?{file:p,typeOnly:!1}:void 0}const d=a.reexports.get(r);if(d){const p=this.aliases.resolve(o,d.specifier);if(!p)return;const c=this.follow(p,d.name,s+1,i);return c?{...c,typeOnly:c.typeOnly||d.typeOnly}:void 0}if(r!=="default")for(const p of a.stars){const c=this.aliases.resolve(o,p);if(!c)continue;const h=this.follow(c,r,s+1,i);if(h)return h}}}const rel=y((e,o)=>path.relative(e,o)||o,"rel");function readRootUse(e,o,r,s){const i=y(a=>l=>s.resolve(a,l)===e.rootEntry,"toBarrel"),u=[];for(const a of o){const l=/\.(?:[cm]?[jt]sx?)$/.test(a)?r.source.read(a):void 0;if(l===void 0){u.push({file:a,values:[],typeOnly:0,wholeModule:!0});continue}const d=(0,source_scan_1.scanImports)(l,i(a));if(d.length===0){u.push({file:a,values:[],typeOnly:0,wholeModule:!0});continue}const p=new Set;let c=0,h=!1;for(const x of d){h||=x.wholeModule;for(const f of x.names)f.typeOnly?c++:p.add(f.imported)}u.push({file:a,values:[...p].sort(),typeOnly:c,wholeModule:h})}return{importers:u}}M(readRootUse,"readRootUse"),y(readRootUse,"readRootUse");function closureWithin(e,o,r,s,i){const u=new Set,a=[...o].filter(l=>l!==s&&r.has(l)&&i(l)===e);for(;a.length;){const l=a.pop();if(!u.has(l)){u.add(l);for(const d of r.get(l)?.dependencies??[])d!==s&&!u.has(d)&&i(d)===e&&r.has(d)&&a.push(d)}}return u}M(closureWithin,"closureWithin"),y(closureWithin,"closureWithin");function subpathFor(e,o,r,s,i,u,a=0){if(r===e.rootEntry)return;const l=u(r);if(l!==e)return l&&a<2?subpathFor(l,o,r,s,i,u,a+1):void 0;const d=e.subpaths.filter(f=>r.startsWith(path.dirname(f.entry)+path.sep)||r===f.entry).filter(f=>s.resolve(f.entry,o)?.file===r).sort((f,$)=>$.entry.length-f.entry.length);if(d[0])return{specifier:d[0].specifier,entry:d[0].entry,exists:!0};const p=path.dirname(e.rootEntry);for(const f of e.wildcards){if(!r.startsWith(f.dir))continue;const $=r.slice(f.dir.length).split(path.sep).join("/").replace(/\.(?:[cm]?[jt]sx?)$/,""),w=$.split("/")[0],v=(0,workspace_libraries_1.resolveSourceFile)(path.join(f.dir,w),i.exists);return v&&v!==r&&s.resolve(v,o)?.file===r?{specifier:`${f.prefix}${w}`,entry:v,exists:!0}:{specifier:`${f.prefix}${$.replace(/\/index$/,"")}`,entry:r,exists:!0}}const c=path.relative(p,r).split(path.sep),h=c.length>1?c[0]:c[0].replace(/\.(?:[cm]?[jt]sx?)$/,""),x=c.length>1?(0,workspace_libraries_1.resolveSourceFile)(path.join(p,h),i.exists)??path.join(p,h,"index.ts"):r;return{specifier:`${e.name}/${h}`,entry:x,exists:!1}}M(subpathFor,"subpathFor"),y(subpathFor,"subpathFor");function measure(e,o,r,s,i,u,a){if(!r.has(o.rootEntry))return;const l=y(t=>a(t)===o,"inLib"),d=e.modules.filter(t=>l(t.resource)),p=e.modules.filter(t=>!l(t.resource)&&t.dependencies.includes(o.rootEntry)).map(t=>t.resource).sort();if(p.length===0)return;const c=s.workspaceRoot,h=s.thresholds,x=d.filter(t=>t.resource!==o.rootEntry&&t.dependencies.includes(o.rootEntry)).map(t=>t.resource),f=new Set;for(const t of e.modules)if(!l(t.resource))for(const n of t.dependencies)n!==o.rootEntry&&l(n)&&f.add(n);const $=readRootUse(o,p,s,i),w=new Set(f),v=new Set,S=new Map,R=new Set,_=new Set;for(const t of $.importers)for(const n of t.values){if(_.add(n),S.has(n)||v.has(n)||R.has(n))continue;const m=u.resolve(o.rootEntry,n);m?m.file===o.rootEntry?R.add(n):m.typeOnly||(S.set(n,m.file),w.add(m.file)):v.add(n)}if(R.size>0)for(const t of u.index(o.rootEntry)?.valueImports??[]){const n=i.resolve(o.rootEntry,t);n&&w.add(n)}const L=$.importers.some(t=>t.wholeModule),B=L?new Set(d.map(t=>t.resource)):closureWithin(o,w,r,o.rootEntry,a),T=y(t=>{let n=0;for(const m of t)n+=r.get(m)?.size??0;return n},"sizeOf"),U=d.reduce((t,n)=>t+n.size,0),z=T(B),A=d.filter(t=>!B.has(t.resource)),I=o.files>0?Math.min(1,d.length/o.files):1,O=new Map,D=new Map,k=y((t,n)=>{let m=D.get(t);return m===void 0&&(m=subpathFor(o,t,n,u,s.source,a)??null,D.set(t,m)),m??void 0},"choose"),F=$.importers.map(t=>{const n=new Map;for(const m of t.values){const g=S.get(m);if(!g)continue;const E=k(m,g);if(!E)continue;const j=O.get(E.specifier)??{specifier:E.specifier,entry:rel(c,E.entry),symbols:[],exists:E.exists};j.symbols.includes(m)||j.symbols.push(m),O.set(E.specifier,j),n.set(E.specifier,[...n.get(E.specifier)??[],m])}return{file:rel(c,t.file),symbols:t.values.slice(0,MAX_SYMBOLS_LISTED),typeOnly:t.typeOnly,wholeModule:t.wholeModule,rewrite:[...n].sort((m,g)=>m[0].localeCompare(g[0])).map(([m,g])=>`import { ${g.join(", ")} } from '${m}';`)}}).sort((t,n)=>Number(n.wholeModule)-Number(t.wholeModule)||n.symbols.length-t.symbols.length||t.file.localeCompare(n.file)),b={project:e.project,library:o.name,libraryRoot:rel(c,o.root),rootEntry:rel(c,o.rootEntry),libraryFiles:o.files,compiledModules:d.length,compiledBytes:U,share:I,rootImporterCount:p.length,rootImporters:F.slice(0,MAX_IMPORTERS_LISTED),internalRootImporters:x.slice(0,MAX_INTERNAL_LISTED).map(t=>rel(c,t)),symbols:_.size,unresolvedSymbols:[...v].sort().slice(0,MAX_SYMBOLS_LISTED),barrelDefines:[...R].sort().slice(0,MAX_SYMBOLS_LISTED),neededModules:B.size,neededBytes:z,avoidableModules:A.length,avoidableBytes:A.reduce((t,n)=>t+n.size,0),subpaths:[...O.values()].map(t=>({...t,symbols:t.symbols.sort().slice(0,MAX_SYMBOLS_LISTED)})).sort((t,n)=>Number(t.exists)-Number(n.exists)||n.symbols.length-t.symbols.length).slice(0,MAX_SUBPATHS_LISTED),fires:!1};return I<h.minShare?b.quiet=`compiles ${pct(I)} of the library (below ${pct(h.minShare)})`:b.compiledModules<h.minModules&&b.compiledBytes<h.minBytes?b.quiet=`compiles ${b.compiledModules} modules / ${mb(b.compiledBytes)} (below ${h.minModules} modules and ${mb(h.minBytes)})`:L?b.quiet="an importer uses the whole module (a namespace passed on, require(), import(), export *) \u2014 it may need all of it":_.size>0&&v.size/_.size>MAX_UNRESOLVED_SHARE?b.quiet=`could not follow ${v.size} of ${_.size} symbols to their files`:b.neededModules>h.maxNeededShare*b.compiledModules?b.quiet=`its importers need ${b.neededModules} of the ${b.compiledModules} compiled modules (above ${pct(h.maxNeededShare)})`:b.fires=!0,b}M(measure,"measure"),y(measure,"measure");const pct=y(e=>`${Math.round(e*100)}%`,"pct"),mb=y(e=>`${(e/(1024*1024)).toFixed(1)} MB`,"mb");function analyzeBarrelImports(e){const o=y(l=>e.source.exists(l),"exists"),r=new AliasResolver(e.libraries,o),s=new ExportReader(e.source,r),i=new Map,u=y(l=>(i.has(l)||i.set(l,(0,workspace_libraries_1.libraryOf)(e.libraries,l)),i.get(l)),"owner"),a=[];for(const l of e.projects){const d=new Map(l.modules.map(p=>[p.resource,p]));for(const p of e.libraries){if(e.expired?.())return{complete:!1,measurements:a};const c=measure(l,p,d,e,r,s,u);c&&a.push(c)}}return{complete:!e.expired?.(),measurements:a}}M(analyzeBarrelImports,"analyzeBarrelImports"),y(analyzeBarrelImports,"analyzeBarrelImports"),exports.EXECUTOR_MB_PER_MODULE=.374;function describeHeavyBarrel(e,o){const r=o&&o.builtModules>=50?o.durationMs/o.builtModules:void 0,s=r!==void 0?Math.round(r*e.avoidableModules):void 0,i=Math.round(exports.EXECUTOR_MB_PER_MODULE*e.avoidableModules),u=e.rootImporters.slice(0,3),a=e.subpaths.filter(c=>!c.exists),l=u.map(c=>`${c.file}: replace its \`${e.library}\` import with ${c.rewrite.length?c.rewrite.join(" "):"imports from the subpaths that export what it uses"}`),d=[`Import ${e.library} by subpath, never by its root barrel (${e.rootEntry}). ${e.rootImporterCount} file(s) of ${e.project}'s build import the root; ${l.length?`start with \u2014 ${l.join(" | ")}`:"see evidence.rootImporters"}${e.rootImporterCount>u.length?` (+${e.rootImporterCount-u.length} more: evidence.rootImporters)`:""}.`];a.length&&d.push(`Add the missing subpath entr${a.length===1?"y":"ies"} to the library: ${a.slice(0,4).map(c=>`"${c.specifier}" \u2192 ${c.entry}`).join(", ")} \u2014 in tsconfig.base.json \`compilerOptions.paths\` and, if the library has a package.json, its \`exports\` ("./<domain>"). Add exact keys (plus "<domain>/*" for single files), never one library-wide "${e.library}/*": a bundler's resolver can rank it above the exact keys and re-route them at runtime while tsc and jest stay green.`),e.barrelDefines.length&&d.push(`${e.rootEntry} defines ${e.barrelDefines.slice(0,4).join(", ")} itself, so importing ${e.barrelDefines.length===1?"it":"them"} runs the whole barrel: move ${e.barrelDefines.length===1?"it":"them"} into a module of ${e.barrelDefines.length===1?"its":"their"} own and import that.`),e.internalRootImporters.length&&d.push(`${e.internalRootImporters.length} file(s) inside ${e.library} import its own root barrel (${e.internalRootImporters.slice(0,3).join(", ")}): make them import the module they need, or every subpath still pulls the whole library in.`),d.push(`Stop the root import from coming back: in ${e.project}'s ESLint config add \`'no-restricted-imports': ['error', { paths: [{ name: '${e.library}', message: 'Import from a domain subpath (${e.library}/<domain>), not the root barrel.' }] }]\`.`);const p=`Save a file of ${e.project} (or restart it) so its dev build recompiles: it should compile about ${e.neededModules} modules of ${e.library} instead of ${e.compiledModules}, and LensMCP retracts this finding \u2014 \`observe_current_status\` no longer lists bundle/heavy-barrel-import for ${e.project}. Then check its pods' live heap (\`memory_pods\`).`;return{subject:e.library,severity:"warning",title:`${e.project} compiles ${e.compiledModules} of the ${e.libraryFiles} files of ${e.library} through its root barrel; its imports need ${e.neededModules}`,summary:`${e.rootImporterCount} file(s) of ${e.project} import ${e.library} through its root entry and take ${e.symbols} symbol(s); those need ${e.neededModules} of the library's modules, but the barrel makes the dev build compile ${e.compiledModules} (${mb(e.compiledBytes)}) \u2014 ${e.avoidableModules} modules (${mb(e.avoidableBytes)}) nothing uses, compiled in every service that does the same and loaded into every pod.`,evidence:{library:e.library,libraryRoot:e.libraryRoot,rootEntry:e.rootEntry,libraryFiles:e.libraryFiles,compiledModules:e.compiledModules,compiledBytes:e.compiledBytes,share:Math.round(e.share*1e3)/1e3,neededModules:e.neededModules,neededBytes:e.neededBytes,avoidableModules:e.avoidableModules,avoidableBytes:e.avoidableBytes,symbols:e.symbols,unresolvedSymbols:e.unresolvedSymbols,barrelDefines:e.barrelDefines,rootImporterCount:e.rootImporterCount,rootImporters:e.rootImporters,internalRootImporters:e.internalRootImporters,subpaths:e.subpaths},cost:{modules:e.avoidableModules,bytes:e.avoidableBytes,...s!==void 0?{compileMs:s}:{},memoryMb:i,basis:`modules/bytes measured in this compilation; memoryMb = ${exports.EXECUTOR_MB_PER_MODULE} MB of webpack-executor heap per compiled module (fitted on FoodGuard's watchers)${s!==void 0?"; compileMs = the last full build's time per built module \xD7 the avoidable modules":""}. Each pod also loads them, at runtime cost the bundle cannot measure.`},fix:d,verify:p}}M(describeHeavyBarrel,"describeHeavyBarrel"),y(describeHeavyBarrel,"describeHeavyBarrel");