Documentation
¶
Overview ¶
Package worker is the ogcode side of the remote-agent-workers control plane. It is a pure ConnectRPC *client*: it dials the master (the separate ogcode-control-plane service), authenticates with the shared pairing secret, and opens ONE long-lived bidi stream. Master->worker commands arrive down that stream and worker->master events/results go back up it — the worker never listens for inbound connections.
It hosts agent sessions by starting one full standalone ogcode server per worktree directory (server.NewWithOptions + Serve, see servers.go) and driving it through its exported HostSession/Guidance/ReplyPermission API — the same wiring a local `ogcode` run has, per directory. Nothing in this package alters ogcode's existing behavior — it only adds a new run-mode.
Index ¶
- func DefaultRepoRoot() string
- type Options
- type Worker
- func (w *Worker) DeprovisionRepo(repoURL string, removeClone bool) (string, error)
- func (w *Worker) EnsureRepo(ctx context.Context, repoURL string) (string, error)
- func (w *Worker) EnsureUserWorktree(repoDir, userName, baseBranch string) (string, string, error)
- func (w *Worker) MergeUserBranch(repoDir, userName, baseBranch string, push bool) (string, error)
- func (w *Worker) RemoveUserWorktree(repoDir, userName string) error
- func (w *Worker) Run(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRepoRoot ¶
func DefaultRepoRoot() string
DefaultRepoRoot is the fallback clone home when the operator does not pass --repo-root. Clones must sit under a configured --workspace root for discoverWorkspaces to pick up their user worktrees, so operators should normally point both at the same directory.
Types ¶
type Options ¶
type Options struct {
// MasterURL is the control-plane endpoint, e.g. "https://master:8443" (TLS)
// or "http://localhost:8443" (h2c, dev only).
MasterURL string
// PairingSecret must match the master's configured secret.
PairingSecret string
// WorkerName is a human-friendly label (defaults to the hostname).
WorkerName string
// Workspaces are the roots this worker offers; worktrees under them are
// discovered automatically.
Workspaces []string
// RepoRoot is where managed repo clones live (default ~/.ogcode/repos).
// For the clones' user worktrees to be discoverable and hostable, this
// must also be offered via --workspace — workspace containment refuses
// directories outside the configured roots.
RepoRoot string
// CACertPath, when set, is a PEM file of extra CA(s) to trust for the master's
// TLS certificate (for a self-signed or private-CA master). Public certs
// (e.g. Let's Encrypt) need nothing here.
CACertPath string
// Insecure skips TLS verification of the master. Development only.
Insecure bool
Logger *slog.Logger
}
Options configures a Worker.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is the running worker daemon.
func (*Worker) DeprovisionRepo ¶
DeprovisionRepo retires the managed repo repoURL: every remaining user worktree is removed (branches kept), and when removeClone is true the clone directory itself is deleted and the clone is forgotten from the repos map. Any hosted session inside a worktree about to be removed fails the whole command without removing anything. Returns a human summary of what was removed.
func (*Worker) EnsureRepo ¶
EnsureRepo returns the local clone directory for repoURL, cloning the repo on first use. One clone per repo per worker: every user of that repo works in a git worktree off this single checkout.
The clone lands under the worker's repo root (default ~/.ogcode/repos, or the --repo-root flag). It only becomes session-hostable when that root is also a configured --workspace: workspace containment (workspaceAllowed) refuses any hosted directory outside the registration-time roots.
Safe for concurrent callers; holds repoLock for the whole operation.
func (*Worker) EnsureUserWorktree ¶
EnsureUserWorktree returns (branch, dir) for userName's worktree off the repo at repoDir, creating it on first assignment: branch user/<name> checked out at <repoDir>/.ogcode/worktrees/user/<name>. The branch is cut from baseBranch when given (as written, or resolved as origin/<name> when the clone only knows it as a remote branch) and from the repo's default branch otherwise, so every user starts from the same place. Already-existing branches and worktrees are tolerated (idempotent backstop for a session start after assignment already provisioned them).
func (*Worker) MergeUserBranch ¶
MergeUserBranch merges the user/<slug> branch back into the repo's base branch and returns what happened ("merged", "already merged", or "merged+pushed"). The merge runs in a temporary worktree on the base branch (a mirror of internal/git's MergeTaskBranch, never disturbing the checked- out user worktrees), and a pushable origin receives the updated base best-effort — a failed push does not fail the merge.
func (*Worker) RemoveUserWorktree ¶
RemoveUserWorktree removes userName's worktree from the repo clone at repoDir, keeping the user's branch (the work survives on user/<slug> and can be merged later or re-checked out). A session still hosted in the worktree refuses the removal; a repo with no such worktree is a successful no-op.
func (*Worker) Run ¶
Run dials the master, authenticates (reusing a persisted token when valid, or re-pairing), and serves the command stream until ctx is cancelled. If the stream drops or a heartbeat is rejected, the worker loops and reconnects with capped backoff — a restarted master re-recognizes the worker's token, so reconnecting does not re-pair. It cleans up all hosted sessions and servers on exit.