manager

package
v0.0.0-...-c5ded03 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 27 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

This section is empty.

Variables

View Source
var AccountFromRequest = func(r *http.Request) string { return "" }

AccountFromRequest resolves the caller account from one MCP HTTP request. cmd/manager installs the concrete resolver (static token -> default account; OAuth -> subject-derived account); without one every request maps to the default account.

Functions

func EmbeddedLegalTXT

func EmbeddedLegalTXT() []byte

EmbeddedLegalTXT exposes the legal notice for the plugin manifest routes.

func EmbeddedLogoPNG

func EmbeddedLogoPNG() []byte

EmbeddedLogoPNG exposes the brand logo for the plugin manifest routes.

func ServeEmbeddedAsset

func ServeEmbeddedAsset(data []byte, contentType string) http.HandlerFunc

ServeEmbeddedAsset is the exported handler factory for baked-in assets.

func ServeGRPC

func ServeGRPC(addr string, srv *GRPCAgentServer) (*grpc.Server, net.Listener, error)

ServeGRPC starts the agent gRPC listener with transport-level keepalive so half-open connections are detected in seconds, not by the 20s application heartbeat.

func ServerVersion

func ServerVersion(v string)

ServerVersion records the build version for per-request servers.

Types

type AccountResolver

type AccountResolver struct {
	Map map[string]string
}

AccountResolver binds OAuth subjects to tenant accounts.

func (*AccountResolver) ForSubject

func (a *AccountResolver) ForSubject(subject string) string

ForSubject resolves the account for an authenticated subject. An empty subject (OAuth disabled, local development) maps to the default account. Unmapped subjects resolve to their own account so no subject can reach another tenant's devices without an explicit operator mapping.

type AdminHandler

type AdminHandler struct {
	Auth       *authstore.Store
	Registry   *Registry
	AdminToken string
	Audit      *auditlog.Logger
	// AuditTail backs the admin UI's audit viewer; nil when the audit log
	// is stdout-only.
	AuditTail *AuditTailer
	// CallStore backs the MCP call history API; nil when CODEBRIDGE_MCP_DB
	// is unset.
	CallStore *mcpcallstore.Store
}

func (*AdminHandler) ServeAdminUI

func (h *AdminHandler) ServeAdminUI(w http.ResponseWriter, r *http.Request)

ServeAdminUI renders the admin page. Token auth is enforced client-side per API call (the page itself is static and secret-free).

func (*AdminHandler) ServeHTTP

func (h *AdminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*AdminHandler) ServePluginManifest

func (h *AdminHandler) ServePluginManifest(publicURL, resource, contactEmail string) http.HandlerFunc

type AgentConn

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

func (*AgentConn) Deliver

func (c *AgentConn) Deliver(requestID string, resp protocol.AgentResponse)

func (*AgentConn) DeliverEvent

func (c *AgentConn) DeliverEvent(requestID string, payload json.RawMessage)

DeliverEvent forwards a progress envelope to the pending request's hook.

func (*AgentConn) FailPending

func (c *AgentConn) FailPending(message string)

type AgentInput

type AgentInput struct {
	DeviceID       string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace      string `json:"workspace" jsonschema:"Workspace the subagent works in"`
	Task           string `json:"task" jsonschema:"Self-contained task description for the subagent"`
	Client         string `json:"client,omitempty" jsonschema:"Subagent harness: omp (default), opencode or codex"`
	Agent          string `json:"agent,omitempty" jsonschema:"opencode agent name, codex profile, or a subagent profile configured on the client"`
	Model          string `json:"model,omitempty" jsonschema:"Model override, provider/model format"`
	Thinking       string `json:"thinking,omitempty" jsonschema:"Reasoning effort: off, minimal, low, medium, high, xhigh, max"`
	TimeoutSeconds int    `json:"timeout_seconds,omitempty" jsonschema:"Optional wall-clock budget in seconds; 0 or omitted means no limit"`
}

type AgentRunIDInput

type AgentRunIDInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace the run belongs to"`
	RunID     string `json:"run_id" jsonschema:"Run ID returned by agent_start"`
}

AgentRunIDInput addresses one run started by agent_start.

type AgentRunsInput

type AgentRunsInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace to list runs for"`
	Limit     int    `json:"limit,omitempty" jsonschema:"Maximum runs to return; default 20, max 100"`
}

type AgentStartInput

