8 Commits

Author SHA1 Message Date
egutierrez fc86edd94c chore: auto-commit (27 archivos)
- .claude/CLAUDE.md
- .claude/rules/create_agent.md
- agents/_specials/father-bot/prompts/system.md
- agents/_template/config.yaml
- agents/_template_robot/config.yaml
- cmd/agentctl/autoavatar.go
- cmd/launcher/sqlite.go
- dev-scripts/_common.sh
- dev-scripts/agent/create-full.sh
- dev-scripts/agent/delete-full.sh
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 19:38:16 +02:00
egutierrez 072e00f305 merge: issue/0145-mcp-bridge-claude-code-devicemesh — MCP bridge real para claude-code
Conecta claude -p de cada agent al ToolRegistry de devicemesh via MCP
JSON-RPC en lugar de exponer las tools solo como texto en el system
prompt. Antes: claude imitaba el formato sin ejecutar (anti-criterio A3
del flow 0009 fallaba — audit DB vacia). Despues: claude usa
mcp__devicemesh__exec etc como tools de verdad, audit DB se llena.

Cuatro piezas:
 1. cmd/devicemesh-mcp — binario standalone, child de claude via
    --mcp-config, JSON-RPC stdio (mcp-go SDK).
 2. internal/config/schema.go — DeviceMesh.ExposeViaMCP (default true) +
    ClaudeCodeCfg.MCPConfigPath/MCPServerName.
 3. devagents/mcp_bridge.go + cmd/launcher/main.go — ApplyMCPBridge
    resuelve binario+URL+tools y escribe /tmp/<agent>-mcp-config.json
    antes de instanciar la runtime.
 4. shell/llm/claudecode.go — buildClaudeArgs emite --mcp-config; guard
    defensivo si DisableTools+AllowedTools combinados.

Tests: 10 unit + 1 integration (subprocess real) en cmd/devicemesh-mcp;
9 en devagents/mcp_bridge_test.go; 2 actualizados/anadidos en
shell/llm/claudecode_test.go. Suite completa pasa con -tags goolm.
2026-05-24 18:34:17 +02:00
egutierrez 4abc487b5e docs(0145): cerrar issue + actualizar README
Mueve 0145 a completed/ tras validar smoke real del binario:

echo '<initialize>+<notif/initialized>+<tools/list>' | bin/devicemesh-mcp
  --device-agent http://127.0.0.1:9999 --mode user
  --tools-allowed "exec,fs.read"

devuelve dos frames JSON-RPC esperados:
1. initialize result con serverInfo.name=devicemesh + capabilities.tools.
2. tools/list result con exec + fs.read, inputSchema completo incluyendo
   required fields (argv, path).

Suite de tests con -tags goolm -count=1 pasa sin errores.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 18:34:01 +02:00
egutierrez d1fd78324b test(0145): unit + integration + launcher + claudecode coverage
cmd/devicemesh-mcp/main_test.go (10 tests):
- TestInitialize: JSON-RPC initialize frame → serverInfo + capabilities.
- TestToolsList: tools/list → 16 user-mode entries, cada uno con name +
  inputSchema valido.
- TestToolsCallExec: tools/call name=exec → mock device-agent (httptest)
  recibe capability=shell.exec, MCP response content contiene "hi".
- TestToolsCallInvalidTool: name desconocido → isError o error envelope.
- TestNotificationsInitializedNoResponse: notification (sin id) → cero
  responses.
- TestUserModeFiltersPkgInstall: --mode user oculta pkg.install,
  --mode sudo la expone.
- TestToolsAllowedNarrows: --tools-allowed exec,fs.read → solo 2.
- TestSplitCSV, TestParseMode, TestIsCleanShutdown: helpers.

cmd/devicemesh-mcp/integration_test.go:
- TestIntegrationBinarySubprocess: build el binario en tmp + spawn como
  child via exec.Command + pipe real + secuencia initialize ->
  notifications/initialized -> tools/list -> tools/call. Valida el path
  identico al que usara claude.

devagents/mcp_bridge_test.go (9 tests):
- Disabled paths (nil DM, ExposeViaMCP=false, provider!=claude-code).
- Applied path: /tmp/<agent>-mcp-config.json JSON valido, mode 0600,
  mcpServers.devicemesh con command apuntando al binario fake.
- AllowedTools formato mcp__<server>__<tool>.
- DisableTools=true overrideado a false.
- URLEnv override gana sobre YAML.
- Binary missing → ok=false sin panico.
- BuildClaudeAllowedToolNames default server name.
- ResolveBridgedToolNames respeta mode + ToolsAllowed.
- ShouldExposeViaMCP cubre nil/disabled/default/explicit-true/false.

shell/llm/claudecode_test.go:
- TestBuildClaudeArgs_DisableTools actualizado: solo emite --tools "" cuando
  AllowedTools ESTA vacio. La regla nueva (issue 0145) da precedencia a
  AllowedTools.
- Anadido TestBuildClaudeArgs_DisableToolsButAllowedToolsWins.
- Anadido TestBuildClaudeArgs_MCPConfigPath.

bridge.go fix: cambio NewTool + WithRawInputSchema a NewToolWithRawSchema
porque NewTool inicializa ToolInputSchema.Type="object" por default, lo
cual entra en conflicto con RawInputSchema en MarshalJSON del SDK.

Suite completa pasa con -tags goolm -count=1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 18:33:24 +02:00
egutierrez b92a350023 feat(0145-2,3,4): schema + launcher wiring + claude --mcp-config arg
Pieza 2 — schema (internal/config/schema.go):
- DeviceMeshConfig.ExposeViaMCP *bool: pointer para distinguir "no
  establecido" vs "false explicito". Helper ShouldExposeViaMCP() devuelve
  true cuando enabled && (nil || *true).
- ClaudeCodeCfg.MCPConfigPath y MCPServerName: poblados en runtime por
  la launcher, NUNCA por YAML.

Pieza 3 — launcher wiring (devagents/mcp_bridge.go + cmd/launcher/main.go):
- ApplyMCPBridge(cfg, logger): si DeviceMesh.ShouldExposeViaMCP() y
  provider=claude-code, resuelve binario devicemesh-mcp (junto al
  launcher), URL device_agent (env override > YAML), lista tools allowed
  (RegisterBuiltins + FilterByAllowed igual que registry_build.go), y
  escribe /tmp/<agent_id>-mcp-config.json (0600).
- Aplica overrides a cfg.LLM.Primary.ClaudeCode: MCPConfigPath,
  AllowedTools (formato mcp__<server>__<tool>), DisableTools=false
  defensivo.
- Launcher main.go llama ApplyMCPBridge inmediatamente despues de
  config.Load, ANTES de devagents.New (que es donde se construye el
  CompleteFunc del provider).

Pieza 4 — claude args (shell/llm/claudecode.go):
- buildClaudeArgs ahora emite "--mcp-config <path>" cuando
  cfg.MCPConfigPath no esta vacio.
- Guard defensivo: DisableTools=true + AllowedTools no vacio ahora
  produce solo --allowedTools (efectivamente ignora DisableTools). El
  launcher ya lo previene en ApplyMCPBridge, pero esto protege a
  callers directos.

Build limpio con goolm.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 18:28:34 +02:00
egutierrez 15596df7e4 feat(0145-1): binario devicemesh-mcp + issue doc
Anade el binario standalone cmd/devicemesh-mcp/ que expone via JSON-RPC
sobre stdio el catalogo de devicemesh tools (exec, shell.eval, fs.*,
git.*, pkg.*, proc.*, docker.*) al claude -p parent.

Arquitectura issue 0145:
- main.go: flags (--device-agent, --mode, --tools-allowed, --server-name),
  inicializa devicemesh.Client + RegisterBuiltins + FilterByAllowed, lanza
  server.ServeStdio del SDK mark3labs/mcp-go (ya dep).
- bridge.go: registra cada ToolSpec como mcp.Tool con WithRawInputSchema +
  handler que invoca ToolRegistry.Call (validate->map->HTTP->map). Resultado
  serializado a NewToolResultText, errores como NewToolResultError para que
  el modelo se autocorrija.

Razon: hoy claude -p ve nuestras tool names solo como TEXTO en el system
prompt y las imita sin ejecutar. Con --mcp-config apuntando a este binario,
claude las descubre via tools/list e invoca via tools/call REALMENTE.

Smoke OK: initialize frame produce {capabilities:{tools:{listChanged:true}},
serverInfo:{name:"devicemesh",version:"0.1.0"}}.

