podagent

package
v0.191.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package podagent is the part of an agent pod's in-pod supervisor that does not depend on which agent runtime the pod runs: muster's agent-facing routes as the pod reaches them, git's routing through muster's connector proxy, and the agent's repository checkout.

Its user is cmd/ccd (the claude-code kind). The code was ccd's; it moved here unchanged in behaviour when a second supervisor needed the same rules. The messages a person reads name the supervisor that wrote them, through Voice.

Index

Constants

View Source
const (
	// GithubConnector is the connector git reaches GitHub through.
	GithubConnector = "github"

	// CheckoutRetry is how often a failed clone is retried. The grants are
	// re-read every GitSyncInterval, so a clone retried after an approval goes
	// through the proxy within CheckoutRetry + GitSyncInterval.
	CheckoutRetry = 30 * time.Second
	// CheckoutTimeout bounds one clone.
	CheckoutTimeout = 10 * time.Minute

	// GithubCloneBase is where a repository is cloned from. A test points git at
	// a local repository with url.<local>.insteadOf this prefix, exactly as the
	// connector routing does with muster's proxy.
	GithubCloneBase = "https://github.com/"
)
View Source
const (
	CheckoutCloning = agents.CheckoutCloning
	CheckoutFailed  = agents.CheckoutFailed
	CheckoutReady   = agents.CheckoutReady
	// CheckoutAwaitingGrant: a clone failed and this agent's github connector
	// request is pending (the supervisor just filed it, or it already was) —
	// the one state the owner's approval alone resolves.
	CheckoutAwaitingGrant = agents.CheckoutAwaitingGrant
)

The states /healthz reports under `repo`. They ARE internal/agents' constants: muster's kickoff deliverer reads this field (agents.DecideFirstTurn) and holds an agent's first turn, unsent and unstamped, while it reads cloning or awaiting_grant — so a spelling that drifted on either side would send the turn into a checkout that does not exist yet.

View Source
const (
	// DeployKeyHost and DeployKeyPort are the SSH endpoint the key is used with.
	DeployKeyHost = "ssh.github.com"
	DeployKeyPort = 443
)
View Source
const (
	// MirrorCloneMessage: the holder could not clone the repository with the key.
	MirrorCloneMessage = "" /* 165-byte string literal not displayed */
	// MirrorNoDefaultBranchMessage: the mirror has no default branch to probe with.
	MirrorNoDefaultBranchMessage = "the deploy-key holder's mirror of the repository has no default branch to probe the key's write access with; nothing was run"
	// DeployKeyWritableMessage: the key could open GitHub's receive-pack.
	DeployKeyWritableMessage = "" /* 193-byte string literal not displayed */
	// PullFetchMessage: the pull request's head could not be fetched.
	PullFetchMessage = "" /* 246-byte string literal not displayed */
	// BaseFetchMessage: the job's base_sha could not be fetched; the base follows.
	BaseFetchMessage = "" /* 206-byte string literal not displayed */
)

The messages MirrorScript fails with (each opens the error a job records).

View Source
const (
	// EnvHQMCP, set to "1", makes `ccd seed` offer the HQ MCP server.
	EnvHQMCP = "CCD_HQ_MCP"
	// HQConnector is the muster connector the server is reached through.
	HQConnector = "hq"
	// HQMCPServerName is the server's key in the CLI's mcpServers.
	HQMCPServerName = "hq"
	// HQCommand is the stdio server's program and arguments.
	HQCommand = "hq"
	// HQAllowEntry is the permissions.allow entry for every tool the server
	// serves (the CLI accepts a `*` in the tool position after a literal
	// mcp__<server>__ prefix in an allow rule).
	HQAllowEntry = "mcp__" + HQMCPServerName + "__*"
)
View Source
const (
	// EnvConnectURL is the base URL of muster's agent-facing connector surface,
	// set on the pod only when the deployment offers it.
	EnvConnectURL = "MUSTER_CONNECT_URL"
	// EnvAgentToken is the agent's OWN per-agent muster token.
	EnvAgentToken = "MUSTER_HOOK_TOKEN"
)
View Source
const (
	// EnvAllowMCPTools is a comma list of muster MCP tool names to pre-allow.
	EnvAllowMCPTools = "CCD_ALLOW_MCP_TOOLS"
	// EnvModel is the model the pod's primary Claude Code session runs
	// ("opus", "sonnet", a full model id); unset leaves the account's default.
	EnvModel = "CCD_MODEL"
	// EnvPermissionMode is the permission mode the pod's sessions start in:
	// unset is the image's default posture (prompts routed for approval,
	// bypass disabled); PermissionModeBypass is every tool allowed, no prompt.
	EnvPermissionMode = "CCD_PERMISSION_MODE"
	// PermissionModeBypass is EnvPermissionMode's one value: the CLI's own
	// bypassPermissions mode.
	PermissionModeBypass = "bypassPermissions"
	// EnvApproveUnanswered says what `ccd approve` does with a permission
	// prompt in a container where NOBODY can answer one: the Compose chief has
	// no approval gate and no terminal muster can reach, so a deferred prompt
	// would hang its turn for ever. Its one value is ApproveUnansweredDeny;
	// unset is today's behaviour (the relay, then the terminal). `ccd compose`
	// sets it in its child's environment itself (cmd/ccd/compose.go childEnv);
	// nothing else sets it.
	EnvApproveUnanswered = "CCD_APPROVE_UNANSWERED"
	// ApproveUnansweredDeny is EnvApproveUnanswered's one value: deny every
	// prompt that reaches the hook. The tools that must run are pre-allowed
	// (EnvAllowMCPTools) and never reach it.
	ApproveUnansweredDeny = "deny"
	// MCPServerName is muster's server name in the CLI's mcpServers
	// (cmd/ccd/connect.go registers it under this name).
	MCPServerName = "muster"
)
View Source
const AskImagePath = "/agent/officer/ask-images"

AskImagePath is muster's route an officer instance uploads an ask image to.

View Source
const GitHubKnownHosts = `` /* 858-byte string literal not displayed */

GitHubKnownHosts is the known_hosts content for DeployKeyHost:DeployKeyPort. MEASURED at the commit that introduced it: identical, key for key, to `ssh-keyscan -p 443 ssh.github.com` and to api.github.com/meta's ssh_keys.

View Source
const GitSyncInterval = 15 * time.Second

GitSyncInterval is how often the routing is re-read from the grants. One cheap GET.

View Source
const MirrorScript = `export LC_ALL=C GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="$3"
unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_PARAMETERS GIT_CONFIG_COUNT GIT_PROXY_COMMAND GIT_ASKPASS SSH_ASKPASS
url=$1 m=$2 pr=$4 base=$5
umask 022
mkdir -p "${m%/*}" || exit 1
if command -v flock >/dev/null 2>&1; then
	exec 9>"$m.lock" && flock 9 || exit 1
fi
if [ ! -f "$m/HEAD" ]; then
	t=$(mktemp -d "$m.XXXXXX") || exit 1
	if ! git clone --bare --quiet -- "$url" "$t/r"; then
		rm -rf "$t"
		echo "` + MirrorCloneMessage + `" >&2
		exit 13
	fi
	git -C "$t/r" config uploadpack.allowAnySHA1InWant true || { rm -rf "$t"; exit 1; }
	mv -T "$t/r" "$m" 2>/dev/null
	rm -rf "$t"
	[ -f "$m/HEAD" ] || exit 1
fi
[ -n "$pr" ] || exit 0
cd "$m" || exit 1
head=$(git rev-parse --verify --quiet 'HEAD^{commit}') ||
	{ echo "` + MirrorNoDefaultBranchMessage + `" >&2; exit 4; }
if git push --dry-run --quiet --no-verify "$url" "+$head:` + ReadOnlyProbeRef + `" >/dev/null 2>&1; then
	echo "` + DeployKeyWritableMessage + `" >&2
	exit 11
fi
git fetch --quiet --no-tags "$url" "+refs/pull/$pr/head:refs/pull/$pr/head" ||
	{ echo "` + PullFetchMessage + `" >&2; exit 8; }
if [ -n "$base" ]; then
	git fetch --quiet --no-tags --no-write-fetch-head "$url" "$base" && git cat-file -e "$base^{commit}" ||
		{ echo "` + BaseFetchMessage + ` (base_sha $base)" >&2; exit 12; }
fi`

MirrorScript runs in the KEY HOLDER, as its uid, with the key: $1 the repository's SSH URL (DeployKeyURL), $2 the mirror's path (a bare repository in the directory shared read-only with the agent's container), $3 GIT_SSH_COMMAND (DeployKeySSHCommand), $4 a pull request number ("" = only make sure the mirror exists), $5 a base commit to fetch ("" = none).

  1. Without a mirror, clone one (`--bare`) into a temporary directory beside it and rename it into place, so a reader sees no mirror or a whole one; `uploadpack.allowAnySHA1InWant`, so a job can fetch its base by id.
  2. With $4: PROBE the key for write access — a `git push --dry-run` of the mirror's default branch to ReadOnlyProbeRef. A dry run sends nothing; it only opens GitHub's receive-pack, which GitHub refuses for a read-only deploy key. Accepted: the key can push, exit 11 (DeployKeyWritableMessage). 🔴 THE REFSPEC IS FORCED ("+"): unforced, a branch of that name already on GitHub at a commit the default branch does not descend from is refused as a non-fast-forward BEFORE write access is asked, and a writable key read as read-only. A probe that fails for any other reason (the network) is not a refusal: the fetch then fails on its own.
  3. Fetch refs/pull/$4/head into the mirror at the same name (exit 8), and $5 by id (exit 12), for the job's worktree script to fetch from the mirror with no credential.

🔴 IT READS NO CONFIGURATION THE SESSION CAN WRITE. Its git directory is the mirror, which only this uid writes (the agent's container mounts it read-only); GIT_CONFIG_NOSYSTEM and GIT_CONFIG_GLOBAL=/dev/null drop the image's and $HOME's; the ssh command fixes every option (-F /dev/null, …). So a push URL, receive-pack or upload-pack program planted in the AGENT's checkout — which once made the probe exit 128 and a writable key read as read-only — is not seen here at all.

⚠ The key reaches no argv and no environment: ssh is given its PATH (IdentityFile=), and reads it itself, in this container.

Serialised by flock(1) on <mirror>.lock where the image has it (Debian's util-linux does): two jobs fetching one pull request's ref at once would otherwise fail one of them on git's ref lock.

View Source
const ReadOnlyProbeRef = "refs/heads/muster-read-only-probe"

ReadOnlyProbeRef is the ref the write probe dry-run-pushes to. Nothing is ever written there: a dry run sends no objects and updates no ref.

Variables

View Source
var ErrOutsideWorkspace = errors.New("the path is outside your workspace")

ErrOutsideWorkspace is a path that resolves outside the workspace root.

View Source
var HQArgs = []string{"mcp"}

HQArgs are HQCommand's arguments: `hq mcp`, every tool the token allows.

View Source
var NoRedirects = &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}

NoRedirects is the client every call to muster uses. 🔴 IT NEVER FOLLOWS A REDIRECT: Go's client resends custom headers (X-Muster-Token among them) to a redirect's target, even on another host. muster's agent routes do not redirect, so a redirect here is something to refuse, not to follow.

Functions

func AllowEntry added in v0.106.0

func AllowEntry(name string) string

AllowEntry is the permissions.allow entry for muster MCP tool name.

func ApplyGitRouting

func ApplyGitRouting(base, token string, c AgentConnector) (bool, error)

ApplyGitRouting brings one connector's routing in line with its grant and reports whether it wrote anything.

func BearerOK

func BearerOK(r *http.Request, want string) bool

BearerOK reports whether r carries `Authorization: Bearer <want>`.

The comparison is over SHA-256 digests with subtle.ConstantTimeCompare, so it takes the same time whatever the presented value's length or content.

func DeployKeySSHCommand added in v0.110.0

func DeployKeySSHCommand(keyPath, knownHostsPath string) (string, error)

DeployKeySSHCommand is GIT_SSH_COMMAND for a fetch with the key at keyPath, checking the server against the known_hosts file at knownHostsPath.

Every option a session could otherwise steer is fixed here: -F /dev/null (no ~/.ssh/config, which the session can write — a ProxyCommand there runs a command), no agent and only this identity (IdentityAgent=none, IdentitiesOnly=yes), the pinned hosts only (UserKnownHostsFile, GlobalKnownHostsFile=/dev/null, StrictHostKeyChecking=yes), no prompt (BatchMode=yes), and no proxy, multiplexing or local command.

⚠ GIT_SSH_COMMAND outranks core.sshCommand, which the checkout's own config (the session's) could set; it is set only on the git that fetches, never in an environment the session inherits.

func DeployKeyURL added in v0.110.0

func DeployKeyURL(repo string) string

DeployKeyURL is the SSH URL repository owner/name is cloned and fetched from with a deploy key.

func FormatAllowMCPTools added in v0.106.0

func FormatAllowMCPTools(names []string) (string, error)

FormatAllowMCPTools is the EnvAllowMCPTools value for names, refusing a name that is not a bare tool name.

func HQProxyURL added in v0.131.0

func HQProxyURL(base, host string) string

HQProxyURL is the base URL the hq client is given: the `hq` connector's prefix on muster's proxy for host. Every HQ API path is appended to it.

func HQServes added in v0.131.0

func HQServes(c AgentConnector) (host string, ok bool)

HQServes reports whether the server should be registered for this answer of GET /agent/connectors/hq, and with which host.

🔴 A GRANT OF "none" OR "pending" REGISTERS IT; ONLY denied AND revoked DO NOT. The chief has no connector_request tool: its grant is filed by its FIRST proxied call (connectors.Proxy.CheckAccess), which an owner's standing grant approves at once and otherwise puts in front of the owner. A gate on "approved" would therefore never open for the chief — nothing would ever file the request. The proxy, not this registration, decides every call.

func LastLines

func LastLines(s string, n, max int) string

LastLines is the last n non-empty lines of s, joined with "; ", control characters removed and capped at max bytes.

func MirrorHolderCommand added in v0.110.0

func MirrorHolderCommand(repo, mirrorPath, keyPath, knownHostsPath string) ([]string, error)

MirrorHolderCommand is the key holder's container command for repository owner/name, its mirror at mirrorPath, and the key and known_hosts at keyPath and knownHostsPath (DeployKeySSHCommand's refusals apply).

