bridge

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: GPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CodeInvalidRequest   = "INVALID_REQUEST"
	CodeInternal         = "INTERNAL_ERROR"
	CodeRateLimited      = "RATE_LIMITED"
	CodeOperationExpired = "OPERATION_EXPIRED"
)

Variables

View Source
var (
	// ErrNotConnected 表示当前没有已配对的扩展连接。
	ErrNotConnected = errors.New("extension not connected")
	// ErrDisconnected 表示在途请求因扩展连接断开而作废。
	ErrDisconnected = errors.New("extension connection lost")
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Code        string `json:"code"`
	Message     string `json:"message"`
	OperationID string `json:"operationId,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type ErrorData

type ErrorData struct {
	Code        string `json:"code"`
	OperationID string `json:"operationId,omitempty"`
}

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      string          `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

Message is one JSON-RPC 2.0 request, notification, success response, or error response.

type RPCError

type RPCError struct {
	Code    int        `json:"code"`
	Message string     `json:"message"`
	Data    *ErrorData `json:"data,omitempty"`
}

type Request

type Request struct {
	ClientID string          `json:"clientId"`
	Action   string          `json:"action"`
	Input    json.RawMessage `json:"input"`
}

type Response

type Response struct {
	OK     bool            `json:"ok"`
	Result json.RawMessage `json:"result,omitempty"`
	Error  *Error          `json:"error,omitempty"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server 是桥接 daemon 的 WS 服务核心:accept、双向认证握手、envelope 路由与阻塞写模型。 v1 只允许一个扩展实例:新完成握手的连接替换旧连接。

信任模型是扁平的:接入(enrollment)建立唯一长期密钥 K 即确立信任,CLI 与所有 MCP agent 都 经这条可信通道继承信任,不再逐客户端配对/铸令牌/撤销(docs/threat-model.md)。

func NewServer

func NewServer(version string, p *protocol.Protocol, keys *store.KeyStore, log *zap.Logger) *Server

NewServer 用协议定义的常量与持久化后端构造服务。

func (*Server) Action

func (s *Server) Action(name string) (protocol.Action, bool)

Action 按名字查协议动作定义(scope 与读写属性),未知 action 返回 ok=false。

func (*Server) AuditSnapshot

func (s *Server) AuditSnapshot() []audit.Event

AuditSnapshot 返回守卫侧安全事件的快照。

func (*Server) BeginEnrollment

func (s *Server) BeginEnrollment() (display string, err error)

BeginEnrollment 打开一次接入窗口,返回展示形配对码(XXXX-XXXX)。供 sctl connect 使用; 码只在终端显示、绝不经 WS 下发给任何连接(docs/threat-model.md)。

func (*Server) Call

func (s *Server) Call(ctx context.Context, req Request) (Response, error)

Call 把一次 bridge action 转发给扩展并阻塞等待应答。write=true 的写调用可能挂起数分钟 (等待用户在浏览器审批)。调用方 ctx 取消 / 超过 writeDecisionTTL / 扩展断开时:

  • ctx 取消 / 超时:向扩展发 $/cancelRequest 作废该操作,返回相应错误;
  • 扩展断开:隐式作废全部在途请求,返回 ErrDisconnected。

func (*Server) ExtConnected

func (s *Server) ExtConnected() bool

ExtConnected 报告当前是否有完成握手的扩展连接。

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener, mux *http.ServeMux) error

Serve 在给定 listener 上运行 WS 服务,阻塞至 ctx 取消后优雅停机。 mux 由调用方提供并可预先挂载其他路径(组装层在此挂上 /control/*,见 internal/daemon); WS 面注册在根路径 "/"。

func (*Server) Version

func (s *Server) Version() string

Version 返回注入的 daemon 版本(hello.daemonVersion 与控制 API 都读它)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL