client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 14 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

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAvailable = errors.New("ticket not available")

ErrNotAvailable is returned when a ticket claim fails with 409 Conflict.

View Source
var ErrNotOwner = errors.New("ticket not owned by this shem")

ErrNotOwner is returned when a phase update is rejected because this shem no longer owns the ticket (e.g. after a requeue).

View Source
var ErrPlanJobNotClaimable = errors.New("plan job not claimable")

ErrPlanJobNotClaimable mirrors the ticket claim's ErrNotAvailable: losing the claim race is routine, not an error worth logging.

Functions

This section is empty.

Types

type AssignedTicket

type AssignedTicket struct {
	TicketID   string `json:"ticket_id"`
	Phase      string `json:"phase"`
	RepoRemote string `json:"repo_remote"`
	// Branch and the epic coordinates let a restarted shem re-run the
	// integration lane for a child it finished but never merged.
	Branch            string `json:"branch,omitempty"`
	EpicID            string `json:"epic_id,omitempty"`
	EpicNodeKey       string `json:"epic_node_key,omitempty"`
	EpicIntegratedSHA string `json:"epic_integrated_sha,omitempty"`
}

AssignedTicket is a lightweight summary of a ticket assigned to this shem.

type AttentionClaim added in v0.1.0

type AttentionClaim struct {
	Claim   *ClaimResponse `json:"claim"`
	Token   string         `json:"token"`
	Reason  string         `json:"reason"`
	Attempt int            `json:"attempt"`
	// WaitResume marks a claim whose supervisor wait just elapsed: resume the
	// failed step directly instead of diagnosing a stale failure.
	WaitResume bool `json:"wait_resume,omitempty"`
}

type AttentionDecision added in v0.1.0

type AttentionDecision struct {
	Question string `json:"question"`
	Choice   string `json:"choice"`
	Reason   string `json:"reason"`
	Basis    string `json:"basis"`
}

AttentionDecision is the decided route's record. It rides the resolve so the decision and the resume it authorizes commit together.

type AttentionResult added in v0.1.0

type AttentionResult struct {
	Token    string `json:"token"`
	Retry    bool   `json:"retry"`
	Feedback string `json:"feedback"`
	Reason   string `json:"reason"`
	// Wait asks the server to park the ticket on the supervisor's clock:
	// "transient" or "usage_limit". The server sets the delay; for a usage
	// limit ResetAt is the reset time the shem parsed, if any.
	Wait     string             `json:"wait,omitempty"`
	ResetAt  *time.Time         `json:"reset_at,omitempty"`
	Decision *AttentionDecision `json:"decision,omitempty"`
}

AttentionResult is one recovery outcome: a retry (with optional decision), a supervisor wait, or a human park (the zero outcome). The server owns every budget and rejects an exhausted one.

type AttentionTicket added in v0.1.0

type AttentionTicket struct {
	TicketID   string `json:"id"`
	RepoRemote string `json:"repo_remote"`
	Reason     string `json:"attention_reason"`
}

type ClaimResponse

type ClaimResponse struct {
	TicketID        string        `json:"ticket_id"`
	Branch          string        `json:"branch"`
	BaseBranch      string        `json:"base_branch"`
	RepoRemote      string        `json:"repo_remote"`
	Description     string        `json:"description"`
	CheckpointPhase *string       `json:"checkpoint_phase"`
	CheckpointSHA   *string       `json:"checkpoint_sha"`
	RetryPhase      string        `json:"retry_phase,omitempty"`
	LogEntries      []db.LogEntry `json:"log_entries"`
	// Backend is the adapter the claiming shem runs.
	Backend string `json:"backend"`
	// Models is every stage's model id; "" means the vendor default.
	Models map[string]string `json:"models"`
	// ManualApproval: stop after brainstorm and after plan until a human approves.
	ManualApproval bool `json:"manual_approval"`
	// TesterRequired: run the tester stage on the pushed head and record a
	// structured verdict — ticket-level, set for any ticket that asks and
	// for epic children whose run requires it.
	TesterRequired bool `json:"tester_required"`
	// VerifyDisabled: skip the worker's self-verification before the
	// review gate (opt-out; verification is the default).
	VerifyDisabled bool `json:"verify_disabled"`
	// AskDecisions and DecisionGuidance: how agents treat open questions;
	// AskDecisions false (also from an orchestrator that predates it) is
	// autonomous.
	AskDecisions     bool   `json:"ask_decisions"`
	DecisionGuidance string `json:"decision_guidance"`
	// Epic is set only for an epic child (api.EpicClaim).
	Epic *EpicClaim `json:"epic,omitempty"`
}

