feat: mensajes progresivos en Matrix con ProgressReporter

Implementa la Fase 2 del issue 0036: mensajes de progreso en tiempo real
que muestran al usuario que herramientas esta usando el agente claude-code.

- SendMarkdownGetID en shell/matrix/client.go: envia mensaje y retorna
  el event ID para editarlo despues
- EditMessage en shell/matrix/client.go: edita un mensaje existente
  usando m.replace (m.relates_to con rel_type=m.replace)
- ProgressReporter en shell/effects/progress.go (NEW): recibe streaming
  events y actualiza un mensaje unico en Matrix mostrando el progreso
  (e.g. "🔧 Bash: ls -la" → "🔧 Read: file.go" → " Completado")
- Rate limiter integrado: max 1 edit/segundo para no saturar el homeserver
- Conectado en devagents/handler.go: cuando provider=claude-code y
  streaming+show_tool_progress habilitados, crea ProgressReporter y
  pasa StreamFunc al CompletionRequest
- MatrixSender interface actualizada con los nuevos metodos
- 10 tests nuevos para ProgressReporter, todos los existentes pasan

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 22:58:03 +00:00
parent 1bdf9344a2
commit 45bd258be1
8 changed files with 482 additions and 8 deletions
+11 -1
View File
@@ -13,11 +13,14 @@ import (
coretypes "github.com/enmanuel/agents/pkg/llm"
"github.com/enmanuel/agents/pkg/personality"
"github.com/enmanuel/agents/shell/audit"
"github.com/enmanuel/agents/shell/effects"
shelllm "github.com/enmanuel/agents/shell/llm"
)
// runLLM executes the LLM completion loop, including iterative tool-use.
func (a *Agent) runLLM(ctx context.Context, msgCtx decision.MessageContext, memKey string) (string, error) {
// progress may be nil; when non-nil, its StreamFunc is attached to the request
// for providers that support streaming (claude-code).
func (a *Agent) runLLM(ctx context.Context, msgCtx decision.MessageContext, memKey string, progress *effects.ProgressReporter) (string, error) {
a.logger.Debug("calling LLM",
"model", a.cfg.LLM.Primary.Model,
"provider", a.cfg.LLM.Primary.Provider,
@@ -62,6 +65,12 @@ func (a *Agent) runLLM(ctx context.Context, msgCtx decision.MessageContext, memK
maxIter = defaultMaxToolIterations
}
// Resolve StreamFunc for providers that support streaming
var streamFn coretypes.StreamFunc
if progress != nil {
streamFn = progress.StreamFunc()
}
// Tool-use loop: call LLM → execute tools → feed results back → repeat
for i := 0; i < maxIter; i++ {
req := coretypes.CompletionRequest{
@@ -71,6 +80,7 @@ func (a *Agent) runLLM(ctx context.Context, msgCtx decision.MessageContext, memK
SystemPrompt: systemPrompt,
Messages: messages,
Tools: llmTools,
StreamFunc: streamFn,
}
resp, err := a.llm(ctx, req)