refactor: mover runtime Go de agents/ a devagents/
agents/ ahora solo contiene carpetas de agentes (config, reglas, prompts). El runtime (Agent, Robot, Runner, registry, handler, commands, llm, memory) vive en devagents/ como package devagents. Cambios: - git mv agents/*.go → devagents/*.go - package agents → package devagents en todos los archivos movidos - Actualizar imports en agents/*/agent.go, cmd/launcher/, dev-scripts/ - Actualizar docs: CLAUDE.md, rules/, docs/e2ee.md, issues pendientes Build y tests pasan sin errores. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+5
-4
@@ -11,7 +11,8 @@ Monorepo Go para bots Matrix autonomos. Modulo: `github.com/enmanuel/agents`.
|
||||
```
|
||||
pkg/ → PURO: tipos, funciones puras, cero side effects
|
||||
shell/ → IMPURO: todo I/O (Matrix, LLM, SSH, filesystem)
|
||||
agents/ → composicion: reglas puras + ensamblado con shell
|
||||
devagents/ → runtime: Agent/Robot ensambla core + shell
|
||||
agents/ → reglas puras por agente + config.yaml + prompts
|
||||
tools/ → Def (puro) + Exec (impuro)
|
||||
```
|
||||
|
||||
@@ -56,9 +57,9 @@ shell/mcp/ cliente y servidor MCP (Model Context Protocol)
|
||||
shell/skills/ loader (filesystem) + executor (scripts)
|
||||
shell/effects/ Runner: []Action → side effects
|
||||
shell/bus/ comunicacion inter-agente
|
||||
agents/types.go Runner interface (comun a Agent y Robot)
|
||||
agents/runtime.go Agent{}: ensambla core + shell (runtime completo con LLM)
|
||||
agents/robot.go Robot{}: runtime ligero command-only (sin LLM, reglas, memoria)
|
||||
devagents/types.go Runner interface (comun a Agent y Robot)
|
||||
devagents/runtime.go Agent{}: ensambla core + shell (runtime completo con LLM)
|
||||
devagents/robot.go Robot{}: runtime ligero command-only (sin LLM, reglas, memoria)
|
||||
agents/<id>/ agent.go (reglas puras) + config.yaml + prompts/system.md
|
||||
tools/ tool registry + tool implementations (subpackages)
|
||||
tools/mcptools/ bridge: convierte MCP tools → tools.Tool
|
||||
|
||||
@@ -7,7 +7,7 @@ Guia ejecutable para Claude. Seguir paso a paso sin desviarse.
|
||||
| | Agent | Robot |
|
||||
|---|---|---|
|
||||
| **Cuando usar** | Necesita LLM, reglas, memoria, tools | Solo responde comandos (!xxx) |
|
||||
| **Runtime** | `agents.New()` — completo | `agents.NewRobot()` — ligero |
|
||||
| **Runtime** | `devagents.New()` — completo | `devagents.NewRobot()` — ligero |
|
||||
| **Config type** | `type: agent` (default) | `type: robot` |
|
||||
| **LLM** | Si | No |
|
||||
| **Reglas** | Si (`agent.go` con `Rules()`) | No (sin `agent.go`) |
|
||||
@@ -57,12 +57,12 @@ Template base (generado por el scaffold):
|
||||
package <pkgname> // sin guiones: "monitor-bot" → package monitor (strip hyphens, strip _bot)
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("<agent-id>", Rules)
|
||||
devdevagents.Register("<agent-id>", Rules)
|
||||
}
|
||||
|
||||
func Rules() []decision.Rule {
|
||||
@@ -84,7 +84,7 @@ func Rules() []decision.Rule {
|
||||
|
||||
**Reglas estrictas:**
|
||||
- **PURO**: solo imports de `pkg/decision` y `agents` (para Register), cero I/O, cero side effects
|
||||
- **Auto-registro**: cada agente se registra via `init()` con `agents.Register("<agent-id>", Rules)`
|
||||
- **Auto-registro**: cada agente se registra via `init()` con `devagents.Register("<agent-id>", Rules)`
|
||||
- Package name = ID sin guiones ni `_bot` (e.g. `monitor-bot` → `package monitor`)
|
||||
- **No usar reglas para comandos** (`!help`, `!ping`, etc.) — los comandos se gestionan via `RegisterCommand` (ver policy `create_command.md`)
|
||||
- Las reglas solo aplican a mensajes normales (sin prefijo `!`)
|
||||
@@ -174,7 +174,7 @@ _ "github.com/enmanuel/agents/agents/<agent-id>"
|
||||
|
||||
Las reglas se registran automáticamente via `init()` en el paquete del agente.
|
||||
No se necesita editar ningún map ni registry manualmente.
|
||||
**El ID en `agents.Register()` DEBE coincidir exactamente con `agent.id` en config.yaml.**
|
||||
**El ID en `devagents.Register()` DEBE coincidir exactamente con `agent.id` en config.yaml.**
|
||||
|
||||
## Convención de env vars — REGLA CRÍTICA
|
||||
|
||||
@@ -228,7 +228,7 @@ tail -f run/launcher.log
|
||||
|
||||
- **Nunca** side effects en `agent.go`
|
||||
- **Siempre** compilar con `-tags goolm`
|
||||
- **Siempre** que `agent.id` coincida entre config.yaml, `agents.Register()` y directorio
|
||||
- **Siempre** que `agent.id` coincida entre config.yaml, `devagents.Register()` y directorio
|
||||
- **No** crear `data/` manualmente — se auto-genera
|
||||
- **No** commitear tokens ni passwords
|
||||
- **No** compartir crypto stores entre agentes
|
||||
|
||||
@@ -28,7 +28,7 @@ Todos los agentes los tienen automáticamente: `!help`, `!ping`, `!tools`, `!too
|
||||
|
||||
### Agent-specific (por agente)
|
||||
|
||||
Se registran con `agent.RegisterCommand(spec, handler)` en el launcher, después de `agents.New()` y antes de `agent.Run()`.
|
||||
Se registran con `agent.RegisterCommand(spec, handler)` en el launcher, después de `devagents.New()` y antes de `agent.Run()`.
|
||||
|
||||
## Pasos para crear un comando de agente
|
||||
|
||||
@@ -79,10 +79,10 @@ type CommandEntry struct {
|
||||
|
||||
### 2. Registrar en el launcher (`cmd/launcher/main.go`)
|
||||
|
||||
Después de `agents.New()` y antes de `wg.Add(1)`:
|
||||
Después de `devagents.New()` y antes de `wg.Add(1)`:
|
||||
|
||||
```go
|
||||
a, err := agents.New(cfg, rules, agentLogger)
|
||||
a, err := devagents.New(cfg, rules, agentLogger)
|
||||
if err != nil { ... }
|
||||
|
||||
// Register agent-specific commands
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewMiTool(/* deps */) Tool {
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Registrar en `agents/runtime.go` → `buildToolRegistry()`
|
||||
### 2. Registrar en `devagents/registry_build.go` → `buildToolRegistry()`
|
||||
|
||||
```go
|
||||
if /* condición basada en config */ {
|
||||
|
||||
@@ -66,5 +66,6 @@ Filosofia completa documentada en `CLAUDE.md` seccion "Trunk-based development".
|
||||
Todas las reglas respetan el patron **pure core / impure shell**:
|
||||
- `pkg/` es puro — nunca añadir side effects
|
||||
- `shell/` es impuro — todo I/O va aqui
|
||||
- `agents/` compone ambos — reglas puras + ensamblado con shell
|
||||
- `devagents/` runtime: Agent/Robot ensambla core + shell
|
||||
- `agents/` reglas puras por agente + config + prompts
|
||||
- `tools/` sigue el mismo patron: `Def` (datos puros) + `Exec` (funcion impura)
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
package _template
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("AGENT_ID_PLACEHOLDER", Rules)
|
||||
devagents.Register("AGENT_ID_PLACEHOLDER", Rules)
|
||||
}
|
||||
|
||||
// Rules devuelve las reglas de este agente (vacio para el template).
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
package asistente2
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("asistente-2", Rules)
|
||||
devagents.Register("asistente-2", Rules)
|
||||
}
|
||||
|
||||
// Rules returns the decision rules for the asistente-2 bot.
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
package assistant
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("assistant-bot", Rules)
|
||||
devagents.Register("assistant-bot", Rules)
|
||||
}
|
||||
|
||||
// Rules returns the decision rules for the assistant bot.
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
package meteorologo
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("meteorologo", Rules)
|
||||
devagents.Register("meteorologo", Rules)
|
||||
}
|
||||
|
||||
// Rules returns the decision rules for the meteorologo bot.
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("test-bot", Rules)
|
||||
devagents.Register("test-bot", Rules)
|
||||
}
|
||||
|
||||
// Rules devuelve las reglas de este agente (vacio para el template).
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
package test_personality
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("test-personality", Rules)
|
||||
devagents.Register("test-personality", Rules)
|
||||
}
|
||||
|
||||
// Rules routes all DMs and mentions to the LLM.
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/internal/config"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
"github.com/enmanuel/agents/pkg/orchestration"
|
||||
@@ -173,10 +173,10 @@ func main() {
|
||||
}
|
||||
|
||||
// Branch: robot (command-only, lightweight) vs agent (full runtime).
|
||||
var runner agents.Runner
|
||||
var runner devagents.Runner
|
||||
|
||||
if cfg.Agent.Type == "robot" {
|
||||
robot, rErr := agents.NewRobot(cfg, agentLogger)
|
||||
robot, rErr := devagents.NewRobot(cfg, agentLogger)
|
||||
if rErr != nil {
|
||||
logger.Error("failed to create robot", "id", cfg.Agent.ID, "err", rErr)
|
||||
agentCleanup()
|
||||
@@ -201,7 +201,7 @@ func main() {
|
||||
"acl_empty", agentACL.Empty(),
|
||||
)
|
||||
|
||||
a, cErr := agents.New(cfg, rules, agentACL, agentLogger, agents.WithLogDir(logDir))
|
||||
a, cErr := devagents.New(cfg, rules, agentACL, agentLogger, devagents.WithLogDir(logDir))
|
||||
if cErr != nil {
|
||||
logger.Error("failed to create agent", "id", cfg.Agent.ID, "err", cErr)
|
||||
agentCleanup()
|
||||
@@ -312,7 +312,7 @@ func startOrchestrator(agentBus *bus.Bus, logger *slog.Logger) (*orchHandle, err
|
||||
// global registry (populated by init() in each agent package).
|
||||
// Returns nil if no rules are registered (command-only bot).
|
||||
func rulesFor(agentID string, logger *slog.Logger) []decision.Rule {
|
||||
factory := agents.GetRules(agentID)
|
||||
factory := devagents.GetRules(agentID)
|
||||
if factory == nil {
|
||||
logger.Warn("no rules registered for agent, using empty ruleset (command-only)", "id", agentID)
|
||||
return nil
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/internal/config"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
"github.com/enmanuel/agents/pkg/orchestration"
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
// runningAgent holds a live runner (Agent or Robot) and the metadata needed to recreate it.
|
||||
type runningAgent struct {
|
||||
runner agents.Runner
|
||||
runner devagents.Runner
|
||||
cfg *config.AgentConfig
|
||||
cfgPath string
|
||||
logger *slog.Logger
|
||||
@@ -139,10 +139,10 @@ func (r *agentRegistry) reload(id string, rulesFor func(string, *slog.Logger) []
|
||||
}
|
||||
|
||||
// 5. Create new runner (validates config before discarding the old one).
|
||||
var newRunner agents.Runner
|
||||
var newRunner devagents.Runner
|
||||
|
||||
if cfg.Agent.Type == "robot" {
|
||||
robot, rErr := agents.NewRobot(cfg, newLogger)
|
||||
robot, rErr := devagents.NewRobot(cfg, newLogger)
|
||||
if rErr != nil {
|
||||
newLogger.Error("reload: failed to create robot", "id", id, "err", rErr)
|
||||
newCleanup()
|
||||
@@ -153,7 +153,7 @@ func (r *agentRegistry) reload(id string, rulesFor func(string, *slog.Logger) []
|
||||
rules := rulesFor(cfg.Agent.ID, newLogger)
|
||||
agentACL := pksecurity.ResolveACL(cfg.Agent.ID, r.deps.secPolicy)
|
||||
newLogger.Debug("resolved acl for agent (reload)", "agent", cfg.Agent.ID, "acl_empty", agentACL.Empty())
|
||||
newAgent, aErr := agents.New(cfg, rules, agentACL, newLogger)
|
||||
newAgent, aErr := devagents.New(cfg, rules, agentACL, newLogger)
|
||||
if aErr != nil {
|
||||
newLogger.Error("reload: failed to create agent", "id", id, "err", aErr)
|
||||
newCleanup()
|
||||
|
||||
@@ -106,12 +106,12 @@ cat > "$DIR/agent.go" << GO
|
||||
package ${PACKAGE}
|
||||
|
||||
import (
|
||||
"github.com/enmanuel/agents/agents"
|
||||
"github.com/enmanuel/agents/devagents"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
func init() {
|
||||
agents.Register("${ID}", Rules)
|
||||
devagents.Register("${ID}", Rules)
|
||||
}
|
||||
|
||||
// Rules returns nil — robots only respond to commands.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Each agent package self-registers via init() using Register.
|
||||
// The launcher retrieves rules via GetRules without importing agent
|
||||
// packages explicitly (only blank imports are needed).
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Package agents defines the Agent runtime that ties core and shell together.
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package agents
|
||||
package devagents
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ La implementación usa Olm puro en Go (`-tags goolm`, sin CGO).
|
||||
```
|
||||
config.yaml (encryption section)
|
||||
↓
|
||||
agents/runtime.go → Agent.New() llama a InitCrypto()
|
||||
devagents/runtime.go → Agent.New() llama a InitCrypto()
|
||||
↓
|
||||
shell/matrix/client.go → InitCrypto() configura cryptohelper
|
||||
↓
|
||||
@@ -144,7 +144,7 @@ Los nuevos mensajes se descifrarán normalmente tras regenerar las claves.
|
||||
|
||||
| Archivo | Propósito |
|
||||
|---------|-----------|
|
||||
| `agents/runtime.go` | Inicializa E2EE por agente |
|
||||
| `devagents/runtime.go` | Inicializa E2EE por agente |
|
||||
| `shell/matrix/client.go` | `InitCrypto()` — setup de cryptohelper |
|
||||
| `cmd/verify/main.go` | Herramienta de cross-signing |
|
||||
| `cmd/launcher/sqlite.go` | Registro driver SQLite |
|
||||
|
||||
Reference in New Issue
Block a user