ClaimResponse is the response from claiming a ticket.

There is deliberately no Title field. The orchestrator still sends one, and this struct ignores it: the issue title is already composed into Description (github.Issue.TicketDescription), and it is Description that the approval hash covers and that every prompt builder interpolates. Decoding the title separately is not merely redundant — in this file it reads like a second path from issue text to an agent prompt, one the operator's approval hash would not cover. Nothing in internal/shem ever read it.

type Client

type Client struct {
	RetryInitial  time.Duration
	RetryFactor   float64
	RetryMax      time.Duration
	RetryAttempts int
	// contains filtered or unexported fields
}

Client is the HTTP client for orchestrator API calls.

func New

func New(baseURL, apiKey, name string) *Client

New creates a new Client with the given base URL, API key, and shem name.

func (*Client) AckInput

func (c *Client) AckInput(ticketID string, inputID uint) error

AckInput resolves a human input with an empty response.

func (*Client) BackendLimit added in v0.1.0

func (c *Client) BackendLimit() (time.Time, error)

BackendLimit returns when this shem's backend is usable again; the zero time means it is not limited. The server stores it on the shem row.

func (*Client) CheckIntegrationGate added in v0.1.0

func (c *Client) CheckIntegrationGate(epicID, nodeKey, headSHA string) (*IntegrationGate, error)

CheckIntegrationGate asks whether this shem may merge headSHA into the run's target ref, and takes the per-run integration slot when it may.

func (*Client) ClaimAttention added in v0.1.0

func (c *Client) ClaimAttention(id string, max int) (*AttentionClaim, error)

func (*Client) ClaimPlanJob added in v0.1.0

func (c *Client) ClaimPlanJob(id string) (*PlanJobClaim, error)

ClaimPlanJob takes the lease on a plan job and returns its payload.

func (*Client) ClaimRevision

func (c *Client) ClaimRevision(id string) (*ClaimResponse, error)

ClaimRevision resumes work on a ticket already assigned to this shem that is in the revising phase (triggered by a ticket_revise push). A 409 (already picked up, or requeued in the meantime) maps to ErrNotAvailable, same log-and-skip semantics as ClaimTicket.

func (*Client) ClaimTicket

func (c *Client) ClaimTicket(id string) (*ClaimResponse, error)

ClaimTicket claims a ticket for this shem.

func (*Client) Deregister

func (c *Client) Deregister() error

Deregister deregisters this shem from the orchestrator.

func (*Client) GetApproval added in v0.1.0

func (c *Client) GetApproval(ticketID string, inputID uint) (*PendingInput, error)

GetApproval returns the approval human input with the given id, resolved or not, or nil if it no longer exists (the ticket was requeued, which deletes its human inputs).

func (*Client) GetAssigned

func (c *Client) GetAssigned() ([]AssignedTicket, error)

GetAssigned returns all tickets currently assigned to this shem (any active phase).

func (*Client) GetAttention added in v0.1.0

func (c *Client) GetAttention() ([]AttentionTicket, error)

func (*Client) GetAvailable

func (c *Client) GetAvailable(repo string) (*string, error)

GetAvailable retrieves the first available ticket for a repo.

