@@ -206,7 +206,7 @@ def _add_read_only_directory(
206206
207207 @classmethod
208208 def get_completions (cls , io , coder , args ) -> List [str ]:
209- """Get completion options for read-only command."""
209+ """Get completion options for read-only-stub command."""
210210 from pathlib import Path
211211
212212 root = Path (coder .root ) if hasattr (coder , "root" ) else Path .cwd ()
@@ -215,9 +215,13 @@ def get_completions(cls, io, coder, args) -> List[str]:
215215 if "/" in args :
216216 # Has directory component
217217 dir_part , file_part = args .rsplit ("/" , 1 )
218- search_dir = root / dir_part
218+ if dir_part == "" :
219+ search_dir = Path ("/" )
220+ path_prefix = "/"
221+ else :
222+ search_dir = (root / dir_part ).resolve ()
223+ path_prefix = dir_part + "/"
219224 search_prefix = file_part .lower ()
220- path_prefix = dir_part + "/"
221225 else :
222226 search_dir = root
223227 search_prefix = args .lower ()
@@ -228,8 +232,9 @@ def get_completions(cls, io, coder, args) -> List[str]:
228232 if search_dir .exists () and search_dir .is_dir ():
229233 for entry in search_dir .iterdir ():
230234 name = entry .name
231- if search_prefix and search_prefix not in name .lower ():
235+ if search_prefix and not name .lower (). startswith ( search_prefix ):
232236 continue
237+
233238 # Add trailing slash for directories
234239 if entry .is_dir ():
235240 completions .append (path_prefix + name + "/" )
@@ -238,6 +243,7 @@ def get_completions(cls, io, coder, args) -> List[str]:
238243 except (PermissionError , OSError ):
239244 pass
240245
246+ # Also include files already in the chat that match
241247 add_completions = coder .commands .get_completions ("/add" )
242248 for c in add_completions :
243249 if args .lower () in str (c ).lower () and str (c ) not in completions :
0 commit comments