Documentation
¶
Overview ¶
Package deps implements the optional dependencies manager described in docs/proposals/multi-workspace-and-code-tab.md §7.
A Dependency is a named external service (e.g. a database container or a code-server instance) that the user can optionally start from the bcd Settings UI. The Registry holds the known dependencies; each one is a self-contained implementation that knows how to report its status and start/stop itself, typically by shelling out to `docker`.
The package is intentionally minimal: no goroutines, no watchers, no background loops. Callers (HTTP handlers, CLI, tests) invoke the methods synchronously and rely on the operating system (Docker) for the real lifecycle.
Index ¶
- Variables
- type BCBrowser
- func (*BCBrowser) Deprecated() bool
- func (*BCBrowser) Description() string
- func (*BCBrowser) DisplayName() string
- func (*BCBrowser) ID() string
- func (*BCBrowser) Logs(_ context.Context, _ int) ([]string, error)
- func (*BCBrowser) Start(_ context.Context) error
- func (*BCBrowser) Status(_ context.Context) (State, error)
- func (*BCBrowser) Stop(_ context.Context) error
- type BCCodeServer
- func (*BCCodeServer) Deprecated() bool
- func (*BCCodeServer) Description() string
- func (*BCCodeServer) DisplayName() string
- func (*BCCodeServer) ID() string
- func (d *BCCodeServer) Logs(ctx context.Context, tail int) ([]string, error)
- func (d *BCCodeServer) SetWorkspaceRoot(path string)
- func (d *BCCodeServer) Start(ctx context.Context) error
- func (d *BCCodeServer) Status(ctx context.Context) (State, error)
- func (d *BCCodeServer) Stop(ctx context.Context) error
- func (d *BCCodeServer) WorkspaceRoot() string
- type BCDB
- func (*BCDB) Deprecated() bool
- func (*BCDB) Description() string
- func (*BCDB) DisplayName() string
- func (*BCDB) ID() string
- func (d *BCDB) Logs(ctx context.Context, tail int) ([]string, error)
- func (d *BCDB) Start(ctx context.Context) error
- func (d *BCDB) Status(ctx context.Context) (State, error)
- func (d *BCDB) Stop(ctx context.Context) error
- type Dependency
- type Registry
- type State
Constants ¶
This section is empty.
Variables ¶
var ErrDeprecated = errors.New("dependency deprecated")
ErrDeprecated is returned by Start on deprecated dependencies.
var ErrNotFound = errors.New("dependency not found")
ErrNotFound is returned by Registry.Get when the ID is not registered.
Functions ¶
This section is empty.
Types ¶
type BCBrowser ¶
type BCBrowser struct{}
BCBrowser is a deprecated dependency kept in the registry for discoverability. The Claude Code browser plugin supersedes it.
func (*BCBrowser) Deprecated ¶
Deprecated implements Dependency.
func (*BCBrowser) Description ¶
Description implements Dependency.
func (*BCBrowser) DisplayName ¶
DisplayName implements Dependency.
type BCCodeServer ¶
type BCCodeServer struct {
// contains filtered or unexported fields
}
BCCodeServer wraps a code-server container that mounts the currently active workspace root at /home/coder/workspace.
The workspaceRoot is mutable because the active workspace can change while bcd is running — callers update it via SetWorkspaceRoot.
func NewBCCodeServer ¶
func NewBCCodeServer(workspaceRoot string) *BCCodeServer
NewBCCodeServer constructs the dependency bound to workspaceRoot.
func NewBCCodeServerWithRunner ¶
func NewBCCodeServerWithRunner(workspaceRoot string, r execRunner) *BCCodeServer
NewBCCodeServerWithRunner is used by tests.
func (*BCCodeServer) Deprecated ¶
func (*BCCodeServer) Deprecated() bool
Deprecated implements Dependency.
func (*BCCodeServer) Description ¶
func (*BCCodeServer) Description() string
Description implements Dependency.
func (*BCCodeServer) DisplayName ¶
func (*BCCodeServer) DisplayName() string
DisplayName implements Dependency.
func (*BCCodeServer) SetWorkspaceRoot ¶
func (d *BCCodeServer) SetWorkspaceRoot(path string)
SetWorkspaceRoot updates the directory that will be bind-mounted on the next Start. It does NOT restart an already-running container.
func (*BCCodeServer) Start ¶
func (d *BCCodeServer) Start(ctx context.Context) error
Start launches (or re-creates) the code-server container.
Since the bind-mounted directory depends on the active workspace, any existing container is removed so the new mount takes effect.
func (*BCCodeServer) Status ¶
func (d *BCCodeServer) Status(ctx context.Context) (State, error)
Status reports the container state. Unknown if docker is unreachable.
func (*BCCodeServer) Stop ¶
func (d *BCCodeServer) Stop(ctx context.Context) error
Stop stops and removes the container so Start can pick up a new mount.
func (*BCCodeServer) WorkspaceRoot ¶
func (d *BCCodeServer) WorkspaceRoot() string
WorkspaceRoot returns the currently configured workspace root.
type BCDB ¶
type BCDB struct {
// contains filtered or unexported fields
}
BCDB wraps the bc-db (unified TimescaleDB) Docker container. It is a singleton per host — one container shared by all workspaces — matching the design in docs/proposals/multi-workspace-and-code-tab.md §7.2.1.
func NewBCDB ¶
func NewBCDB() *BCDB
NewBCDB constructs a BCDB dependency using the default exec runner.
func NewBCDBWithRunner ¶
func NewBCDBWithRunner(r execRunner) *BCDB
NewBCDBWithRunner is the constructor used in tests to inject a mock exec runner.
func (*BCDB) Start ¶
Start ensures the bc-db container is running. If a container with the expected name already exists (running or stopped), it is reused via `docker start`; otherwise a fresh `docker run` is issued.
type Dependency ¶
type Dependency interface {
// ID is the stable short identifier, e.g. "bc-db".
ID() string
// DisplayName is the human-friendly name shown in the UI.
DisplayName() string
// Description is a one-line explanation of the dependency.
Description() string
// Status reports the current state of the dependency.
Status(ctx context.Context) (State, error)
// Start launches the dependency. It is safe to call when already running.
Start(ctx context.Context) error
// Stop halts the dependency. It is safe to call when already stopped.
Stop(ctx context.Context) error
// Logs returns up to tail lines of recent output, newest last.
Logs(ctx context.Context, tail int) ([]string, error)
// Deprecated reports whether the dependency is retained for
// discoverability only. Deprecated deps refuse Start.
Deprecated() bool
}
Dependency is the contract every optional service must satisfy.
Implementations are expected to be cheap to instantiate and to do all real work inside the interface methods so the registry itself can be built eagerly at server boot without side effects.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a small, concurrency-safe map of dependencies keyed by ID.
func (*Registry) Get ¶
func (r *Registry) Get(id string) (Dependency, error)
Get returns the dependency with the given ID, or ErrNotFound.
func (*Registry) List ¶
func (r *Registry) List() []Dependency
List returns every registered dependency sorted by ID for stable output.
func (*Registry) Register ¶
func (r *Registry) Register(d Dependency)
Register adds d to the registry, overwriting any existing entry with the same ID. Passing nil is a no-op.
type State ¶
type State string
State is the coarse runtime state of a dependency.
const ( StateRunning State = "running" StateStopped State = "stopped" StateStarting State = "starting" StateStopping State = "stopping" StateError State = "error" StateUnknown State = "unknown" )
Known state values. Implementations should stick to these so the UI can map them to colored status dots.