type AgentStartInput struct {
	DeviceID       string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace      string `json:"workspace" jsonschema:"Workspace the subagent works in"`
	Task           string `json:"task" jsonschema:"Self-contained task description for the subagent"`
	Client         string `json:"client,omitempty" jsonschema:"Subagent harness: omp (default), opencode or codex"`
	Agent          string `json:"agent,omitempty" jsonschema:"Profile name from agents_list"`
	Model          string `json:"model,omitempty" jsonschema:"Model override, provider/model format"`
	Thinking       string `json:"thinking,omitempty" jsonschema:"Reasoning effort: off, minimal, low, medium, high, xhigh, max"`
	TimeoutSeconds int    `json:"timeout_seconds,omitempty" jsonschema:"Optional wall-clock budget in seconds; 0 or omitted means no limit"`
}

AgentStartInput accepts a long-running subagent task. It mirrors AgentInput, but the call returns as soon as the run is accepted; AgentRunIDInput and AgentRunsInput follow that run up.

type ApplyPatchInput

type ApplyPatchInput struct {
	DeviceID  string      `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string      `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	Edits     []PatchEdit `json:"edits" jsonschema:"All-or-nothing edits applied together"`
	Preview   bool        `json:"preview,omitempty" jsonschema:"Return the proposed diff without writing"`
	Confirm   bool        `json:"confirm,omitempty" jsonschema:"Required true to actually write"`
}

type AuditTailer

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

auditTailer reads the newest lines from the audit log for the UI. The manager wires it to the configured audit file; when the audit log goes to stdout (no file configured) the tailer stays nil and the UI hides the audit panel.

func NewAuditTailer

func NewAuditTailer(path string) *AuditTailer

func (*AuditTailer) Tail

func (t *AuditTailer) Tail(n int) []string

type BashInput

type BashInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	Command   string `json:"command" jsonschema:"Shell command to run in the workspace root"`
}

type Device

type Device struct {
	ID          string               `json:"id"`
	Name        string               `json:"name"`
	AccountID   string               `json:"account_id"`
	Version     string               `json:"version"`
	Online      bool                 `json:"online"`
	ConnectedAt time.Time            `json:"connected_at"`
	LastSeen    time.Time            `json:"last_seen"`
	Workspaces  []protocol.Workspace `json:"workspaces"`
	// ToolPolicy is the MCP method surface this device advertised at
	// registration; the Manager applies it when building tools/list.
	ToolPolicy *protocol.ToolPolicy `json:"tool_policy,omitempty"`
}

type DeviceInput

type DeviceInput struct {
	DeviceID string `json:"device_id" jsonschema:"ID of the connected device"`
}

type EditInput

type EditInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	Path      string `json:"path" jsonschema:"Workspace-relative file path"`
	// Write-only replaces the whole file content.
	Content string `json:"content,omitempty" jsonschema:"Full new file content (write mode)"`
	// Edit replaces exactly one occurrence of OldText with NewText.
	OldText string `json:"old_text,omitempty" jsonschema:"Exact current text to replace; must match once"`
	NewText string `json:"new_text,omitempty" jsonschema:"Replacement text"`
	// Preview/confirm mirror the two-step apply flow.
	Preview bool `json:"preview,omitempty" jsonschema:"Return the proposed diff without writing"`
	Confirm bool `json:"confirm,omitempty" jsonschema:"Required true to actually write"`
}

type GRPCAgentServer

type GRPCAgentServer struct {
	pb.UnimplementedAgentServiceServer
	Auth      *authstore.Store
	Registry  *Registry
	Audit     *auditlog.Logger
	RunEvents *RunEventBroker
	// contains filtered or unexported fields
}

GRPCAgentServer adapts the gRPC bidi stream onto the existing Registry, reusing the Registry's registration, account-binding and dispatch semantics. One stream equals one device session.

func (*GRPCAgentServer) Connect

Connect implements the device session: register, then relay envelopes.

type ListInput

type ListInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	Path      string `json:"path,omitempty" jsonschema:"Optional workspace-relative directory; default ."`
}

type PatchEdit

type PatchEdit struct {
	Path    string `json:"path" jsonschema:"Workspace-relative file path"`
	OldText string `json:"old_text,omitempty" jsonschema:"Exact current text; must match once (replace) or be the whole file (delete)"`
	NewText string `json:"new_text,omitempty" jsonschema:"Replacement text; empty deletes the file"`
}

PatchEdit is one all-or-nothing edit inside apply_patch: replace (old_text and new_text), create (new_text only) or delete (old_text only).

type PermissionGrantInput

type PermissionGrantInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device the request belongs to"`
	Workspace string `json:"workspace" jsonschema:"Workspace the request belongs to"`
	RequestID string `json:"request_id" jsonschema:"ID of the pending permission request reported by a blocked tool call"`
	// Once approves this single execution; always persists a rule; deny rejects.
	Decision string `json:"decision" jsonschema:"once, always, or deny"`
}