func (*Client) GetAvailablePlanJob added in v0.1.0

func (c *Client) GetAvailablePlanJob(repo string) (*PlanJob, error)

GetAvailablePlanJob returns the first claimable plan job for a repo, or nil when there is none — the plan-job counterpart of GetAvailable.

func (*Client) GetPendingApproval

func (c *Client) GetPendingApproval(ticketID string) (*PendingInput, error)

GetPendingApproval retrieves the oldest pending approval for a ticket. Returns nil, nil if no pending approval exists.

func (*Client) GetPendingFeedback

func (c *Client) GetPendingFeedback(ticketID string) (*PendingInput, error)

GetPendingFeedback retrieves the oldest unresolved feedback for a ticket. Returns nil, nil if none exists.

func (*Client) GetPendingInput

func (c *Client) GetPendingInput(ticketID string) (*PendingInput, error)

GetPendingInput retrieves the oldest unresolved human input for a ticket. Returns nil, nil if none exists.

func (*Client) GetReaped added in v0.1.0

func (c *Client) GetReaped() ([]string, error)

GetReaped returns the IDs of tickets the orchestrator's heartbeat reaper released from this shem and nobody has claimed since.

func (*Client) GetResumable

func (c *Client) GetResumable() ([]*ClaimResponse, error)

GetResumable returns tickets assigned to this shem that have a checkpoint and were mid-execution when the shem last died.

func (*Client) Migratable added in v0.1.0

func (c *Client) Migratable() ([]MigratableTicket, error)

Migratable lists the tickets this shem may move off itself.

func (*Client) MigrateTicket added in v0.1.0

func (c *Client) MigrateTicket(id, sha, captured string) error

MigrateTicket moves a limit-waiting ticket to the pool, naming the checkpoint the caller verified and, when it captured unfinished work, the pushed commit to resume from.

func (*Client) PostApprovalRequest

func (c *Client) PostApprovalRequest(ticketID string, prompt string) (uint, error)

PostApprovalRequest posts an approval request for a ticket and returns the id of the created human input, so the caller can wait on exactly that row.

func (*Client) PostBranchPushed added in v0.1.0

func (c *Client) PostBranchPushed(ticketID, prBody string) error

PostBranchPushed tells the orchestrator that the ticket branch now exists on the remote, which is the precondition for opening a pull request. Returns ErrNotOwner if the orchestrator rejects the update because this shem no longer owns the ticket (409 Conflict — e.g. after a requeue). PostBranchPushed reports that the ticket's branch reached the remote.

prBody is the generated pull request description, and may be empty: the orchestrator falls back to a minimal body rather than withholding the pull request, because the branch is already pushed and the work is done.

func (*Client) PostCheckpoint

func (c *Client) PostCheckpoint(ticketID string, phase, sha string) error

PostCheckpoint records a checkpoint for a ticket.

func (*Client) PostDocumentFile

func (c *Client) PostDocumentFile(ticketID string, entryType, fromRole, filePath string) (uint, error)

PostDocumentFile sends sanitized file content as a document log entry. The file is sent as a raw body (no JSON wrapping); metadata travels in headers.

func (*Client) PostEpicVerdict added in v0.1.0

func (c *Client) PostEpicVerdict(epicID string, v EpicVerdictPayload) error

PostEpicVerdict records the tester stage's structured verdict for one merge candidate. The orchestrator validates the shape; the lane still matches the head SHA before it merges, so a verdict here is evidence, never an order.

func (*Client) PostFailure added in v0.1.0

func (c *Client) PostFailure(id, reason string) error

PostFailure opts only worker-originated failures into bounded diagnosis. Legacy PostPhase("needs-attention") and human parks remain untouched.

func (*Client) PostGraphBuildResult added in v0.1.0

func (c *Client) PostGraphBuildResult(repoRemote, buildErr string) error

