api

package
v0.2.1 Latest Latest
Warning

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

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

View Source
const PhaseStopped = "stopped"

PhaseStopped is a ticket a human has interrupted. Nothing automatic moves it: not the claim poll, not resume after a shem restart, not the pull-request monitor. Only a person starting it again.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimResponse

type ClaimResponse struct {
	TicketID string `json:"ticket_id"`
	Branch   string `json:"branch"`
	// BaseBranch is what a conflict is resolved against. The shem fetches
	// it into the agent's repo so `git merge origin/<base>` works without
	// handing the agent a credential, and it cannot be read from the
	// worktree's own config because the agent owns and can rewrite that.
	BaseBranch      string        `json:"base_branch"`
	Title           string        `json:"title"`
	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: pause for a human after brainstorm and after plan.
	ManualApproval bool `json:"manual_approval"`
	// TesterRequired: run the tester stage on the pushed head and record a
	// structured verdict on the ticket. Ticket-level: it is set for any
	// ticket that asks for it, and for epic children whose run requires it
	// (the epic's policy lands on the child at materialization; the claim
	// also ORs the run's policy so children created before the ticket flag
	// existed keep their gate).
	TesterRequired bool `json:"tester_required"`
	// VerifyDisabled: skip the worker's self-verification before the
	// review gate. Verification is the default; a ticket opts out at
	// creation.
	VerifyDisabled bool `json:"verify_disabled"`
	// AskDecisions and DecisionGuidance: how agents treat open questions on
	// this ticket; see db.Ticket.
	AskDecisions     bool   `json:"ask_decisions"`
	DecisionGuidance string `json:"decision_guidance"`
	// Epic is set only for an epic child.
	Epic *EpicClaim `json:"epic,omitempty"`
}

ClaimResponse is returned by a successful ticket claim.

type EpicClaim added in v0.1.0

type EpicClaim struct {
	EpicID  string `json:"epic_id"`
	NodeKey string `json:"node_key"`
	// BaseFallback (the run's base branch) seeds the integration ref
	// until the first child creates it.
	BaseFallback string `json:"base_fallback"`
	// TesterRequired: run the tester on the pushed head and post a verdict.
	TesterRequired     bool     `json:"tester_required"`
	AcceptanceCommands []string `json:"acceptance_commands,omitempty"`
}

EpicClaim is what a worker needs to run an epic child.

type Handlers

type Handlers struct {
	DB           *gorm.DB
	Hub          *ws.Hub
	Broker       *sse.Broker
	LogEntryHTML func(sse.LogEntryEvent) string // renders a log entry to HTML for SSE; nil = send JSON
	// BaseURL is the orchestrator's externally reachable base URL, used to
	// build ticket links in GitHub comments. Empty renders a relative link.
	BaseURL string
	// Sync triggers an immediate manual GitHub ingest pass. It is nil
	// whenever GitHub sync is not running (no repos enabled, or the token is
	// missing) — the default install. Handlers must check for nil before
	// calling it and respond 503, never let it reach a nil-pointer panic.
	Sync SyncTrigger
	// ManualSyncCooldown is the minimum gap between manual syncs of one repo.
	ManualSyncCooldown time.Duration
	// GitHubTokenEnv is the NAME of the environment variable the GitHub token
	// is read from — config.github.token_env, which a deployment may rename.
	// It is used only to tell an operator which variable to set when sync is
	// not running; the value is never read here. Empty falls back to the
	// documented default, so a handler built without wiring still gives an
	// answer that is right for almost every deployment.
	GitHubTokenEnv string
	// Wait holds the supervisor's configurable usage-limit wait caps.
	Wait WaitPolicy
}

Handlers holds the shared dependencies for all API handlers.

func NewHandlers

func NewHandlers(gdb *gorm.DB, hub *ws.Hub, broker *sse.Broker) *Handlers

NewHandlers creates a Handlers with the given dependencies.

func (*Handlers) ClaimTicket

func (h *Handlers) ClaimTicket(ticketID string, shemID uint) (*ClaimResponse, error)

ClaimTicket atomically claims a ticket for shemID. Exactly one concurrent caller wins; all others receive a non-nil error.

The (issue_number IS NULL OR (intake_approved AND approved_body_hash = body_hash)) half of the predicate (spec Amendment 1) is provenance, not phase: an externally-sourced ticket (non-nil issue_number) must have been explicitly released by actionStart, regardless of what phase gymnastics (close, needs-attention, requeue, ...) it has been through since. A web-form ticket has a nil issue_number and is unaffected.

Checking approved_body_hash = body_hash, not just intake_approved, closes a fix-round-4 gap (round 5): a ticket claimed while approved deliberately keeps intake_approved=true and its now-stale approved_body_hash if the issue is edited afterward (the running shem is not yanked — see ghsync.applyIssue), but body_hash keeps tracking the live issue. Without this half of the predicate, that ticket became claimable again — with the attacker's edited text — the moment it returned to the pool via requeue or the heartbeat reaper, neither of which re-checks the hash. Requiring equality here means approval means "a human approved THIS text", checked at the one place it matters, regardless of how many paths return a ticket to the pool now or later.

