feat(agent): cloud-side LLM agent for managed recovery #1

Open
hug wants to merge 3 commits from feat/managed-tunnel into main
Owner

Summary

Cloud-side agent that connects to the relay, registers MCP tools, and runs an OpenRouter tool-use loop.

Packages

  • internal/tools/register.go — MCP initialize + tools/list handshake → []openai.Tool
  • internal/loop/run.go — ReAct loop: stream LLM response, collect tool_call deltas, execute via MCP tools/call, feed results back; streams narration as SSE narration events; finish_reason=stop → session_done
  • internal/loop/config.goConfig{Model, OpenRouterKey, ApprovalTools}; default model google/gemini-2.5-flash
  • internal/approval/gate.goGate() sends approval_required SSE event and blocks on approvalCh; wired into loop before write-like tool calls
  • internal/portal/push.goPushEvents() drains eventCh to relay as push_event frames; buffers 256 events and reconnects on disconnect
  • cmd/recova-agent/main.go — entry point scaffold (loop wiring in future task)

Test plan

  • go test ./... passes (tools, loop MCP dispatch, approval gate x3, portal push)
  • go build ./... clean
## Summary Cloud-side agent that connects to the relay, registers MCP tools, and runs an OpenRouter tool-use loop. ### Packages - `internal/tools/register.go` — MCP initialize + tools/list handshake → `[]openai.Tool` - `internal/loop/run.go` — ReAct loop: stream LLM response, collect tool_call deltas, execute via MCP tools/call, feed results back; streams narration as SSE narration events; `finish_reason=stop` → session_done - `internal/loop/config.go` — `Config{Model, OpenRouterKey, ApprovalTools}`; default model `google/gemini-2.5-flash` - `internal/approval/gate.go` — `Gate()` sends approval_required SSE event and blocks on approvalCh; wired into loop before write-like tool calls - `internal/portal/push.go` — `PushEvents()` drains eventCh to relay as push_event frames; buffers 256 events and reconnects on disconnect - `cmd/recova-agent/main.go` — entry point scaffold (loop wiring in future task) ## Test plan - [ ] `go test ./...` passes (tools, loop MCP dispatch, approval gate x3, portal push) - [ ] `go build ./...` clean
internal/tools/register.go performs the MCP initialize + tools/list
handshake over a relay.Conn and converts the tool list to
[]openai.Tool for the OpenRouter function-calling loop.

cmd/recova-agent/main.go scaffolds the binary entry point; the
OpenRouter loop is wired in the t-agent-loop task.
internal/loop/run.go: Run() drives the ReAct loop — stream LLM response,
collect tool_call deltas, execute each via MCP tools/call JSON-RPC over
relay.Conn, feed results back. Streams narration tokens to eventCh as
SSETypeNarration events. Sends SSETypeSessionDone on finish_reason=stop.

Default model: google/gemini-2.5-flash via OpenRouter.
internal/approval/gate.go: Gate() sends approval_required SSE event and
blocks on approvalCh; returns true if decision is 'apply'. Loop wires it
before write-like tool calls (write/repair/fix/patch/restore keywords).

internal/portal/push.go: PushEvents() opens a relay.Conn and drains
eventCh as push_event WebSocket frames. Buffers up to 256 events on
disconnect and replays them after reconnect.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/managed-tunnel:feat/managed-tunnel
git switch feat/managed-tunnel

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff feat/managed-tunnel
git switch feat/managed-tunnel
git rebase main
git switch main
git merge --ff-only feat/managed-tunnel
git switch feat/managed-tunnel
git rebase main
git switch main
git merge --no-ff feat/managed-tunnel
git switch main
git merge --squash feat/managed-tunnel
git switch main
git merge --ff-only feat/managed-tunnel
git switch main
git merge feat/managed-tunnel
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hug/recova-agent!1
No description provided.