55const fs = require ( 'fs' ) ;
66const path = require ( 'path' ) ;
77const { HOMEDIR , DATA_DIR , SKILLS_DIR } = require ( './config' ) ;
8+ // TODO: countSkillFiles and listSkillNames are synchronous and block the event loop.
9+ // Converting them to async (fs.promises) would require changes across skills.js and
10+ // all callers. Until then, calls here are the main latency source in scanSystem.
811const { countSkillFiles, listSkillNames } = require ( './skills' ) ;
912const {
1013 HOSTS ,
@@ -13,7 +16,7 @@ const {
1316 CONFIG_FILE_NAMES ,
1417 OPPORTUNITY_FILES ,
1518} = require ( './system-scan-definitions' ) ;
16- const { probeIDEs, probeAIExtensions } = require ( './system-scan-ides' ) ;
19+ const { probeIDEs, probeAIExtensions, isDir } = require ( './system-scan-ides' ) ;
1720
1821// ---- Helpers ----
1922
@@ -44,14 +47,6 @@ async function isFile(p) {
4447 return false ;
4548 }
4649}
47- /** @param {string } p */
48- async function isDir ( p ) {
49- try {
50- return ( await fs . promises . stat ( p ) ) . isDirectory ( ) ;
51- } catch {
52- return false ;
53- }
54- }
5550
5651/** @param {string } p */
5752async function readJsonSafe ( p ) {
@@ -307,7 +302,7 @@ async function probeHostDir(hostDef, homedir) {
307302
308303 // Opportunities (missing global config)
309304 const expected = OPPORTUNITY_FILES [ /** @type {keyof typeof OPPORTUNITY_FILES } */ ( hostDef . id ) ] ;
310- if ( expected ) {
305+ if ( expected != null ) {
311306 const filePath = path . join ( hostPath , expected ) ;
312307 const homedirFile = path . join ( homedir , expected ) ;
313308 // If config doesn't exist inside host dir or at homedir root
@@ -324,7 +319,7 @@ async function probeHostDir(hostDef, homedir) {
324319}
325320
326321/** @param {Array<{id: string, label: string, path: string, exe: string}> } ideList */
327- async function probeIdegGroup ( ideList ) {
322+ async function probeIdeGroup ( ideList ) {
328323 if ( ! ideList . length ) return null ;
329324 const perIde = await probeAIExtensions ( ) ;
330325 return {
@@ -362,8 +357,8 @@ async function scanSystem(customPaths = [], opts = {}) {
362357 }
363358
364359 // Probe host dirs from drives
360+ const drives = ! skipDrives ? await getDriveRoots ( ) : [ ] ;
365361 if ( ! skipDrives ) {
366- const drives = await getDriveRoots ( ) ;
367362 const driveResults = await Promise . all (
368363 drives . flatMap ( ( drive ) =>
369364 HOSTS . map ( async ( h ) => {
@@ -445,7 +440,6 @@ async function scanSystem(customPaths = [], opts = {}) {
445440 await scanStandaloneFiles ( HOMEDIR , hosts ) ;
446441 }
447442 if ( ! skipDrives ) {
448- const drives = await getDriveRoots ( ) ;
449443 await Promise . all ( drives . map ( ( d ) => scanStandaloneFiles ( d , hosts ) ) ) ;
450444 }
451445 await Promise . all ( workspaces . map ( ( /** @type {string } */ ws ) => scanStandaloneFiles ( ws , hosts ) ) ) ;
@@ -462,7 +456,7 @@ async function scanSystem(customPaths = [], opts = {}) {
462456 ) ;
463457
464458 // IDE group
465- const ides = await probeIdegGroup ( ideList ) ;
459+ const ides = await probeIdeGroup ( ideList ) ;
466460
467461 return {
468462 hosts : populated ,
0 commit comments