How emprider/cursor-byok works
1. This repository is a cross-platform desktop application, not just a backend library. The top-level shape is: a Go runtime and local service layer, a Vue-based embedded UI, and several supporting subsystems for Cursor integration, model-provider routing, and network/proxy control.
2. The desktop shell is built around Wails 3. The frontend lives in frontend/ and is packaged into the Go app through generated Wails bindings under build/frontend/bindings/.... The UI pages (Home, Config, ModelConfig, ModelEditor) are driven by a small client API layer and shared app state, so the browser-like UI is only a presentation layer over backend-managed state.
3. The backend entry point is main.go plus internal/app. That layer owns application startup, tray/locale behavior, appdata path management, migration, and update lifecycle. It is the orchestration boundary for the whole desktop app.
4. The core control plane is internal/backend/server. It provides configuration management, request routing, local middleware/policy enforcement, and a notion of “upstream” communication. This is the part that likely exposes the local API the UI uses and coordinates access to external model services or Cursor services.
5. The most important execution pipeline is internal/backend/forwarder. This subsystem appears to be the agent/session engine: it handles prompts, tool catalogs, tool execution, file writes, shell recovery, compaction, runtime summaries, token accounting, replay/debug artifacts, and workspace/index maintenance. In architecture terms, it is the layer that turns UI/config input into agent actions and streamed results.
6. Agent behavior is split from forwarding mechanics in internal/backend/agent. That package contains:
- core for plan creation, tool arguments, and MCP-related logic,
- model adapters for providers such as OpenAI and Anthropic,
- prompt rendering/replay support,
- protocol and bridge layers for execution/interaction boundaries,
- step recording for tracing or replay.
This is the provider-agnostic agent abstraction layer.
7. Cursor-specific integration is handled by internal/cursor, internal/client, internal/bridge, and internal/mitm. These packages manage Cursor app state, device/cert handling, client lifecycle, licensing/config discovery, localization/window integration, and local relay behavior. The presence of internal/certs, internal/netproxy, and MITM code strongly suggests the app intercepts or reroutes Cursor’s network traffic through a local trusted proxy.
8. The runtime’s external I/O boundary is therefore local-first: the UI talks to the Go backend; the backend reads Cursor/app state and configuration; the proxy/cert layer can intercept requests; and the model adapter layer sends normalized requests to external model APIs. The main external services are model providers and whatever upstream Cursor-related API the project proxies or emulates.
9. There is a separate cursor-tab-server/ Go service. It is an auxiliary server with its own go.mod, config, Dockerfile, and README, so it should be treated as a standalone deployment unit rather than a library. It likely supports a specific browser/tab or extension workflow alongside the main desktop app.
10. Protocol compatibility is a first-class concern. The proto/ tree contains agent_v1.proto, aiserver_v1.proto, extracted extension protos, and helper tooling. This indicates the project preserves or reuses Cursor/extension wire contracts so it can interoperate with existing Cursor components and extension-style tooling.
11. The repo is heavily platform-aware. There are OS-specific implementations for macOS, Windows, and Linux in network proxy, certificates, packaging, tray behavior, and build scripts. The build/ tree contains Wails/build packaging, DMG, NSIS, MSIX, Docker cross-builds, and release workflow automation, so deployment differs by platform even though the application architecture is shared.
12. Operationally, the app also maintains local state and telemetry-like history data. internal/appdata, internal/historymetrics, and the related scripts suggest persisted config/history/usage data and reporting around cache or usage metrics. Those are supporting services around the main agent/proxy flow, not the primary user interaction path.
Main entry points: app App runtime · forwarder Forwarder · server Local server · frontend Vue UI
Components 19
Desktop shell
Wails-based desktop application UI and startup orchestration.
- App entry · Process bootstrap and top-level execution.
main.go - App runtime · App lifecycle, tray/locale behavior, migrations, and update coordination.
internal/app - Vue UI · Presentation layer with views, state, router, and client API.
frontend - Wails bindings · Generated frontend bindings used to connect the web UI to the Go backend.
build/frontend/bindings/github.com/wailsapp/wails/v3/internal - Updater · Versioning and update management for the desktop application.
internal/updater
Backend core
Local API, agent pipeline, and runtime services inside the Go app.
- Local server · Configuration, routing, middleware, and upstream coordination for the local API.
internal/backend/server - Forwarder · Core execution pipeline for prompts, tools, file writes, replay, and workspace maintenance.
internal/backend/forwarder - Agent core · Agent abstraction layer for plans, prompts, protocol boundaries, steps, and model adapters.
internal/backend/agent - Model routing · Normalization and routing for model providers such as OpenAI and Anthropic.
internal/backend/agent/model - Prompt system · Prompt templates, rendering, and replay support for agent interactions.
internal/backend/agent/prompt
Cursor integration
Cursor app state, client lifecycle, proxying, certs, and MITM relay.
- Cursor state · Cursor settings, device identity, and local state database access.
internal/cursor - Client lifecycle · License, lifecycle, config discovery, and model-adapter-related client behavior.
internal/client - Local bridge · Window, localization, metrics, and proxy-facing bridge helpers.
internal/bridge - MITM relay · Local relay service that participates in request interception and forwarding.
internal/mitm - Certs · Local certificate authority material used for trusted interception.
internal/certs - Net proxy · Platform-specific proxy control for redirecting local and external traffic.
internal/netproxy
Contracts
Protocol buffers and prompt assets that define external and agent-facing interfaces.
- Wire contracts · Agent and server protocol definitions plus extracted extension schemas.
proto - Prompt assets · Packaged prompts and tool manifests used by agent modes.
prompt
Auxiliary service
Standalone supporting server shipped alongside the main desktop app.
- Tab server · Standalone Go service with its own deployment and config for tab/extension workflows.
cursor-tab-server
Connections 20
- App entry → App runtime: boots · Main process starts the application runtime.
- App runtime → Vue UI: hosts · The runtime serves the embedded UI.
- Vue UI → Wails bindings: calls · UI actions use generated Wails bindings to reach Go services.
- Vue UI → Local server: uses API · Views and shared state are backed by the local control plane.
- App runtime → Local server: initializes · App startup wires the local backend server.
- Local server → Forwarder: dispatches · The control plane routes agent work into the execution pipeline.
- Forwarder → Agent core: invokes · Forwarder uses provider-agnostic agent logic for plans and tools.
- Agent core → Model routing: adapts · Agent logic normalizes provider-specific model interactions.
- Agent core → Prompt system: renders · Prompt templates and replay logic shape agent requests.
- Forwarder → Wire contracts: speaks · Pipeline respects protocol and compatibility contracts.
- Forwarder → Prompt assets: loads · Packaged prompts define behavior for different agent modes.
- App runtime → Updater: manages · Application runtime coordinates update lifecycle.
- App runtime → Local bridge: bridges · Desktop shell integrates window, localization, and metrics helpers.
- Local server → MITM relay: routes · Server-side policy can direct traffic through local relay behavior.
- MITM relay → Certs: trusts · MITM interception relies on local CA material.
- MITM relay → Net proxy: controls · Relay behavior depends on platform proxy control.
- Client lifecycle → Cursor state: reads state · Client lifecycle is tied to Cursor configuration and state.
- Local bridge → Net proxy: configures · Bridge helpers participate in proxy and window integration.
- Tab server → Wire contracts: compatible with · Auxiliary server participates in the same protocol ecosystem.
- Forwarder → Tab server: supports · Auxiliary service may feed or complement forwarder workflows.