PostGraphBuildResult records the outcome of a graph build the orchestrator asked for. An empty buildErr means it succeeded.

func (*Client) PostIntegrationResult added in v0.1.0

func (c *Client) PostIntegrationResult(epicID, nodeKey string, r IntegrationResult) error

PostIntegrationResult posts the receipt end of the integration lane.

func (*Client) PostLog

func (c *Client) PostLog(ticketID string, p LogPayload) (uint, error)

PostLog logs a message to a ticket.

func (*Client) PostPhase

func (c *Client) PostPhase(ticketID string, phase string) error

PostPhase updates the phase of a ticket. Returns ErrNotOwner if the orchestrator rejects the update because this shem no longer owns the ticket (409 Conflict — e.g. after a requeue).

func (*Client) PostPlanJobProgress added in v0.1.0

func (c *Client) PostPlanJobProgress(id, tail string, newAttempt bool) error

PostPlanJobProgress refreshes the lease and reports the session log tail. newAttempt marks the start of a fresh agent session (the first try, or the repair pass after invalid output) and consumes one attempt.

func (*Client) PostPlanJobResult added in v0.1.0

func (c *Client) PostPlanJobResult(id, draftJSON, runErr string) error

PostPlanJobResult reports the outcome: the generated draft JSON, or an error. The orchestrator re-validates the draft before storing it.

func (*Client) PostTicketVerdict added in v0.1.0

func (c *Client) PostTicketVerdict(ticketID string, v TicketVerdictPayload) error

PostTicketVerdict records the tester stage's structured verdict for a standalone ticket. It is evidence on the ticket, never an order.

func (*Client) Reclaim added in v0.1.0

func (c *Client) Reclaim(ticketID string) error

Reclaim takes back a ticket the reaper released from this shem, restoring the phase it was in. Returns ErrNotAvailable when it is no longer reclaimable — claimed by someone else, requeued, closed or re-gated.

func (*Client) Register

func (c *Client) Register(name string, repos []string, backend string, catalog models.Catalog) (uint, error)

Register registers this shem and reports the backend it runs.

func (*Client) ReleaseTicket added in v0.1.0

func (c *Client) ReleaseTicket(id string) error

ReleaseTicket hands a claimed, unstarted ticket back to the pool.

func (*Client) ReportBackendLimit added in v0.1.0

func (c *Client) ReportBackendLimit(until time.Time) error

ReportBackendLimit records on the server that this shem hit a usage limit lifting at until, so a restart still holds.

func (*Client) ResolveAttention added in v0.1.0

func (c *Client) ResolveAttention(id string, result AttentionResult) (*ClaimResponse, error)

type EpicClaim added in v0.1.0

type EpicClaim struct {
	EpicID             string   `json:"epic_id"`
	NodeKey            string   `json:"node_key"`
	BaseFallback       string   `json:"base_fallback"`
	TesterRequired     bool     `json:"tester_required"`
	AcceptanceCommands []string `json:"acceptance_commands,omitempty"`
}

EpicClaim mirrors api.EpicClaim.

type EpicVerdictPayload added in v0.1.0

type EpicVerdictPayload struct {
	EpicNodeKey string `json:"epic_node_key"`
	HeadSHA     string `json:"head_sha"`
	BaseSHA     string `json:"base_sha"`
	Verdict     string `json:"verdict"`
	Scenarios   string `json:"scenarios"`
	Evidence    string `json:"evidence"`
	Backend     string `json:"backend"`
}

EpicVerdictPayload mirrors the orchestrator's verdict request body.

type GraphBuildResult added in v0.1.0

type GraphBuildResult struct {
	RepoRemote string `json:"repo_remote"`
	Error      string `json:"error,omitempty"`
}

GraphBuildResult is the body of a graph-build outcome report.

type IntegrationGate added in v0.1.0

