internal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAgent = &AgentManager{
	stop: make(chan struct{}),
	done: make(chan struct{}),
}

DefaultAgent is the singleton agent manager.

Functions

func AddCronJob

func AddCronJob(schedule, command, comment string) error

AddCronJob appends a new entry to the code-server crontab.

func AddService

func AddService(repoName, serviceName string, spec InfraService) error

AddService adds a service to a project's infra.json.

func AgentLastHeartbeat

func AgentLastHeartbeat() string

AgentLastHeartbeat returns when the last heartbeat was.

func AgentStatus

func AgentStatus() string

AgentStatus returns status for templates.

func AllocatePort

func AllocatePort() (int, error)

AllocatePort finds the next available port starting at 5002. Scans running Docker containers for used host ports.

func BinaryLogs

func BinaryLogs(repoName, serviceName string, lines int) (string, error)

BinaryLogs returns recent log output from a binary service.

func BinaryName

func BinaryName(repoName, serviceName string) string

BinaryName returns the binary path inside code-server for a service.

func BuildBinary

func BuildBinary(repoName, source string, serviceName string) error

BuildBinary builds a Go binary inside code-server.

func BuildImage

func BuildImage(contextPath, tag string, dockerfilePath ...string) error

BuildImage builds a Docker image from a context path. If dockerfilePath is non-empty, it specifies the Dockerfile location relative to contextPath.

func CloneRepository

func CloneRepository(repoURL, name string) error

CloneRepository clones a git repo into the code-server container.

func CoderExec

func CoderExec(command string) (string, error)

CoderExec runs a command inside the code-server container.

func CoderProxy

func CoderProxy() http.Handler

CoderProxy returns an HTTP reverse proxy to code-server.

func CoderRestart

func CoderRestart() error

CoderRestart stops and starts the code-server container.

func CommitInfra

func CommitInfra(repoName, message string) error

CommitInfra commits infra.json changes in the project's git repo.

func ContainerLogs

func ContainerLogs(name string, lines int) (string, error)

ContainerLogs returns recent log output.

func ContainerNameFor

func ContainerNameFor(repoName, serviceName string) string

ContainerNameFor returns the Docker container name for a project service.

func CreateProject

func CreateProject(name string, flags []string) error

CreateProject runs `congo init` to scaffold a new project in the repos directory. Flags are passed directly to congo init (e.g., "--no-frontend", "--no-assistant").

func DeleteRepository

func DeleteRepository(name string) error

DeleteRepository removes a repo from the filesystem and database.

func EnsureCoder

func EnsureCoder() error

EnsureCoder starts the code-server container if it isn't already running. Non-critical tools (Go, Node, Claude) log warnings on failure but don't prevent startup. Only the container itself is critical.

func EnsureCronDaemon

func EnsureCronDaemon()

EnsureCronDaemon installs cron if needed, starts the daemon, and restores persisted crontab from the data volume (survives container restarts).

func ImageNameFor

func ImageNameFor(repoName, serviceName string) string

ImageNameFor returns the Docker image name for a project service.

func InfraSummary

func InfraSummary(cfg *InfraConfig) string

InfraSummary returns a brief human-readable summary of the infra config.

func InitInfraCache

func InitInfraCache()

InitInfraCache loads all project infra.json files into memory. Call once at boot after code-server is ready.

func InitRepository

func InitRepository(name string) error

InitRepository creates a new empty git repo.

func IsAgentAvailable

func IsAgentAvailable() bool

IsAgentAvailable checks if Claude Code CLI is authenticated in the code-server.

func IsBinaryRunning

func IsBinaryRunning(repoName, serviceName string) bool

IsBinaryRunning checks if a binary process is alive.

func IsCoderRunning

func IsCoderRunning() bool

IsCoderRunning checks if the code-server container is running.

func IsContainerRunning

func IsContainerRunning(name string) bool

IsContainerRunning checks if a container is in running state.

func LocalRepoPath

func LocalRepoPath(coderPath string) string

LocalRepoPath translates a code-server repo path (/home/coder/repos/<name>) to the dev container's local path (DATA_DIR/repos/<name>). Docker operations (build, etc.) need paths accessible from this container.

func LogFile

func LogFile(repoName, serviceName string) string

logFile returns the log file path for a binary service.

func PullRepository

func PullRepository(repoName string) error

PullRepository fetches latest changes.

func RefreshInfraCache

func RefreshInfraCache(repoName string)

RefreshInfraCache reloads a single project's infra from disk into cache.

func RemoveContainer

func RemoveContainer(name string) error

RemoveContainer removes a container.

func RemoveCronJob

func RemoveCronJob(schedule, command string) error

RemoveCronJob removes a cron entry matching the given schedule and command.

