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
- func NewProjectMD(repos []RepoInfo) string
- func RenderTable(repos []RepoInfo) string
- func RepoName(raw string) (owner, repo string)
- func SameRemote(a, b string) bool
- func UpdateProjectMD(doc string, repos []RepoInfo) string
- type Manager
- func (m *Manager) AddRepository(ctx context.Context, spec *devboxv1.RepositorySpec, key string) (*devboxv1.Checkout, error)
- func (m *Manager) ApplyBundle(ctx context.Context, name, remoteURL string, bundle io.Reader) (*devboxv1.Checkout, error)
- func (m *Manager) ApplySkel() error
- func (m *Manager) CheckoutInfo() []*devboxv1.Checkout
- func (m *Manager) Checkouts() []string
- func (m *Manager) Clone(ctx context.Context, spec *devboxv1.RepositorySpec) (string, error)
- func (m *Manager) DirFor(spec *devboxv1.RepositorySpec) (string, error)
- func (m *Manager) Hydrate(ctx context.Context, repos []*devboxv1.RepositorySpec) error
- func (m *Manager) Hydrated() bool
- func (m *Manager) List(ctx context.Context, includeWorktrees bool) *devboxv1.ListRepositoriesResponse
- func (m *Manager) ProjectMDPath() string
- func (m *Manager) Refresh(ctx context.Context) error
- func (m *Manager) ThreadWorktrees(threadID string) []string
- func (m *Manager) Watch(ctx context.Context)
- func (m *Manager) Worktrees(threadID string, repos []string) (string, error)
- func (m *Manager) WriteInstructions() error
- type Options
- type RepoInfo
Constants ¶
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.
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 )
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 ¶
NewProjectMD is the initial Project.md for a fresh instance.
func RenderTable ¶
RenderTable renders the managed block (markers included).
func SameRemote ¶
SameRemote compares clone URLs ignoring scheme, credentials, case of the host and a .git suffix.
func UpdateProjectMD ¶
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 (*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 ¶
ApplySkel copies the image skeleton into the home directory once, without overwriting existing files.
func (*Manager) CheckoutInfo ¶
CheckoutInfo returns the cached checkouts (for the instance aggregate).
func (*Manager) Clone ¶
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 ¶
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 ¶
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 ¶
ProjectMDPath is the absolute path of Project.md.
func (*Manager) Refresh ¶
Refresh rescans checkouts and regenerates Project.md's managed table and stubs.
func (*Manager) ThreadWorktrees ¶
ThreadWorktrees returns a thread's worktree paths.
func (*Manager) Watch ¶
Watch keeps Project.md current: a watch on the home directory's top level, debounced, plus a periodic rescan.
func (*Manager) Worktrees ¶
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 ¶
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.