Navegador

navegador / hooks / gemini-hook.py
Source Blame History 60 lines
4be3595… lmata 1 #!/usr/bin/env python3
4be3595… lmata 2 """
4be3595… lmata 3 Navegador hook for Gemini CLI (gemini-cli).
4be3595… lmata 4
4be3595… lmata 5 Gemini CLI supports tool hooks via GEMINI.md + shell scripts executed
4be3595… lmata 6 after tool calls. This script is designed to be invoked as a post-tool hook.
4be3595… lmata 7
4be3595… lmata 8 Install:
4be3595… lmata 9 Copy to your project root as .gemini/hooks/navegador.py
4be3595… lmata 10 Reference in GEMINI.md:
4be3595… lmata 11
4be3595… lmata 12 ## Hooks
4be3595… lmata 13 After editing or creating any source file, run:
4be3595… lmata 14 python3 .gemini/hooks/navegador.py <tool_name> <file_path>
4be3595… lmata 15
4be3595… lmata 16 This keeps the navegador knowledge graph in sync with your changes.
4be3595… lmata 17
4be3595… lmata 18 Usage (called by gemini-cli hook runner):
4be3595… lmata 19 python3 navegador.py edit src/auth.py
4be3595… lmata 20 python3 navegador.py write src/new_module.py
4be3595… lmata 21 """
4be3595… lmata 22
4be3595… lmata 23 import os
4be3595… lmata 24 import subprocess
4be3595… lmata 25 import sys
4be3595… lmata 26
4be3595… lmata 27 NAV_DB = os.environ.get("NAVEGADOR_DB", ".navegador/graph.db")
4be3595… lmata 28 NAV_CMD = os.environ.get("NAVEGADOR_CMD", "navegador")
4be3595… lmata 29 INGESTABLE = {".py", ".ts", ".tsx", ".js", ".jsx"}
4be3595… lmata 30
4be3595… lmata 31
4be3595… lmata 32 def run_nav(*args):
4be3595… lmata 33 subprocess.run([NAV_CMD, "--db", NAV_DB, *args], capture_output=True)
4be3595… lmata 34
4be3595… lmata 35
4be3595… lmata 36 def main():
4be3595… lmata 37 args = sys.argv[1:]
4be3595… lmata 38 if len(args) < 2:
4be3595… lmata 39 sys.exit(0)
4be3595… lmata 40
4be3595… lmata 41 _tool, file_path = args[0], args[1]
4be3595… lmata 42 ext = os.path.splitext(file_path)[1]
4be3595… lmata 43
4be3595… lmata 44 if ext in INGESTABLE and os.path.exists(file_path):
4be3595… lmata 45 repo_root = _find_repo_root(file_path)
4be3595… lmata 46 if repo_root:
4be3595… lmata 47 run_nav("ingest", repo_root)
4be3595… lmata 48
4be3595… lmata 49
4be3595… lmata 50 def _find_repo_root(path: str) -> str | None:
4be3595… lmata 51 d = os.path.dirname(os.path.abspath(path))
4be3595… lmata 52 while d != os.path.dirname(d):
4be3595… lmata 53 if os.path.exists(os.path.join(d, ".git")):
4be3595… lmata 54 return d
4be3595… lmata 55 d = os.path.dirname(d)
4be3595… lmata 56 return None
4be3595… lmata 57
4be3595… lmata 58
4be3595… lmata 59 if __name__ == "__main__":
4be3595… lmata 60 main()

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button