Navegador

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

Keyboard Shortcuts

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