func MirrorUploadPack added in v0.110.0

func MirrorUploadPack(mirror string) (string, error)

MirrorUploadPack is the --upload-pack command for every fetch, clone and ls-remote the agent's container makes from the key holder's mirror at mirror (ccd's clone, the job script's fetches).

🔴 WHY UPLOAD-PACK'S OWN COMMAND LINE. The mirror is owned by the holder's uid, and git refuses another user's repository ("detected dubious ownership") unless safe.directory names it in protected configuration. For a local path git CLEARS the config environment before it spawns upload-pack, so `-c safe.directory=…` or GIT_CONFIG_* on the calling git never reach it, and git 2.39's upload-pack checks ownership itself (measured on the image's git 2.39.5: clone and fetch die with rc 128). Global and system config are off for muster's gits (GIT_CONFIG_GLOBAL=/dev/null, GIT_CONFIG_NOSYSTEM=1), and the global file is the session's to write anyway. So the `-c` goes on upload-pack's own command line, which git runs through a shell with the path appended. git 2.55 needs none of it, so only the image's smoke (images/claude-code-agent/deploykey-smoke.sh, which pins this string) can show the failure.

The path is interpolated into that shell command, so it is held to DeployKeySSHCommand's rule (absolute, A-Za-z0-9._/- only).

func MusterCall

func MusterCall(ctx context.Context, client *http.Client, method, base, token, path string, in, out any) (int, []byte, error)

MusterCall sends one request to muster's agent routes with the agent's own token, decoding a 2xx JSON answer into out (when non-nil), and reports the status. A non-2xx is NOT an error here: callers that branch on the status (the approval relay) read it; MusterGET and MusterPOST turn it into one. client nil is NoRedirects.

func MusterGET

func MusterGET(ctx context.Context, base, token, path string, out any) error

MusterGET reads one of muster's agent JSON routes into out. It is a GET and files nothing.

func MusterPOST

func MusterPOST(ctx context.Context, base, token, path string, body any) error

MusterPOST sends a JSON body to one of muster's agent routes.

func ParseAllowMCPTools added in v0.106.0

func ParseAllowMCPTools(v string) ([]string, error)

ParseAllowMCPTools turns an EnvAllowMCPTools value into permissions.allow entries (each "mcp__muster__<name>"), refusing the whole value if any name is not a bare tool name. "" is no entries.

func ParseHQMCP added in v0.131.0

func ParseHQMCP(v string) (bool, error)

ParseHQMCP reads an EnvHQMCP value: "" off, exactly "1" on, anything else an error (a value muster did not write is refused, never guessed at).

func ParseModel added in v0.106.0

func ParseModel(v string) (string, error)

ParseModel validates an EnvModel value; "" is unset.

func ParsePermissionMode added in v0.108.0

func ParsePermissionMode(v string) (bypass bool, err error)

ParsePermissionMode reads an EnvPermissionMode value: "" is the default posture, exactly PermissionModeBypass is bypass, and anything else — a near-miss spelling, surrounding space, another CLI mode — is an error. It is never trimmed or case-folded: a value muster did not write exactly is refused.

func ParseRepo

func ParseRepo(repo string) bool

ParseRepo reports whether repo is owner/name in the shape a checkout accepts.

func PromptFrom

func PromptFrom(raw json.RawMessage) (string, error)

PromptFrom extracts the LAST user message's text from `input`, which may be a bare string or an array of items whose content is a string or an array of {type: input_text|text, text} parts.

func ProxyPrefix

func ProxyPrefix(base, name string) string

ProxyPrefix is connector name's prefix on muster's proxy.

func RecordExit

func RecordExit(exits []time.Time, now time.Time, window time.Duration, maxExits int,
	backoffMin, backoffMax time.Duration) (kept []time.Time, delay time.Duration, latched bool)

RecordExit counts one exit at now against the exits already within window and decides what follows it: the delay before the next start, or (latched) no next start at all. It returns the exits still within the window, including this one.

func ResolveBearer

func ResolveBearer(who, hooksToken, gatewayBearer string) (string, error)

ResolveBearer decides the credential a pod supervisor's /v1/responses accepts. who names the supervisor in the error ("ccd").

🔴 THE DERIVATION IS muster's OWN FUNCTION, IMPORTED, NOT A COPY. The supervisors live in muster's module precisely so the `hooks-sha256` formula cannot drift between the side that sends the bearer (agentgateway.Gateway) and the side that checks it.

muster's agent spec ships BOTH the raw token (HOOKS_TOKEN) and the derived value (MUSTER_GATEWAY_BEARER). Either is enough; when both are present they must agree, because a pod holding two credentials that disagree would accept one and 401 the other, and which one muster sends is not this process's decision.

func ResolveWorkspaceFile added in v0.144.0

func ResolveWorkspaceFile(root, p string) (string, error)

ResolveWorkspaceFile is p resolved inside root, or an error: p relative is joined to root; every symlink on either is resolved; the result must be root itself's descendant (ErrOutsideWorkspace otherwise) and a regular file.

func RunGitRoutingLoop

func RunGitRoutingLoop(ctx context.Context, who, base, token string, interval time.Duration, logf func(string, ...any))

RunGitRoutingLoop runs SyncGitRouting now and every interval until ctx ends. A failed round (muster unreachable) leaves the routing as it is: with muster down the proxy is down too, and tearing the routing out would only make the next round's restore a change. who prefixes the log lines ("ccd").

func SyncGitRouting

func SyncGitRouting(ctx context.Context, base, token string) ([]string, error)

SyncGitRouting makes git's global config route exactly the connectors this agent holds an approved grant on, and nothing else under this muster's /connect/ prefix. It writes only what changed, so a git command running at the same moment never sees a routing torn down and rebuilt for nothing. It returns the names whose routing it changed.

func UploadAskImage added in v0.144.0

func UploadAskImage(ctx context.Context, client *http.Client, base, token, root, p string) (askimage.Record, error)

UploadAskImage sends workspace file p (ResolveWorkspaceFile against root) to muster at base as an ask image, with the agent's own token, and returns HQ's record of it. The type is sniffed from the file's leading bytes and must be one of askimage.Types; the size is capped at askimage.MaxBytes, before the upload (Stat) and while it streams. client nil is NoRedirects.

func ValidModel added in v0.106.0

func ValidModel(m string) error

ValidModel reports whether m is a model the session settings accept.

func WriteFailure

func WriteFailure(w http.ResponseWriter, f *Failure)

WriteFailure writes f as the response.

func WriteResponse

func WriteResponse(w http.ResponseWriter, id string, items []ReplyItem, stream bool)

WriteResponse writes a settled turn. The REPLY is the text segments (each its own message item; muster joins items with a blank line); tool calls are streamed as native tool items.

func WriteResponseUsage added in v0.191.0

func WriteResponseUsage(w http.ResponseWriter, id string, items []ReplyItem, usage *Usage, stream bool)

WriteResponseUsage is WriteResponse with the turn's token usage on response.completed's response (nil: none, as WriteResponse writes).

Types

type AgentConnector

type AgentConnector struct {
	Name   string   `json:"name"`
	Exists bool     `json:"exists"`
	Hosts  []string `json:"hosts"`
	Grant  string   `json:"grant"`
}

AgentConnector is the subset of muster's /agent/connectors answers read here.

func (AgentConnector) Usable

func (c AgentConnector) Usable() bool

Usable reports whether the connector exists and this agent's grant on it is approved.

type ApprovalDecision

type ApprovalDecision int

ApprovalDecision is what the relay concluded.

const (
	// ApprovalUndecided: no answer (the caller's fallback applies).
	ApprovalUndecided ApprovalDecision = iota
	ApprovalApproved
	ApprovalRejected
)

func ApprovalResponse

func ApprovalResponse(resp string) ApprovalDecision

ApprovalResponse maps the router's decision vocabulary onto a decision. 🔴 ONLY THE TWO SPELLINGS A HUMAN'S APPROVE CAN PRODUCE MAP TO APPROVED. Anything else, including "ignore" (a dismissed card) and an empty value, is undecided.

type ApprovalRelay

type ApprovalRelay struct {
	Base, Token string
	// Deadline bounds the wait for an answer.
	Deadline time.Duration
	Poll     time.Duration
	Client   *http.Client
	Logf     func(format string, args ...any)
	// Fallback names what the caller does with ApprovalUndecided, for the log
	// ("deferring", "denying"); TimeoutFallback is the same for the deadline
	// ("deferring to the terminal prompt").
	Fallback, TimeoutFallback string
}

ApprovalRelay files one prompt and waits for its answer.

func (ApprovalRelay) Decide

func (r ApprovalRelay) Decide(ctx context.Context, req map[string]any) ApprovalDecision

Decide files req (the body muster's POST /agent/approvals takes) and waits for the answer, clearing the card on every exit that is not a decision.

type Checkout

type Checkout struct {

	// Retry is how often a failed clone is retried.
	Retry time.Duration
	// Timeout bounds one clone; 0 is CheckoutTimeout.
	Timeout time.Duration
	Logf    func(string, ...any)
	// contains filtered or unexported fields
}

Checkout is one agent's repository checkout. Retry, Timeout and Logf may be changed before Run.

func NewCheckout

func NewCheckout(cfg CheckoutConfig) (*Checkout, error)

NewCheckout makes the checkout cfg describes, in state cloning. The caller has validated cfg.Repo with ParseRepo and made cfg.Dir absolute. It refuses a mirror path that is not a clean absolute one.

func (*Checkout) Attempt

func (c *Checkout) Attempt(ctx context.Context) error

Attempt makes the checkout exist: an existing one is used as it is; an empty (or absent) directory is cloned into; a directory holding anything else is refused rather than cloned over.

A failure of anything but git reaching GitHub is a *localError: the checkout's own files, and a clone command that failed on THIS side (localCloneFailure).

🔴 A CHECKOUT IS A .git WITH A COMMIT CHECKED OUT, NOT A .git. A clone that is killed (the timeout, the supervisor shutting down, the pod evicted) leaves a .git whose HEAD names no commit; treating that as ready would start the agent in an empty tree. So: the clone goes into a sibling scratch directory and is moved into place (moveCheckout, .git last) only once `git rev-parse --verify HEAD` succeeds there — a kill leaves the workspace untouched (the scratch directory is replaced on the next attempt) — and an existing .git counts only when HEAD verifies too. One with no HEAD (an interrupted clone by an older supervisor) is refused, not deleted: it never removes what it did not just create. The one exception is an EMPTY repository (emptyCloneKey).

func (*Checkout) Explain

func (c *Checkout) Explain(ctx context.Context, cloneErr error) (detail string, awaiting bool)

Explain is the operator-facing sentence for a failed clone: git's error, and what the `github` connector needs — filing this agent's request for it when it holds no grant (see the file comment). awaiting reports that the agent's request for the connector is pending — the one case the owner's approval alone resolves.

func (*Checkout) NotReady

func (c *Checkout) NotReady() string

NotReady is the not_ready message a turn gets while there is no checkout.

func (*Checkout) Ready

func (c *Checkout) Ready() bool

Ready reports whether the checkout exists.

func (*Checkout) Run

func (c *Checkout) Run(ctx context.Context)

Run clones until it succeeds or ctx ends.

func (*Checkout) SetStateForTest

func (c *Checkout) SetStateForTest(state, detail string)

SetStateForTest overwrites the reported state without running a clone. It exists for a supervisor's own tests (a package outside this one cannot reach the unexported state), never for production code.

func (*Checkout) State

func (c *Checkout) State() CheckoutState

State is what /healthz reports.

func (*Checkout) Wait

func (c *Checkout) Wait(ctx context.Context) bool

Wait blocks until the checkout exists (true) or ctx ends (false).

type CheckoutConfig

type CheckoutConfig struct {
	Repo, Branch, Dir string
	// ConnectBase and Token reach muster's connector routes; empty when the pod
	// is not offered the connector store.
	ConnectBase, Token string
	Voice              Voice
	// Mirror, set, is the absolute path of a bare MIRROR of the repository that
	// the pod's deploy-key holder made (deploykey.go): the clone is a local
	// one, from it, and needs no credential — this process never holds the
	// key. Empty: the anonymous HTTPS clone (GithubCloneBase).
	Mirror string
}

CheckoutConfig is what a checkout is made from.

type CheckoutState

type CheckoutState struct {
	Repo   string `json:"repo"`
	Branch string `json:"branch,omitempty"`
	Dir    string `json:"dir"`
	State  string `json:"state"`
	Detail string `json:"detail,omitempty"`
}

CheckoutState is the `repo` object /healthz reports.

type Failure

type Failure struct {
	Status   int    `json:"-"`
	Type     string `json:"type"`
	Code     string `json:"code,omitempty"`            // the runtime's own error code, when there is one
	Upstream int    `json:"upstream_status,omitempty"` // the API's HTTP status, when known
	Message  string `json:"message"`
}

Failure is a typed failed turn: `{"error":{type,code,upstream_status,message}}`.

func (*Failure) Error

func (f *Failure) Error() string

type NativeToolItem

type NativeToolItem struct {
	Type      string `json:"type"`
	ID        string `json:"id"`
	CallID    string `json:"call_id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	// Status: "completed", "failed", or "in_progress" (no result before the
	// turn ended).
	Status string `json:"status"`
	Output string `json:"output,omitempty"`
}

NativeToolItem is one tool call the agent ran itself during the turn, streamed as a cctranscript.NativeToolItem output item so muster draws it as a collapsed row and never dispatches it. It never appears in response.completed's output.

func NewNativeToolItem

func NewNativeToolItem(id, name, arguments, status, output string) NativeToolItem

NewNativeToolItem is a NativeToolItem for call id with the given fields.

type ReplyItem

type ReplyItem struct {
	Text string
	Tool *NativeToolItem
}

ReplyItem is one piece of a settled turn, in order: a text segment, or one tool call.

type Usage added in v0.191.0

type Usage struct {
	InputTokens              int64 `json:"input_tokens"`
	OutputTokens             int64 `json:"output_tokens"`
	CacheReadInputTokens     int64 `json:"cache_read_input_tokens"`
	CacheCreationInputTokens int64 `json:"cache_creation_input_tokens"`
}

Usage is a settled turn's token usage, in the Anthropic split muster's client reads (internal/agents turnusage.go): uncached input, output, cache read and cache creation, summed over the turn's API calls.

type Voice

type Voice struct {
	// Who is the supervisor ("ccd"): log prefixes, "<who> retries".
	Who string
	// Agent is the thing that starts once the checkout exists, with its article
	// ("the Claude Code session").
	Agent string
	// AgentOf is the same with a possessive ("its Claude Code session"), for the
	// reason filed with the connector request.
	AgentOf string
}

Voice is how a supervisor names itself and the agent it starts in the sentences a person reads.

Jump to

Keyboard shortcuts

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