type ReadInput

type ReadInput struct {
	DeviceID  string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace string `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	Path      string `json:"path" jsonschema:"Workspace-relative file path"`
	MaxBytes  int    `json:"max_bytes,omitempty" jsonschema:"Optional byte cap; default 256 KiB"`
}

type Registry

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

func NewRegistry

func NewRegistry(maxInflight ...int) *Registry

func (*Registry) Call

func (r *Registry) Call(ctx context.Context, account, deviceID string, req protocol.AgentRequest) (json.RawMessage, error)

func (*Registry) CallProgress

func (r *Registry) CallProgress(ctx context.Context, account, deviceID string, req protocol.AgentRequest, onEvent func(json.RawMessage)) (json.RawMessage, error)

CallProgress is Call with a hook receiving live progress envelopes for the in-flight request (subagent event stream today).

func (*Registry) Disconnect

func (r *Registry) Disconnect(id string) bool

func (*Registry) Get

func (r *Registry) Get(id string) (*AgentConn, bool)

func (*Registry) List

func (r *Registry) List() []Device

func (*Registry) ListAccount

func (r *Registry) ListAccount(account string) []Device

ListAccount returns only devices that belong to the given account. It backs the MCP list_devices tool; admin surfaces use List for deployment-wide state.

func (*Registry) Put

func (r *Registry) Put(dev Device, ws streamConn) *AgentConn

func (*Registry) Remove

func (r *Registry) Remove(id string, target *AgentConn)

func (*Registry) Touch

func (r *Registry) Touch(id string)

func (*Registry) Workspaces

func (r *Registry) Workspaces(account, id string) ([]protocol.Workspace, error)

type RollbackPatchInput

type RollbackPatchInput struct {
	DeviceID     string `json:"device_id" jsonschema:"ID of the connected device"`
	Workspace    string `json:"workspace" jsonschema:"Workspace name exposed by the local agent"`
	CheckpointID string `json:"checkpoint_id" jsonschema:"Checkpoint ID returned by apply_patch, write or edit"`
}

type RunEventBroker

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

RunEventBroker tracks the highest contiguous Runtime-event sequence received for each account/device/run. It is intentionally metadata-only: the Client remains the durable event store and RT-004 replays any gap after reconnect.

func NewRunEventBroker

func NewRunEventBroker() *RunEventBroker

func (*RunEventBroker) Accept

func (b *RunEventBroker) Accept(account, deviceID string, ev protocol.RunEvent) (head int64, accepted bool, err error)

Accept ingests one event idempotently. Out-of-order events are held in a bounded pending set until the missing sequence arrives; duplicates are ignored. The returned head is the highest contiguous sequence now known.

func (*RunEventBroker) Head

func (b *RunEventBroker) Head(account, deviceID, runID string) int64

Head returns the highest contiguous sequence the Manager has accepted for one account/device/run. RT-004 uses this as the replay cursor on reconnect.

func (*RunEventBroker) Last

func (b *RunEventBroker) Last(account, deviceID, runID string) (protocol.RunEvent, bool)

Last returns the last event that advanced the contiguous head.

func (*RunEventBroker) Missing

func (b *RunEventBroker) Missing(account, deviceID string, heads []protocol.RunHead) (protocol.RunReplayRequest, error)

Missing returns the exact journal suffixes the Manager needs from one reconnecting Client. Entries already fully synchronized are omitted.

type ToolService

type ToolService struct {
	Registry    *Registry
	Accounts    *AccountResolver
	OAuthScopes []string
	Audit       *auditlog.Logger
	// CallStore persists MCP tool calls for the admin console (optional;
	// nil disables the query API, the JSONL audit log still records them).
	CallStore *mcpcallstore.Store
}

ToolService installs the MCP tool surface onto servers.

func (*ToolService) Register

func (t *ToolService) Register(server *mcp.Server)

Register installs every built-in tool onto the server.

func (*ToolService) RegisterOne

func (t *ToolService) RegisterOne(server *mcp.Server, name string)

RegisterOne installs a single built-in tool by name. Unknown names are a programming error.

func (*ToolService) ServerForRequest

func (t *ToolService) ServerForRequest(r *http.Request) *mcp.Server

ServerForRequest builds the MCP server for one HTTP request. The tool surface reflects the caller's account: a built-in tool is hidden only when every device of that account disabled it (intersection semantics, so one restrictive device cannot hide tools for the whole account), and custom tool wrappers from any of the account's devices are exposed (union).

Jump to

Keyboard shortcuts

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