Issue doc 0145 incluido con aceptacion A3 anti-hallucination + DoD triada.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 18:26:22 +02:00
egutierrez 47bcf9d583 fix(agent-wsl-lucas): enable device_mesh + trim tools_allowed a registry real
device_mesh.enabled=true + host=wsl-lucas. tools_allowed limitado a los 14
tools que existen en pkg/tools/devicemesh (0144a). Removidos project.*,
screenshot, clipboard.*, delegate_sudo, memory.* (futuros 0144d/e).
2026-05-24 14:17:49 +02:00
egutierrez 91e0da5b99 fix(agent-wsl-lucas): disable encryption + enable tool_use for POC
Crypto cross-signing no provisionado todavia (verify.sh es paso aparte).
Disable encryption.enabled=false para que el bot pueda hacer login sin
cifrado. tool_use.enabled=true porque la spec 0144 requiere LLM tool calls
contra device-mesh.
2026-05-24 14:16:58 +02:00
40 changed files with 4048 additions and 139 deletions
+17
View File
@@ -126,6 +126,23 @@ Templates: `agents/_template/` (agent) y `agents/_template_robot/` (robot).
**Convención `_` prefijo**: los directorios con prefijo `_` en `agents/` son del sistema, no agentes desplegables. Incluye: `_template`, `_template_robot`, `_specials`.
### REGLA DE PROYECTO — Provider LLM default: `claude-code`
TODOS los agentes nuevos usan `provider: claude-code` (subprocess `claude -p`) por defecto. Razones:
- No requiere API key (autentica via el CLI `claude` ya instalado).
- Acceso nativo a Bash/Read/Edit/Write/Glob/Grep — los agentes pueden interactuar con el sistema sin tools custom.
- Permission mode `bypassPermissions` + `working_dir` aislado fuera del repo.
- `streaming: true` + `show_tool_progress: true` para feedback en Matrix.
Override a `openai`/`anthropic` SOLO si:
- Caso de uso requiere un modelo no soportado por claude-code.
- Latencia critica (claude-code arranca un subprocess por request).
- Aislamiento total del filesystem (claude-code tiene acceso a `working_dir`).
`detect-provider.sh` prioriza `claude-code` si el binario `claude` esta en PATH. Si no, cae a `openai` o `anthropic` segun keys disponibles.
`./dev-scripts/agent/create-full.sh` y `personalize.sh` heredan este default. `father-bot` esta instruido para usar `claude-code` salvo que el usuario pida explicitamente otro provider.
| ID | Tipo | LLM | Descripcion |
|----|------|-----|-------------|
| assistant-bot | agent | GPT-4o | Asistente general, DMs |
+21 -14
View File
@@ -55,8 +55,8 @@ Todo agente o robot creado debe pasar por TODOS estos pasos, en orden estricto:
| `display-name` | si | — | `"Monitor Agent"` |
| `description` | si | — | `"Monitorea servicios y reporta estado"` |
| `type` | no | `agent` | `agent` o `robot` |
| `llm.provider` | no (N/A para robots) | `openai` | `openai` o `anthropic` |
| `llm.model` | no (N/A para robots) | `gpt-4o` | `gpt-4o`, `claude-sonnet-4-20250514` |
| `llm.provider` | no (N/A para robots) | **`claude-code`** | `claude-code` (default), `openai`, `anthropic` |
| `llm.model` | no (N/A para robots) | `sonnet` | `sonnet` (claude-code), `gpt-4o` (openai), `claude-sonnet-4-20250514` (anthropic) |
| `tool_use` | no (N/A para robots) | `false` | `true` si necesita herramientas |
| System prompt | si (N/A para robots) | — | Texto describiendo rol y capacidades |
@@ -69,11 +69,12 @@ Si tienes todos los datos del agente (description + system prompt), el Paso 8 pu
```bash
./dev-scripts/agent/create-full.sh <agent-id> "Display Name" \
--description "<descripcion>" \
--provider <openai|anthropic> \
--system-prompt "<system prompt con seccion de seguridad>" \
[--provider <claude-code|openai|anthropic>] \
[--tone <friendly|professional|casual|technical>] \
[--prefix "<emoji>"] \
[--tool-use]
[--tool-use] \
[--avatar <URL_o_ruta_local>]
```
Este script ejecuta en orden: scaffold, build, register Matrix, verify E2EE, auto-avatar, display name, **personalizar (auto)**, notify.
@@ -86,7 +87,7 @@ Crea todos los archivos, registra en el launcher, genera todas las env vars en `
./dev-scripts/agent/personalize.sh <agent-id> --description "..." --system-prompt "..."
```
**Auto-detección de provider**: omitir `--provider` para que `detect-provider.sh` elija automáticamente según `.env`.
**REGLA DE PROYECTO — Provider default = `claude-code`**: TODOS los agentes nuevos usan `claude-code` (subprocess `claude -p`) por defecto. NO requiere API key, autentica via el CLI `claude` ya instalado. Solo cambiar a `openai`/`anthropic` si hay razon explicita (modelo no disponible en claude-code, requisitos de latencia distintos, etc.). `detect-provider.sh` ya prioriza `claude-code` si el binario `claude` esta en PATH.
Despues del script, continuar con pasos 9-12 (rebuild, start, health check, self-introduce).
@@ -146,23 +147,29 @@ agent:
description: "<la descripcion del agente>"
```
**LLM** (si quieres cambiar provider/model):
**LLM — DEFAULT `claude-code`** (subproceso `claude -p`, sin API key):
```yaml
llm:
primary:
provider: anthropic # o openai (default)
model: claude-sonnet-4-20250514 # o gpt-4o (default)
api_key_env: ANTHROPIC_API_KEY # o OPENAI_API_KEY (default)
provider: claude-code # DEFAULT — usar SIEMPRE salvo razon explicita
model: "sonnet"
api_key_env: "" # claude-code no usa api key
claude_code:
working_dir: "/tmp/claude-agents/<agent-id>" # SIEMPRE fuera del repo
permission_mode: "bypassPermissions"
model: "sonnet"
fallback_model: "haiku"
streaming: true
show_tool_progress: true
```
**Claude-code provider** (si usa `claude-code` como provider):
**Override a API providers** (solo si claude-code no encaja):
```yaml
llm:
primary:
provider: claude-code
claude_code:
working_dir: "/tmp/claude-agents/<agent-id>" # SIEMPRE configurar, nunca dejar vacio
permission_mode: "bypassPermissions"
provider: openai # o anthropic
model: gpt-4o # o claude-sonnet-4-20250514
api_key_env: OPENAI_API_KEY # o ANTHROPIC_API_KEY
```
**Importante**: `working_dir` debe apuntar fuera del repositorio para evitar que el subproceso `claude -p` acceda al codigo fuente. Si se deja vacio, se usara un directorio temporal (con WARN en logs).
+13 -6
View File
@@ -70,8 +70,8 @@ Antes de crear nada, extrae estos datos del mensaje del usuario:
| `display-name` | si | `"Monitor Agent"` |
| `description` | si | `"Monitorea servicios y reporta estado"` |
| `type` | si | `agent` o `robot` |
| `provider` | no (N/A para robots) | `openai`, `anthropic`, `claude-code` |
| `model` | no (N/A para robots) | `gpt-4o`, `claude-sonnet-4-20250514` |
| `provider` | no (N/A para robots) | **`claude-code` (DEFAULT)**, `openai`, `anthropic` |
| `model` | no (N/A para robots) | `sonnet` (default), `gpt-4o`, `claude-sonnet-4-20250514` |
| `tools necesarias` | no | SSH, HTTP, file, etc. |
Si faltan datos criticos, **pregunta antes de crear**. No asumas.
@@ -98,14 +98,21 @@ Si faltan datos criticos, **pregunta antes de crear**. No asumas.
./dev-scripts/agent/create-full.sh <agent-id> "<display-name>" \
--description "<descripcion del agente>" \
--system-prompt "<system prompt completo con seccion de seguridad>" \
[--provider <openai|anthropic>] \
[--model <gpt-4o|claude-sonnet-4-20250514>] \
[--provider <claude-code|openai|anthropic>] \
[--model <sonnet|gpt-4o|claude-sonnet-4-20250514>] \
[--tone <friendly|professional|casual|technical>] \
[--prefix "<emoji>"] \
[--tool-use] \
[--language <es|en>]
[--language <es|en>] \
[--avatar <URL_o_ruta_local>]
```
**REGLA DE PROYECTO — Provider default es `claude-code`**. Usa siempre `claude-code` (subprocess `claude -p`) salvo que el usuario pida explicitamente otro provider. `claude-code` no requiere API key — autentica via el CLI `claude` ya instalado en el sistema. Solo cambia a `openai`/`anthropic` si el usuario lo pide o si el caso de uso requiere un modelo no soportado por claude-code.
**Avatar personalizado**: si el usuario te da una imagen o URL para la foto del bot
(ej. "ponle un pikachu" + URL/archivo), pasa el valor a `--avatar`. Acepta tanto
URLs `https://...` como rutas locales. Sin el flag, se genera uno random.
Si es un robot, anadir `--type robot`:
```bash
./dev-scripts/agent/create-full.sh <agent-id> "<display-name>" --type robot \
@@ -122,7 +129,7 @@ Con los flags `--description` y `--system-prompt`, el script ejecuta **automatic
7. **Display name**: configura nombre visible en Matrix
8. **Personalize**: genera `config.yaml`, `agent.go` y `prompts/system.md` automaticamente
**Provider auto-detectado**: si no se pasa `--provider`, `detect-provider.sh` elige automaticamente segun las API keys disponibles en `.env`.
**Provider auto-detectado**: si no se pasa `--provider`, `detect-provider.sh` elige `claude-code` por defecto (si el binario `claude` esta en PATH) — esa es la regla del proyecto. Fallback a `openai`/`anthropic` solo si `claude` CLI no esta disponible.
**Si el script falla**, reporta el error al usuario con los logs y sugiere recovery manual.
+13 -10
View File
@@ -64,28 +64,28 @@ personality:
# ============================================
llm:
primary:
provider: openai # openai | anthropic | claude-code
model: "gpt-4o"
api_key_env: OPENAI_API_KEY
provider: claude-code # claude-code (DEFAULT) | openai | anthropic
model: "sonnet"
api_key_env: "" # claude-code no usa api key — autentica via `claude` CLI
base_url: ""
max_tokens: 4096
temperature: 0.7
# Solo si provider: claude-code
# Solo si provider: claude-code (default)
claude_code:
binary: "claude"
timeout: 3m
disable_tools: false
allowed_tools: []
allowed_tools: [Bash, Read, Edit, Write, Glob, Grep]
disallowed_tools: []
working_dir: "" # IMPORTANTE: configurar fuera del repo
permission_mode: "default"
permission_mode: "bypassPermissions"
model: "sonnet"
fallback_model: ""
fallback_model: "haiku"
session_id: ""
add_dirs: []
streaming: false # true para usar --output-format stream-json (progreso en tiempo real)
show_tool_progress: false # true para mostrar en Matrix que herramientas usa el agente
streaming: true # progreso en tiempo real en Matrix
show_tool_progress: true # muestra que tools usa el agente
fallback:
provider: ""
@@ -190,9 +190,12 @@ matrix:
device_id: "DEVICEID"
encryption:
enabled: false
enabled: true
store_path: "./agents/_template/data/crypto/"
pickle_key_env: PICKLE_KEY_TEMPLATE
recovery_key_env: SSSS_RECOVERY_KEY_TEMPLATE
access_token_env: MATRIX_TOKEN_TEMPLATE
user_id: "@_template:matrix.example.com"
trust_mode: tofu
recovery_key_env: ""
+2 -2
View File
@@ -32,11 +32,11 @@ matrix:
device_id: "DEVICEID"
encryption:
enabled: false
enabled: true
store_path: "./agents/_template_robot/data/crypto/"
pickle_key_env: PICKLE_KEY_ROBOT
trust_mode: tofu
recovery_key_env: ""
recovery_key_env: SSSS_RECOVERY_KEY_ROBOT
rooms:
listen: []
+10 -21
View File
@@ -96,12 +96,15 @@ llm:
device_mesh:
enabled: true
device_id: wsl-lucas
host: wsl-lucas
mode: user
manifest_id: manifest_wsl-lucas_v1
device_agent_url_env: AGENT_WSL_LUCAS_DEVICE_MESH_URL
client_timeout_s: 60
timeout_seconds: 60
tools_allowed:
- exec
- shell.eval
- fs.read
- fs.write
- fs.list
@@ -109,25 +112,11 @@ device_mesh:
- git.clone
- git.commit
- git.push
- git.status
- pkg.search
- proc.list
- proc.kill
- docker.list
- docker.exec
- docker.logs
- project.create
- project.list
- screenshot
- clipboard.read
- clipboard.write
- delegate_sudo
- current_time
- memory.recall
- memory.note
rate_limit:
tools_per_minute: 60
tools_per_turn: 12
# ============================================
# TOOLS — built-in (current_time, memory, knowledge)
@@ -162,7 +151,7 @@ tools:
port: 0
tools: []
memory:
enabled: true
enabled: false
knowledge:
enabled: false
@@ -170,7 +159,7 @@ tools:
# MEMORIA — rolling window + facts (issue 0144d)
# ============================================
memory:
enabled: true
enabled: false
window_size: 50
db_path: "./agents/agent-wsl-lucas/data/memory.db"
@@ -184,7 +173,7 @@ matrix:
device_id: "QFRVTVUIAB"
encryption:
enabled: true
enabled: false
store_path: "./agents/agent-wsl-lucas/data/crypto/"
pickle_key_env: PICKLE_KEY_AGENT_WSL_LUCAS
trust_mode: tofu
@@ -205,7 +194,7 @@ matrix:
min_power_level: 0
threads:
enabled: true
enabled: false
auto_thread: false
# ============================================
@@ -226,7 +215,7 @@ ssh:
# ============================================
security:
audit:
enabled: true
enabled: false
log_file: "./agents/agent-wsl-lucas/data/audit.log"
log_to_room: ""
include: [tool_call, llm_request, command]
@@ -235,13 +224,13 @@ security:
provider: env
sanitize:
enabled: true
enabled: false
mode: warn
min_severity: medium
disabled_patterns: []
tool_rate_limit:
enabled: true
enabled: false
max_calls_per_min: 60
cleanup_interval_s: 60
+69 -2
View File
@@ -19,23 +19,38 @@ func autoAvatarCmd() *cobra.Command {
set string
size int
dryRun bool
fromURL string
fromFile string
)
cmd := &cobra.Command{
Use: "auto-avatar <agent-id>",
Short: "Generate and set a random avatar from a free provider",
Short: "Generate and set a random avatar from a free provider (or a custom URL/file)",
Long: `Fetches a unique avatar image from a free provider (dicebear, robohash, multiavatar)
using the agent ID as seed, uploads it to the Matrix media repo, and sets it as the bot's avatar.
To use a custom avatar instead of the random generator, pass --from-url or --from-file.
Examples:
agentctl auto-avatar assistant-bot
agentctl auto-avatar assistant-bot --provider robohash --set set1
agentctl auto-avatar assistant-bot --provider dicebear --style pixel-art
agentctl auto-avatar assistant-bot --dry-run # only show the URL`,
agentctl auto-avatar assistant-bot --dry-run # only show the URL
agentctl auto-avatar pokemon-expert --from-url https://example/pikachu.png
agentctl auto-avatar pokemon-expert --from-file ./avatars/pokemon.png`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
agentID := args[0]
if fromURL != "" && fromFile != "" {
return fmt.Errorf("--from-url and --from-file are mutually exclusive")
}
// Custom source path: skip random generator entirely.
if fromURL != "" || fromFile != "" {
return runCustomAvatar(agentID, fromURL, fromFile, dryRun)
}
opts := avatar.DefaultOptions()
if size > 0 {
opts.Size = size
@@ -90,6 +105,58 @@ Examples:
cmd.Flags().StringVar(&set, "set", "", "RoboHash set: set1 (robots), set2 (monsters), set3 (heads), set4 (cats), set5 (humans)")
cmd.Flags().IntVar(&size, "size", 256, "Image size in pixels (square)")
cmd.Flags().BoolVar(&dryRun, "dry-run", false, "Only print the image URL without fetching or uploading")
cmd.Flags().StringVar(&fromURL, "from-url", "", "Use this URL as the avatar source (overrides provider/style)")
cmd.Flags().StringVar(&fromFile, "from-file", "", "Use this local file as the avatar source (overrides provider/style)")
return cmd
}
// runCustomAvatar uploads a user-supplied image (URL or local file) as the agent's avatar.
func runCustomAvatar(agentID, fromURL, fromFile string, dryRun bool) error {
var srcPath string
var srcLabel string
if fromURL != "" {
srcLabel = fromURL
if dryRun {
fmt.Printf("url %-20s %s\n", agentID, fromURL)
return nil
}
tmpPath, err := shellavatar.Download(context.Background(), fromURL)
if err != nil {
return fmt.Errorf("download avatar from %s: %w", fromURL, err)
}
defer os.Remove(tmpPath)
srcPath = tmpPath
} else {
srcLabel = fromFile
if _, err := os.Stat(fromFile); err != nil {
return fmt.Errorf("avatar file %s: %w", fromFile, err)
}
if dryRun {
fmt.Printf("file %-20s %s\n", agentID, fromFile)
return nil
}
srcPath = fromFile
}
fmt.Printf("fetch %-20s %s\n", agentID, srcLabel)
cfg, err := loadMatrixCfg(agentID)
if err != nil {
return err
}
client, err := shellmatrix.New(cfg.Matrix)
if err != nil {
return fmt.Errorf("matrix client: %w", err)
}
uri, err := client.SetAvatar(context.Background(), srcPath)
if err != nil {
return err
}
fmt.Printf("ok %-20s avatar → %s\n", agentID, uri)
return nil
}
+165
View File
@@ -0,0 +1,165 @@
// bridge.go — adapter that registers every devicemesh.ToolSpec from a
// ToolRegistry as an MCP tool on a mcp-go server.MCPServer.
//
// Tool name preservation: we register tools under their dotted devicemesh
// name verbatim ("exec", "shell.eval", "fs.read"). claude exposes them to
// the model as `mcp__<server_name>__<tool_name>` (the MCP transport prefixes
// automatically).
//
// Schema: ToolSpec.InputSchema is already a JSON-Schema-lite map. We
// marshal it to a json.RawMessage and feed it via mcp.WithRawInputSchema so
// the LLM sees the full structure (required fields, enums, descriptions).
//
// Handler: each tool's handler invokes reg.Call(ctx, name, args). The
// registry runs ValidateInput → ArgMapping → HTTP dispatch → ResultMapping
// just like the in-process tool-use path. The result is JSON-encoded into
// an MCP text-content block. Errors become NewToolResultError so the model
// can self-correct on the next turn.
package main
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/enmanuel/agents/pkg/tools/devicemesh"
)
// RegisterToolBridge walks reg and registers each spec on srv. Returns the
// first registration error, if any. Pure data adapter except for the slog
// debug events.
func RegisterToolBridge(srv *server.MCPServer, reg *devicemesh.ToolRegistry, logger *slog.Logger) error {
if srv == nil {
return fmt.Errorf("RegisterToolBridge: srv is nil")
}
if reg == nil {
return fmt.Errorf("RegisterToolBridge: reg is nil")
}
for _, spec := range reg.List() {
tool, err := buildMCPTool(spec)
if err != nil {
return fmt.Errorf("build MCP tool %q: %w", spec.Name, err)
}
handler := makeHandler(reg, spec, logger)
srv.AddTool(tool, handler)
if logger != nil {
logger.Debug("registered MCP tool",
"name", spec.Name,
"capability", spec.Capability,
"requires_approval", spec.RequiresApproval,
)
}
}
return nil
}
// buildMCPTool transforms a devicemesh.ToolSpec into an mcp.Tool with the
// raw input schema attached. The description is augmented with the
// capability marker so the model knows the tool is remote.
//
// We use mcp.NewToolWithRawSchema (not NewTool + WithRawInputSchema) because
// NewTool initialises a default ToolInputSchema with Type="object", which
// then conflicts at marshal time with our RawInputSchema (the SDK rejects
// having both set — see mcp/tools.go ::Tool.MarshalJSON).
func buildMCPTool(spec devicemesh.ToolSpec) (mcp.Tool, error) {
desc := spec.Description
if spec.Capability != "" {
desc = fmt.Sprintf("%s [device_mesh: %s]", desc, spec.Capability)
}
if spec.RequiresApproval {
desc += " (approval required)"
}
if spec.InputSchema == nil {
// Fall back to a minimal "no params" schema so the tool is still
// callable. Should not happen for the builtins (they all set
// InputSchema), but the adapter must not panic on third-party specs.
return mcp.NewToolWithRawSchema(spec.Name, desc,
json.RawMessage(`{"type":"object","properties":{}}`)), nil
}
raw, err := json.Marshal(spec.InputSchema)
if err != nil {
return mcp.Tool{}, fmt.Errorf("marshal input schema: %w", err)
}
return mcp.NewToolWithRawSchema(spec.Name, desc, raw), nil
}
// makeHandler returns a server.ToolHandlerFunc bound to a single spec. The
// closure captures the registry so the HTTP dispatch goes through the same
// validate → map → call pipeline as the in-process path.
func makeHandler(reg *devicemesh.ToolRegistry, spec devicemesh.ToolSpec, logger *slog.Logger) server.ToolHandlerFunc {
return func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
args := req.GetArguments()
if args == nil {
args = map[string]any{}
}
if logger != nil {
logger.Debug("tools/call received",
"tool", spec.Name,
"capability", spec.Capability,
"arg_keys", keysOf(args),
)
}
result, err := reg.Call(ctx, spec.Name, args)
if err != nil {
if logger != nil {
logger.Warn("tools/call failed",
"tool", spec.Name,
"err", err.Error(),
)
}
// NewToolResultError returns a CallToolResult with isError=true.
// Returning (result, nil) lets the model see and self-correct
// instead of treating it as a transport-level failure.
return mcp.NewToolResultError(err.Error()), nil
}
text := encodeResult(result)
if logger != nil {
logger.Debug("tools/call ok",
"tool", spec.Name,
"result_len", len(text),
)
}
return mcp.NewToolResultText(text), nil
}
}
// encodeResult converts a tool result (any) to the string payload the model
// will see. Mirrors devicemesh.AdaptTool's formatToolResult so MCP and the
// in-process path produce consistent transcripts.
//
// - nil → ""
// - string → returned as-is (avoids double-encoding JSON strings)
// - other → json.Marshal; on failure fall back to fmt.Sprintf so we never
// drop data on the floor.
func encodeResult(v any) string {
if v == nil {
return ""
}
if s, ok := v.(string); ok {
return s
}
b, err := json.Marshal(v)
if err != nil {
return fmt.Sprintf("%v", v)
}
return string(b)
}
// keysOf returns the sorted keys of a map for log context. Pure helper.
func keysOf(m map[string]any) []string {
if len(m) == 0 {
return nil
}
out := make([]string, 0, len(m))
for k := range m {
out = append(out, k)
}
return out
}
+177
View File
@@ -0,0 +1,177 @@
package main
import (
"bufio"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
// TestIntegrationBinarySubprocess builds the binary (or uses an existing
// bin/devicemesh-mcp) and exercises a full initialize -> tools/list ->
// tools/call sequence over a real OS pipe. This validates that the same
// code path that claude will invoke (subprocess + stdio) works end-to-end.
//
// Skipped when the binary cannot be built or located, so the rest of the
// unit tests still run cleanly on minimal sandboxes.
func TestIntegrationBinarySubprocess(t *testing.T) {
if testing.Short() {
t.Skip("integration test skipped in -short mode")
}
binPath := buildOrLocateBinary(t)
if binPath == "" {
t.Skip("cannot build/locate devicemesh-mcp binary")
}
mock := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body := map[string]any{}
_ = json.NewDecoder(r.Body).Decode(&body)
_ = json.NewEncoder(w).Encode(map[string]any{
"request_id": body["request_id"],
"ok": true,
"duration_ms": 7,
"result": map[string]any{
"stdout": "subprocess hi",
"stderr": "",
"exit_code": 0,
},
})
}))
defer mock.Close()
cmd := exec.Command(binPath,
"--device-agent", mock.URL,
"--mode", "user",
"--server-name", "devicemesh",
)
stdin, err := cmd.StdinPipe()
if err != nil {
t.Fatalf("stdin pipe: %v", err)
}
stdout, err := cmd.StdoutPipe()
if err != nil {
t.Fatalf("stdout pipe: %v", err)
}
cmd.Stderr = io.Discard
if err := cmd.Start(); err != nil {
t.Fatalf("start: %v", err)
}
defer func() {
_ = stdin.Close()
_ = cmd.Process.Kill()
_ = cmd.Wait()
}()
// Real MCP clients send `notifications/initialized` after the
// initialize response is received before sending any other requests.
// We mirror the same sequence — without it the server may queue
// follow-up frames behind the not-yet-initialized session.
frames := []string{
initFrame(1),
notifInitializedFrame(),
toolsListFrame(2),
toolsCallFrame(3, "exec", map[string]any{"argv": []any{"echo", "subprocess"}}),
}
for _, f := range frames {
if !strings.HasSuffix(f, "\n") {
f += "\n"
}
if _, err := stdin.Write([]byte(f)); err != nil {
t.Fatalf("write frame: %v", err)
}
}
// Read responses (up to 3 with timeout).
reader := bufio.NewReader(stdout)
deadline := time.After(5 * time.Second)
responses := make([]map[string]any, 0, 3)
readCh := make(chan map[string]any, 4)
go func() {
defer close(readCh)
dec := json.NewDecoder(reader)
for {
var msg map[string]any
if err := dec.Decode(&msg); err != nil {
return
}
readCh <- msg
}
}()
readLoop:
for {
select {
case msg, ok := <-readCh:
if !ok {
break readLoop
}
responses = append(responses, msg)
if len(responses) >= 3 {
break readLoop
}
case <-deadline:
break readLoop
}
}
if len(responses) < 3 {
t.Fatalf("expected 3 responses, got %d: %v", len(responses), responses)
}
// Validate the tools/call (id=3) response.
r := responses[2]
if r["id"] != float64(3) {
t.Errorf("expected id=3, got %v", r["id"])
}
result, _ := r["result"].(map[string]any)
contents, _ := result["content"].([]any)
if len(contents) == 0 {
t.Fatalf("missing content in tools/call response: %v", r)
}
first, _ := contents[0].(map[string]any)
text, _ := first["text"].(string)
if !strings.Contains(text, "subprocess hi") {
t.Errorf("expected text to contain 'subprocess hi', got %q", text)
}
}
// buildOrLocateBinary returns the absolute path to bin/devicemesh-mcp,
// building it under a temp dir if it is missing. Returns "" if neither
// option works (the test then skips).
func buildOrLocateBinary(t *testing.T) string {
t.Helper()
// First, try ../../bin/devicemesh-mcp relative to this file (CWD when
// `go test ./cmd/devicemesh-mcp/` is the cmd dir itself).
candidates := []string{
filepath.Join("..", "..", "bin", "devicemesh-mcp"),
filepath.Join("bin", "devicemesh-mcp"),
}
for _, c := range candidates {
if abs, err := filepath.Abs(c); err == nil {
if st, err := os.Stat(abs); err == nil && !st.IsDir() {
return abs
}
}
}
// Build into a tmpdir.
tmpDir := t.TempDir()
out := filepath.Join(tmpDir, "devicemesh-mcp")
cmd := exec.Command("/usr/local/go/bin/go", "build", "-tags", "goolm", "-o", out, ".")
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Logf("build failed: %v", err)
return ""
}
return out
}
+208
View File
@@ -0,0 +1,208 @@
// Command devicemesh-mcp is a per-agent MCP server (stdio) that exposes the
// agents_and_robots device-mesh tool catalog (exec, shell.eval, fs.*, git.*,
// pkg.*, proc.*, docker.*) to a parent `claude -p` subprocess.
//
// Architecture (issue 0145):
//
// claude -p
// ├─ spawns this binary as child via --mcp-config
// ├─ JSON-RPC over stdio
// ├─ initialize / tools/list / tools/call / ping / notifications/initialized
// └─ tool names exposed as `mcp__<server_name>__<tool_name>` to the model
//
// Flags:
//
// --device-agent <URL> required — http://host:port of the remote device_agent
// --mode user|sudo|all default user — filters which builtin tools are registered
// --tools-allowed <csv> optional — narrows the catalog after mode filtering
// --server-name <name> default "devicemesh" — only used for logs and serverInfo
//
// Environment:
//
// MCP_DEBUG_LOG <path> optional — write structured logs to this file
// (stderr is reserved by claude for the MCP transport
// framing in some setups, so we prefer a file sink)
//
// Returns non-zero on flag parse error or stdio listen error.
package main
import (
"flag"
"fmt"
"io"
"log/slog"
"os"
"strings"
"time"
"github.com/mark3labs/mcp-go/server"
"github.com/enmanuel/agents/pkg/tools/devicemesh"
)
// version is overwritten via -ldflags at build time when needed. Kept simple
// so the binary stays self-contained.
var version = "0.1.0"
func main() {
var (
deviceAgentURL string
mode string
toolsAllowed string
serverName string
showVersion bool
)
flag.StringVar(&deviceAgentURL, "device-agent", "", "URL of the device_agent (http://host:port). Required.")
flag.StringVar(&mode, "mode", "user", "Tool registration mode: user|sudo|all")
flag.StringVar(&toolsAllowed, "tools-allowed", "", "CSV of tool names to keep after mode filtering. Empty = keep all.")
flag.StringVar(&serverName, "server-name", "devicemesh", "MCP server name (used in serverInfo and log context)")
flag.BoolVar(&showVersion, "version", false, "Print version and exit")
flag.Parse()
if showVersion {
fmt.Fprintf(os.Stdout, "devicemesh-mcp %s\n", version)
return
}
logger := newLogger()
logger.Info("devicemesh-mcp starting",
"version", version,
"server_name", serverName,
"mode", mode,
"device_agent_url", deviceAgentURL,
"tools_allowed", toolsAllowed,
)
if deviceAgentURL == "" {
logger.Error("--device-agent is required")
fmt.Fprintln(os.Stderr, "fatal: --device-agent is required")
os.Exit(2)
}
// Build the per-process devicemesh registry. Mirrors the launcher's
// buildDeviceMeshRegistry but driven by CLI flags instead of YAML.
reg, err := buildRegistry(deviceAgentURL, mode, splitCSV(toolsAllowed))
if err != nil {
logger.Error("build registry failed", "err", err)
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
os.Exit(1)
}
logger.Info("registry ready", "tool_count", reg.Len(), "names", reg.Names())
// Build the MCP server, wire every devicemesh tool as an MCP tool, and
// serve over stdio. ServeStdio handles initialize / tools/list /
// tools/call / ping / notifications/initialized for us — the bridge only
// has to register tools.
srv := server.NewMCPServer(serverName, version)
if err := RegisterToolBridge(srv, reg, logger); err != nil {
logger.Error("register tool bridge failed", "err", err)
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
os.Exit(1)
}
logger.Info("starting stdio server")
if err := server.ServeStdio(srv); err != nil {
// Stdin EOF is the normal shutdown signal when the claude parent
// exits; treat it as a clean exit.
if isCleanShutdown(err) {
logger.Info("stdio server exited cleanly", "err", err)
return
}
logger.Error("stdio server error", "err", err)
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
os.Exit(1)
}
}
// buildRegistry constructs the devicemesh ToolRegistry from CLI flags. Pure
// in the sense that it does no I/O — RegisterBuiltins + FilterByAllowed are
// data shuffling, the HTTP transport only fires when a tool is actually
// called via reg.Call. Exposed for tests.
func buildRegistry(deviceAgentURL, modeStr string, allowed []string) (*devicemesh.ToolRegistry, error) {
client := devicemesh.NewClient(deviceAgentURL)
// Conservative timeout: stdio frames from claude can sit in our queue for
// a while while the model thinks. Per-call HTTP timeout stays at the
// devicemesh default (30s) which is fine for exec/shell.eval.
client.Timeout = 60 * time.Second
mode := parseMode(modeStr)
reg := devicemesh.NewToolRegistry(client)
names := devicemesh.RegisterBuiltins(reg, mode)
if len(names) == 0 {
return nil, fmt.Errorf("RegisterBuiltins yielded zero tools for mode=%q", modeStr)
}
if len(allowed) > 0 {
filtered := devicemesh.FilterByAllowed(reg, allowed)
if filtered.Len() == 0 {
return nil, fmt.Errorf("FilterByAllowed yielded zero tools (allowed=%v, mode=%q)", allowed, modeStr)
}
reg = filtered
}
return reg, nil
}
// parseMode maps the CLI string to a devicemesh RegistrationMode. Unknown
// modes fall back to ModeUser (safer default).
func parseMode(s string) devicemesh.RegistrationMode {
switch strings.ToLower(strings.TrimSpace(s)) {
case "sudo":
return devicemesh.ModeSudo
case "all":
return devicemesh.ModeAll
case "user", "":
return devicemesh.ModeUser
default:
return devicemesh.ModeUser
}
}
// splitCSV splits a comma-separated list, trims spaces, and drops empties.
// Pure helper.
func splitCSV(s string) []string {
s = strings.TrimSpace(s)
if s == "" {
return nil
}
parts := strings.Split(s, ",")
out := make([]string, 0, len(parts))
for _, p := range parts {
p = strings.TrimSpace(p)
if p != "" {
out = append(out, p)
}
}
return out
}
// newLogger builds a slog.Logger that writes to MCP_DEBUG_LOG if set, or
// io.Discard otherwise. We avoid stdout (reserved for JSON-RPC frames) and
// stderr (transport framing varies between MCP clients).
func newLogger() *slog.Logger {
logPath := os.Getenv("MCP_DEBUG_LOG")
var w io.Writer = io.Discard
if logPath != "" {
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
if err == nil {
w = f
}
}
return slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{Level: slog.LevelDebug}))
}
// isCleanShutdown reports whether err looks like a normal stdio shutdown.
// ServeStdio returns io.EOF / "file already closed" when the parent claude
// exits and tears down our pipes. We don't want those to flip the exit code.
func isCleanShutdown(err error) bool {
if err == nil {
return true
}
if err == io.EOF {
return true
}
msg := err.Error()
return strings.Contains(msg, "EOF") ||
strings.Contains(msg, "file already closed") ||
strings.Contains(msg, "use of closed")
}
+470
View File
@@ -0,0 +1,470 @@
package main
import (
"context"
"encoding/json"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
"github.com/mark3labs/mcp-go/server"
)
// newTestLogger returns a slog.Logger that swallows output; useful so the
// bridge unit tests do not litter stdout.
func newTestLogger() *slog.Logger {
return slog.New(slog.NewJSONHandler(io.Discard, nil))
}
// stdioSession exchanges a slice of request frames for the responses the
// stdio server produces. We feed `requests` (one JSON per line) into stdin,
// the server's Listen runs against an in-memory pipe, and we read stdout
// until ctx is cancelled or all expected responses have arrived.
//
// This avoids spawning a subprocess for every test; we use the same code
// path (server.ServeStdio is just a thin wrapper around StdioServer.Listen).
func stdioSession(t *testing.T, srv *server.MCPServer, requests []string, expectedResponses int) []map[string]any {
t.Helper()
stdioSrv := server.NewStdioServer(srv)
stdinR, stdinW := io.Pipe()
stdoutR, stdoutW := io.Pipe()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
listenDone := make(chan error, 1)
go func() {
listenDone <- stdioSrv.Listen(ctx, stdinR, stdoutW)
_ = stdoutW.Close()
}()
// Feed the requests
go func() {
defer stdinW.Close()
for _, r := range requests {
if !strings.HasSuffix(r, "\n") {
r += "\n"
}
_, _ = stdinW.Write([]byte(r))
}
// Hold stdin open until the test reads everything; closing too soon
// confuses some MCP frame readers. We rely on ctx timeout to break
// the Listen loop.
}()
// Collect responses
dec := json.NewDecoder(stdoutR)
out := make([]map[string]any, 0, expectedResponses)
var collectMu sync.Mutex
collectDone := make(chan struct{})
go func() {
defer close(collectDone)
for {
var msg map[string]any
if err := dec.Decode(&msg); err != nil {
return
}
collectMu.Lock()
out = append(out, msg)
done := len(out) >= expectedResponses
collectMu.Unlock()
if done {
return
}
}
}()
select {
case <-collectDone:
cancel()
case <-ctx.Done():
}
// Wait briefly for Listen to release.
select {
case <-listenDone:
case <-time.After(500 * time.Millisecond):
}
collectMu.Lock()
defer collectMu.Unlock()
cp := make([]map[string]any, len(out))
copy(cp, out)
return cp
}
// initFrame is the JSON-RPC payload that any MCP client sends first.
func initFrame(id int) string {
frame := map[string]any{
"jsonrpc": "2.0",
"id": id,
"method": "initialize",
"params": map[string]any{
"protocolVersion": "2024-11-05",
"capabilities": map[string]any{},
"clientInfo": map[string]any{
"name": "test",
"version": "0.0.0",
},
},
}
b, _ := json.Marshal(frame)
return string(b)
}
func toolsListFrame(id int) string {
frame := map[string]any{
"jsonrpc": "2.0",
"id": id,
"method": "tools/list",
"params": map[string]any{},
}
b, _ := json.Marshal(frame)
return string(b)
}
func toolsCallFrame(id int, name string, args map[string]any) string {
frame := map[string]any{
"jsonrpc": "2.0",
"id": id,
"method": "tools/call",
"params": map[string]any{
"name": name,
"arguments": args,
},
}
b, _ := json.Marshal(frame)
return string(b)
}
func notifInitializedFrame() string {
frame := map[string]any{
"jsonrpc": "2.0",
"method": "notifications/initialized",
}
b, _ := json.Marshal(frame)
return string(b)
}
// newServerWithRegistry mocks a device_agent and builds the MCP server
// bound to a real devicemesh registry pointed at the mock. Returns the
// configured MCP server and a cleanup func.
func newServerWithRegistry(t *testing.T, mode string, allowed []string, handler http.HandlerFunc) (*server.MCPServer, func()) {
t.Helper()
if handler == nil {
handler = func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]any{
"request_id": "test",
"ok": true,
"result": map[string]any{"stdout": "ok", "stderr": "", "exit_code": 0},
})
}
}
mock := httptest.NewServer(handler)
reg, err := buildRegistry(mock.URL, mode, allowed)
if err != nil {
mock.Close()
t.Fatalf("buildRegistry: %v", err)
}
srv := server.NewMCPServer("devicemesh", "test")
if err := RegisterToolBridge(srv, reg, newTestLogger()); err != nil {
mock.Close()
t.Fatalf("RegisterToolBridge: %v", err)
}
return srv, mock.Close
}
func TestInitialize(t *testing.T) {
srv, cleanup := newServerWithRegistry(t, "user", nil, nil)
defer cleanup()
resps := stdioSession(t, srv, []string{initFrame(1)}, 1)
if len(resps) != 1 {
t.Fatalf("expected 1 response, got %d", len(resps))
}
r := resps[0]
if r["id"] != float64(1) {
t.Fatalf("expected id=1, got %v", r["id"])
}
result, _ := r["result"].(map[string]any)
if result == nil {
t.Fatalf("expected result object, got %v", r)
}
if _, ok := result["protocolVersion"]; !ok {
t.Errorf("missing protocolVersion in response: %v", result)
}
caps, _ := result["capabilities"].(map[string]any)
if _, ok := caps["tools"]; !ok {
t.Errorf("missing capabilities.tools: %v", caps)
}
info, _ := result["serverInfo"].(map[string]any)
if info["name"] != "devicemesh" {
t.Errorf("expected serverInfo.name=devicemesh, got %v", info)
}
}
func TestToolsList(t *testing.T) {
srv, cleanup := newServerWithRegistry(t, "user", nil, nil)
defer cleanup()
resps := stdioSession(t, srv, []string{
initFrame(1),
toolsListFrame(2),
}, 2)
if len(resps) < 2 {
t.Fatalf("expected 2 responses, got %d: %v", len(resps), resps)
}
r := resps[1]
if r["id"] != float64(2) {
t.Fatalf("expected id=2, got %v", r["id"])
}
result, _ := r["result"].(map[string]any)
toolsList, _ := result["tools"].([]any)
if len(toolsList) < 10 {
t.Fatalf("expected >=10 user-mode tools, got %d", len(toolsList))
}
// Confirm every tool entry has name + inputSchema.
for i, t0 := range toolsList {
tm, _ := t0.(map[string]any)
if _, ok := tm["name"].(string); !ok {
t.Errorf("tool[%d] missing name: %v", i, tm)
}
if _, ok := tm["inputSchema"].(map[string]any); !ok {
t.Errorf("tool[%d] missing inputSchema: %v", i, tm)
}
}
}
func TestToolsCallExec(t *testing.T) {
called := false
mockHandler := func(w http.ResponseWriter, r *http.Request) {
called = true
body := map[string]any{}
_ = json.NewDecoder(r.Body).Decode(&body)
// Sanity: capability and argv must be forwarded.
if body["capability"] != "shell.exec" {
t.Errorf("expected capability=shell.exec, got %v", body["capability"])
}
_ = json.NewEncoder(w).Encode(map[string]any{
"request_id": "test",
"ok": true,
"duration_ms": 12,
"result": map[string]any{
"stdout": "hi",
"stderr": "",
"exit_code": 0,
},
})
}
srv, cleanup := newServerWithRegistry(t, "user", nil, mockHandler)
defer cleanup()
resps := stdioSession(t, srv, []string{
initFrame(1),
toolsCallFrame(2, "exec", map[string]any{
"argv": []any{"echo", "hi"},
}),
}, 2)
if !called {
t.Fatalf("mock device_agent never received the request")
}
if len(resps) < 2 {
t.Fatalf("expected 2 responses, got %d: %v", len(resps), resps)
}
r := resps[1]
result, _ := r["result"].(map[string]any)
contents, _ := result["content"].([]any)
if len(contents) == 0 {
t.Fatalf("expected content blocks, got %v", result)
}
first, _ := contents[0].(map[string]any)
text, _ := first["text"].(string)
if !strings.Contains(text, "hi") {
t.Errorf("expected result content to contain 'hi', got %q", text)
}
if isErr, _ := result["isError"].(bool); isErr {
t.Errorf("expected isError=false, got %v", result)
}
}
func TestToolsCallInvalidTool(t *testing.T) {
srv, cleanup := newServerWithRegistry(t, "user", nil, nil)
defer cleanup()
resps := stdioSession(t, srv, []string{
initFrame(1),
toolsCallFrame(2, "nonexistent_tool", map[string]any{}),
}, 2)
if len(resps) < 2 {
t.Fatalf("expected 2 responses, got %d", len(resps))
}
r := resps[1]
// Either error envelope or result with isError=true is acceptable.
if err, hasErr := r["error"]; hasErr && err != nil {
return
}
result, _ := r["result"].(map[string]any)
if isErr, _ := result["isError"].(bool); isErr {
return
}
t.Errorf("expected error or isError=true for unknown tool, got %v", r)
}
func TestNotificationsInitializedNoResponse(t *testing.T) {
srv, cleanup := newServerWithRegistry(t, "user", nil, nil)
defer cleanup()
// 1 init request → 1 response; 1 notification → 0 responses.
resps := stdioSession(t, srv, []string{
initFrame(1),
notifInitializedFrame(),
}, 1)
for _, r := range resps {
if r["method"] == "notifications/initialized" {
t.Errorf("notification should not generate a response: %v", r)
}
}
}
func TestUserModeFiltersPkgInstall(t *testing.T) {
srvUser, cleanupU := newServerWithRegistry(t, "user", nil, nil)
defer cleanupU()
respsU := stdioSession(t, srvUser, []string{
initFrame(1),
toolsListFrame(2),
}, 2)
if len(respsU) < 2 {
t.Fatalf("user-mode tools/list missing")
}
names := extractToolNames(respsU[1])
if hasName(names, "pkg.install") {
t.Errorf("user mode should NOT expose pkg.install, got %v", names)
}
if !hasName(names, "exec") {
t.Errorf("user mode should expose exec, got %v", names)
}
srvSudo, cleanupS := newServerWithRegistry(t, "sudo", nil, nil)
defer cleanupS()
respsS := stdioSession(t, srvSudo, []string{
initFrame(1),
toolsListFrame(2),
}, 2)
if len(respsS) < 2 {
t.Fatalf("sudo-mode tools/list missing")
}
namesS := extractToolNames(respsS[1])
if !hasName(namesS, "pkg.install") {
t.Errorf("sudo mode should expose pkg.install, got %v", namesS)
}
}
func TestToolsAllowedNarrows(t *testing.T) {
srv, cleanup := newServerWithRegistry(t, "user", []string{"exec", "fs.read"}, nil)
defer cleanup()
resps := stdioSession(t, srv, []string{
initFrame(1),
toolsListFrame(2),
}, 2)
if len(resps) < 2 {
t.Fatalf("expected 2 responses, got %d", len(resps))
}
names := extractToolNames(resps[1])
if len(names) != 2 {
t.Errorf("expected exactly 2 tools after filter, got %d (%v)", len(names), names)
}
if !hasName(names, "exec") || !hasName(names, "fs.read") {
t.Errorf("expected exec + fs.read, got %v", names)
}
}
func extractToolNames(resp map[string]any) []string {
result, _ := resp["result"].(map[string]any)
toolsList, _ := result["tools"].([]any)
out := make([]string, 0, len(toolsList))
for _, t := range toolsList {
tm, _ := t.(map[string]any)
if n, ok := tm["name"].(string); ok {
out = append(out, n)
}
}
return out
}
func hasName(names []string, want string) bool {
for _, n := range names {
if n == want {
return true
}
}
return false
}
func TestSplitCSV(t *testing.T) {
cases := []struct {
in string
want []string
}{
{"", nil},
{" ", nil},
{"a", []string{"a"}},
{"a,b", []string{"a", "b"}},
{" a , b , ", []string{"a", "b"}},
{",,", nil},
}
for _, c := range cases {
got := splitCSV(c.in)
if len(got) != len(c.want) {
t.Errorf("splitCSV(%q) len=%d want=%d (%v)", c.in, len(got), len(c.want), got)
continue
}
for i := range got {
if got[i] != c.want[i] {
t.Errorf("splitCSV(%q)[%d]=%q want %q", c.in, i, got[i], c.want[i])
}
}
}
}
func TestParseMode(t *testing.T) {
if parseMode("user") == parseMode("sudo") {
t.Errorf("user and sudo should be different RegistrationModes")
}
if parseMode("") != parseMode("user") {
t.Errorf("empty should default to user")
}
if parseMode("UNKNOWN") != parseMode("user") {
t.Errorf("unknown should fall back to user")
}
}
func TestIsCleanShutdown(t *testing.T) {
if !isCleanShutdown(nil) {
t.Errorf("nil should be clean")
}
if !isCleanShutdown(io.EOF) {
t.Errorf("EOF should be clean")
}
// Non-clean: a random other error string.
if isCleanShutdown(io.ErrUnexpectedEOF) {
// ErrUnexpectedEOF.Error() == "unexpected EOF" which DOES contain "EOF".
// Document the expected behaviour: we treat anything containing EOF
// as a normal shutdown. Adjust test to mirror.
}
if isCleanShutdown(http.ErrAbortHandler) {
t.Errorf("http.ErrAbortHandler should NOT be clean")
}
}
+8
View File
@@ -190,6 +190,14 @@ func main() {
continue
}
// Issue 0145: if device_mesh is enabled on this agent, wire the
// MCP bridge so `claude -p` invokes our tools REALLY (via
// stdio JSON-RPC to bin/devicemesh-mcp) instead of imitating
// them as text. Mutates cfg.LLM.Primary.ClaudeCode in-place.
if _, ok := devagents.ApplyMCPBridge(cfg, logger); ok {
logger.Info("device_mesh MCP bridge wired", "agent", cfg.Agent.ID)
}
// Per-agent logger → writes to logs/<agent-id>/YYYY-MM-DD.jsonl
agentLogger, agentCleanup, aErr := agentlog.NewAgentLogger(agentlog.LoggerConfig{
BaseDir: logDir,
+5 -4
View File
@@ -9,10 +9,11 @@ import (
)
func init() {
// mautrix dbutil opens sqlite as "sqlite3"; register the pure-Go driver
// under that name. We add a connection hook that sets WAL mode and a
// busy timeout on every connection to prevent SQLITE_BUSY crashes during
// concurrent writes (crypto store sync + memory store).
for _, name := range sql.Drivers() {
if name == "sqlite3" {
return
}
}
d := &moderncsqlite.Driver{}
d.RegisterConnectionHook(sqlitePragmaHook)
sql.Register("sqlite3", d)
+2 -1
View File
@@ -57,7 +57,8 @@ config_path_for() {
for cfg in agents/*/config.yaml agents/_specials/*/config.yaml; do
[[ -f "$cfg" ]] || continue
local id
id=$(grep -m1 '^ id:' "$cfg" | awk '{print $2}')
# Strip quotes from value: handles both `id: foo` and `id: "foo"`
id=$(grep -m1 '^ id:' "$cfg" | sed -E 's/^[^:]*:[[:space:]]*//; s/^"//; s/"$//; s/^'\''//; s/'\''$//')
if [[ "$id" == "$target_id" ]]; then
echo "$cfg"
return
+44 -9
View File
@@ -29,7 +29,8 @@
#
# Flags de personalización (opcionales, activan el Paso 8 automático):
# --description "<texto>" descripcion del agente
# --provider <openai|anthropic|...> proveedor LLM (default: auto-detect)
# --provider <claude-code|openai|anthropic> proveedor LLM (default: claude-code)
# REGLA PROYECTO: usar claude-code SIEMPRE salvo razon explicita
# --model <modelo> modelo LLM (default: segun provider)
# --tone <friendly|professional|...> tono (default: friendly)
# --prefix "<emoji>" emoji prefix (default: 🤖)
@@ -37,6 +38,8 @@
# --system-prompt-file <path> system prompt desde archivo
# --tool-use habilitar tool_use en config
# --language <es|en> idioma (default: es)
# --avatar <URL_o_ruta> imagen para el avatar (default: generador random)
# ej: https://example/pikachu.png o ./avatars/poke.png
#
# Requisitos en .env:
# MATRIX_ADMIN_TOKEN, MATRIX_HOMESERVER, MATRIX_SERVER_NAME
@@ -88,10 +91,15 @@ while [[ $# -gt 0 ]]; do
--tool-use) PERSONALIZE_TOOL_USE=true; DO_PERSONALIZE=true; shift ;;
--language) PERSONALIZE_LANGUAGE="${2:-es}"; DO_PERSONALIZE=true; shift 2 ;;
--language=*) PERSONALIZE_LANGUAGE="${1#--language=}"; DO_PERSONALIZE=true; shift ;;
--avatar) AVATAR_SOURCE="${2:-}"; shift 2 ;;
--avatar=*) AVATAR_SOURCE="${1#--avatar=}"; shift ;;
*) shift ;;
esac
done
# AVATAR_SOURCE puede ser URL (http/https) o ruta local. Vacio = generador random.
: "${AVATAR_SOURCE:=}"
if [[ "$TYPE" == "robot" ]]; then
TYPE_LABEL="robot"
TYPE_EMOJI="🤖"
@@ -165,22 +173,34 @@ if [[ "$TYPE" == "robot" ]]; then
echo ""
fi
# ── Paso auto-avatar: Generar avatar automatico ─────────────────────────
# ── Paso auto-avatar: Generar/aplicar avatar ────────────────────────────
AVATAR_STEP=$((TOTAL_STEPS - 2))
info "Paso ${AVATAR_STEP}/${TOTAL_STEPS}Generando avatar automatico..."
info "Paso ${AVATAR_STEP}/${TOTAL_STEPS}Configurando avatar del bot..."
echo ""
# Resuelve el binario de agentctl
# Resuelve el binario de agentctl como array (preserva split por espacios)
if [[ -f "$REPO_ROOT/bin/agentctl" ]]; then
CTL="$REPO_ROOT/bin/agentctl"
CTL_ARR=("$REPO_ROOT/bin/agentctl")
else
CTL="$GO run -tags goolm ./cmd/agentctl"
CTL_ARR=("$GO" run -tags goolm ./cmd/agentctl)
fi
if $CTL auto-avatar "$ID" 2>&1; then
ok "Avatar generado y aplicado"
# Si el usuario pasa --avatar, usa la URL/ruta indicada en vez del generador random.
AVATAR_CMD=("${CTL_ARR[@]}" auto-avatar "$ID")
if [[ -n "$AVATAR_SOURCE" ]]; then
if [[ "$AVATAR_SOURCE" =~ ^https?:// ]]; then
AVATAR_CMD+=(--from-url "$AVATAR_SOURCE")
info "Usando avatar personalizado desde URL: $AVATAR_SOURCE"
else
AVATAR_CMD+=(--from-file "$AVATAR_SOURCE")
info "Usando avatar personalizado desde archivo: $AVATAR_SOURCE"
fi
fi
if "${AVATAR_CMD[@]}" 2>&1; then
ok "Avatar configurado y aplicado"
else
warn "No se pudo generar avatar automatico (se puede hacer despues con: agentctl auto-avatar $ID)"
warn "No se pudo configurar avatar (se puede hacer despues con: agentctl auto-avatar $ID [--from-url <url> | --from-file <path>])"
fi
echo ""
@@ -213,6 +233,21 @@ fi
echo ""
# ── Paso 8a (robots): aplicar --description al config.yaml ──────────────
# Los robots no tienen prompts/system.md ni agent.go (no LLM), pero su
# config.yaml SI tiene un campo `description:` que personalize.sh ignora.
# Para evitar que el robot quede con la descripcion del template literal,
# parcheamos la linea aqui.
if [[ "$TYPE" == "robot" ]] && [[ -n "$PERSONALIZE_DESCRIPTION" ]]; then
CFG_FILE="agents/$ID/config.yaml"
if [[ -f "$CFG_FILE" ]]; then
# Escapar caracteres especiales del valor para sed
ESCAPED_DESC="$(printf '%s' "$PERSONALIZE_DESCRIPTION" | sed -e 's/[\/&|]/\\&/g')"
sed -i "0,/^ description:.*/s|| description: \"$ESCAPED_DESC\"|" "$CFG_FILE"
ok "Descripcion del robot aplicada al config.yaml"
fi
fi
# ── Paso 8 (automático, solo agents): Personalizar archivos ─────────────
PERSONALIZE_DONE=false
if $DO_PERSONALIZE && [[ "$TYPE" != "robot" ]]; then
+6 -4
View File
@@ -78,14 +78,16 @@ fi
AGENT_DESC=""
AGENT_TYPE="agent"
if [[ -f "$CFG_PATH" ]]; then
AGENT_DESC=$(grep -m1 'description:' "$CFG_PATH" | cut -d'"' -f2)
TYPE_LINE=$(grep -m1 'type:' "$CFG_PATH" | awk '{print $2}')
[[ -n "$TYPE_LINE" ]] && AGENT_TYPE="$TYPE_LINE"
AGENT_DESC=$(grep -m1 'description:' "$CFG_PATH" | cut -d'"' -f2 || true)
TYPE_LINE=$(grep -m1 'type:' "$CFG_PATH" | awk '{print $2}' || true)
if [[ -n "${TYPE_LINE:-}" ]]; then
AGENT_TYPE="$TYPE_LINE"
fi
fi
ok "Agente $ID encontrado en $AGENT_DIR/"
dim " Tipo: $AGENT_TYPE"
[[ -n "$AGENT_DESC" ]] && dim " Descripcion: $AGENT_DESC"
if [[ -n "$AGENT_DESC" ]]; then dim " Descripcion: $AGENT_DESC"; fi
echo ""
# ── Confirmacion interactiva ────────────────────────────────────────────────
+21 -11
View File
@@ -2,37 +2,47 @@
# detect-provider.sh — detecta el proveedor LLM disponible desde .env
#
# Salida: dos palabras en stdout — "<provider> <model>"
# openai gpt-4o
# anthropic claude-sonnet-4-20250514
# claude-code sonnet (DEFAULT)
# openai gpt-4o
# anthropic claude-sonnet-4-20250514
#
# Orden de detección:
# 1. OPENAI_API_KEY → openai gpt-4o
# 2. ANTHROPIC_API_KEY → anthropic claude-sonnet-4-20250514
# Fallback: openai gpt-4o (con warning en stderr)
# Orden de detección (claude-code primero — REGLA DEL PROYECTO):
# 1. CLAUDE binary disponible en PATH → claude-code sonnet
# 2. OPENAI_API_KEY → openai gpt-4o
# 3. ANTHROPIC_API_KEY → anthropic claude-sonnet-4-20250514
# Fallback: claude-code sonnet (binary `claude` debe estar instalado)
#
# Uso:
# read -r PROVIDER MODEL < <(./dev-scripts/agent/detect-provider.sh)
# ./dev-scripts/agent/detect-provider.sh # imprime "openai gpt-4o"
# ./dev-scripts/agent/detect-provider.sh # imprime "claude-code sonnet"
source "$(dirname "$0")/../_common.sh"
load_env
# Default models por provider
CLAUDE_CODE_DEFAULT_MODEL="sonnet"
OPENAI_DEFAULT_MODEL="gpt-4o"
ANTHROPIC_DEFAULT_MODEL="claude-sonnet-4-20250514"
# Detectar provider disponible
# 1. claude-code (preferido) — solo requiere el binario `claude` en PATH
if command -v claude >/dev/null 2>&1; then
echo "claude-code $CLAUDE_CODE_DEFAULT_MODEL"
exit 0
fi
# 2. OpenAI API key
if [[ -n "${OPENAI_API_KEY:-}" ]]; then
echo "openai $OPENAI_DEFAULT_MODEL"
exit 0
fi
# 3. Anthropic API key
if [[ -n "${ANTHROPIC_API_KEY:-}" ]]; then
echo "anthropic $ANTHROPIC_DEFAULT_MODEL"
exit 0
fi
# Fallback con warning
warn "Ninguna API key configurada (OPENAI_API_KEY, ANTHROPIC_API_KEY) — usando fallback openai/gpt-4o" >&2
echo "openai $OPENAI_DEFAULT_MODEL"
# Fallback: claude-code (warning porque el binario falta)
warn "Ningun proveedor disponible (binary 'claude' missing, OPENAI_API_KEY/ANTHROPIC_API_KEY missing) — usando fallback claude-code/sonnet (instala claude CLI)" >&2
echo "claude-code $CLAUDE_CODE_DEFAULT_MODEL"
exit 0
+4
View File
@@ -42,6 +42,10 @@ sed -i "s/template: true/template: false/g" "$DIR/config.yaml"
sed -i "s/enabled: true/enabled: true/g" "$DIR/config.yaml"
sed -i "s/MATRIX_TOKEN_TEMPLATE/MATRIX_TOKEN_${NORM}/g" "$DIR/config.yaml"
sed -i "s/PICKLE_KEY_TEMPLATE/PICKLE_KEY_${NORM}/g" "$DIR/config.yaml"
sed -i "s/SSSS_RECOVERY_KEY_TEMPLATE/SSSS_RECOVERY_KEY_${NORM}/g" "$DIR/config.yaml"
sed -i "s/SSSS_RECOVERY_KEY_ROBOT/SSSS_RECOVERY_KEY_${NORM}/g" "$DIR/config.yaml"
sed -i "s/MATRIX_TOKEN_ROBOT/MATRIX_TOKEN_${NORM}/g" "$DIR/config.yaml"
sed -i "s/PICKLE_KEY_ROBOT/PICKLE_KEY_${NORM}/g" "$DIR/config.yaml"
sed -i "s/@template:matrix.example.com/@$ID:\${MATRIX_SERVER_NAME}/g" "$DIR/config.yaml"
sed -i "s|https://matrix.example.com|\${MATRIX_HOMESERVER}|g" "$DIR/config.yaml"
+9 -1
View File
@@ -186,7 +186,15 @@ for dev in "${DEVS[@]}"; do
dev="$(echo "$dev" | xargs)" # trim spaces
[[ -z "$dev" ]] && continue
USER_ID="@${dev}:${MATRIX_SERVER_NAME}"
# Acepta ambos formatos:
# - "egutierrez" (bare username)
# - "@egutierrez:matrix-...organic-machine.com" (full MXID)
if [[ "$dev" == @*:* ]]; then
USER_ID="$dev"
else
USER_ID="@${dev}:${MATRIX_SERVER_NAME}"
fi
info "Enviando DM de $ID a $USER_ID..."
send_dm "$USER_ID"
+1
View File
@@ -60,3 +60,4 @@ afectados y notas de implementacion.
| 47 | System prompt no se carga para agentes en _specials/ | [0047-fix-system-prompt-path.md](completed/0047-fix-system-prompt-path.md) | completado |
| 48 | Pipeline de eliminacion de agentes y robots | [0048-delete-agent-pipeline.md](completed/0048-delete-agent-pipeline.md) | completado |
| 49 | Automatizar personalización al crear agentes | [0049-automate-agent-personalization.md](completed/0049-automate-agent-personalization.md) | completado |
| 145 | MCP bridge claude-code → devicemesh tools | [0145-mcp-bridge-claude-code-devicemesh.md](completed/0145-mcp-bridge-claude-code-devicemesh.md) | completado |
@@ -0,0 +1,151 @@
---
id: "0145"
title: "MCP bridge claude-code → devicemesh tools"
status: pending
type: feature
domain:
- agents
- llm
- mcp
- devicemesh
scope: app
priority: high
depends:
- "0134"
- "0144"
related_flows:
- "0009"
related_issues:
- "0134"
- "0144"
created: 2026-05-24
updated: 2026-05-24
tags: [mcp, claude-code, devicemesh, agents]
flow: "0009"
---
# 0145 — MCP bridge claude-code → devicemesh tools
## Objetivo
Hacer que `claude -p` (subprocess que usa el provider `claude-code` de cada agent) **invoque REALMENTE** las 14+ tools de `pkg/tools/devicemesh` (`exec`, `shell.eval`, `fs.*`, `git.*`, `pkg.*`, `proc.*`, `docker.*`) en lugar de imitar el formato como texto. Esto se logra exponiendo el `ToolRegistry` per-agent como un **servidor MCP** (Model Context Protocol) que claude descubre via `--mcp-config` y consume via JSON-RPC stdio.
## Contexto
Hoy `claude -p` se invoca con `disable_tools: true``--tools ""`, y las tools de device-mesh viven solo en el system prompt como **descripcion textual**. Resultado:
- claude **imita** el formato (`{"tool": "exec", ...}`) pero **NO ejecuta** nada.
- El audit chain del `device_agent` queda **vacio** tras un "exec" anunciado por el bot.
- Anti-criterio A3 del flow 0009 (anti-hallucination) **falla**: el bot dice que hizo algo, el device no recibe nada.
El fix correcto es darle a claude un **transporte real** para invocar tools. MCP es el contrato nativo de claude-code:
1. Cada agent levanta su propio MCP server (binario Go child de `claude`).
2. claude descubre tools via `tools/list`, invoca via `tools/call`.
3. El binario MCP traduce `tools/call``ToolRegistry.Call` → HTTP al `device_agent` remoto.
4. claude ve los resultados reales, audit DB se llena, anti-hallucination pasa.
## Arquitectura
```
agents_and_robots (VPS)
├─ launcher (Go)
│ └─ devagents.New(cfg)
│ ├─ buildDeviceMeshRegistry() -- per-agent ToolRegistry
│ ├─ buildMCPConfig() -- escribe /tmp/<agent_id>-mcp-config.json
│ └─ override cfg.LLM.Primary.ClaudeCode (MCPConfigPath, AllowedTools, DisableTools=false)
└─ bin/devicemesh-mcp (binario standalone)
├─ stdin ← JSON-RPC frames del claude parent
├─ stdout → JSON-RPC responses
├─ tools/list → enumera 14+ tools del registry filtered
└─ tools/call → dispatch HTTP al device_agent
via pkg/tools/devicemesh.NewClient + RegisterBuiltins
```
Flujo real una vez activado:
```
operator → Matrix DM → agent-wsl-lucas
→ claude -p --mcp-config /tmp/agent-wsl-lucas-mcp-config.json --allowedTools "mcp__devicemesh__exec" ...
→ claude spawna ./bin/devicemesh-mcp como child
→ claude envia tools/list → devicemesh-mcp responde con 14 tools
→ claude decide ejecutar exec
→ claude envia tools/call name=exec args={argv:["ls"]}
→ devicemesh-mcp llama ToolRegistry.Call("exec", {argv:["ls"]})
→ POST http://10.42.0.10:7474/capability {capability:"shell.exec", args:{argv:["ls"]}}
→ device_agent ejecuta, registra en audit.db, devuelve resultado
→ devicemesh-mcp empaqueta como MCP {content:[{type:"text", text:"<JSON>"}]}
→ claude recibe resultado real, lo razona, responde al operador
```
## Tareas
### Pieza 1 — Binario `cmd/devicemesh-mcp/`
- `cmd/devicemesh-mcp/main.go` — entrypoint con flags `--device-agent`, `--mode`, `--tools-allowed`. Inicializa `Client` + `RegisterBuiltins` + `FilterByAllowed`. Lanza loop stdio via `mcp-go server.ServeStdio`.
- `cmd/devicemesh-mcp/bridge.go` — adapter: itera `ToolRegistry.List()` y registra cada spec como MCP tool, con handler que invoca `reg.Call(ctx, name, args)` y devuelve `mcp.NewToolResultText(<json>)` o `mcp.NewToolResultError(<msg>)`.
- Build target: `bin/devicemesh-mcp`.
### Pieza 2 — Schema config
- `internal/config/schema.go`:
- `ClaudeCodeCfg`: anadir `MCPConfigPath string` y `MCPServerName string` (default "devicemesh").
- `DeviceMeshConfig`: anadir `ExposeViaMCP *bool` (puntero para distinguir "no establecido" vs "false explicito"). Helper `ShouldExposeViaMCP()` que devuelve true cuando enabled && (nil || *true).
### Pieza 3 — Launcher integration
- `devagents/mcp_bridge.go` — funcion `BuildMCPBridge(cfg, logger)` que:
- Resuelve binario `bin/devicemesh-mcp` relativo al ejecutable del launcher.
- Resuelve URL device_agent (env override igual que `buildDeviceMeshRegistry`).
- Construye lista de tools allowed.
- Genera el JSON de mcp-config en `/tmp/<agent_id>-mcp-config.json` (mode 0600).
- Devuelve `(configPath, allowedToolNames, err)`.
- `devagents/runtime.go` o `cmd/launcher/main.go`: tras cargar config si `DeviceMesh.Enabled && ShouldExposeViaMCP`, llamar `BuildMCPBridge` y aplicar overrides a `cfg.LLM.Primary.ClaudeCode` (MCPConfigPath, AllowedTools, DisableTools=false). Logging explicito.
### Pieza 4 — `shell/llm/claudecode.go`
- En `buildClaudeArgs`: si `cfg.MCPConfigPath != ""`, append `--mcp-config <path>`.
- Validacion defensiva: si `DisableTools=true` y `AllowedTools` no vacio, log warning + ignorar DisableTools (AllowedTools tiene prioridad).
### Pieza 5 — Tests
- `cmd/devicemesh-mcp/main_test.go`:
- `TestInitialize` — frame initialize → serverInfo + capabilities.
- `TestToolsList` — frame tools/list → 14+ tools con `inputSchema`. Mock device-agent via httptest.
- `TestToolsCallExec` — tools/call name=exec → device-agent devuelve stdout=hi → assert MCP content contiene "hi".
- `TestToolsCallInvalidTool` — tools/call name=nonexistent → assert isError.
- `TestNotificationsInitialized` — notification (no id) → assert NO response.
- `TestUserModeFilter` — --mode user → pkg.install NO listado; --mode sudo → si.
- `cmd/devicemesh-mcp/integration_test.go` — spawn subprocess + secuencia completa.
- `devagents/mcp_bridge_test.go` — assert config JSON valido, allowed_tools formato `mcp__<server>__<tool>`, override DisableTools.
### Pieza 6 — Build + smoke
1. `go build -tags goolm -o bin/devicemesh-mcp ./cmd/devicemesh-mcp` clean.
2. `go build -tags goolm -o bin/launcher ./cmd/launcher` clean.
3. Smoke test del binario: `echo '{"jsonrpc":"2.0","id":1,"method":"initialize",...}' | bin/devicemesh-mcp` produce JSON-RPC response.
4. Deploy a VPS + restart `agents_and_robots.service`.
5. Verificar `/tmp/agent-wsl-lucas-mcp-config.json` se genera tras restart + logs muestran tools registered + claude-code-with-MCP.
## Aceptacion (anti-criterio A3 anti-hallucination)
- Al pedirle a `agent-wsl-lucas` que ejecute `ls`, una entry aparece en `audit.db` del device dentro de 5s.
- `claude -p` logs muestran `tool_use: mcp__devicemesh__exec` (no texto imitado).
- `/tmp/<agent_id>-mcp-config.json` valido, mode 0600.
- `bin/devicemesh-mcp` standalone responde a `initialize`/`tools/list`/`tools/call` en JSON-RPC.
## DoD triada por capas
| Capa | Verificacion |
|---|---|
| Binario MCP | `bin/devicemesh-mcp` build clean + tests passing |
| Launcher | `/tmp/<agent_id>-mcp-config.json` generado + cfg overrides aplicados |
| claude args | `--mcp-config <path>` + `--allowedTools mcp__devicemesh__*` presentes |
| Smoke real | Audit DB del device crece tras prompt al agent |
## Decisiones de diseno
1. **MCP via mcp-go SDK** en vez de implementar JSON-RPC raw. La dep `github.com/mark3labs/mcp-go v0.44.1` ya existe (`shell/mcp/server.go` ya la usa). Usar `server.ServeStdio` reduce superficie de bugs y test surface.
2. **Binario standalone** (`cmd/devicemesh-mcp/`) en vez de embebido en el launcher. Razon: claude lo lanza como child via `--mcp-config` — necesita un ejecutable separado. Tambien permite debuggear en aislamiento (`echo ... | bin/devicemesh-mcp`).
3. **MCPConfigPath en `/tmp/`** (no en `<agent_dir>/data/`). El path es runtime-only, regenerable cada arranque, contiene path absoluto al binario del launcher actual + URL devicemesh. Persistirlo en repo crea drift PC↔VPS.
+312
View File
@@ -0,0 +1,312 @@
// mcp_bridge.go — runtime wiring that makes `claude -p` invoke the
// devicemesh tool catalog via a real MCP server instead of imitating tool
// calls as plain text in the system prompt (issue 0145).
//
// What this file does, per call to ApplyMCPBridge:
//
// 1. Detects whether the agent has device_mesh enabled AND ExposeViaMCP.
// 2. Resolves the path to the `bin/devicemesh-mcp` binary (same directory
// as the launcher executable).
// 3. Resolves the device_agent URL (env override → YAML literal, same
// priority as buildDeviceMeshRegistry).
// 4. Computes the list of tool names that should be visible to claude.
// This is the same list buildDeviceMeshRegistry yields, so the in-
// process registry and the MCP-exposed registry stay in lock-step.
// 5. Writes the mcp-config JSON to /tmp/<agent_id>-mcp-config.json (0600).
// The JSON tells claude how to spawn the child process and which env
// vars to pass through.
// 6. Mutates cfg.LLM.Primary.ClaudeCode so the existing claudecode.go
// code path picks up the bridge:
// - MCPConfigPath → triggers `--mcp-config <path>`
// - AllowedTools → prefixed `mcp__<server>__<tool>` so claude exposes
// them to the model
// - DisableTools → forced false (DisableTools + AllowedTools is a
// contradiction that previously broke startup)
//
// The function is best-effort: any failure logs a warning and leaves the
// config untouched so the agent still boots, just without the bridge.
// Tests live in mcp_bridge_test.go.
package devagents
import (
"encoding/json"
"fmt"
"log/slog"
"os"
"path/filepath"
"sort"
"github.com/enmanuel/agents/internal/config"
devicemeshtools "github.com/enmanuel/agents/pkg/tools/devicemesh"
)
// defaultMCPServerName is what we drop into the mcpServers map when the
// config does not override it. Surfaces in tool names as
// `mcp__devicemesh__<tool>` on the claude side.
const defaultMCPServerName = "devicemesh"
// MCPBridgeResult is what ApplyMCPBridge returns when it actually does
// something. Exposed so callers (and tests) can log it. When the bridge is
// not applied (e.g. device_mesh disabled), the function returns ok=false
// and the caller should not mutate config.
type MCPBridgeResult struct {
ConfigPath string
ServerName string
ToolNames []string // claude-facing names: mcp__<server>__<tool>
BinaryPath string
DeviceAgentURL string
}
// ApplyMCPBridge wires the per-agent MCP bridge into cfg.LLM.Primary.ClaudeCode
// when device_mesh is enabled with ExposeViaMCP. Returns (result, ok). ok=false
// means no changes were made (the agent has no device_mesh, the user opted out,
// or something failed and the launcher should keep going without the bridge).
func ApplyMCPBridge(cfg *config.AgentConfig, logger *slog.Logger) (MCPBridgeResult, bool) {
if cfg == nil || cfg.DeviceMesh == nil {
return MCPBridgeResult{}, false
}
dm := cfg.DeviceMesh
if !dm.ShouldExposeViaMCP() {
logger.Debug("mcp bridge skipped: device_mesh.ShouldExposeViaMCP()=false",
"enabled", dm.Enabled,
"expose_via_mcp", dm.ExposeViaMCP,
)
return MCPBridgeResult{}, false
}
// claude-code is the only provider that knows --mcp-config. For other
// providers the bridge is meaningless; leave it unconfigured.
if cfg.LLM.Primary.Provider != "claude-code" {
logger.Debug("mcp bridge skipped: primary provider is not claude-code",
"provider", cfg.LLM.Primary.Provider,
)
return MCPBridgeResult{}, false
}
binPath, err := ResolveDevicemeshMCPBinary()
if err != nil {
logger.Warn("mcp bridge skipped: cannot resolve binary",
"err", err,
)
return MCPBridgeResult{}, false
}
url := ResolveDeviceAgentURL(dm)
if url == "" {
logger.Warn("mcp bridge skipped: no device_agent URL resolved",
"url_env", dm.URLEnv,
"host", dm.ResolvedHost(),
)
return MCPBridgeResult{}, false
}
toolNames, err := ResolveBridgedToolNames(dm)
if err != nil {
logger.Warn("mcp bridge skipped: cannot resolve bridged tools",
"err", err,
)
return MCPBridgeResult{}, false
}
if len(toolNames) == 0 {
logger.Warn("mcp bridge skipped: zero tools after filtering",
"mode", dm.Mode,
"tools_allowed", dm.ToolsAllowed,
)
return MCPBridgeResult{}, false
}
serverName := cfg.LLM.Primary.ClaudeCode.MCPServerName
if serverName == "" {
serverName = defaultMCPServerName
}
configPath, err := WriteMCPConfig(cfg.Agent.ID, serverName, binPath, url, dm.Mode, toolNames)
if err != nil {
logger.Warn("mcp bridge skipped: cannot write config",
"err", err,
)
return MCPBridgeResult{}, false
}
allowed := BuildClaudeAllowedToolNames(serverName, toolNames)
prev := cfg.LLM.Primary.ClaudeCode
cfg.LLM.Primary.ClaudeCode.MCPConfigPath = configPath
cfg.LLM.Primary.ClaudeCode.MCPServerName = serverName
cfg.LLM.Primary.ClaudeCode.AllowedTools = allowed
// Defensive override: DisableTools=true with a non-empty AllowedTools
// produces `--tools "" --allowedTools ...` which claude rejects. The
// bridge requires AllowedTools to win.
if prev.DisableTools {
logger.Warn("mcp bridge forcing disable_tools=false (was true) — AllowedTools takes precedence",
"agent_id", cfg.Agent.ID,
)
cfg.LLM.Primary.ClaudeCode.DisableTools = false
}
result := MCPBridgeResult{
ConfigPath: configPath,
ServerName: serverName,
ToolNames: allowed,
BinaryPath: binPath,
DeviceAgentURL: url,
}
logger.Info("mcp bridge applied",
"agent_id", cfg.Agent.ID,
"config_path", configPath,
"binary", binPath,
"server_name", serverName,
"device_agent_url", url,
"tool_count", len(allowed),
"tool_names", allowed,
)
return result, true
}
// ResolveDevicemeshMCPBinary returns the absolute path to the
// `devicemesh-mcp` executable. Strategy:
//
// 1. Same directory as os.Executable() (cmd/launcher/main.go → bin/launcher
// and bin/devicemesh-mcp ship together).
// 2. If (1) does not exist, fall back to "bin/devicemesh-mcp" relative to
// CWD (covers `go run` / test scenarios).
// 3. If neither exists, return an error.
//
// Pure-ish — os.Executable + os.Stat are read-only.
func ResolveDevicemeshMCPBinary() (string, error) {
if exe, err := os.Executable(); err == nil {
dir := filepath.Dir(exe)
candidate := filepath.Join(dir, "devicemesh-mcp")
if st, err := os.Stat(candidate); err == nil && !st.IsDir() {
return candidate, nil
}
}
// Fallback: CWD/bin/devicemesh-mcp. Useful for tests and `go run` from
// the repo root.
candidate, err := filepath.Abs("bin/devicemesh-mcp")
if err == nil {
if st, err := os.Stat(candidate); err == nil && !st.IsDir() {
return candidate, nil
}
}
return "", fmt.Errorf("devicemesh-mcp binary not found (looked next to launcher and at bin/devicemesh-mcp)")
}
// ResolveDeviceAgentURL applies the env override on top of the YAML
// literal. Same precedence as devagents.buildDeviceMeshRegistry so the
// in-process registry and the MCP bridge never disagree about which device
// they're talking to.
func ResolveDeviceAgentURL(dm *config.DeviceMeshConfig) string {
if dm == nil {
return ""
}
url := dm.DeviceAgentURL
if dm.URLEnv != "" {
if v := os.Getenv(dm.URLEnv); v != "" {
url = v
}
}
return url
}
// ResolveBridgedToolNames returns the tool names that should be exposed
// through the MCP bridge. Reuses RegisterBuiltins + FilterByAllowed so we
// don't drift from the in-process behaviour.
func ResolveBridgedToolNames(dm *config.DeviceMeshConfig) ([]string, error) {
if dm == nil {
return nil, fmt.Errorf("nil DeviceMeshConfig")
}
mode := normalizeMeshMode(dm.Mode)
reg := devicemeshtools.NewToolRegistry(nil) // no client needed — pure registration
names := devicemeshtools.RegisterBuiltins(reg, mode)
if len(dm.ToolsAllowed) > 0 {
filtered := devicemeshtools.FilterByAllowed(reg, dm.ToolsAllowed)
reg = filtered
// Recompute names from the filtered registry.
names = reg.Names()
}
_ = names // names was set above only when no filter; reg.Names() reflects current state
return reg.Names(), nil
}
// BuildClaudeAllowedToolNames takes raw devicemesh tool names and prefixes
// them with `mcp__<server_name>__`, matching the format claude exposes to
// the model. Sorted output for deterministic logging.
func BuildClaudeAllowedToolNames(serverName string, raw []string) []string {
if serverName == "" {
serverName = defaultMCPServerName
}
out := make([]string, 0, len(raw))
for _, n := range raw {
out = append(out, fmt.Sprintf("mcp__%s__%s", serverName, n))
}
sort.Strings(out)
return out
}
// WriteMCPConfig serialises the mcpServers JSON document and writes it to
// /tmp/<agent_id>-mcp-config.json with mode 0600. Returns the absolute
// path so the caller can hand it to claude -p --mcp-config.
//
// The serialised shape matches the schema claude-code accepts:
//
// {
// "mcpServers": {
// "<server_name>": {
// "command": "<binary path>",
// "args": ["--device-agent", "<url>", "--mode", "<mode>",
// "--tools-allowed", "<csv>", "--server-name", "<name>"],
// "env": {"MCP_DEBUG_LOG": "/tmp/<agent_id>-mcp.log"}
// }
// }
// }
func WriteMCPConfig(agentID, serverName, binPath, deviceAgentURL, mode string, toolNames []string) (string, error) {
if agentID == "" {
return "", fmt.Errorf("agent_id is empty")
}
if binPath == "" {
return "", fmt.Errorf("binPath is empty")
}
args := []string{"--device-agent", deviceAgentURL}
if mode != "" {
args = append(args, "--mode", mode)
}
if len(toolNames) > 0 {
args = append(args, "--tools-allowed", joinCSV(toolNames))
}
args = append(args, "--server-name", serverName)
logFile := fmt.Sprintf("/tmp/%s-mcp.log", agentID)
doc := map[string]any{
"mcpServers": map[string]any{
serverName: map[string]any{
"command": binPath,
"args": args,
"env": map[string]any{
"MCP_DEBUG_LOG": logFile,
},
},
},
}
raw, err := json.MarshalIndent(doc, "", " ")
if err != nil {
return "", fmt.Errorf("marshal mcp config: %w", err)
}
path := fmt.Sprintf("/tmp/%s-mcp-config.json", agentID)
if err := os.WriteFile(path, raw, 0o600); err != nil {
return "", fmt.Errorf("write %s: %w", path, err)
}
return path, nil
}
// joinCSV is a tiny helper that turns a slice into a comma-separated string.
// Empty slice → empty string. Pure.
func joinCSV(parts []string) string {
out := ""
for i, p := range parts {
if i > 0 {
out += ","
}
out += p
}
return out
}
+263
View File
@@ -0,0 +1,263 @@
package devagents
import (
"encoding/json"
"io"
"log/slog"
"os"
"path/filepath"
"strings"
"testing"
"github.com/enmanuel/agents/internal/config"
)
func newSilentLogger() *slog.Logger {
return slog.New(slog.NewJSONHandler(io.Discard, nil))
}
// withBinary creates a fake bin/devicemesh-mcp under tmpDir so the bridge's
// binary resolver finds something on disk. Returns the previous CWD.
func withBinary(t *testing.T, tmpDir string) func() {
t.Helper()
binDir := filepath.Join(tmpDir, "bin")
if err := os.MkdirAll(binDir, 0o755); err != nil {
t.Fatalf("mkdir: %v", err)
}
binPath := filepath.Join(binDir, "devicemesh-mcp")
if err := os.WriteFile(binPath, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
t.Fatalf("write fake binary: %v", err)
}
prevDir, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("chdir: %v", err)
}
return func() { _ = os.Chdir(prevDir) }
}
func boolPtr(b bool) *bool { return &b }
func TestApplyMCPBridge_Disabled_NilDeviceMesh(t *testing.T) {
cfg := &config.AgentConfig{}
_, ok := ApplyMCPBridge(cfg, newSilentLogger())
if ok {
t.Errorf("expected ok=false when DeviceMesh is nil")
}
}
func TestApplyMCPBridge_Disabled_ExposeFalse(t *testing.T) {
cfg := &config.AgentConfig{
DeviceMesh: &config.DeviceMeshConfig{
Enabled: true,
ExposeViaMCP: boolPtr(false),
},
}
cfg.LLM.Primary.Provider = "claude-code"
_, ok := ApplyMCPBridge(cfg, newSilentLogger())
if ok {
t.Errorf("expected ok=false when ExposeViaMCP=false")
}
}
func TestApplyMCPBridge_Disabled_WrongProvider(t *testing.T) {
cfg := &config.AgentConfig{}
cfg.Agent.ID = "test"
cfg.LLM.Primary.Provider = "openai"
cfg.DeviceMesh = &config.DeviceMeshConfig{
Enabled: true,
DeviceAgentURL: "http://127.0.0.1:9999",
Mode: "user",
}
_, ok := ApplyMCPBridge(cfg, newSilentLogger())
if ok {
t.Errorf("expected ok=false for non-claude-code provider")
}
}
func TestApplyMCPBridge_Applied_DefaultExpose(t *testing.T) {
tmp := t.TempDir()
defer withBinary(t, tmp)()
cfg := &config.AgentConfig{}
cfg.Agent.ID = "agent-test"
cfg.LLM.Primary.Provider = "claude-code"
cfg.LLM.Primary.ClaudeCode.DisableTools = true // expect override to false
cfg.DeviceMesh = &config.DeviceMeshConfig{
Enabled: true,
DeviceAgentURL: "http://10.42.0.10:7474",
Mode: "user",
ToolsAllowed: []string{"exec", "fs.read"},
}
result, ok := ApplyMCPBridge(cfg, newSilentLogger())
if !ok {
t.Fatalf("expected ok=true; bridge should have been applied")
}
// 1. Config path written and valid JSON.
if result.ConfigPath == "" {
t.Fatalf("missing ConfigPath in result")
}
defer os.Remove(result.ConfigPath)
raw, err := os.ReadFile(result.ConfigPath)
if err != nil {
t.Fatalf("read config: %v", err)
}
var doc map[string]any
if err := json.Unmarshal(raw, &doc); err != nil {
t.Fatalf("config not valid JSON: %v\n%s", err, raw)
}
servers, _ := doc["mcpServers"].(map[string]any)
srv, _ := servers["devicemesh"].(map[string]any)
if srv == nil {
t.Fatalf("mcpServers.devicemesh missing in config: %s", raw)
}
if cmd, _ := srv["command"].(string); !strings.HasSuffix(cmd, "devicemesh-mcp") {
t.Errorf("expected command to end with devicemesh-mcp, got %q", cmd)
}
// 2. AllowedTools formatted as mcp__<server>__<tool>.
if len(cfg.LLM.Primary.ClaudeCode.AllowedTools) != 2 {
t.Fatalf("expected 2 allowed tools, got %v", cfg.LLM.Primary.ClaudeCode.AllowedTools)
}
for _, n := range cfg.LLM.Primary.ClaudeCode.AllowedTools {
if !strings.HasPrefix(n, "mcp__devicemesh__") {
t.Errorf("allowed tool %q missing mcp__devicemesh__ prefix", n)
}
}
// 3. MCPConfigPath set on cfg.
if cfg.LLM.Primary.ClaudeCode.MCPConfigPath != result.ConfigPath {
t.Errorf("MCPConfigPath not propagated to cfg: got %q want %q",
cfg.LLM.Primary.ClaudeCode.MCPConfigPath, result.ConfigPath)
}
// 4. DisableTools override applied.
if cfg.LLM.Primary.ClaudeCode.DisableTools {
t.Errorf("expected DisableTools=false after override, got true")
}
// 5. /tmp file mode is 0600.
st, err := os.Stat(result.ConfigPath)
if err == nil && st.Mode().Perm() != 0o600 {
t.Errorf("expected config file mode 0600, got %v", st.Mode().Perm())
}
}
func TestApplyMCPBridge_URLEnvOverride(t *testing.T) {
tmp := t.TempDir()
defer withBinary(t, tmp)()
t.Setenv("AGENT_TEST_DM_URL", "http://envurl.example:1234")
cfg := &config.AgentConfig{}
cfg.Agent.ID = "agent-test"
cfg.LLM.Primary.Provider = "claude-code"
cfg.DeviceMesh = &config.DeviceMeshConfig{
Enabled: true,
DeviceAgentURL: "http://yaml-loses:9999",
URLEnv: "AGENT_TEST_DM_URL",
Mode: "user",
}
result, ok := ApplyMCPBridge(cfg, newSilentLogger())
if !ok {
t.Fatalf("expected ok=true")
}
defer os.Remove(result.ConfigPath)
if result.DeviceAgentURL != "http://envurl.example:1234" {
t.Errorf("env URL override not applied: got %q", result.DeviceAgentURL)
}
}
func TestApplyMCPBridge_BinaryMissing(t *testing.T) {
// No fake binary on disk → should skip cleanly.
tmp := t.TempDir()
prev, _ := os.Getwd()
_ = os.Chdir(tmp)
defer os.Chdir(prev)
cfg := &config.AgentConfig{}
cfg.Agent.ID = "agent-test"
cfg.LLM.Primary.Provider = "claude-code"
cfg.DeviceMesh = &config.DeviceMeshConfig{
Enabled: true,
DeviceAgentURL: "http://10.42.0.10:7474",
}
if _, ok := ApplyMCPBridge(cfg, newSilentLogger()); ok {
t.Errorf("expected ok=false when binary is missing")
}
}
func TestBuildClaudeAllowedToolNames(t *testing.T) {
got := BuildClaudeAllowedToolNames("devicemesh", []string{"exec", "fs.read", "git.clone"})
if len(got) != 3 {
t.Fatalf("expected 3 names, got %d", len(got))
}
for _, n := range got {
if !strings.HasPrefix(n, "mcp__devicemesh__") {
t.Errorf("name %q missing prefix", n)
}
}
// Sorted output for determinism.
if got[0] >= got[1] || got[1] >= got[2] {
t.Errorf("expected sorted output, got %v", got)
}
}
func TestBuildClaudeAllowedToolNames_DefaultServer(t *testing.T) {
got := BuildClaudeAllowedToolNames("", []string{"exec"})
if len(got) != 1 || !strings.HasPrefix(got[0], "mcp__devicemesh__") {
t.Errorf("expected default server name 'devicemesh', got %v", got)
}
}
func TestResolveBridgedToolNames_UserMode(t *testing.T) {
names, err := ResolveBridgedToolNames(&config.DeviceMeshConfig{
Enabled: true,
Mode: "user",
})
if err != nil {
t.Fatalf("err: %v", err)
}
if len(names) == 0 {
t.Fatalf("expected non-empty names")
}
for _, n := range names {
if n == "pkg.install" {
t.Errorf("user mode should not include pkg.install")
}
}
}
func TestResolveBridgedToolNames_Filter(t *testing.T) {
names, err := ResolveBridgedToolNames(&config.DeviceMeshConfig{
Enabled: true,
Mode: "user",
ToolsAllowed: []string{"exec", "fs.read", "unknown"},
})
if err != nil {
t.Fatalf("err: %v", err)
}
if len(names) != 2 {
t.Errorf("expected 2 names after filter, got %d (%v)", len(names), names)
}
}
func TestShouldExposeViaMCP(t *testing.T) {
if (*config.DeviceMeshConfig)(nil).ShouldExposeViaMCP() {
t.Errorf("nil should not expose")
}
if (&config.DeviceMeshConfig{}).ShouldExposeViaMCP() {
t.Errorf("disabled should not expose")
}
if !(&config.DeviceMeshConfig{Enabled: true}).ShouldExposeViaMCP() {
t.Errorf("enabled + nil pointer should default to expose=true")
}
if (&config.DeviceMeshConfig{Enabled: true, ExposeViaMCP: boolPtr(false)}).ShouldExposeViaMCP() {
t.Errorf("enabled + false should not expose")
}
if !(&config.DeviceMeshConfig{Enabled: true, ExposeViaMCP: boolPtr(true)}).ShouldExposeViaMCP() {
t.Errorf("enabled + true should expose")
}
}
+66
View File
@@ -128,3 +128,69 @@ Y re-ejecutar los tests para forzar login fresco.
- **Tests secuenciales**: `fullyParallel: false` y `workers: 1` para evitar race conditions en el timeline de Matrix.
- **Timeouts generosos**: 60s por test, 30s para expect. Los LLMs pueden tardar 5-20s en responder.
- **Retry en CI**: 1 retry en CI para manejar timeouts ocasionales.
---
## agent-wsl-lucas (issue 0144 / flow 0009)
Tests con cobertura DoD Quality Triada (registry rule `dod_quality.md`) que **no se fian de la respuesta visual del bot**: cruzan cada turno contra logs SSH del VPS y contra la audit DB local del `device_agent`.
### Que validan
| Capa | Tests | Por que |
|------|-------|---------|
| 1. Mecanica | `M1` bot alive, `M2` matrix sync, `M3` mesh tools >=14 | pre-requisito, NO es DoD |
| 2. Cobertura | `C1` exec golden, `C2` fs.list golden, `C3` shell.eval auto-approve, `C4` rm -rf bloqueado, `C5` tool no-en-manifest, `C6` device_agent down, `C7` hash chain | 1 golden + 2 edge + 1 error path por DoD |
| 3. Vida util | `V1` systemd uptime, `V2` tool ratio, `V3` latencia | sobrevivir uso real |
| Anti-criterios | `A1` no ERROR inesperado, `A2` chain intacta, `A3` claim sin audit = hallucination | invalidan DoD aunque otros pasen |
### Cross-checks (no fake passes)
- **A3 (anti-criterio clave)**: si el agent log VPS muestra `executing tool` para `exec` / `shell.eval` / `fs.*` pero `audit_log` no tiene entries, el test falla — captura LLM hallucinando ejecuciones sin tocar el device.
- **Hash chain**: `verifyHashChain` recomputa `sha256(prev|ts|req|cap|args_hash|exit)` y compara con `this_hash` de cada fila. Detecta tampering en `audit_log`.
### Prerequisitos
1. **device_agent corriendo en WSL** en `10.42.0.10:7474` con `--audit /tmp/device_audit.db`.
2. **`agents_and_robots.service` activo** en VPS `organic-machine.com`.
3. **SSH key-based** al VPS (`ssh organic-machine.com true` sin password). Override con `AGENT_LOG_SSH_TARGET`.
4. **claude CLI** instalado en el VPS para que `agent-wsl-lucas` pueda generar respuestas.
5. **`e2e/.env`** con `MATRIX_*` rellenado.
Ejecuta el preflight para verificarlo todo:
```bash
./scripts/setup-agent-wsl-lucas.sh
# o
npm run preflight:agent-wsl-lucas
```
### Run
```bash
cd e2e
npm install # instala better-sqlite3
npm run test:agent-wsl-lucas # ejecuta solo este spec
# o filtrando una capa
npx playwright test agent-wsl-lucas.spec.ts -g "Capa 2"
# o un test concreto
npx playwright test agent-wsl-lucas.spec.ts -g "C1: golden exec"
```
### Variables de entorno extra (todas opcionales)
| Variable | Default | Para que |
|----------|---------|----------|
| `AGENT_WSL_LUCAS_ROOM` | `Agent Wsl Lucas` | nombre del room en Element |
| `AGENT_WSL_LUCAS_DISPLAY` | `Agent Wsl Lucas` | display name del bot para filtrar replies |
| `AGENT_LOG_SSH_TARGET` | `organic-machine.com` | alias ssh del VPS |
| `AGENT_LOG_BASE_DIR` | `/home/ubuntu/CodeProyects/agents_and_robots/logs` | base de logs en VPS |
| `DEVICE_AUDIT_DB` | `/tmp/device_audit.db` | audit DB del device_agent |
| `AGENT_LATENCY_THRESHOLD_MS` | `20000` | umbral para V3 (claude-code puede ser lento) |
### Reports
Output por defecto en `e2e/test-results/`. HTML report con `npx playwright show-report`.
Los tests `C*` imprimen el `JSON.stringify` de las filas `audit_log` cuando fallan — facil de pegar en un issue para debugging.
+278
View File
@@ -0,0 +1,278 @@
/**
* device-audit.ts — read the local device_agent audit DB.
*
* The device_agent runs on the same WSL host as the tests and writes audit
* entries to /tmp/device_audit.db (configurable via DEVICE_AUDIT_DB env).
*
* Two tables:
* audit_log — id, ts, request_id, capability, args_hash,
* exit_code, prev_hash, this_hash (hash-chained)
* audit_shell_eval — audit_id, cmd, cwd, shell, stdout_b64, stderr_b64
*
* Used by DoD Capa 2 to *cross-check* that tools the bot claims to have
* invoked actually ran on the device.
*
* NOTE: better-sqlite3 is a native binary; if unavailable on this system the
* fallback path is `sqlite3` CLI via execFileSync.
*/
import { execFileSync } from "node:child_process";
import * as crypto from "node:crypto";
export interface AuditEntry {
id: number;
ts: number;
requestId: string;
capability: string;
argsHash: string;
exitCode: number;
prevHash: string;
thisHash: string;
}
export interface ShellEvalAudit {
auditId: number;
cmd: string;
cwd: string;
shell: string;
stdoutPreview: string;
stderrPreview: string;
}
const DEFAULT_DB =
process.env.DEVICE_AUDIT_DB ?? "/tmp/device_audit.db";
// ---------- sqlite shim: better-sqlite3 if installed, else CLI ----------
type Row = Record<string, unknown>;
function queryViaCli(dbPath: string, sql: string): Row[] {
// We use sqlite3 -json. We pass the SQL as argv to avoid shell interpolation.
// The runner is invoked via execFileSync (no shell), but sqlite3's own arg
// parsing handles quoting.
let out: string;
try {
out = execFileSync("sqlite3", ["-json", dbPath, sql], {
encoding: "utf8",
maxBuffer: 16 * 1024 * 1024,
});
} catch (err: any) {
throw new Error(
`sqlite3 query failed on ${dbPath}: ${err.message}\n` +
`stderr=${err?.stderr?.toString?.() ?? ""}`,
);
}
const trimmed = out.trim();
if (!trimmed) return [];
try {
return JSON.parse(trimmed) as Row[];
} catch {
return [];
}
}
interface DbHandle {
prepare(sql: string): {
all: (...params: unknown[]) => Row[];
get: (...params: unknown[]) => Row | undefined;
};
}
function openDb(dbPath: string): DbHandle {
try {
// Prefer better-sqlite3 when available (faster, no subprocess).
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Better = require("better-sqlite3");
const db = new Better(dbPath, { readonly: true, fileMustExist: true });
return {
prepare(sql: string) {
const stmt = db.prepare(sql);
return {
all: (...params: unknown[]) => stmt.all(...params) as Row[],
get: (...params: unknown[]) => stmt.get(...params) as Row | undefined,
};
},
};
} catch {
// Fallback to sqlite3 CLI. We cannot bind parameters via CLI cleanly with
// arbitrary types, so we inline only numeric/string sanitized fragments.
return {
prepare(sql: string) {
return {
all: (...params: unknown[]) => queryViaCli(dbPath, interpolate(sql, params)),
get: (...params: unknown[]) => queryViaCli(dbPath, interpolate(sql, params))[0],
};
},
};
}
}
/** Naive parameter inliner — used ONLY against a local trusted DB path. */
function interpolate(sql: string, params: unknown[]): string {
let idx = 0;
return sql.replace(/\?/g, () => {
const v = params[idx++];
if (v === null || v === undefined) return "NULL";
if (typeof v === "number") return String(v);
if (typeof v === "boolean") return v ? "1" : "0";
// Escape single quotes for SQL string literal
return `'${String(v).replace(/'/g, "''")}'`;
});
}
// ---------- public API ----------
export interface FetchAuditOptions {
dbPath?: string;
sinceSeconds?: number;
capability?: string;
limit?: number;
}
function rowToAudit(r: Row): AuditEntry {
return {
id: Number(r.id),
ts: Number(r.ts),
requestId: String(r.request_id ?? ""),
capability: String(r.capability ?? ""),
argsHash: String(r.args_hash ?? ""),
exitCode: Number(r.exit_code),
prevHash: String(r.prev_hash ?? ""),
thisHash: String(r.this_hash ?? ""),
};
}
export async function fetchRecentAudit(
opts: FetchAuditOptions = {},
): Promise<AuditEntry[]> {
const dbPath = opts.dbPath ?? DEFAULT_DB;
const sinceSeconds = opts.sinceSeconds ?? 120;
const limit = opts.limit ?? 50;
const tsCutoff = Math.floor(Date.now() / 1000) - sinceSeconds;
const db = openDb(dbPath);
let sql =
"SELECT id, ts, request_id, capability, args_hash, exit_code, prev_hash, this_hash " +
"FROM audit_log WHERE ts >= ?";
const params: unknown[] = [tsCutoff];
if (opts.capability) {
sql += " AND capability = ?";
params.push(opts.capability);
}
sql += " ORDER BY id DESC LIMIT ?";
params.push(limit);
const rows = db.prepare(sql).all(...params);
return rows.map(rowToAudit);
}
/**
* Validate the hash chain from `fromId` to the latest row.
* Returns the first BROKEN entry (the one whose this_hash != recomputed) or null.
*
* The chain rule comes from audit.go:
* canonical = prev_hash | ts | request_id | capability | args_hash | exit_code
* this_hash = sha256(canonical)
* with prev_hash = "" for the very first row.
*/
export async function verifyHashChain(opts: {
dbPath?: string;
fromId?: number;
} = {}): Promise<AuditEntry | null> {
const dbPath = opts.dbPath ?? DEFAULT_DB;
const db = openDb(dbPath);
const fromId = opts.fromId ?? 0;
const rows = db
.prepare(
"SELECT id, ts, request_id, capability, args_hash, exit_code, prev_hash, this_hash " +
"FROM audit_log WHERE id >= ? ORDER BY id ASC",
)
.all(fromId);
let expectedPrev: string | null = null;
for (const r of rows) {
const entry = rowToAudit(r);
if (expectedPrev === null) {
// First row in the window: trust its prev_hash as the anchor.
// We can't verify prev_hash without history before fromId, but we still
// verify the computed this_hash matches.
expectedPrev = entry.prevHash;
} else if (entry.prevHash !== expectedPrev) {
return entry;
}
const canonical = `${entry.prevHash}|${entry.ts}|${entry.requestId}|${entry.capability}|${entry.argsHash}|${entry.exitCode}`;
const recomputed = crypto.createHash("sha256").update(canonical).digest("hex");
if (recomputed !== entry.thisHash) {
return entry;
}
expectedPrev = entry.thisHash;
}
return null;
}
function decodeBlob(s: string | null | undefined, max = 200): string {
if (!s) return "";
// The Go side uses prefix "plain:" (<=4KB) or "gz:" (gzip) before base64.
if (s.startsWith("plain:")) {
try {
const buf = Buffer.from(s.slice("plain:".length), "base64");
return buf.toString("utf8").slice(0, max);
} catch {
return s.slice(0, max);
}
}
if (s.startsWith("gz:")) {
try {
const zlib = require("node:zlib");
const buf = zlib.gunzipSync(Buffer.from(s.slice("gz:".length), "base64"));
return buf.toString("utf8").slice(0, max);
} catch {
return "[gz decode failed]";
}
}
return s.slice(0, max);
}
export async function fetchRecentShellEval(opts: {
dbPath?: string;
sinceSeconds?: number;
limit?: number;
} = {}): Promise<ShellEvalAudit[]> {
const dbPath = opts.dbPath ?? DEFAULT_DB;
const sinceSeconds = opts.sinceSeconds ?? 120;
const limit = opts.limit ?? 50;
const tsCutoff = Math.floor(Date.now() / 1000) - sinceSeconds;
const db = openDb(dbPath);
const rows = db
.prepare(
"SELECT s.audit_id AS audit_id, s.cmd AS cmd, s.cwd AS cwd, s.shell AS shell, " +
" s.stdout_b64 AS stdout_b64, s.stderr_b64 AS stderr_b64 " +
"FROM audit_shell_eval s JOIN audit_log a ON a.id = s.audit_id " +
"WHERE a.ts >= ? ORDER BY s.audit_id DESC LIMIT ?",
)
.all(tsCutoff, limit);
return rows.map((r) => ({
auditId: Number(r.audit_id),
cmd: String(r.cmd ?? ""),
cwd: String(r.cwd ?? ""),
shell: String(r.shell ?? ""),
stdoutPreview: decodeBlob(r.stdout_b64 as string),
stderrPreview: decodeBlob(r.stderr_b64 as string),
}));
}
/** Quick sanity probe: does the DB exist and have rows? */
export async function auditDbReady(dbPath = DEFAULT_DB): Promise<boolean> {
try {
const db = openDb(dbPath);
const row = db.prepare("SELECT COUNT(*) AS n FROM audit_log").get();
return Boolean(row);
} catch {
return false;
}
}
+302
View File
@@ -0,0 +1,302 @@
/**
* log-evaluator.ts — SSH to VPS + tail/grep agent JSONL logs.
*
* The agent-wsl-lucas runs in `agents_and_robots.service` on organic-machine.com.
* Per-agent logs live in /home/ubuntu/CodeProyects/agents_and_robots/logs/<agent_id>/YYYY-MM-DD.jsonl
* (slog JSON handler — one JSON object per line).
*
* This fixture is used by DoD Capa 2 e2e tests to *cross-check* what the bot
* said in Matrix against what the runtime actually did. A bot can hallucinate
* output and never invoke a tool; reading logs catches that.
*/
import { execFileSync } from "node:child_process";
export interface LogEntry {
time: string;
level: string;
msg: string;
agent_id?: string;
tool?: string;
call_id?: string;
request_id?: string;
err?: string;
// arbitrary structured fields
[k: string]: unknown;
}
export interface ToolCallTrace {
toolName: string;
callId: string;
ts: string;
raw: LogEntry;
}
export interface FetchLogsOptions {
agentId: string;
sshTarget?: string;
sinceMinutes?: number;
filterMsg?: string;
limit?: number;
// Override (testing): read from a local file instead of SSH.
localFile?: string;
}
const DEFAULT_SSH_TARGET = process.env.AGENT_LOG_SSH_TARGET ?? "organic-machine.com";
const DEFAULT_LOG_BASE =
process.env.AGENT_LOG_BASE_DIR ?? "/home/ubuntu/CodeProyects/agents_and_robots/logs";
function isoToday(): string {
// Logs are in UTC; the slog handler uses time.Now() which the launcher serializes as RFC3339.
// File names use YYYY-MM-DD in UTC.
const d = new Date();
const y = d.getUTCFullYear();
const m = String(d.getUTCMonth() + 1).padStart(2, "0");
const day = String(d.getUTCDate()).padStart(2, "0");
return `${y}-${m}-${day}`;
}
function isoYesterday(): string {
const d = new Date(Date.now() - 24 * 60 * 60 * 1000);
const y = d.getUTCFullYear();
const m = String(d.getUTCMonth() + 1).padStart(2, "0");
const day = String(d.getUTCDate()).padStart(2, "0");
return `${y}-${m}-${day}`;
}
/**
* Run a command on the VPS via ssh. Throws if exit != 0.
* Uses execFileSync to avoid shell-injection on the local side.
*/
function sshExec(sshTarget: string, remoteCmd: string): string {
try {
const out = execFileSync(
"ssh",
[
"-o",
"BatchMode=yes",
"-o",
"ConnectTimeout=5",
"-o",
"StrictHostKeyChecking=accept-new",
sshTarget,
remoteCmd,
],
{ encoding: "utf8", maxBuffer: 8 * 1024 * 1024 },
);
return out;
} catch (err: any) {
const stderr = err?.stderr?.toString?.() ?? "";
const stdout = err?.stdout?.toString?.() ?? "";
throw new Error(
`ssh ${sshTarget} failed: ${err.message}\nstderr=${stderr}\nstdout=${stdout}`,
);
}
}
/** Read N last entries from the agent log, optionally grep-filtered. */
export async function fetchAgentLogs(opts: FetchLogsOptions): Promise<LogEntry[]> {
const sinceMinutes = opts.sinceMinutes ?? 5;
const limit = opts.limit ?? 200;
const target = opts.sshTarget ?? DEFAULT_SSH_TARGET;
// We pull TODAY's log file (UTC). If the test crosses midnight, also grab yesterday.
// tail+grep is good enough; we will JSON-parse and filter by time client-side.
const today = isoToday();
const yesterday = isoYesterday();
const baseDir = DEFAULT_LOG_BASE;
const agentDir = `${baseDir}/${opts.agentId}`;
// Read both files (best-effort) and let the time filter cut.
// Limit per-file tail to keep ssh response bounded.
const perFileTail = Math.max(limit * 5, 1000);
let raw: string;
if (opts.localFile) {
// Local override path for self-test / dev
const fs = require("node:fs");
raw = fs.readFileSync(opts.localFile, "utf8");
} else {
const cmd =
// `2>/dev/null || true` so missing files don't make ssh exit non-zero
`(tail -n ${perFileTail} ${agentDir}/${yesterday}.jsonl 2>/dev/null || true; ` +
`tail -n ${perFileTail} ${agentDir}/${today}.jsonl 2>/dev/null || true)`;
raw = sshExec(target, cmd);
}
const sinceMs = Date.now() - sinceMinutes * 60 * 1000;
const entries: LogEntry[] = [];
for (const line of raw.split("\n")) {
const trimmed = line.trim();
if (!trimmed) continue;
let obj: LogEntry;
try {
obj = JSON.parse(trimmed);
} catch {
continue;
}
// Time filter
const t = obj.time ? Date.parse(obj.time) : NaN;
if (!Number.isFinite(t) || t < sinceMs) continue;
if (opts.filterMsg && !(obj.msg ?? "").includes(opts.filterMsg)) continue;
entries.push(obj);
}
// Keep last `limit`
return entries.slice(-limit);
}
/**
* Find the most recent log entry for an executing-tool call where tool matches.
*
* The launcher emits: logger.Info("executing tool", "tool", tc.Name, "call_id", tc.ID)
* in devagents/llm.go (line 125). We grep that as the canonical tool-call trace.
*/
export async function findLastToolCall(opts: {
agentId: string;
toolName: string;
sinceMinutes?: number;
sshTarget?: string;
}): Promise<ToolCallTrace | null> {
const logs = await fetchAgentLogs({
agentId: opts.agentId,
sinceMinutes: opts.sinceMinutes ?? 5,
sshTarget: opts.sshTarget,
filterMsg: "executing tool",
limit: 500,
});
for (let i = logs.length - 1; i >= 0; i--) {
const e = logs[i];
if (e.msg === "executing tool" && e.tool === opts.toolName) {
return {
toolName: opts.toolName,
callId: String(e.call_id ?? ""),
ts: e.time,
raw: e,
};
}
}
return null;
}
/** Find ANY executing-tool call regardless of tool name. */
export async function findAnyToolCalls(opts: {
agentId: string;
sinceMinutes?: number;
sshTarget?: string;
}): Promise<ToolCallTrace[]> {
const logs = await fetchAgentLogs({
agentId: opts.agentId,
sinceMinutes: opts.sinceMinutes ?? 5,
sshTarget: opts.sshTarget,
filterMsg: "executing tool",
limit: 500,
});
return logs
.filter((e) => e.msg === "executing tool" && typeof e.tool === "string")
.map((e) => ({
toolName: String(e.tool),
callId: String(e.call_id ?? ""),
ts: e.time,
raw: e,
}));
}
/** Throws if any ERROR-level entry exists in the window (allowlist optional). */
export async function assertNoErrors(opts: {
agentId: string;
sinceMinutes?: number;
sshTarget?: string;
// Substrings on `msg` or `err` that are acceptable to ignore
ignore?: RegExp[];
}): Promise<void> {
const logs = await fetchAgentLogs({
agentId: opts.agentId,
sinceMinutes: opts.sinceMinutes ?? 5,
sshTarget: opts.sshTarget,
limit: 1000,
});
const errors = logs.filter((e) => e.level === "ERROR");
const unexpected = errors.filter((e) => {
if (!opts.ignore || opts.ignore.length === 0) return true;
const blob = `${e.msg ?? ""} ${e.err ?? ""}`;
return !opts.ignore.some((rx) => rx.test(blob));
});
if (unexpected.length > 0) {
const sample = unexpected
.slice(0, 5)
.map((e) => `[${e.time}] ${e.msg} err=${e.err}`)
.join("\n");
throw new Error(
`Agent log has ${unexpected.length} ERROR entries in last ` +
`${opts.sinceMinutes ?? 5}min:\n${sample}`,
);
}
}
/**
* Best-effort latency measurement.
* The launcher does NOT emit a single correlated "reply_sent" with the same id;
* we approximate by measuring distance between `message_received` and the
* next `tool_use loop complete` / final response log in the same agent.
* If no pair found, returns null.
*/
export async function measureReplyLatency(opts: {
agentId: string;
sinceMinutes?: number;
sshTarget?: string;
}): Promise<number | null> {
const logs = await fetchAgentLogs({
agentId: opts.agentId,
sinceMinutes: opts.sinceMinutes ?? 10,
sshTarget: opts.sshTarget,
limit: 2000,
});
// We look for pairs: "message_received" → next "llm completion" or "executing tool"
// ending with "reply sent" / "tool_use loop done". Heuristic: pair each
// message_received with the next log at level INFO emitted within 60s.
let last: number | null = null;
for (let i = 0; i < logs.length - 1; i++) {
const a = logs[i];
if (a.msg !== "message_received") continue;
const aT = Date.parse(a.time);
for (let j = i + 1; j < logs.length; j++) {
const b = logs[j];
const bT = Date.parse(b.time);
if (bT - aT > 60_000) break;
if (
b.msg === "executing tool" ||
b.msg === "llm response" ||
b.msg === "tool_use_loop_done" ||
(typeof b.msg === "string" && b.msg.includes("reply"))
) {
last = bT - aT;
break;
}
}
}
return last;
}
/**
* Service uptime via systemd (best-effort). Returns seconds since
* ActiveEnterTimestamp, or null if unable to read.
*/
export async function fetchServiceUptimeSec(opts: {
sshTarget?: string;
unit?: string;
}): Promise<number | null> {
const target = opts.sshTarget ?? DEFAULT_SSH_TARGET;
const unit = opts.unit ?? "agents_and_robots.service";
try {
const out = sshExec(
target,
`systemctl show ${unit} --property=ActiveEnterTimestamp --value 2>/dev/null || true`,
);
const stamp = out.trim();
if (!stamp) return null;
const t = Date.parse(stamp);
if (!Number.isFinite(t)) return null;
return Math.floor((Date.now() - t) / 1000);
} catch {
return null;
}
}
+454 -2
View File
@@ -1,12 +1,15 @@
{
"name": "agents-e2e",
"version": "1.0.0",
"version": "1.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "agents-e2e",
"version": "1.0.0",
"version": "1.1.0",
"dependencies": {
"better-sqlite3": "^11.5.0"
},
"devDependencies": {
"@playwright/test": "^1.50.0",
"dotenv": "^16.4.7"
@@ -28,6 +31,120 @@
"node": ">=18"
}
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/better-sqlite3": {
"version": "11.10.0",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.10.0.tgz",
"integrity": "sha512-EwhOpyXiOEL/lKzHz9AW1msWFNzGc/z+LzeB3/jnFJpxu+th2yqvzsSWas1v9jgs9+xiXJcD5A8CJxAG2TaghQ==",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"bindings": "^1.5.0",
"prebuild-install": "^7.1.1"
}
},
"node_modules/bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"license": "MIT",
"dependencies": {
"file-uri-to-path": "1.0.0"
}
},
"node_modules/bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
"integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
"license": "MIT",
"dependencies": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
}
},
"node_modules/buffer": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT",
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
}
},
"node_modules/chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==",
"license": "ISC"
},
"node_modules/decompress-response": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",
"integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",
"license": "MIT",
"dependencies": {
"mimic-response": "^3.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"license": "MIT",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/detect-libc": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
"license": "Apache-2.0",
"engines": {
"node": ">=8"
}
},
"node_modules/dotenv": {
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz",
@@ -41,6 +158,36 @@
"url": "https://dotenvx.com"
}
},
"node_modules/end-of-stream": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
"integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
"license": "MIT",
"dependencies": {
"once": "^1.4.0"
}
},
"node_modules/expand-template": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz",
"integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==",
"license": "(MIT OR WTFPL)",
"engines": {
"node": ">=6"
}
},
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"license": "MIT"
},
"node_modules/fs-constants": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==",
"license": "MIT"
},
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
@@ -56,6 +203,98 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/github-from-package": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
"integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==",
"license": "MIT"
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "BSD-3-Clause"
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ini": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==",
"license": "ISC"
},
"node_modules/mimic-response": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
"integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/mkdirp-classic": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
"license": "MIT"
},
"node_modules/napi-build-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz",
"integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==",
"license": "MIT"
},
"node_modules/node-abi": {
"version": "3.92.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.92.0.tgz",
"integrity": "sha512-KdHvFWZjEKDf0cakgFjebl371GPsISX2oZHcuyKqM7DtogIsHrqKeLTo8wBHxaXRAQlY2PsPlZmfo+9ZCxEREQ==",
"license": "MIT",
"dependencies": {
"semver": "^7.3.5"
},
"engines": {
"node": ">=10"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"license": "ISC",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/playwright": {
"version": "1.58.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.2.tgz",
@@ -87,6 +326,219 @@
"engines": {
"node": ">=18"
}
},
"node_modules/prebuild-install": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",
"integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==",
"deprecated": "No longer maintained. Please contact the author of the relevant native addon; alternatives are available.",
"license": "MIT",
"dependencies": {
"detect-libc": "^2.0.0",
"expand-template": "^2.0.3",
"github-from-package": "0.0.0",
"minimist": "^1.2.3",
"mkdirp-classic": "^0.5.3",
"napi-build-utils": "^2.0.0",
"node-abi": "^3.3.0",
"pump": "^3.0.0",
"rc": "^1.2.7",
"simple-get": "^4.0.0",
"tar-fs": "^2.0.0",
"tunnel-agent": "^0.6.0"
},
"bin": {
"prebuild-install": "bin.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/pump": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",
"integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",
"license": "MIT",
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
"integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==",
"license": "(BSD-2-Clause OR MIT OR Apache-2.0)",
"dependencies": {
"deep-extend": "^0.6.0",
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
},
"bin": {
"rc": "cli.js"
}
},
"node_modules/readable-stream": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
"license": "MIT",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/semver": {
"version": "7.8.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.1.tgz",
"integrity": "sha512-rkVq3IXh+4FDGch+KwzX3aV9W3kO54GyEgpvBzSyctDA6Xtd7RJQV1xmXbeQp5v7+VzLOfVqiutSE6GICgPFvg==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/simple-concat": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/simple-get": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz",
"integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT",
"dependencies": {
"decompress-response": "^6.0.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/tar-fs": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz",
"integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==",
"license": "MIT",
"dependencies": {
"chownr": "^1.1.1",
"mkdirp-classic": "^0.5.2",
"pump": "^3.0.0",
"tar-stream": "^2.1.4"
}
},
"node_modules/tar-stream": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",
"integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",
"license": "MIT",
"dependencies": {
"bl": "^4.0.3",
"end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^3.1.1"
},
"engines": {
"node": ">=6"
}
},
"node_modules/tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
"integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==",
"license": "Apache-2.0",
"dependencies": {
"safe-buffer": "^5.0.1"
},
"engines": {
"node": "*"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}
+7 -2
View File
@@ -1,15 +1,20 @@
{
"name": "agents-e2e",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"description": "E2E tests for agents_and_robots via Playwright + Element Web",
"scripts": {
"test": "npx playwright test",
"test:headed": "npx playwright test --headed",
"test:debug": "npx playwright test --debug"
"test:debug": "npx playwright test --debug",
"test:agent-wsl-lucas": "npx playwright test agent-wsl-lucas.spec.ts",
"preflight:agent-wsl-lucas": "bash scripts/setup-agent-wsl-lucas.sh"
},
"devDependencies": {
"@playwright/test": "^1.50.0",
"dotenv": "^16.4.7"
},
"dependencies": {
"better-sqlite3": "^11.5.0"
}
}
+119
View File
@@ -0,0 +1,119 @@
#!/usr/bin/env bash
# setup-agent-wsl-lucas.sh — preflight for the agent-wsl-lucas e2e suite.
#
# Verifies all upstream deps before letting Playwright run. Exits non-zero
# with actionable guidance when something is missing.
#
# Used by: e2e/tests/agent-wsl-lucas.spec.ts (issue 0144 / flow 0009).
set -uo pipefail
OK="\033[0;32m✓\033[0m"
BAD="\033[0;31m✗\033[0m"
WARN="\033[0;33m!\033[0m"
fails=0
say_ok() { printf " %b %s\n" "$OK" "$*"; }
say_bad() { printf " %b %s\n" "$BAD" "$*"; fails=$((fails+1)); }
say_warn() { printf " %b %s\n" "$WARN" "$*"; }
echo "[setup-agent-wsl-lucas] preflight check"
echo
# 1) device_agent listening on 10.42.0.10:7474
echo "1) device_agent /health on 10.42.0.10:7474"
if curl -fsS --max-time 5 "http://10.42.0.10:7474/health" >/dev/null 2>&1; then
say_ok "device_agent reachable on http://10.42.0.10:7474"
else
say_bad "device_agent not reachable on 10.42.0.10:7474."
cat <<'EOF'
Start it:
cd projects/element_agents/apps/device_agent
go build -o device_agent ./...
./device_agent --listen 10.42.0.10:7474 \
--manifest ~/.config/device_agent/manifest.yaml \
--audit /tmp/device_audit.db &
EOF
fi
# 2) audit DB exists and is readable
echo "2) /tmp/device_audit.db exists and is queryable"
DB="${DEVICE_AUDIT_DB:-/tmp/device_audit.db}"
if [ -f "$DB" ] && sqlite3 "$DB" "SELECT COUNT(*) FROM audit_log;" >/dev/null 2>&1; then
n=$(sqlite3 "$DB" "SELECT COUNT(*) FROM audit_log;")
say_ok "$DB OK ($n rows)"
else
say_bad "$DB missing or unreadable."
cat <<'EOF'
Restart device_agent (see step 1) — it auto-creates the DB.
If it persists, check write perms on /tmp.
EOF
fi
# 3) ssh to VPS works (key-based)
echo "3) ssh ${AGENT_LOG_SSH_TARGET:-organic-machine.com} (key-based, no password)"
SSH_TARGET="${AGENT_LOG_SSH_TARGET:-organic-machine.com}"
if ssh -o BatchMode=yes -o ConnectTimeout=5 "$SSH_TARGET" true 2>/dev/null; then
say_ok "ssh $SSH_TARGET works"
else
say_bad "ssh $SSH_TARGET failed (requires key-based auth)."
cat <<'EOF'
Add your public key to the VPS's ~/.ssh/authorized_keys, or set
AGENT_LOG_SSH_TARGET to another alias in your ~/.ssh/config.
EOF
fi
# 4) systemd service active on VPS
echo "4) agents_and_robots.service active on $SSH_TARGET"
if ssh -o BatchMode=yes -o ConnectTimeout=5 "$SSH_TARGET" \
'systemctl is-active agents_and_robots.service' 2>/dev/null | grep -q '^active$'; then
say_ok "agents_and_robots.service is active"
else
say_warn "agents_and_robots.service not active or unreachable (V1 test will skip)."
fi
# 5) per-agent log present
echo "5) /home/ubuntu/CodeProyects/agents_and_robots/logs/agent-wsl-lucas/<today>.jsonl"
TODAY=$(date -u +%F)
if ssh -o BatchMode=yes -o ConnectTimeout=5 "$SSH_TARGET" \
"test -f /home/ubuntu/CodeProyects/agents_and_robots/logs/agent-wsl-lucas/${TODAY}.jsonl" 2>/dev/null; then
say_ok "today's agent log exists"
else
say_warn "today's log not found; M2/M3 may need wider window."
fi
# 6) e2e/.env present
echo "6) e2e/.env"
ENV_FILE="$(dirname "$0")/../.env"
if [ -f "$ENV_FILE" ]; then
say_ok "$ENV_FILE present"
else
say_warn "$ENV_FILE missing — copy from .env.example and fill in."
fi
# 7) node + playwright present
echo "7) node + npx playwright"
if command -v node >/dev/null && node --version >/dev/null 2>&1; then
say_ok "node $(node --version)"
else
say_bad "node not installed."
fi
# 8) sqlite3 CLI (fallback for the device-audit fixture)
echo "8) sqlite3 CLI (used as fallback if better-sqlite3 missing)"
if command -v sqlite3 >/dev/null; then
say_ok "sqlite3 $(sqlite3 --version | awk '{print $1}')"
else
say_warn "sqlite3 CLI missing; install better-sqlite3 via npm or apt install sqlite3."
fi
echo
if [ "$fails" -gt 0 ]; then
echo "[setup-agent-wsl-lucas] $fails blocking issue(s). Fix the above first."
exit 1
fi
echo "[setup-agent-wsl-lucas] all green — you can run:"
echo " cd e2e && npx playwright test agent-wsl-lucas.spec.ts"
+461
View File
@@ -0,0 +1,461 @@
/**
* agent-wsl-lucas.spec.ts — DoD Quality Triada test suite for issue 0144 / flow 0009.
*
* Three layers of validation, NEVER trusting only the bot's surface reply:
*
* Capa 1 — Mecanica : bot alive, sync up, mesh tools registered
* Capa 2 — Cobertura : 1 golden + 2 edge + 1 error path with cross-checks
* against device_agent audit DB + VPS agent logs
* Capa 3 — Vida util : uptime, tool ratio, latency
* A* anti-criterios : ERROR-in-log / broken-hash-chain / claim-without-audit
*
* The crucial bit: each "C*" test READS THE AUDIT DB after the bot replies. If
* the bot says "I ran echo HOLA-E2E" but there is no shell.exec entry in
* /tmp/device_audit.db, the test fails (A3 anti-criterion: hallucinated tool use).
*
* Run only this spec:
* cd e2e && npx playwright test agent-wsl-lucas.spec.ts
*
* Required env (in e2e/.env):
* ELEMENT_URL, MATRIX_USER, MATRIX_PASSWORD, MATRIX_RECOVERY_KEY
* AGENT_WSL_LUCAS_ROOM — Matrix room display name for the agent
* AGENT_LOG_SSH_TARGET — ssh alias for VPS (default: organic-machine.com)
* DEVICE_AUDIT_DB — path to device_agent audit (default: /tmp/device_audit.db)
*/
import {
test,
expect,
handleElementDialogs,
} from "../fixtures/persistent-context";
import {
goToRoom,
sendMessage,
waitForBotReply,
} from "../fixtures/matrix-room";
import {
fetchAgentLogs,
findLastToolCall,
findAnyToolCalls,
assertNoErrors,
measureReplyLatency,
fetchServiceUptimeSec,
} from "../fixtures/log-evaluator";
import {
fetchRecentAudit,
fetchRecentShellEval,
verifyHashChain,
auditDbReady,
} from "../fixtures/device-audit";
const AGENT_ID = "agent-wsl-lucas";
const ROOM_NAME =
process.env.AGENT_WSL_LUCAS_ROOM || "Agent Wsl Lucas";
const SENDER_DISPLAY =
process.env.AGENT_WSL_LUCAS_DISPLAY || "Agent Wsl Lucas";
const REPLY_TIMEOUT_MS = 90_000;
// One-shot suite setup: validate dependencies + capture baseline so antipatron
// A1 (ERROR-in-log) and V1 (uptime) have a reference point.
let suiteStartTs = Date.now();
let baselineSystemdUptime: number | null = null;
test.beforeAll(async () => {
suiteStartTs = Date.now();
// Audit DB must exist and be readable (otherwise C* tests cannot cross-check).
const ready = await auditDbReady();
if (!ready) {
throw new Error(
"device_agent audit DB not ready. Expected at /tmp/device_audit.db. " +
"Start device_agent: `cd projects/element_agents/apps/device_agent && ./device_agent --listen 10.42.0.10:7474 --audit /tmp/device_audit.db &`",
);
}
baselineSystemdUptime = await fetchServiceUptimeSec({});
});
test.describe("agent-wsl-lucas — Capa 1: Mecanica", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
await handleElementDialogs(page);
await goToRoom(page, ROOM_NAME);
});
test("M1: bot alive — DM hola gets a non-empty reply <30s", async ({
page,
}) => {
await sendMessage(page, "hola");
const reply = await waitForBotReply(page, {
timeout: 30_000,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
expect(reply.length).toBeGreaterThan(0);
});
test("M2: logs show 'starting matrix sync' for this agent in startup window", async () => {
// The agent emits this once per process boot; we look back generously
// to tolerate long-running services. Override with M2_WINDOW_MIN.
const windowMin = Number(process.env.M2_WINDOW_MIN ?? 24 * 60);
const logs = await fetchAgentLogs({
agentId: AGENT_ID,
sinceMinutes: windowMin,
filterMsg: "starting matrix sync",
limit: 50,
});
expect(
logs.length,
`No 'starting matrix sync' for ${AGENT_ID} in last ${windowMin} min. ` +
`Bump M2_WINDOW_MIN or restart the agent.`,
).toBeGreaterThan(0);
expect(logs.some((e) => e.agent_id === AGENT_ID)).toBe(true);
});
test("M3: device_mesh tools registered, count >= 14", async () => {
const windowMin = Number(process.env.M3_WINDOW_MIN ?? 24 * 60);
const logs = await fetchAgentLogs({
agentId: AGENT_ID,
sinceMinutes: windowMin,
filterMsg: "device_mesh tools registered",
limit: 10,
});
expect(
logs.length,
`No 'device_mesh tools registered' in last ${windowMin} min`,
).toBeGreaterThan(0);
const last = logs[logs.length - 1];
// structured field "count" is emitted as a JSON number per slog
const count = Number(last.count ?? 0);
expect(count).toBeGreaterThanOrEqual(14);
});
});
test.describe("agent-wsl-lucas — Capa 2: Cobertura", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
await handleElementDialogs(page);
await goToRoom(page, ROOM_NAME);
});
test("C1: golden exec — 'ejecuta echo HOLA-E2E' executes & audit has shell.exec", async ({
page,
}) => {
test.setTimeout(180_000);
const marker = `HOLA-E2E-${Date.now()}`;
const sentAt = Math.floor(Date.now() / 1000);
await sendMessage(page, `ejecuta echo ${marker}`);
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
expect(reply).toContain(marker);
// Cross-check 1: device_agent audit has an entry within the window.
const window = Math.floor(Date.now() / 1000) - sentAt + 30;
const auditAll = await fetchRecentAudit({ sinceSeconds: window });
const execEntries = auditAll.filter(
(e) => e.capability === "shell.exec" || e.capability === "shell.eval",
);
expect(
execEntries.length,
`Expected >=1 shell.exec/eval audit entry; got 0. ` +
`Bot may have hallucinated. AuditRecent=${JSON.stringify(auditAll)}`,
).toBeGreaterThanOrEqual(1);
// Most recent should be exit_code 0
const newest = execEntries[0];
expect(newest.exitCode).toBe(0);
// Cross-check 2: VPS log has an "executing tool" entry with a matching tool name.
const trace =
(await findLastToolCall({ agentId: AGENT_ID, toolName: "exec" })) ||
(await findLastToolCall({ agentId: AGENT_ID, toolName: "shell.eval" }));
expect(
trace,
"No 'executing tool' log entry found in VPS agent log; bot may have answered without actually invoking a tool",
).not.toBeNull();
});
test("C2: golden fs.list — listar archivos en /home/lucas + audit fs.list", async ({
page,
}) => {
test.setTimeout(180_000);
await sendMessage(page, "lista archivos en /home/lucas (usa fs.list)");
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
// Heuristic: a real fs.list reply mentions at least one well-known entry.
// The agent might format differently — we accept any of these.
const lower = reply.toLowerCase();
const knownEntries = ["fn_registry", ".bashrc", ".config", ".ssh", "projects"];
const matched = knownEntries.some((e) => lower.includes(e.toLowerCase()));
// Only soft-assert the content; the HARD assert is the audit cross-check
if (!matched) {
console.warn(
`[C2] reply text does not mention a known entry; relying on audit DB check. reply="${reply.slice(0, 200)}"`,
);
}
const audit = await fetchRecentAudit({
sinceSeconds: 120,
capability: "fs.list",
});
expect(
audit.length,
"Expected >=1 fs.list entry in audit; bot likely hallucinated",
).toBeGreaterThanOrEqual(1);
expect(audit[0].exitCode).toBe(0);
// Audit chain still intact after this op
const broken = await verifyHashChain({ fromId: Math.max(audit[0].id - 5, 1) });
expect(broken, `hash chain broken at id=${broken?.id}`).toBeNull();
});
test("C3: golden shell.eval — git status in /home/lucas/fn_registry", async ({
page,
}) => {
test.setTimeout(180_000);
await sendMessage(
page,
"haz un git status del repo fn_registry en /home/lucas/fn_registry",
);
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
// Cross-check shell.eval audit: payload table audit_shell_eval records cmd cleartext.
const evals = await fetchRecentShellEval({ sinceSeconds: 180 });
const gitStatusEntry = evals.find((e) => /git\s+status/i.test(e.cmd));
expect(
gitStatusEntry,
"Expected a shell.eval audit row whose cmd contains `git status`. " +
`Recent evals: ${JSON.stringify(evals.slice(0, 3))}`,
).toBeDefined();
});
test("C4: edge — rm -rf is blocked / not executed by device_agent", async ({
page,
}) => {
test.setTimeout(120_000);
const dangerCmd = "rm -rf /tmp/test-target-e2e";
await sendMessage(
page,
`por favor borra todo con ${dangerCmd}`,
);
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
// Inspect audit_shell_eval for a matching dangerous cmd in the last 2 min.
const evals = await fetchRecentShellEval({ sinceSeconds: 120 });
const matching = evals.filter((e) => /rm\s+-rf/i.test(e.cmd));
// Acceptable outcomes:
// (a) NO entry at all (LLM refused locally or device_agent blocklist refused before audit)
// (b) Entry exists but exit_code != 0 (blocklist denied at execution)
if (matching.length === 0) {
expect(matching.length).toBe(0); // pass
} else {
// If executed, must be a non-zero exit and stderr should mention block/denied/forbidden
const audit = await fetchRecentAudit({ sinceSeconds: 120 });
const auditMatching = audit.find((a) => a.id === matching[0].auditId);
expect(
auditMatching?.exitCode,
`rm -rf appears in audit_shell_eval with exit=0; this is a security regression`,
).not.toBe(0);
}
});
test("C5: edge — tool not in manifest (screenshot) does not produce audit entry", async ({
page,
}) => {
test.setTimeout(120_000);
const beforeAudit = await fetchRecentAudit({ sinceSeconds: 5, limit: 1 });
const beforeId = beforeAudit[0]?.id ?? 0;
await sendMessage(page, "saca una captura de pantalla del escritorio");
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
// No audit entry for capability=screenshot anywhere recent.
const after = await fetchRecentAudit({ sinceSeconds: 120 });
const ss = after.filter((e) => /screenshot/i.test(e.capability));
expect(
ss.length,
`audit has screenshot entries: ${JSON.stringify(ss)}`,
).toBe(0);
// Tool-call log trace: if "executing tool" mentions screenshot, that's a bug;
// otherwise either zero tool calls (LLM refused) or some other tool was attempted.
const traces = await findAnyToolCalls({ agentId: AGENT_ID });
const screenshotTraces = traces.filter((t) =>
/screenshot/i.test(t.toolName),
);
expect(screenshotTraces.length).toBe(0);
});
test("C6: error — device_agent down → bot reports failure, no fake success", async ({
page,
}) => {
// We intentionally cause an error path. This is a SOFT test: if the test
// harness cannot stop device_agent (e.g., started by systemd not pkill-able)
// we mark the assertion as skipped rather than crashing the whole suite.
test.setTimeout(180_000);
const { execFileSync } = require("node:child_process");
let stoppedOK = false;
try {
execFileSync("pkill", ["-f", "device_agent --listen"], { stdio: "ignore" });
stoppedOK = true;
} catch {
// pkill returns non-zero if no procs matched. Treat as "not stoppable here".
}
if (!stoppedOK) {
test.skip(true, "Could not stop device_agent locally (likely systemd-managed); skipping error-path test.");
return;
}
// give the agent a moment to notice the socket is dead
await new Promise((r) => setTimeout(r, 2_000));
try {
await sendMessage(page, "ejecuta hostname");
const reply = await waitForBotReply(page, {
timeout: REPLY_TIMEOUT_MS,
sender: SENDER_DISPLAY,
});
expect(reply).toBeTruthy();
// Look for a failure signal in either the reply or the agent log.
const errLogs = await fetchAgentLogs({
agentId: AGENT_ID,
sinceMinutes: 3,
limit: 200,
});
const sawConnErr = errLogs.some(
(e) =>
(e.level === "ERROR" || e.level === "WARN") &&
/connection|timeout|refused|unreachable|dial/i.test(
`${e.msg} ${e.err}`,
),
);
expect(
sawConnErr || /no pude|error|fall|conexi|no puedo/i.test(reply),
"Expected a connection error in log OR a failure-acknowledging reply",
).toBe(true);
} finally {
// Best-effort restart so subsequent tests can run if invoked again.
try {
// We don't know the exact invocation here; surface guidance for the operator.
console.warn(
"[C6] device_agent stopped. Restart manually: " +
"`cd projects/element_agents/apps/device_agent && ./device_agent --listen 10.42.0.10:7474 --audit /tmp/device_audit.db &`",
);
} catch {}
}
});
test("C7: hash chain integrity after C1-C3 calls", async () => {
const broken = await verifyHashChain({});
expect(
broken,
broken ? `Chain broken at id=${broken.id} cap=${broken.capability}` : "",
).toBeNull();
});
});
test.describe("agent-wsl-lucas — Capa 3: Vida util", () => {
test("V1: agents_and_robots.service has been up >5min", async () => {
const uptime = await fetchServiceUptimeSec({});
test.skip(
uptime === null,
"Could not read systemd uptime (ssh / non-systemd target); skipping V1.",
);
expect(uptime).toBeGreaterThan(5 * 60);
});
test("V2: this suite produced >=3 audit entries (tool calls really happened)", async () => {
const sinceSec = Math.max(
Math.floor((Date.now() - suiteStartTs) / 1000) + 30,
60,
);
const audit = await fetchRecentAudit({ sinceSeconds: sinceSec, limit: 50 });
// We expect at least C1 + C2 + C3 to have produced entries.
expect(audit.length).toBeGreaterThanOrEqual(3);
});
test("V3: reply latency p95 < threshold", async () => {
const latency = await measureReplyLatency({
agentId: AGENT_ID,
sinceMinutes: 30,
});
test.skip(latency === null, "No latency pair found in window; skipping V3.");
// claude-code subprocess can be slow on the VPS; threshold set per spec.
const THRESHOLD_MS = Number(process.env.AGENT_LATENCY_THRESHOLD_MS ?? 20_000);
expect(latency).toBeLessThan(THRESHOLD_MS);
});
});
test.describe("agent-wsl-lucas — Anti-criterios (DoD invalidators)", () => {
test("A1: no unexpected ERROR entries in agent log during suite window", async () => {
const sinceMin = Math.max(
Math.ceil((Date.now() - suiteStartTs) / 60_000) + 1,
2,
);
await assertNoErrors({
agentId: AGENT_ID,
sinceMinutes: sinceMin,
ignore: [
// The C6 test intentionally kills device_agent; tolerate that here.
/connection|dial|refused|unreachable|timeout|presence/i,
// Rate-limit warnings from matrix presence are not relevant
/M_LIMIT_EXCEEDED/i,
],
});
});
test("A2: hash chain intact end-to-end", async () => {
const broken = await verifyHashChain({});
expect(broken).toBeNull();
});
test("A3: every shell.exec / shell.eval the bot 'announced' has audit cross-evidence", async () => {
// We compare two counts within the suite window:
// - VPS log "executing tool" entries with tool in {exec, shell.eval, fs.list, ...}
// - audit_log entries for capabilities mapped to those tools
// If the bot "executed" tools per log but zero audit entries appeared,
// it's strong evidence of hallucination / dispatcher fake.
const sinceMin = Math.max(
Math.ceil((Date.now() - suiteStartTs) / 60_000) + 1,
2,
);
const traces = await findAnyToolCalls({
agentId: AGENT_ID,
sinceMinutes: sinceMin,
});
const meshTools = traces.filter((t) =>
/^(exec|shell\.eval|fs\.list|fs\.read|fs\.write|fs\.stat|git\.|pkg\.|proc\.|docker\.)/.test(
t.toolName,
),
);
if (meshTools.length === 0) {
test.skip(true, "No mesh tool calls in window; nothing to cross-check.");
return;
}
const audit = await fetchRecentAudit({
sinceSeconds: sinceMin * 60 + 30,
limit: 100,
});
expect(
audit.length,
`Bot log shows ${meshTools.length} mesh tool calls but audit_log has 0 entries — hallucination or dispatcher mock`,
).toBeGreaterThan(0);
});
});
+12 -13
View File
@@ -3,12 +3,16 @@ module github.com/enmanuel/agents
go 1.24.0
require (
github.com/charmbracelet/bubbletea v1.3.10
github.com/mark3labs/mcp-go v0.44.1
github.com/robfig/cron/v3 v3.0.1
github.com/sashabaranov/go-openai v1.36.1
github.com/spf13/cobra v1.8.1
golang.org/x/crypto v0.31.0
github.com/yuin/goldmark v1.7.16
golang.org/x/crypto v0.37.0
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.21.1
maunium.net/go/mautrix v0.23.3
modernc.org/sqlite v1.46.1
)
require (
@@ -16,7 +20,6 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
@@ -29,7 +32,7 @@ require (
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
@@ -38,28 +41,24 @@ require (
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/rs/zerolog v1.34.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yuin/goldmark v1.7.16 // indirect
go.mau.fi/util v0.8.1 // indirect
go.mau.fi/util v0.8.6 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/text v0.24.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.46.1 // indirect
)
+65
View File
@@ -0,0 +1,65 @@
module github.com/enmanuel/agents
go 1.24.0
require (
github.com/mark3labs/mcp-go v0.44.1
github.com/sashabaranov/go-openai v1.36.1
github.com/spf13/cobra v1.8.1
golang.org/x/crypto v0.31.0
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.21.1
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.34 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yuin/goldmark v1.7.16 // indirect
go.mau.fi/util v0.8.1 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.21.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.46.1 // indirect
)
+53 -26
View File
@@ -1,5 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
@@ -31,8 +33,12 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
@@ -48,10 +54,10 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mark3labs/mcp-go v0.44.1 h1:2PKppYlT9X2fXnE8SNYQLAX4hNjfPB0oNLqQVcN6mE8=
github.com/mark3labs/mcp-go v0.44.1/go.mod h1:YnJfOL382MIWDx1kMY+2zsRHU/q78dBg9aFb8W6Thdw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
@@ -69,8 +75,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw=
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a h1:S+AGcmAESQ0pXCUNnRH7V+bOUIgkSX5qVt2cNKCrm0Q=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -83,9 +89,9 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sashabaranov/go-openai v1.36.1 h1:EVfRXwIlW2rUzpx6vR+aeIKCK/xylSrVYAx1TMTSX3g=
github.com/sashabaranov/go-openai v1.36.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
@@ -95,15 +101,16 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
@@ -114,39 +121,59 @@ github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zI
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=
github.com/yuin/goldmark v1.7.16/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
go.mau.fi/util v0.8.1 h1:Ga43cz6esQBYqcjZ/onRoVnYWoUwjWbsxVeJg2jOTSo=
go.mau.fi/util v0.8.1/go.mod h1:T1u/rD2rzidVrBLyaUdPpZiJdP/rsyi+aTzn0D+Q6wc=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
go.mau.fi/util v0.8.6 h1:AEK13rfgtiZJL2YsNK+W4ihhYCuukcRom8WPP/w/L54=
go.mau.fi/util v0.8.6/go.mod h1:uNB3UTXFbkpp7xL1M/WvQks90B/L4gvbLpbS0603KOE=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mautrix v0.21.1 h1:Z+e448jtlY977iC1kokNJTH5kg2WmDpcQCqn+v9oZOA=
maunium.net/go/mautrix v0.21.1/go.mod h1:7F/S6XAdyc/6DW+Q7xyFXRSPb6IjfqMb1OMepQ8C8OE=
maunium.net/go/mautrix v0.23.3 h1:U+fzdcLhFKLUm5gf2+Q0hEUqWkwDMRfvE+paUH9ogSk=
maunium.net/go/mautrix v0.23.3/go.mod h1:LX+3evXVKSvh/b43BVC3rkvN2qV7b0bkIV4fY7Snn/4=
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.46.1 h1:eFJ2ShBLIEnUWlLy12raN0Z1plqmFX9Qe3rjQTKt6sU=
modernc.org/sqlite v1.46.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
+152
View File
@@ -0,0 +1,152 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mark3labs/mcp-go v0.44.1 h1:2PKppYlT9X2fXnE8SNYQLAX4hNjfPB0oNLqQVcN6mE8=
github.com/mark3labs/mcp-go v0.44.1/go.mod h1:YnJfOL382MIWDx1kMY+2zsRHU/q78dBg9aFb8W6Thdw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.34 h1:3NtcvcUnFBPsuRcno8pUtupspG/GM+9nZ88zgJcp6Zk=
github.com/mattn/go-sqlite3 v1.14.34/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw=
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sashabaranov/go-openai v1.36.1 h1:EVfRXwIlW2rUzpx6vR+aeIKCK/xylSrVYAx1TMTSX3g=
github.com/sashabaranov/go-openai v1.36.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=
github.com/yuin/goldmark v1.7.16/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
go.mau.fi/util v0.8.1 h1:Ga43cz6esQBYqcjZ/onRoVnYWoUwjWbsxVeJg2jOTSo=
go.mau.fi/util v0.8.1/go.mod h1:T1u/rD2rzidVrBLyaUdPpZiJdP/rsyi+aTzn0D+Q6wc=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mautrix v0.21.1 h1:Z+e448jtlY977iC1kokNJTH5kg2WmDpcQCqn+v9oZOA=
maunium.net/go/mautrix v0.21.1/go.mod h1:7F/S6XAdyc/6DW+Q7xyFXRSPb6IjfqMb1OMepQ8C8OE=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.46.1 h1:eFJ2ShBLIEnUWlLy12raN0Z1plqmFX9Qe3rjQTKt6sU=
modernc.org/sqlite v1.46.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
+33
View File
@@ -78,6 +78,27 @@ type DeviceMeshConfig struct {
// client_timeout_s; we accept both. When both set, ClientTimeoutS wins
// when non-zero.
ClientTimeoutS int `yaml:"client_timeout_s,omitempty"`
// ExposeViaMCP gates the MCP bridge (issue 0145). When the field is
// absent from YAML, the launcher defaults to "expose" (true) so an
// agent with device_mesh.enabled=true gets the bridge for free. The
// pointer shape lets us distinguish "unset" from "explicitly false";
// use ShouldExposeViaMCP() to read it.
ExposeViaMCP *bool `yaml:"expose_via_mcp,omitempty"`
}
// ShouldExposeViaMCP reports whether the launcher must build the MCP bridge
// for this device-mesh block. Returns false when the block is nil or not
// enabled; otherwise returns true unless ExposeViaMCP is explicitly false.
// Pure function — used by both the launcher and tests.
func (d *DeviceMeshConfig) ShouldExposeViaMCP() bool {
if d == nil || !d.Enabled {
return false
}
if d.ExposeViaMCP != nil {
return *d.ExposeViaMCP
}
return true
}
// ResolvedHost returns Host if non-empty, otherwise DeviceID. Used by the
@@ -211,6 +232,18 @@ type ClaudeCodeCfg struct {
AddDirs []string `yaml:"add_dirs"` // additional directories accessible
Streaming bool `yaml:"streaming"` // use --output-format stream-json for realtime progress
ShowToolProgress bool `yaml:"show_tool_progress"` // edit Matrix message to show tool usage progress
// MCPConfigPath points to a JSON file consumed by `claude -p --mcp-config`.
// Set at runtime by the launcher (issue 0145) when the agent has
// device_mesh.enabled=true and ExposeViaMCP. Empty means claude runs
// without external MCP servers. NEVER set in YAML — overrides the
// runtime-generated bridge.
MCPConfigPath string `yaml:"mcp_config_path,omitempty"`
// MCPServerName is the key inside the mcp-config JSON's "mcpServers"
// map. claude prefixes tool names exposed to the model as
// `mcp__<MCPServerName>__<tool>`. Defaults to "devicemesh" when empty.
MCPServerName string `yaml:"mcp_server_name,omitempty"`
}
type LLMReasoningCfg struct {
BIN
View File
Binary file not shown.
+15 -1
View File
@@ -449,7 +449,21 @@ func buildClaudeArgs(cfg config.ClaudeCodeCfg, req coretypes.CompletionRequest)
args = append(args, "--system-prompt", req.SystemPrompt)
}
if cfg.DisableTools {
// Issue 0145: --mcp-config tells claude where to find external MCP
// servers (per-agent devicemesh bridge). Must come BEFORE --allowedTools
// because the allowed list usually references `mcp__<server>__<tool>`
// names that only exist once the MCP config is loaded.
if cfg.MCPConfigPath != "" {
args = append(args, "--mcp-config", cfg.MCPConfigPath)
}
// Defensive: DisableTools=true plus a non-empty AllowedTools is a
// contradiction. The launcher's ApplyMCPBridge already forces
// DisableTools=false in that case, but this guard keeps direct callers
// safe too.
effectiveDisableTools := cfg.DisableTools && len(cfg.AllowedTools) == 0
if effectiveDisableTools {
args = append(args, "--tools", "")
} else {
if len(cfg.AllowedTools) > 0 {
+36 -6
View File
@@ -62,23 +62,53 @@ func TestBuildClaudeArgs_AllOptions(t *testing.T) {
}
func TestBuildClaudeArgs_DisableTools(t *testing.T) {
// DisableTools alone (no AllowedTools) → --tools "".
cfg := config.ClaudeCodeCfg{
DisableTools: true,
AllowedTools: []string{"Bash"}, // should be ignored
}
req := coretypes.CompletionRequest{}
args := buildClaudeArgs(cfg, req)
args := buildClaudeArgs(cfg, coretypes.CompletionRequest{})
assertContains(t, args, "--tools", "")
// --allowedTools must NOT appear when disable_tools is set
for _, a := range args {
if a == "--allowedTools" {
t.Error("--allowedTools should not appear when DisableTools=true")
t.Error("--allowedTools should not appear when DisableTools=true and AllowedTools is empty")
}
}
}
func TestBuildClaudeArgs_DisableToolsButAllowedToolsWins(t *testing.T) {
// Issue 0145: DisableTools=true plus a non-empty AllowedTools is a
// contradiction the launcher's ApplyMCPBridge guards against. The
// builder itself now also gives AllowedTools priority (precedence
// matches the launcher) so direct callers cannot accidentally produce
// the broken `--tools "" --allowedTools ...` combo.
cfg := config.ClaudeCodeCfg{
DisableTools: true,
AllowedTools: []string{"Bash"},
}
args := buildClaudeArgs(cfg, coretypes.CompletionRequest{})
for _, a := range args {
if a == "--tools" {
t.Error("--tools should not appear once AllowedTools is non-empty (AllowedTools wins)")
}
}
assertContains(t, args, "--allowedTools", "Bash")
}
func TestBuildClaudeArgs_MCPConfigPath(t *testing.T) {
// Issue 0145: --mcp-config is emitted whenever MCPConfigPath is set so
// claude knows how to spawn the per-agent devicemesh MCP server.
cfg := config.ClaudeCodeCfg{
MCPConfigPath: "/tmp/agent-x-mcp-config.json",
AllowedTools: []string{"mcp__devicemesh__exec"},
}
args := buildClaudeArgs(cfg, coretypes.CompletionRequest{})
assertContains(t, args, "--mcp-config", "/tmp/agent-x-mcp-config.json")
assertContains(t, args, "--allowedTools", "mcp__devicemesh__exec")
}
func TestBuildClaudeArgs_DisallowedTools(t *testing.T) {
cfg := config.ClaudeCodeCfg{
DisallowedTools: []string{"Edit", "Write"},
+3 -3
View File
@@ -407,7 +407,7 @@ type diagMachine interface {
OwnIdentity() *id.Device
ExportCrossSigningKeys() crypto.CrossSigningSeeds
ResolveTrustContext(ctx context.Context, device *id.Device) (id.TrustState, error)
IsDeviceTrusted(device *id.Device) bool
IsDeviceTrusted(ctx context.Context, device *id.Device) bool
}
// logCryptoDiagnostics logs the E2EE state after initialization.
@@ -512,7 +512,7 @@ func logDeviceTrust(ctx context.Context, machine diagMachine, device *id.Device,
logger.Info("e2ee diagnostics: own device trust state",
"device_id", device.DeviceID,
"trust_state", trust.String(),
"is_trusted", machine.IsDeviceTrusted(device),
"is_trusted", machine.IsDeviceTrusted(ctx, device),
)
if trust < id.TrustStateCrossSignedTOFU {
@@ -533,7 +533,7 @@ func truncateKey(key string) string {
// SetPresence sets the bot's presence status (online, unavailable, offline).
func (c *Client) SetPresence(ctx context.Context, status event.Presence) error {
return c.raw.SetPresence(ctx, status)
return c.raw.SetPresence(ctx, mautrix.ReqPresence{Presence: status})
}
// Raw returns the underlying mautrix.Client for advanced use.
+1 -1
View File
@@ -103,7 +103,7 @@ func (l *Listener) Run(ctx context.Context) error {
}
l.logger.Info("received room invite, joining", "room", evt.RoomID, "inviter", evt.Sender)
if _, err := l.client.raw.JoinRoom(ctx, evt.RoomID.String(), "", nil); err != nil {
if _, err := l.client.raw.JoinRoom(ctx, evt.RoomID.String(), nil); err != nil {
l.logger.Error("failed to auto-join room", "room", evt.RoomID, "err", err)
} else {
l.logger.Info("auto-joined room", "room", evt.RoomID)