MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _ChatCompleter

Class _ChatCompleter

openkb/agent/chat.py:226–267  ·  view source on GitHub ↗

Complete slash commands and file paths after /add.

Source from the content-addressed store, hash-verified

224
225
226class _ChatCompleter(Completer):
227 """Complete slash commands and file paths after /add."""
228
229 def __init__(self) -> None:
230 self._path_completer = PathCompleter(expanduser=True)
231
232 def get_completions(self, document: Document, complete_event: Any) -> Any:
233 text = document.text_before_cursor
234
235 # After "/add ", complete file paths (skip dotfiles)
236 if text.lstrip().lower().startswith("/add "):
237 path_text = text.lstrip()[5:]
238 # Strip leading quote so PathCompleter resolves the real path
239 quote_char = ""
240 if path_text and path_text[0] in ("'", '"'):
241 quote_char = path_text[0]
242 path_text = path_text[1:]
243 path_doc = Document(path_text, len(path_text))
244 for c in self._path_completer.get_completions(path_doc, complete_event):
245 # Hide dotfiles unless the user explicitly typed a dot
246 basename = c.text.lstrip("/")
247 if basename.startswith(".") and not path_text.rpartition("/")[2].startswith("."):
248 continue
249 # Append closing quote for files; skip for directories so
250 # the user can keep navigating into subdirectories.
251 if quote_char and not c.text.endswith("/"):
252 comp_text = c.text + quote_char
253 else:
254 comp_text = c.text
255 yield Completion(
256 comp_text,
257 start_position=c.start_position,
258 display=c.display,
259 display_meta=c.display_meta,
260 )
261 return
262
263 # Complete slash commands with descriptions
264 if text.startswith("/"):
265 for cmd, desc in _SLASH_COMMANDS:
266 if cmd.startswith(text.lower()):
267 yield Completion(cmd, start_position=-len(text), display_meta=desc)
268
269
270def _make_prompt_session(

Callers 1

_make_prompt_sessionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected