hanuscode 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hanus/__init__.py +5 -0
- hanus/__main__.py +10 -0
- hanus/action_handlers.py +76 -0
- hanus/action_parser.py +82 -0
- hanus/agent_runner.py +1445 -0
- hanus/analysis/__init__.py +5 -0
- hanus/analysis/debt.py +702 -0
- hanus/analysis/dependencies.py +475 -0
- hanus/cache/__init__.py +5 -0
- hanus/cache/response_cache.py +560 -0
- hanus/config.py +401 -0
- hanus/connectors/__init__.py +19 -0
- hanus/connectors/base.py +114 -0
- hanus/connectors/claude_connector.py +146 -0
- hanus/connectors/gemini_connector.py +141 -0
- hanus/connectors/glm_connector.py +160 -0
- hanus/connectors/ollama_connector.py +174 -0
- hanus/connectors/openai_connector.py +122 -0
- hanus/connectors/registry.py +26 -0
- hanus/context/__init__.py +7 -0
- hanus/context/manager.py +837 -0
- hanus/context/selective.py +626 -0
- hanus/error_recovery/__init__.py +5 -0
- hanus/error_recovery/auto_fix.py +605 -0
- hanus/hooks/__init__.py +5 -0
- hanus/hooks/manager.py +247 -0
- hanus/instincts/__init__.py +44 -0
- hanus/instincts/cli.py +372 -0
- hanus/instincts/detector.py +281 -0
- hanus/instincts/evolver.py +361 -0
- hanus/instincts/manager.py +343 -0
- hanus/instincts/types.py +253 -0
- hanus/logger.py +81 -0
- hanus/memory/__init__.py +8 -0
- hanus/memory/manager.py +265 -0
- hanus/memory/types.py +119 -0
- hanus/monitor.py +341 -0
- hanus/parallel/__init__.py +5 -0
- hanus/parallel/executor.py +300 -0
- hanus/permissions.py +182 -0
- hanus/plan/__init__.py +8 -0
- hanus/plan/mode.py +267 -0
- hanus/plan/models.py +152 -0
- hanus/plugin_manager.py +754 -0
- hanus/plugin_registry.py +391 -0
- hanus/plugins/__init__.py +1 -0
- hanus/plugins/arena.py +630 -0
- hanus/plugins/code_review.py +123 -0
- hanus/plugins/cortex.py +1750 -0
- hanus/plugins/deps_check.py +27 -0
- hanus/plugins/git_ops.py +33 -0
- hanus/plugins/metasploit.py +530 -0
- hanus/plugins/notes.py +583 -0
- hanus/plugins/search_code.py +59 -0
- hanus/plugins/searchsploit.py +495 -0
- hanus/plugins/strategist.py +175 -0
- hanus/plugins/webui.py +5200 -0
- hanus/profiles.py +479 -0
- hanus/profiles_builtin/__init__.py +0 -0
- hanus/profiles_builtin/architect/profile.yaml +12 -0
- hanus/profiles_builtin/architect/system_prompt.txt +71 -0
- hanus/profiles_builtin/deep/profile.yaml +12 -0
- hanus/profiles_builtin/deep/system_prompt.txt +66 -0
- hanus/profiles_builtin/developer/__init__.py +0 -0
- hanus/profiles_builtin/developer/profile.yaml +9 -0
- hanus/profiles_builtin/developer/system_prompt.txt +176 -0
- hanus/profiles_builtin/speed/profile.yaml +12 -0
- hanus/profiles_builtin/speed/system_prompt.txt +51 -0
- hanus/project_tools.py +177 -0
- hanus/query_engine.py +1594 -0
- hanus/rules/__init__.py +237 -0
- hanus/search/__init__.py +5 -0
- hanus/search/semantic.py +596 -0
- hanus/session_manager.py +547 -0
- hanus/skill_manager.py +702 -0
- hanus/skills/__init__.py +4 -0
- hanus/subagent/__init__.py +8 -0
- hanus/subagent/agents/__init__.py +253 -0
- hanus/subagent/manager.py +309 -0
- hanus/subagent/types.py +266 -0
- hanus/suggestions/__init__.py +5 -0
- hanus/suggestions/proactive.py +451 -0
- hanus/tasks/__init__.py +8 -0
- hanus/tasks/manager.py +330 -0
- hanus/tasks/models.py +106 -0
- hanus/terminal_prompt.py +166 -0
- hanus/tools.py +1849 -0
- hanus/ui.py +939 -0
- hanuscode-1.0.0.dist-info/METADATA +1151 -0
- hanuscode-1.0.0.dist-info/RECORD +93 -0
- hanuscode-1.0.0.dist-info/WHEEL +5 -0
- hanuscode-1.0.0.dist-info/entry_points.txt +2 -0
- hanuscode-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# plugins/code_review.py — Revisión de código con IA
|
|
2
|
+
"""
|
|
3
|
+
Usa Claude o Ollama para revisar código y detectar problemas.
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import json
|
|
8
|
+
import urllib.request
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
NAME = "code_review"
|
|
12
|
+
DESCRIPTION = "Revisa código con IA: detecta bugs, mejoras y problemas de seguridad"
|
|
13
|
+
USAGE = "<ruta_del_archivo>"
|
|
14
|
+
AGENT_DOC = """
|
|
15
|
+
Revisa un archivo de código en busca de bugs, problemas de seguridad y mejoras.
|
|
16
|
+
Ejemplo: <run_plugin name="code_review" args="src/auth.py"/>
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def run(args: str = "") -> str:
|
|
21
|
+
path_str = args.strip()
|
|
22
|
+
if not path_str:
|
|
23
|
+
return "Indica la ruta del archivo: <run_plugin name='code_review' args='ruta/archivo.py'/>"
|
|
24
|
+
|
|
25
|
+
path = Path(path_str)
|
|
26
|
+
if not path.exists():
|
|
27
|
+
path = Path(".") / path_str
|
|
28
|
+
if not path.exists():
|
|
29
|
+
return f"Archivo no encontrado: {path_str}"
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
code = path.read_text(encoding="utf-8", errors="replace")
|
|
33
|
+
except Exception as e:
|
|
34
|
+
return f"Error leyendo {path_str}: {e}"
|
|
35
|
+
|
|
36
|
+
if len(code) > 15_000:
|
|
37
|
+
code = code[:15_000] + "\n…(truncado)"
|
|
38
|
+
|
|
39
|
+
prompt = f"""Revisa el siguiente código y proporciona:
|
|
40
|
+
1. **Bugs detectados** (con número de línea si es posible)
|
|
41
|
+
2. **Problemas de seguridad**
|
|
42
|
+
3. **Mejoras de rendimiento**
|
|
43
|
+
4. **Sugerencias de legibilidad/mantenimiento**
|
|
44
|
+
5. **Calificación general** (1-10)
|
|
45
|
+
|
|
46
|
+
Archivo: {path.name}
|
|
47
|
+
```{path.suffix.lstrip('.')}
|
|
48
|
+
{code}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Sé conciso y específico. Si el código está bien, indícalo."""
|
|
52
|
+
|
|
53
|
+
# Intentar Claude primero
|
|
54
|
+
api_key = os.environ.get("ANTHROPIC_API_KEY", "")
|
|
55
|
+
if api_key:
|
|
56
|
+
result = _try_claude(prompt, api_key, path.name)
|
|
57
|
+
if result:
|
|
58
|
+
return result
|
|
59
|
+
|
|
60
|
+
# Intentar Ollama local
|
|
61
|
+
result = _try_ollama(prompt, path.name)
|
|
62
|
+
if result:
|
|
63
|
+
return result
|
|
64
|
+
|
|
65
|
+
return "No se pudo conectar a ningún modelo de IA. Configura ANTHROPIC_API_KEY o usa Ollama local."
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _try_claude(prompt: str, api_key: str, filename: str) -> str:
|
|
69
|
+
"""Llama a Claude para revisar código."""
|
|
70
|
+
try:
|
|
71
|
+
payload = json.dumps({
|
|
72
|
+
"model": "claude-haiku-4-5",
|
|
73
|
+
"max_tokens": 2000,
|
|
74
|
+
"system": "Eres un experto revisor de código. Analiza el código proporcionado y da feedback claro y accionable.",
|
|
75
|
+
"messages": [{"role": "user", "content": prompt}],
|
|
76
|
+
}).encode()
|
|
77
|
+
req = urllib.request.Request(
|
|
78
|
+
"https://api.anthropic.com/v1/messages",
|
|
79
|
+
data=payload,
|
|
80
|
+
headers={
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
"x-api-key": api_key,
|
|
83
|
+
"anthropic-version": "2023-06-01",
|
|
84
|
+
},
|
|
85
|
+
method="POST",
|
|
86
|
+
)
|
|
87
|
+
with urllib.request.urlopen(req, timeout=30) as r:
|
|
88
|
+
data = json.loads(r.read())
|
|
89
|
+
result = data["content"][0]["text"]
|
|
90
|
+
return f"## 🔍 Revisión de código: {filename}\n\n{result}"
|
|
91
|
+
except Exception:
|
|
92
|
+
return ""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _try_ollama(prompt: str, filename: str) -> str:
|
|
96
|
+
"""Intenta usar Ollama local."""
|
|
97
|
+
try:
|
|
98
|
+
import requests
|
|
99
|
+
ollama_url = os.environ.get("OLLAMA_URL", "http://localhost:11434")
|
|
100
|
+
|
|
101
|
+
# Verificar que Ollama está disponible
|
|
102
|
+
try:
|
|
103
|
+
requests.get(f"{ollama_url}/api/tags", timeout=2)
|
|
104
|
+
except Exception:
|
|
105
|
+
return ""
|
|
106
|
+
|
|
107
|
+
payload = {
|
|
108
|
+
"model": "llama3",
|
|
109
|
+
"prompt": prompt,
|
|
110
|
+
"system": "Eres un experto revisor de código. Analiza el código proporcionado y da feedback claro y accionable.",
|
|
111
|
+
"stream": False,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
r = requests.post(f"{ollama_url}/api/generate", json=payload, timeout=60)
|
|
115
|
+
r.raise_for_status()
|
|
116
|
+
text = r.json().get("response", "")
|
|
117
|
+
|
|
118
|
+
if text:
|
|
119
|
+
return f"## 🔍 Revisión de código: {filename}\n\n{text}"
|
|
120
|
+
except Exception:
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
return ""
|