func RemoveService

func RemoveService(repoName, serviceName string) error

RemoveService removes a service from a project's infra.json.

func RepoSlug

func RepoSlug(name string) string

RepoSlug converts a name to a URL-safe slug for use as a model ID.

func RunAgentChat

func RunAgentChat(message string) (string, error)

RunAgentChat sends a message to Claude Code CLI and returns the response. It builds context about the current infrastructure state and passes it along.

func RunBinary

func RunBinary(repoName, serviceName string, env map[string]string) error

RunBinary starts a binary as a background process inside code-server. env is a map of environment variables to set (e.g., PORT).

func RunContainer

func RunContainer(name, image string, opts RunOptions) error

RunContainer starts a new Docker container.

func SetupDomain

func SetupDomain(domain string) error

SetupDomain registers a domain as a system route. System routes tell autocert to issue TLS certs and identify the app's own domain. Safe to call multiple times.

func StartContainer

func StartContainer(name string) error

StartContainer starts a stopped container.

func StopBinary

func StopBinary(repoName, serviceName string) error

StopBinary kills a running binary process.

func StopContainer

func StopContainer(name string) error

StopContainer stops a running container.

func SyncFromFilesystem

func SyncFromFilesystem()

SyncFromFilesystem scans repos directory and syncs DB state.

func SystemDomain

func SystemDomain() string

SystemDomain returns the primary system domain, if one exists.

func TriggerFilePath

func TriggerFilePath() string

TriggerFilePath returns the path to the twin trigger file, accessible from both the dev container and the code-server container.

func UpdateService

func UpdateService(repoName, serviceName string, spec InfraService) error

UpdateService updates a service in a project's infra.json.

func WriteProjectInfra

func WriteProjectInfra(repoName string, cfg *InfraConfig) error

WriteProjectInfra writes infra.json to a project via the code-server container and updates the cache.

Types

type AgentManager

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

AgentManager runs work cycles using Claude Code in print mode. Each cycle: check tasks → do work → log results → heartbeat. The Monitor goroutine runs cycles and restarts on failure.

func (*AgentManager) IsAlive

func (m *AgentManager) IsAlive() bool

IsAlive returns whether a work cycle is currently running.

func (*AgentManager) Monitor

func (m *AgentManager) Monitor()

Monitor waits for code-server to be ready, then runs work cycles. Call Stop() to gracefully shut down.

func (*AgentManager) Stop

func (m *AgentManager) Stop()

Stop signals the monitor to shut down and waits for it to finish.

type ContainerInfo

type ContainerInfo struct {
	ID      string `json:"ID"`
	Name    string `json:"Names"`
	Image   string `json:"Image"`
	Status  string `json:"Status"`
	State   string `json:"State"`
	Ports   string `json:"Ports"`
	Created string `json:"CreatedAt"`
}

ContainerInfo holds Docker container details.

func InspectContainer

func InspectContainer(name string) (*ContainerInfo, error)

InspectContainer returns container details.

func ListContainers

func ListContainers() ([]*ContainerInfo, error)

ListContainers returns all Docker containers.

type CronJob

type CronJob struct {
	Schedule string // e.g. "*/5 * * * *"
	Command  string // e.g. "cd /home/coder/repos/myapp && go test ./..."
	Comment  string // from preceding # comment line
}

CronJob represents a parsed crontab entry.

func ListCronJobs

func ListCronJobs() []CronJob

ListCronJobs reads cron entries from the code-server container.

func (CronJob) Describe

func (j CronJob) Describe() string

Describe returns a human-readable schedule description for common patterns.

type DomainDNSStatus

type DomainDNSStatus struct {
	Resolves   bool   // Domain resolves in DNS
	PointsHere bool   // Resolves to this server's IP
	ResolvedIP string // What IP it resolved to
	ServerIP   string // This server's IP
}

DomainDNSStatus describes whether a domain resolves to this server.

func CheckDomainDNS

func CheckDomainDNS(host string) *DomainDNSStatus

CheckDomainDNS verifies if a domain points to this server's IP.

type InfraConfig

type InfraConfig struct {
	Platforms map[string]InfraPlatform   `json:"platforms,omitempty"`
	Servers   map[string]InfraServer     `json:"servers,omitempty"`
	Services  map[string]InfraService    `json:"services,omitempty"`
	Instances map[string][]InfraInstance `json:"instances,omitempty"`
}

InfraConfig mirrors the CLI's infra.json structure. The dev platform uses this as the source of truth for service definitions.

func ReadProjectInfra

func ReadProjectInfra(repoName string) (*InfraConfig, error)

ReadProjectInfra returns the cached infra config, falling back to disk.

type InfraInstance

