deps

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrDeprecated = errors.New("dependency deprecated")

ErrDeprecated is returned by Start on deprecated dependencies.

View Source
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 NewBCBrowser

func NewBCBrowser() *BCBrowser

NewBCBrowser constructs the deprecated stub.

func (*BCBrowser) Deprecated

func (*BCBrowser) Deprecated() bool

Deprecated implements Dependency.

func (*BCBrowser) Description

func (*BCBrowser) Description() string

Description implements Dependency.

func (*BCBrowser) DisplayName

func (*BCBrowser) DisplayName() string

DisplayName implements Dependency.

func (*BCBrowser) ID

func (*BCBrowser) ID() string

ID implements Dependency.

func (*BCBrowser) Logs

func (*BCBrowser) Logs(_ context.Context, _ int) ([]string, error)

Logs returns an empty slice.

func (*BCBrowser) Start

func (*BCBrowser) Start(_ context.Context) error

Start refuses — the dependency is deprecated.

func (*BCBrowser) Status

func (*BCBrowser) Status(_ context.Context) (State, error)

Status always reports stopped.

func (*BCBrowser) Stop

func (*BCBrowser) Stop(_ context.Context) error

Stop is a no-op.

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) ID

func (*BCCodeServer) ID() string

ID implements Dependency.

func (*BCCodeServer) Logs

func (d *BCCodeServer) Logs(ctx context.Context, tail int) ([]string, error)

Logs returns the last `tail` lines from `docker logs`.

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) Deprecated

func (*BCDB) Deprecated() bool

Deprecated implements Dependency.

func (*BCDB) Description

func (*BCDB) Description() string

Description implements Dependency.

func (*BCDB) DisplayName

func (*BCDB) DisplayName() string

DisplayName implements Dependency.

func (*BCDB) ID

func (*BCDB) ID() string

ID implements Dependency.

func (*BCDB) Logs

func (d *BCDB) Logs(ctx context.Context, tail int) ([]string, error)

Logs returns the last `tail` lines from `docker logs`.

func (*BCDB) Start

func (d *BCDB) Start(ctx context.Context) error

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.

func (*BCDB) Status

func (d *BCDB) Status(ctx context.Context) (State, error)

Status inspects the container and reports running/stopped/unknown.

func (*BCDB) Stop

func (d *BCDB) Stop(ctx context.Context) error

Stop stops the bc-db container but does not remove it so data is retained on disk via the named volume.

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 NewRegistry

func NewRegistry() *Registry

NewRegistry constructs an empty registry.

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.

Jump to

Keyboard shortcuts

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