workspace

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 19 Imported by: 0

Documentation

Overview

Package workspace hydrates and maintains the multi-repo home directory (DBX-44, section 4.2b): skeleton files, repository clones with the naming rule, the home instruction file, Project.md's managed table and stubs, AddRepository, per-thread worktrees, and uploaded git bundles.

Index

Constants

View Source
const (
	BlockStart = "<!-- devbox:repos:start (managed by devbox-daemon; do not edit) -->"
	BlockEnd   = "<!-- devbox:repos:end -->"
)

Managed block markers in Project.md. The daemon only ever rewrites what's between them, and appends `### <repo>` stubs under "## Repositories"; it never rewrites prose.

View Source
const (
	// ProjectMD is the cross-repo map's file name in the home directory.
	ProjectMD = "Project.md"
	// ThreadsDir holds per-thread worktrees.
	ThreadsDir = ".threads"

	// DefaultCloneRetry is how long hydration keeps retrying clones that can't reach their remote.
	DefaultCloneRetry = 3 * time.Minute
)
View Source
const AgentsMD = `# Plural DevBox

You are working in a Plural DevBox: a sandbox whose home directory (~) holds every repository of this project as
sibling checkouts.

1. Read ~/Project.md before starting work, to learn which repositories exist and how they relate.
2. Every repository lives at ~/<repo>. To work on one that isn't there, clone it with ` + "`git clone <url> ~/<repo>`" + `.
   Never clone elsewhere (not under /tmp, not inside another repository), and never nest repositories.
3. After cloning a repository, or learning something durable about one, update its entry in ~/Project.md: what it
   is for, how to build and test it, and how it relates to the others.
4. Keep ~/Project.md a concise, current map, not a log: edit entries in place, remove what's stale, and mark
   guesses as unverified. Never record secrets, tokens or customer data. Don't edit the table between the
   devbox:repos markers; the sandbox maintains it.
5. Put cross-repo knowledge in ~/Project.md and repo-specific knowledge in that repository's own AGENTS.md, if it
   should be committed.

Network access goes through an egress gateway that injects credentials: don't configure tokens or API keys
yourself. Cloning a repository that isn't allowlisted fails with HTTP 403; report it instead of working around it.
`

AgentsMD is the home-directory instruction file (section 4.2b), read natively by Codex, OpenCode and Pi, and by Claude and Gemini through the CLAUDE.md / GEMINI.md symlinks.

Variables

This section is empty.

Functions

func NewProjectMD

func NewProjectMD(repos []RepoInfo) string

NewProjectMD is the initial Project.md for a fresh instance.

func RenderTable

func RenderTable(repos []RepoInfo) string

RenderTable renders the managed block (markers included).

func RepoName

func RepoName(raw string) (owner, repo string)

RepoName returns owner and repo from a clone URL.

func SameRemote

func SameRemote(a, b string) bool

SameRemote compares clone URLs ignoring scheme, credentials, case of the host and a .git suffix.

func UpdateProjectMD

func UpdateProjectMD(doc string, repos []RepoInfo) string

UpdateProjectMD regenerates the managed table and appends stubs for checkouts without a `### <repo>` entry under "## Repositories". Everything else is left byte-for-byte as it was.

Types

type Manager

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

Manager maintains the workspace.

func New

func New(opts Options) (*Manager, error)

New returns a Manager and loads the recorded workspace state.

func (*Manager) AddRepository

func (m *Manager) AddRepository(ctx context.Context, spec *devboxv1.RepositorySpec, key string) (*devboxv1.Checkout, error)

AddRepository clones a repository and registers it. Repeating an idempotency key returns the same checkout.

func (*Manager) ApplyBundle

func (m *Manager) ApplyBundle(ctx context.Context, name, remoteURL string, bundle io.Reader) (*devboxv1.Checkout, error)

ApplyBundle applies an uploaded `git bundle` of local commits to ~/<name> (the `plural devbox push` path): the bundle's branches land under refs/remotes/bundle/*, the current branch fast-forwards when it can, and other branches are created locally when absent. A missing checkout is cloned from the bundle.

func (*Manager) ApplySkel

func (m *Manager) ApplySkel() error

ApplySkel copies the image skeleton into the home directory once, without overwriting existing files.

func (*Manager) CheckoutInfo

func (m *Manager) CheckoutInfo() []*devboxv1.Checkout

CheckoutInfo returns the cached checkouts (for the instance aggregate).

func (*Manager) Checkouts

func (m *Manager) Checkouts() []string

Checkouts returns the main checkouts' paths (files.Checkouts).

func (*Manager) Clone

func (m *Manager) Clone(ctx context.Context, spec *devboxv1.RepositorySpec) (string, error)

Clone clones a repository into its directory (idempotent when it's already there).

func (*Manager) DirFor

func (m *Manager) DirFor(spec *devboxv1.RepositorySpec) (string, error)

DirFor applies the naming rule: ~/<repo>, or ~/<owner>-<repo> when ~/<repo> is another repository's.

func (*Manager) Hydrate

func (m *Manager) Hydrate(ctx context.Context, repos []*devboxv1.RepositorySpec) error

Hydrate prepares the workspace at boot: skeleton, instructions, clones (first boot only: a snapshot's workspace is already hydrated), and Project.md.

func (*Manager) Hydrated

func (m *Manager) Hydrated() bool

Hydrated reports whether the workspace was hydrated (on this or a previous boot, including a snapshot's).

func (*Manager) List

func (m *Manager) List(ctx context.Context, includeWorktrees bool) *devboxv1.ListRepositoriesResponse

List implements ListRepositories.

func (*Manager) ProjectMDPath

func (m *Manager) ProjectMDPath() string

ProjectMDPath is the absolute path of Project.md.

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context) error

Refresh rescans checkouts and regenerates Project.md's managed table and stubs.

func (*Manager) ThreadWorktrees

func (m *Manager) ThreadWorktrees(threadID string) []string

ThreadWorktrees returns a thread's worktree paths.

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context)

Watch keeps Project.md current: a watch on the home directory's top level, debounced, plus a periodic rescan.

func (*Manager) Worktrees

func (m *Manager) Worktrees(threadID string, repos []string) (string, error)

Worktrees creates ~/.threads/<id>/<repo> worktrees (branch devbox/<id>) and returns the session cwd: the worktree itself for one repository, else ~/.threads/<id>. ~/.threads/<id> gets Project.md and AGENTS.md symlinks so the thread still sees the cross-repo map.

func (*Manager) WriteInstructions

func (m *Manager) WriteInstructions() error

WriteInstructions writes ~/AGENTS.md and links ~/CLAUDE.md and ~/GEMINI.md to it. Existing regular files are left alone (the user owns them).

type Options

type Options struct {
	Home     string
	StateDir string
	// SkelDir is copied into the home directory on first boot without overwriting (/etc/devbox/skel).
	SkelDir string
	Log     *slog.Logger
	// Condition reports a daemon condition (hydration failures).
	Condition func(typ, severity, msg string, active bool)
	// OnChange is called after the checkout list changed.
	OnChange func()
	// CloneRetry bounds how long hydration retries clones that can't reach their remote (DefaultCloneRetry when
	// zero, none when negative).
	CloneRetry time.Duration
}

Options configure a Manager.

type RepoInfo

type RepoInfo struct {
	Checkout    *devboxv1.Checkout
	Description string
}

RepoInfo is one row of the managed table.

Jump to

Keyboard shortcuts

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