@@ -19,7 +19,10 @@ import {
1919} from './utils.js'
2020import { createIntentFsCache } from './fs-cache.js'
2121import { detectPackageManager } from './package-manager.js'
22- import { findWorkspaceRoot } from './workspace-patterns.js'
22+ import {
23+ findWorkspacePackages ,
24+ findWorkspaceRoot ,
25+ } from './workspace-patterns.js'
2326import type { IntentFsCache } from './fs-cache.js'
2427import type { ReadFs } from './utils.js'
2528import type {
@@ -451,6 +454,28 @@ function getScanScope(options: ScanOptions): ScanScope {
451454 return options . scope ?? ( options . includeGlobal ? 'local-and-global' : 'local' )
452455}
453456
457+ function createWorkspacePackageKeySet (
458+ workspaceRoot : string | null ,
459+ getFsIdentity : ( path : string ) => string ,
460+ ) : Set < string > {
461+ if ( ! workspaceRoot ) return new Set ( )
462+
463+ return new Set (
464+ findWorkspacePackages ( workspaceRoot ) . map ( ( dir ) => getFsIdentity ( dir ) ) ,
465+ )
466+ }
467+
468+ function createPackageKindResolver (
469+ workspacePackageKeys : Set < string > ,
470+ getFsIdentity : ( path : string ) => string ,
471+ ) : ( packageRoot : string ) => IntentPackage [ 'kind' ] {
472+ return ( packageRoot : string ) : IntentPackage [ 'kind' ] => {
473+ return workspacePackageKeys . has ( getFsIdentity ( packageRoot ) )
474+ ? 'workspace'
475+ : 'npm'
476+ }
477+ }
478+
454479export function scanForIntents (
455480 root ?: string ,
456481 options : ScanOptions = { } ,
@@ -495,6 +520,11 @@ export function scanForIntents(
495520 > ( )
496521 let pnpApi : PnpApi | null | undefined
497522
523+ const getPackageKind = createPackageKindResolver (
524+ createWorkspacePackageKeySet ( workspaceRoot , fsCache . getFsIdentity ) ,
525+ fsCache . getFsIdentity ,
526+ )
527+
498528 function getPnpApi ( ) : PnpApi | null {
499529 if ( scanScope === 'global' ) return null
500530 if ( pnpApi === undefined ) {
@@ -545,6 +575,7 @@ export function scanForIntents(
545575 deriveIntentConfig,
546576 discoverSkills : ( skillsDir ) => discoverSkills ( skillsDir , fsCache ) ,
547577 getPackageDepth,
578+ getPackageKind,
548579 getFsIdentity : fsCache . getFsIdentity ,
549580 exists : fsCache . exists ,
550581 packageIndexes,
@@ -726,6 +757,13 @@ export function scanIntentPackageAtRoot(
726757 const warnings : Array < string > = [ ]
727758 const packageIndexes = new Map < string , number > ( )
728759 const fsCache = options . fsCache ?? createIntentFsCache ( )
760+ const getPackageKind = createPackageKindResolver (
761+ createWorkspacePackageKeySet (
762+ findWorkspaceRoot ( projectRoot ) ,
763+ fsCache . getFsIdentity ,
764+ ) ,
765+ fsCache . getFsIdentity ,
766+ )
729767
730768 function readPkgJson ( dirPath : string ) : Record < string , unknown > | null {
731769 return fsCache . readPackageJson ( dirPath )
@@ -744,6 +782,7 @@ export function scanIntentPackageAtRoot(
744782 )
745783 : ( skillsDir ) => discoverSkills ( skillsDir , fsCache ) ,
746784 getPackageDepth,
785+ getPackageKind,
747786 getFsIdentity : fsCache . getFsIdentity ,
748787 exists : fsCache . exists ,
749788 packageIndexes,
0 commit comments