Commit Graph

2 Commits

Author SHA1 Message Date
egutierrez 2546e43ee2 refactor: extraer campo sender en Agent para desacoplar envio de mensajes
Añade un campo `sender effects.MatrixSender` al struct Agent que reemplaza
las llamadas directas a `a.matrix` para enviar mensajes (sendReply, typing,
SendMarkdown en handleTaskEvent). En produccion, sender apunta al mismo
*matrix.Client. Esto permite inyectar un spy en tests sin requerir una
conexion real a Matrix.

El campo `a.matrix` se mantiene para operaciones que no son de envio
(SetPresence, Raw, etc.).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 20:22:36 +00:00
egutierrez 42251ecada refactor: separar runtime.go en archivos por responsabilidad
Divide agents/runtime.go (1188 lineas) en 5 archivos especializados:

- runtime.go (350 lineas): struct Agent, New(), Run(), Stop(), lifecycle
- handler.go: handleEvent(), executeActions(), command routing, bus, sanitizacion
- llm.go: runLLM(), tool-use loop, system prompt, initLLM(), prompt-commands
- memory.go: ensureWindowLoaded(), appendToWindow(), persistMessage(), ClearWindow()
- registry_build.go: buildToolRegistry(), initToolDeps(), initRateLimiter()

Zero cambios en API publica. Todos los metodos siguen siendo del struct Agent,
solo viven en archivos separados por responsabilidad.

Funciones helper extraidas de New() para reducir su tamaño:
- initCrypto(): inicializacion E2EE
- initLLM(): cliente LLM con fallback
- initMemoryStore(): store SQLite + window size
- initToolDeps(): knowledge, MCP, skills
- initRateLimiter(): rate limiting de tools

Reduccion: 1188 → 350 lineas en runtime.go (70% menos).
2026-04-09 00:21:42 +00:00