Documentation
¶
Overview ¶
Package client provides the API client for communicating with the Musher platform.
The client handles authentication and provides methods for:
- Validating API keys (service accounts)
- Claiming jobs from queues
- Reporting job completion/failure
- Sending job heartbeats
Index ¶
- Constants
- type AgentConstraints
- type ClaudeConfig
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) ClaimJob(ctx context.Context, habitatID, queueID string, waitTimeoutSeconds int) (*Job, error)
- func (c *Client) CompleteJob(ctx context.Context, jobID string, output map[string]any) error
- func (c *Client) DeregisterLink(ctx context.Context, linkID string, req DeregisterLinkRequest) error
- func (c *Client) FailJob(ctx context.Context, jobID, errorCode, errorMsg string, shouldRetry bool) error
- func (c *Client) GetQueueInstructionAvailability(ctx context.Context, queueID string) (*InstructionAvailability, error)
- func (c *Client) GetRunnerConfig(ctx context.Context) (*RunnerConfigResponse, error)
- func (c *Client) HeartbeatJob(ctx context.Context, jobID string) (*Job, error)
- func (c *Client) HeartbeatLink(ctx context.Context, linkID, currentJobID string) (*LinkHeartbeatResponse, error)
- func (c *Client) ListHabitats(ctx context.Context) ([]HabitatSummary, error)
- func (c *Client) ListQueues(ctx context.Context, habitatID string) ([]QueueSummary, error)
- func (c *Client) RegisterLink(ctx context.Context, req *RegisterLinkRequest) (*RegisterLinkResponse, error)
- func (c *Client) ReleaseJob(ctx context.Context, jobID string) error
- func (c *Client) StartJob(ctx context.Context, jobID string) (*Job, error)
- func (c *Client) ValidateKey(ctx context.Context) (*Identity, error)
- type DeregisterLinkRequest
- type ExecutionConfig
- type HabitatSummary
- type Identity
- type InstructionAvailability
- type InstructionConfig
- type Job
- type JobClaimRequest
- type JobClaimResponse
- type JobCompleteRequest
- type JobFailRequest
- type LinkHeartbeatRequest
- type LinkHeartbeatResponse
- type QueueSummary
- type RegisterLinkRequest
- type RegisterLinkResponse
- type RunnerConfigError
- type RunnerConfigResponse
- type RunnerProviderConfig
- type RunnerProviderCredential
- type RunnerProviderFlags
- type RunnerProviderMCP
- type SandboxConfig
Constants ¶
const ( // DefaultTimeout is the default HTTP request timeout. DefaultTimeout = 60 * time.Second // DefaultLeaseDurationMs is the default job lease duration (45s to allow margin over 30s heartbeat). DefaultLeaseDurationMs = 45000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConstraints ¶
type AgentConstraints struct {
// MaxTurns limits the number of agentic turns (API round-trips) before stopping.
MaxTurns int `json:"maxTurns,omitempty"`
// MaxBudgetUSD caps API spending in USD.
MaxBudgetUSD float64 `json:"maxBudgetUsd,omitempty"`
// TimeoutMs overrides the job timeout in milliseconds.
TimeoutMs int `json:"timeoutMs,omitempty"`
}
AgentConstraints holds agent-agnostic execution limits.
type ClaudeConfig ¶
type ClaudeConfig struct {
// AllowedTools restricts which tools Claude can use (e.g., ["Read", "Bash", "Edit"]).
AllowedTools []string `json:"allowedTools,omitempty"`
// DisallowedTools blocks specific tools (e.g., ["Task"] to disable subtasks).
DisallowedTools []string `json:"disallowedTools,omitempty"`
// SystemPromptAppend is text appended to the system prompt.
SystemPromptAppend string `json:"systemPromptAppend,omitempty"`
}
ClaudeConfig holds Claude-specific execution settings.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Musher API client.
func NewWithHTTPClient ¶ added in v1.3.0
NewWithHTTPClient creates a new API client with an injected HTTP client. If httpClient is nil, a default client with DefaultTimeout is used.
func (*Client) ClaimJob ¶
func (c *Client) ClaimJob(ctx context.Context, habitatID, queueID string, waitTimeoutSeconds int) (*Job, error)
ClaimJob attempts to claim a job from the queue. This is a long-poll endpoint that blocks until a job is available or timeout.
func (*Client) CompleteJob ¶
CompleteJob marks a job as successfully completed.
func (*Client) DeregisterLink ¶
func (c *Client) DeregisterLink(ctx context.Context, linkID string, req DeregisterLinkRequest) error
DeregisterLink gracefully disconnects a link. Called on mush shutdown (SIGTERM/SIGINT).
func (*Client) FailJob ¶
func (c *Client) FailJob(ctx context.Context, jobID, errorCode, errorMsg string, shouldRetry bool) error
FailJob marks a job as failed.
func (*Client) GetQueueInstructionAvailability ¶
func (c *Client) GetQueueInstructionAvailability(ctx context.Context, queueID string) (*InstructionAvailability, error)
GetQueueInstructionAvailability checks if a queue has an active instruction.
func (*Client) GetRunnerConfig ¶ added in v1.2.0
func (c *Client) GetRunnerConfig(ctx context.Context) (*RunnerConfigResponse, error)
GetRunnerConfig fetches runner runtime configuration for startup provisioning.
func (*Client) HeartbeatJob ¶
HeartbeatJob sends a heartbeat for a claimed job to extend the lease.
func (*Client) HeartbeatLink ¶
func (c *Client) HeartbeatLink(ctx context.Context, linkID, currentJobID string) (*LinkHeartbeatResponse, error)
HeartbeatLink sends a heartbeat for a link. Should be called every 30 seconds to keep the link alive.
func (*Client) ListHabitats ¶
func (c *Client) ListHabitats(ctx context.Context) ([]HabitatSummary, error)
ListHabitats fetches available habitats in the runner's workspace.
func (*Client) ListQueues ¶
ListQueues fetches active queues, optionally filtered by habitat.
func (*Client) RegisterLink ¶
func (c *Client) RegisterLink(ctx context.Context, req *RegisterLinkRequest) (*RegisterLinkResponse, error)
RegisterLink registers a new link with the platform. Called on mush start. Returns link ID for subsequent heartbeats/deregister.
func (*Client) ReleaseJob ¶
ReleaseJob releases a job back to the queue without completing.
type DeregisterLinkRequest ¶
type DeregisterLinkRequest struct {
Reason string `json:"reason,omitempty"`
JobsCompleted int `json:"jobsCompleted"`
JobsFailed int `json:"jobsFailed"`
}
DeregisterLinkRequest is the request body for deregistering a link.
type ExecutionConfig ¶
type ExecutionConfig struct {
// AgentType specifies which agent to use ("claude", "bash").
AgentType string `json:"agentType,omitempty"`
// RenderedInstruction is the fully rendered prompt/command (template already applied).
RenderedInstruction string `json:"renderedInstruction,omitempty"`
// TimeoutMs is the execution timeout in milliseconds.
TimeoutMs int `json:"timeoutMs"`
// WorkingDirectory is the optional working directory for execution.
WorkingDirectory string `json:"workingDirectory,omitempty"`
// Environment contains environment variables to set for execution.
Environment map[string]string `json:"environment,omitempty"`
// Sandbox contains optional sandbox configuration.
Sandbox *SandboxConfig `json:"sandbox,omitempty"`
// Constraints holds agent-agnostic execution limits.
Constraints *AgentConstraints `json:"constraints,omitempty"`
// Claude holds Claude-specific configuration (when AgentType is "claude").
Claude *ClaudeConfig `json:"claude,omitempty"`
}
ExecutionConfig contains everything needed to execute a job. The server renders the Jinja2 template and provides the fully prepared instruction.
func (*ExecutionConfig) GetAgentType ¶
func (e *ExecutionConfig) GetAgentType() string
GetAgentType returns the agent type.
func (*ExecutionConfig) GetRenderedInstruction ¶
func (e *ExecutionConfig) GetRenderedInstruction() string
GetRenderedInstruction returns the rendered instruction.
type HabitatSummary ¶
type HabitatSummary struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Status string `json:"status"`
HabitatType string `json:"habitatType"`
}
HabitatSummary represents a habitat for CLI selection.
type Identity ¶
type Identity struct {
CredentialType string `json:"credentialType"`
CredentialID string `json:"credentialId"`
CredentialName string `json:"credentialName"`
WorkerID string `json:"workerId"`
WorkspaceID string `json:"workspaceId"`
WorkspaceName string `json:"workspaceName"`
}
Identity represents the authenticated service account identity.
type InstructionAvailability ¶
type InstructionAvailability struct {
QueueID string `json:"queueId"`
HasActiveInstruction bool `json:"hasActiveInstruction"`
InstructionID string `json:"instructionId,omitempty"`
InstructionName string `json:"instructionName,omitempty"`
InstructionSlug string `json:"instructionSlug,omitempty"`
}
InstructionAvailability represents queue instruction availability for runners.
type InstructionConfig ¶
type InstructionConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Instruction string `json:"instruction"` // Jinja2 template (not rendered)
}
InstructionConfig represents the instruction template configuration from API. This defines *what* to execute (the template). The CLI's Agent interface (ClaudeAgent, BashAgent) executes instructions.
type Job ¶
type Job struct {
ID string `json:"id"`
WorkspaceID string `json:"workspaceId"`
JobType string `json:"jobType"`
CeType string `json:"ceType"`
CeSource string `json:"ceSource"`
CeSubject string `json:"ceSubject,omitempty"`
Data map[string]any `json:"data,omitempty"`
RouteID string `json:"routeId,omitempty"`
QueueID string `json:"queueId,omitempty"`
HabitatID string `json:"habitatId,omitempty"`
Priority string `json:"priority"`
Status string `json:"status"`
StatusReason string `json:"statusReason,omitempty"`
WorkerID string `json:"workerId,omitempty"`
ClaimedAt *time.Time `json:"claimedAt,omitempty"`
HeartbeatDeadlineAt *time.Time `json:"heartbeatDeadlineAt,omitempty"`
AttemptNumber int `json:"attemptNumber"`
MaxAttempts int `json:"maxAttempts"`
NextRetryAt *time.Time `json:"nextRetryAt,omitempty"`
InputData map[string]any `json:"inputData,omitempty"`
OutputData map[string]any `json:"outputData,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
ErrorDetails map[string]any `json:"errorDetails,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
DurationMs *int `json:"durationMs,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Instruction *InstructionConfig `json:"-"`
Execution *ExecutionConfig `json:"-"`
WebhookConfig map[string]any `json:"-"`
ExecutionError string `json:"-"`
}
Job represents a job claimed from the queue.
func (*Job) GetAgentType ¶
GetAgentType returns the agent type for this job, checking multiple sources.
func (*Job) GetDisplayName ¶
GetDisplayName returns a human-friendly job label.
func (*Job) GetRenderedInstruction ¶
GetRenderedInstruction returns the rendered instruction for execution.
type JobClaimRequest ¶
type JobClaimRequest struct {
QueueID string `json:"queueId,omitempty"`
HabitatID string `json:"habitatId,omitempty"`
LeaseDurationMs int `json:"leaseDurationMs"`
}
JobClaimRequest is the request body for claiming a job.
type JobClaimResponse ¶
type JobClaimResponse struct {
Job Job `json:"job"`
WebhookConfig map[string]any `json:"webhookConfig,omitempty"`
Instruction *InstructionConfig `json:"instruction,omitempty"`
Execution *ExecutionConfig `json:"execution,omitempty"`
ExecutionError string `json:"executionError,omitempty"`
}
JobClaimResponse wraps the claim response payload.
type JobCompleteRequest ¶
JobCompleteRequest is the request body for completing a job.
type JobFailRequest ¶
type JobFailRequest struct {
ErrorCode string `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
ErrorDetails map[string]any `json:"errorDetails,omitempty"`
ShouldRetry bool `json:"shouldRetry"`
}
JobFailRequest is the request body for failing a job.
type LinkHeartbeatRequest ¶
type LinkHeartbeatRequest struct {
CurrentJobID string `json:"currentJobId,omitempty"`
}
LinkHeartbeatRequest is the request body for link heartbeat.
type LinkHeartbeatResponse ¶
type LinkHeartbeatResponse struct {
Status string `json:"status"`
HeartbeatDeadlineAt time.Time `json:"heartbeatDeadlineAt"`
}
LinkHeartbeatResponse is the response from link heartbeat.
type QueueSummary ¶
type QueueSummary struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Status string `json:"status"`
HabitatID string `json:"habitatId,omitempty"`
}
QueueSummary represents a queue for CLI selection.
type RegisterLinkRequest ¶
type RegisterLinkRequest struct {
InstanceID string `json:"instanceId"`
HabitatID string `json:"habitatId"`
Name string `json:"name,omitempty"`
LinkType string `json:"linkType"`
ClientVersion string `json:"clientVersion,omitempty"`
ClientMetadata map[string]any `json:"clientMetadata,omitempty"`
}
RegisterLinkRequest is the request body for registering a link.
type RegisterLinkResponse ¶
type RegisterLinkResponse struct {
LinkID string `json:"linkId"`
WorkerID string `json:"workerId"`
HeartbeatDeadlineAt time.Time `json:"heartbeatDeadlineAt"`
HeartbeatIntervalMs int `json:"heartbeatIntervalMs"`
}
RegisterLinkResponse is the response from registering a link.
type RunnerConfigError ¶ added in v1.2.0
type RunnerConfigError struct {
Provider string `json:"provider"`
Code string `json:"code"`
Message string `json:"message"`
}
RunnerConfigError contains partial error details for provider config resolution.
type RunnerConfigResponse ¶ added in v1.2.0
type RunnerConfigResponse struct {
ConfigVersion string `json:"configVersion"`
WorkspaceID string `json:"workspaceId"`
GeneratedAt time.Time `json:"generatedAt"`
RefreshAfterSeconds int `json:"refreshAfterSeconds"`
Providers map[string]RunnerProviderConfig `json:"providers"`
Errors []RunnerConfigError `json:"errors,omitempty"`
}
RunnerConfigResponse is the generic runner configuration payload.
type RunnerProviderConfig ¶ added in v1.2.0
type RunnerProviderConfig struct {
Status string `json:"status"`
Credential *RunnerProviderCredential `json:"credential,omitempty"`
Flags RunnerProviderFlags `json:"flags,omitempty"`
MCP *RunnerProviderMCP `json:"mcp,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
RunnerProviderConfig contains provider-specific runner configuration.
type RunnerProviderCredential ¶ added in v1.2.0
type RunnerProviderCredential struct {
AccessToken string `json:"accessToken"`
TokenType string `json:"tokenType,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
}
RunnerProviderCredential contains provider credentials for runtime use.
type RunnerProviderFlags ¶ added in v1.2.0
type RunnerProviderFlags struct {
MCP bool `json:"mcp"`
}
RunnerProviderFlags contains feature flags for a provider.
type RunnerProviderMCP ¶ added in v1.2.0
type RunnerProviderMCP struct {
URL string `json:"url"`
Transport string `json:"transport,omitempty"`
}
RunnerProviderMCP contains MCP endpoint metadata for a provider.