type InfraInstance struct {
	ID     string `json:"id,omitempty"`
	Name   string `json:"name"`
	IP     string `json:"ip,omitempty"`
	Region string `json:"region,omitempty"`
}

type InfraPlatform

type InfraPlatform struct {
	Provider string `json:"provider"`
	Token    string `json:"token,omitempty"`
	Region   string `json:"region,omitempty"`
}

type InfraPort

type InfraPort struct {
	Host      int    `json:"host"`
	Container int    `json:"container"`
	Bind      string `json:"bind,omitempty"`
}

type InfraServer

type InfraServer struct {
	Platform string        `json:"platform,omitempty"`
	Size     string        `json:"size"`
	Setup    string        `json:"setup,omitempty"`
	Volumes  []InfraVolume `json:"volumes,omitempty"`
	Services []string      `json:"services,omitempty"`
}

type InfraService

type InfraService struct {
	Image       string             `json:"image,omitempty"`
	Source      string             `json:"source,omitempty"`
	Setup       string             `json:"setup,omitempty"`
	Command     []string           `json:"command,omitempty"`
	Ports       []InfraPort        `json:"ports,omitempty"`
	Volumes     []InfraVolumeMount `json:"volumes,omitempty"`
	Env         map[string]string  `json:"env,omitempty"`
	EnvFiles    map[string]string  `json:"env_files,omitempty"`
	Network     string             `json:"network,omitempty"`
	Healthcheck string             `json:"healthcheck,omitempty"`
	Privileged  bool               `json:"privileged,omitempty"`
	Domain      string             `json:"domain,omitempty"`
}

type InfraVolume

type InfraVolume struct {
	Name  string `json:"name"`
	Size  int    `json:"size,omitempty"`
	Mount string `json:"mount"`
}

type InfraVolumeMount

type InfraVolumeMount struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

type LocalService

type LocalService struct {
	RepoName      string       // project name
	RepoID        string       // repository ID for linking
	Name          string       // service name (key in infra.json services map)
	Spec          InfraService // full spec from infra.json
	ContainerName string       // Docker container name: "{repo}-{service}"
	Status        string       // running/stopped/not_deployed (from Docker or binary process)
	Mode          string       // "docker", "binary", or "" (not_deployed)
	ContainerPort int          // port the app listens on inside the container
	ExposedPorts  []InfraPort  // explicit host port bindings (edge cases like SMTP)
	Domain        string       // from Domain records
	Image         string       // Docker image name
}

LocalService combines an infra.json service definition with runtime Docker state.

func AllLocalServices

func AllLocalServices() []LocalService

AllLocalServices returns all services from all projects' cached infra configs combined with live Docker state.

func GetService

func GetService(repoName, serviceName string) (*LocalService, error)

GetService returns a single service by repo name and service name from cache.

func ProjectServices

func ProjectServices(repoName, repoID string) []LocalService

ProjectServices returns services for a specific project from cache.

func (*LocalService) Slug

func (s *LocalService) Slug() string

Slug returns a URL-safe identifier for this service.

type RunOptions

type RunOptions struct {
	Network string
	Ports   map[int]int       // host:container
	Volumes map[string]string // host:container
	Env     map[string]string
	Restart string // "always", "unless-stopped"
	Detach  bool
	Command []string
}

RunOptions configures docker run.

type RunningContainer

type RunningContainer struct {
	Name     string // container name
	Image    string // Docker image
	Status   string // human-readable uptime from docker ps
	Ports    string // raw port mapping string
	Domain   string // domain if mapped
	RepoName string // project name, empty for standalone infrastructure
	SvcName  string // service name from infra.json, empty for standalone
}

RunningContainer represents a Docker container for dashboard display.

func AllRunningContainers

func AllRunningContainers() []RunningContainer

AllRunningContainers returns all running Docker containers enriched with project and domain information for dashboard display.

func (RunningContainer) ShortPorts

func (c RunningContainer) ShortPorts() string

ShortPorts formats the docker ps Ports field into a compact display. Deduplicates IPv4/IPv6 bindings (e.g. 0.0.0.0:5001->5000 and :::5001->5000).

type SystemStats

type SystemStats struct {
	Hostname    string
	OS          string
	Arch        string
	NumCPU      int
	CPUPercent  int
	MemTotal    string
	MemUsed     string
	MemPercent  int
	DiskTotal   string
	DiskUsed    string
	DiskPercent int
	DataTotal   string // data volume (if separate from root)
	DataUsed    string
	DataPercent int
	HasDataDisk bool // true when data dir is on a different filesystem
	LoadAvg     string
}

SystemStats holds system resource information.

func GetSystemStats

func GetSystemStats() *SystemStats

GetSystemStats reads system metrics from /proc and syscall.

Jump to

Keyboard shortcuts

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