bridgeclient

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package bridgeclient is the daemon side of the bridge protocol: it connects an outbound websocket to ccproxy, accepts RPCs from the server, and executes them against the local filesystem rooted at --root.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auditor

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

Auditor appends one JSON line per RPC to a log file. Best-effort: write errors are dropped so a misbehaving filesystem can't crash the daemon.

func NewAuditor

func NewAuditor(path string) (*Auditor, error)

NewAuditor opens the log at path (creating the directory if needed) in append mode. Pass an empty path to disable auditing — the returned Auditor will be a no-op.

func (*Auditor) Close

func (a *Auditor) Close() error

Close flushes and releases the file. Idempotent.

func (*Auditor) Log

func (a *Auditor) Log(method, path, result string)

Log writes one entry. The entry is a flat object so jq-friendly tooling can filter on method/path easily.

type Client

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

Client is a single bridge connection. Use Run to dial and serve until the context is cancelled or the server disconnects.

func New

func New(opts Options, handlers Handlers, log loggerFunc) *Client

New returns an initialized client. The handlers parameter must not be nil; pass NewStubHandlers() for protocol-only testing.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run dials the server and serves frames until ctx is cancelled or the connection terminates. Returns nil on clean shutdown, error otherwise.

type ConfirmFunc

type ConfirmFunc func(op, path string) bool

ConfirmFunc is called before any write/exec RPC. Return false to deny. The op string is short and human-readable: "write", "remove", "exec", etc.

type EventEmitter

type EventEmitter interface {
	// contains filtered or unexported methods
}

EventEmitter is what the watcher uses to publish notifications back to the server. The daemon's connection (a *daemonSession) implements it.

type FSHandlers

type FSHandlers struct {
	Root         string
	MaxFileBytes int64       // reject reads above this; 0 = unlimited
	Ignore       *IgnoreList // optional; nil disables denylist
	Confirm      ConfirmFunc // optional; nil auto-approves
}

FSHandlers implements Handlers against a real filesystem rooted at Root. All input paths are interpreted relative to Root and clamped — any path that, after Clean+EvalSymlinks, escapes Root returns ErrCodeOutOfRoot.

func NewFSHandlers

func NewFSHandlers(root string) *FSHandlers

NewFSHandlers builds an FSHandlers with a 32 MiB default file size limit.

func (*FSHandlers) Chmod

func (*FSHandlers) Create

func (*FSHandlers) Exec

func (*FSHandlers) Mkdir

func (*FSHandlers) Read

func (*FSHandlers) ReadDir

func (*FSHandlers) Remove

func (*FSHandlers) Rename

func (*FSHandlers) Stat

func (*FSHandlers) Write

type Handlers

Handlers is the set of FS operations the daemon exposes. A stub is available via NewStubHandlers for protocol-only testing.

func NewStubHandlers

func NewStubHandlers() Handlers

type IgnoreList

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

IgnoreList is a glob-pattern allowlist/denylist read from a .ccproxyignore file at the daemon's root. It uses the same simplified semantics as .gitignore: blank lines and lines starting with `#` are comments; trailing slashes mark directory-only patterns; patterns are matched with filepath.Match against each path segment.

Defaults always denied even if no .ccproxyignore exists:

.ssh, .aws, .gnupg, id_rsa*, id_ed25519*, .env*

func LoadIgnore

func LoadIgnore(root string) (*IgnoreList, error)

LoadIgnore reads .ccproxyignore from root (if present) and merges with the built-in deny list.

func (*IgnoreList) Match

func (i *IgnoreList) Match(rel string) bool

Match reports whether rel (a path relative to root) hits any deny pattern. Hidden segments are matched independently so a pattern like `.ssh` denies `foo/.ssh/key`.

type Options

type Options struct {
	ServerURL   string // wss://host/bridge
	BearerToken string
	Root        string
	AllowWrite  bool
	AllowExec   bool
	Version     string
	// PingInterval is how often the daemon sends application-level keepalives
	// (server expects to see traffic regularly).
	PingInterval time.Duration
	// AuditPath, if non-empty, is the file the daemon appends one JSON
	// line per RPC to (audit log).
	AuditPath string
	// Watch enables fsnotify-backed change detection that streams
	// bridge.EventWatch frames back to the server.
	Watch bool
}

Options configures a daemon Client.

type StubHandlers

type StubHandlers struct{}

StubHandlers is a placeholder Handlers implementation that fails every call with ErrCodeUnsupported. Used to prove the protocol works before the real filesystem handlers land.

func (StubHandlers) Chmod

func (StubHandlers) Create

func (StubHandlers) Mkdir

func (StubHandlers) Remove

func (StubHandlers) Rename

type TTYConfirm

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

TTYConfirm prompts the user on stdin/stderr for each operation and returns the answer. Concurrent calls are serialized so prompts don't interleave.

func NewTTYConfirm

func NewTTYConfirm() *TTYConfirm

NewTTYConfirm wires the prompt to stderr+stdin. Returns nil if stdin isn't a terminal (no point prompting nobody) — caller should fall back to auto-approve.

func (*TTYConfirm) Ask

func (t *TTYConfirm) Ask(op, path string) bool

Ask blocks until the user answers y/Y or n/N. Default is no.

Jump to

Keyboard shortcuts

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