The non-empty test is not redundant with the equality (re-review finding F1). A database last written by a build in the window [f9e87e0, fef123b) — after intake_approved shipped, before the two hash columns did — migrates forward with AutoMigrate adding both columns at their zero value, so a ticket a human approved under that build arrives as

intake_approved = 1, approved_body_hash = '', body_hash = ''

and the equality alone evaluates to TRUE, because the empty string equals itself. That row was claimable with no hash binding at all — and that build's applyIssue had no re-gate either, so its stored description may be text edited after the approval and read by nobody. Emptiness is not approval. Requiring a non-empty approved_body_hash costs one comparison and makes the whole class unreachable regardless of migration history. issue_number IS NULL still short-circuits ahead of it, so web-form tickets — which carry two empty hashes for their whole life — are unaffected. admin.BackfillBodyHash repairs such rows; TestEmptyHashesAreNotAnApproval pins all four predicates.

func (*Handlers) RegisterEpicPlanJobRoutes added in v0.1.0

func (h *Handlers) RegisterEpicPlanJobRoutes(mux *http.ServeMux)

RegisterEpicPlanJobRoutes adds the plan-generation job routes. The generate/status pair is session-authenticated for the page; the rest are shem-authenticated, mirroring the ticket claim pattern.

func (*Handlers) RegisterEpicRoutes added in v0.1.0

func (h *Handlers) RegisterEpicRoutes(mux *http.ServeMux)

RegisterEpicRoutes adds the Epic Run routes.

func (*Handlers) RegisterGitHubRoutes added in v0.1.0

func (h *Handlers) RegisterGitHubRoutes(mux *http.ServeMux)

RegisterGitHubRoutes adds GitHub integration routes to mux. Manual sync is session-authenticated only: it is a deliberate human action, and a shem holding a valid API key must not be able to drive GitHub polling.

func (*Handlers) RegisterHumanRoutes

func (h *Handlers) RegisterHumanRoutes(mux *http.ServeMux)

RegisterHumanRoutes adds human-input management and ticket action routes to mux.

func (*Handlers) RegisterLogRoutes

func (h *Handlers) RegisterLogRoutes(mux *http.ServeMux)

RegisterLogRoutes adds log-ingestion and live-streaming routes to mux.

func (*Handlers) RegisterModelRoutes added in v0.1.0

func (h *Handlers) RegisterModelRoutes(mux *http.ServeMux)

RegisterModelRoutes adds the model-catalog route to mux.

func (*Handlers) RegisterShemRoutes

func (h *Handlers) RegisterShemRoutes(mux *http.ServeMux)

RegisterShemRoutes adds shem-facing routes to mux.

func (*Handlers) RegisterTicketRoutes

func (h *Handlers) RegisterTicketRoutes(mux *http.ServeMux)

RegisterTicketRoutes adds ticket-related routes to mux.

func (*Handlers) ReviseClaim

func (h *Handlers) ReviseClaim(ticketID string, shemID uint) (*ClaimResponse, error)

ReviseClaim resumes a ticket already assigned to shemID that is in the revising phase. Unlike ClaimTicket it does not change phase or assigned_shem — the ticket is already owned by this shem.

The approval clause matches resumableTickets' posture (Task 20): a ticket can sit in ready-for-review for hours or days awaiting a human, visible on GitHub the whole time via the golem:ready-for-review label mirror. If the issue is edited during that window and the routine human "request-changes" action moves the ticket to revising, ghsync.applyIssue refreshes Description/BodyHash but — because the ticket is still assigned — deliberately does not yank phase or IntakeApproved back to pending-approval (the running shem may be mid-run). Without this clause, revise-claim would serve that edited, never-reviewed text straight into buildRevisePrompt with no race required. Requiring approved_body_hash = body_hash here means approval means "a human approved THIS text", checked at the point revise-claim actually hands the description to a shem; a mismatch simply refuses the resume and leaves a human to re-approve, exactly as resumableTickets does.

type SyncTrigger added in v0.1.0

type SyncTrigger interface {
	TriggerSync(repoID uint) bool
}

SyncTrigger requests an immediate ingest pass for one repository. It is satisfied by *ghsync.Worker; the interface keeps this package free of a dependency on the worker's internals and lets tests substitute a stub.

type WaitPolicy added in v0.1.0

type WaitPolicy struct {
	// UsageLimitMax caps a single wait for a parsed reset time.
	UsageLimitMax time.Duration
	// LimitBackoff is the schedule used when no reset time could be parsed;
	// its last step repeats until LimitBackoffMax is spent.
	LimitBackoff    []time.Duration
	LimitBackoffMax time.Duration
	// Failover maps a backend to the one its limit-waiting tickets move to; empty
	// means they wait. FailoverAfter is the shortest wait worth moving for.
	Failover      map[string]string
	FailoverAfter time.Duration
}

WaitPolicy holds the configurable caps for usage-limit waits. Zero fields take the defaults (see config.SupervisorConfig).

Jump to

Keyboard shortcuts

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