@@ -20,6 +20,40 @@ interface AgentsListProps {
2020 isCreatingAgent ?: boolean ;
2121}
2222
23+ // Robust URL normalization function
24+ const normalizeRepoUrl = ( url : string | undefined | null ) : string => {
25+ if ( ! url ) return "" ;
26+
27+ let normalized = url . trim ( ) ;
28+
29+ // Convert SSH to HTTPS: git@github .com:owner/repo.git -> https://github.com/owner/repo
30+ if ( normalized . startsWith ( "[email protected] :" ) ) { 31+ normalized = normalized . replace ( "[email protected] :" , "https://github.com/" ) ; 32+ }
33+
34+ // Convert shorthand owner/repo to full URL
35+ if (
36+ normalized . includes ( "/" ) &&
37+ ! normalized . startsWith ( "http" ) &&
38+ ! normalized . startsWith ( "git@" )
39+ ) {
40+ normalized = `https://github.com/${ normalized } ` ;
41+ }
42+
43+ // Remove .git suffix
44+ if ( normalized . endsWith ( ".git" ) ) {
45+ normalized = normalized . slice ( 0 , - 4 ) ;
46+ }
47+
48+ // Remove trailing slash
49+ if ( normalized . endsWith ( "/" ) ) {
50+ normalized = normalized . slice ( 0 , - 1 ) ;
51+ }
52+
53+ // Normalize to lowercase
54+ return normalized . toLowerCase ( ) ;
55+ } ;
56+
2357export function AgentsList ( { isCreatingAgent = false } : AgentsListProps ) {
2458 const { session } = useAuth ( ) ;
2559 const ideMessenger = useContext ( IdeMessengerContext ) ;
@@ -44,16 +78,14 @@ export function AgentsList({ isCreatingAgent = false }: AgentsListProps) {
4478 dir,
4579 } ) ;
4680 if ( repoNameResult . status === "success" && repoNameResult . content ) {
47- // Normalize repo URL
48- const repoName = repoNameResult . content ;
49- const normalizedUrl =
50- repoName . includes ( "/" ) && ! repoName . startsWith ( "http" )
51- ? `https://github.com/${ repoName } `
52- : repoName ;
53- repoUrls . push ( normalizedUrl ) ;
81+ const normalizedUrl = normalizeRepoUrl ( repoNameResult . content ) ;
82+ if ( normalizedUrl ) {
83+ repoUrls . push ( normalizedUrl ) ;
84+ }
5485 }
5586 }
5687 setWorkspaceRepoUrls ( repoUrls ) ;
88+ console . log ( "Workspace repo URLs:" , repoUrls ) ;
5789 }
5890 } catch ( err ) {
5991 console . error ( "Failed to fetch workspace repos:" , err ) ;
@@ -113,14 +145,18 @@ export function AgentsList({ isCreatingAgent = false }: AgentsListProps) {
113145 } , [ session , ideMessenger , currentOrg ] ) ;
114146
115147 // Helper function to check if an agent's repo matches any workspace repo
116- const isAgentInCurrentWorkspace = ( agentRepoUrl : string ) : boolean => {
117- const normalizedAgentRepo =
118- agentRepoUrl . includes ( "/" ) && ! agentRepoUrl . startsWith ( "http" )
119- ? `https://github.com/${ agentRepoUrl } `
120- : agentRepoUrl ;
148+ const isAgentInCurrentWorkspace = ( agent : Agent ) : boolean => {
149+ // Get all possible agent repo URLs (both repoUrl and metadata.github_repo)
150+ const agentUrls = [ agent . repoUrl , agent . metadata ?. github_repo ]
151+ . filter ( Boolean )
152+ . map ( normalizeRepoUrl )
153+ . filter ( ( url ) => url !== "" ) ;
154+
155+ console . log ( "Agent URLs:" , agentUrls , "Workspace URLs:" , workspaceRepoUrls ) ;
121156
122- return workspaceRepoUrls . some (
123- ( workspaceUrl ) => workspaceUrl === normalizedAgentRepo ,
157+ // Check if any of the agent URLs match any workspace URL
158+ return workspaceRepoUrls . some ( ( workspaceUrl ) =>
159+ agentUrls . some ( ( agentUrl ) => agentUrl === workspaceUrl ) ,
124160 ) ;
125161 } ;
126162
@@ -160,7 +196,7 @@ export function AgentsList({ isCreatingAgent = false }: AgentsListProps) {
160196 </ div >
161197 < div className = "flex flex-col gap-1 px-2" >
162198 { agents . map ( ( agent ) => {
163- const isInWorkspace = isAgentInCurrentWorkspace ( agent . repoUrl ) ;
199+ const isInWorkspace = isAgentInCurrentWorkspace ( agent ) ;
164200 const canOpenLocally = isInWorkspace ;
165201
166202 return (
0 commit comments