type IntegrationGate struct {
	LeaseID        string `json:"lease_id"`
	Outcome        string `json:"outcome"` // granted | wait | done
	TargetRef      string `json:"target_ref"`
	ExpiresAt      string `json:"expires_at"`
	RetryAfterSecs int    `json:"retry_after_secs"`
	Reason         string `json:"reason"`
	MergeSHA       string `json:"merge_sha"`
}

IntegrationGate is the orchestrator's answer to an integration gate check (api.integrateCheckEpicNode).

type IntegrationResult added in v0.1.0

type IntegrationResult struct {
	LocalOnly bool   `json:"local_only,omitempty"`
	LeaseID   string `json:"lease_id"`
	HeadSHA   string `json:"head_sha"`
	Status    string `json:"status"` // merged | contained | conflict | moved | error
	MergeSHA  string `json:"merge_sha,omitempty"`
	Detail    string `json:"detail,omitempty"`
}

IntegrationResult reports what the merge into the run's target ref did.

type LogPayload

type LogPayload struct {
	EntryType string `json:"entry_type"`
	FromRole  string `json:"from_role"`
	ToRole    string `json:"to_role"`
	Message   string `json:"message"`
	Model     string `json:"model"`
	Backend   string `json:"backend"`
}

LogPayload is the request body for logging.

type MigratableTicket added in v0.1.0

type MigratableTicket struct {
	TicketID      string `json:"id"`
	RepoRemote    string `json:"repo_remote"`
	Branch        string `json:"branch"`
	CheckpointSHA string `json:"checkpoint_sha"`
}

MigratableTicket is a limit-waiting ticket the server allows this shem to move.

type PendingInput

type PendingInput struct {
	ID        uint      `json:"id"`
	TicketID  string    `json:"ticket_id"`
	Kind      string    `json:"kind"`
	Prompt    string    `json:"prompt"`
	CreatedAt time.Time `json:"created_at"`
	// Response and ResolvedAt are set once a human has answered.
	Response   *string    `json:"response"`
	ResolvedAt *time.Time `json:"resolved_at"`
}

PendingInput represents a pending human input.

type PlanJob added in v0.1.0

type PlanJob struct {
	ID      string `json:"id"`
	EpicID  string `json:"epic_id"`
	Status  string `json:"status"`
	Attempt int    `json:"attempt"`
}

PlanJob is the shem-facing view of an epic plan-generation job.

type PlanJobClaim added in v0.1.0

type PlanJobClaim struct {
	Job          PlanJob `json:"job"`
	EpicTitle    string  `json:"epic_title"`
	SpecMarkdown string  `json:"spec_markdown"`
	RepoRemote   string  `json:"repo_remote"`
	BranchTarget string  `json:"branch_target"`
}

PlanJobClaim is the payload returned when a plan job is claimed: the job plus everything the planning session needs.

type TicketVerdictPayload added in v0.1.0

type TicketVerdictPayload struct {
	HeadSHA   string `json:"head_sha"`
	BaseSHA   string `json:"base_sha"`
	Verdict   string `json:"verdict"`
	Scenarios string `json:"scenarios"`
	Evidence  string `json:"evidence"`
	Backend   string `json:"backend"`
}

TicketVerdictPayload is the standalone-ticket counterpart of EpicVerdictPayload: the same structured verdict without the epic node key, because the ticket itself is the scope.

type WSClient

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

WSClient is a WebSocket client for the orchestrator push channel.

func (*WSClient) Connect

func (wc *WSClient) Connect(url, apiKey, name string) error

Connect establishes a WebSocket connection to the orchestrator.

func (*WSClient) Listen

func (wc *WSClient) Listen(onMsg func(ws.WSMessage)) error

Listen reads messages from the WebSocket and calls onMsg for each message. It runs until an error occurs (typically connection close).

func (*WSClient) SendPing

func (wc *WSClient) SendPing() error

SendPing sends a heartbeat ping to the orchestrator.

Jump to

Keyboard shortcuts

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