Skip to content

feat(mcp): expose Agent event stream and batch runtime status - #1133

Open
JoyaWang wants to merge 2 commits into
vastsa:mainfrom
JoyaWang:feat/mcp-agent-events
Open

JoyaWang wants to merge 2 commits into
vastsa:mainfrom
JoyaWang:feat/mcp-agent-events

Conversation

@JoyaWang

Copy link
Copy Markdown
Contributor

Summary

This PR adds an event-first status path for remote/local clients without changing the existing MCP POST contract or renderer IPC contract.

  • Add authenticated loopback GET /events SSE endpoint.
  • Forward the existing normalized AgentEventEnvelope from local sidecar, native-agent, and remote-host event paths.
  • Add bounded session filtering, subscriber limits, disconnect cleanup, and heartbeat frames.
  • Add agent/getStatuses and pi_agent_status_batch for one-call initial/reconnect snapshots.
  • Keep all existing permission/lifecycle validation on the Electron-main IPC path.
  • Update English and Chinese IPC specs and register E2E-221.

Why

The current mobile client must poll pi_agent_status and pi_session_get. That creates per-session RPC fan-out, adds visible latency, and loses intermediate retry/error/progress events. The new contract is subscribe-first, snapshot-on-start/reconnect, with polling only as a compatibility fallback for older transports.

Validation

  • pnpm --filter @pi-desktop/agent-runtime build — PASS
  • pnpm --filter @pi-desktop/shared build — PASS
  • pnpm --filter @pi-desktop/desktop typecheck — PASS
  • pnpm lint:biome — PASS
  • pnpm docs:check — PASS (81 English/Chinese pairs, 517 docs pages)
  • node --test apps/desktop/test/agent-events.test.mjs apps/desktop/test/mcp-control.test.mjs — 11/11 PASS
  • pnpm check:pr-base — PASS

Full Electron E2E was not run in this environment; E2E-221 documents the required candidate validation and remaining risk.

Refs: mocode #467

Add an authenticated loopback SSE endpoint that forwards the normalized Agent
EventEnvelope already consumed by the renderer. Add a bounded batch status
operation for initial snapshots and reconnects, keeping the existing MCP POST
contract and IPC permission path unchanged.

The event hub is process-memory only, filters by session, bounds subscribers,
and cleans up disconnected clients. Local sidecar, native agent, and remote
host event paths all feed the same hub. Update English/Chinese IPC specs and
register E2E-221 for event-first status delivery.

Refs: mocode vastsa#467
@JoyaWang

JoyaWang commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@vastsa — gentle ping on this one: it has been open since 2026-09-27 with all four CI jobs green and no review comments yet, so I suspect it may have slipped off the radar.

Where it stands:

  • feat(mcp): expose Agent event stream and batch runtime status — 13 files, +450/−27, head 2b9e25d95
  • CI: Docs checks / Head contains latest base / JS build+typecheck+lint+architecture+test / Rust host-core — all pass
  • Merge state was CLEAN at last check

It is the natural companion to #1014 (which exposes pending asktool questions): this one adds the Agent event stream plus a batched runtime-status read, so a remote client can follow a turn without polling per-entity calls.

If it needs a rebase onto the current main — main has moved a few hundred commits since this was opened — say the word and I will rebase, resolve, and re-run the same validation set I used for #1014. If the design needs changes, a review with the specific concerns is more useful to me than silence, and I am happy to iterate.

Thank you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant