worker

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: 37 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

This section is empty.

Functions

func CloneIfMissing

func CloneIfMissing(ctx context.Context, repoPath, remote string) error

CloneIfMissing clones remote into repoPath when there is no git repository there yet. Only http/https/ssh/git URL schemes are permitted, to prevent git ext:: injection.

"Missing" means no git repository, not merely no directory. The earlier os.IsNotExist check was wrong in a way that produced a baffling failure: a directory that exists but is not a repository — an empty volume mount, or one where a previous run's `golem init` had already created .golem — silently skipped the clone, and the first git command to follow died with

creating worktree: git worktree add: exit status 128
fatal: not a git repository (or any of the parent directories): .git

several steps away from the actual cause.

A directory that already contains something other than a git repository is reported rather than cloned into: git clone refuses a non-empty target, and working around that with init-plus-fetch would be operating on a directory whose contents nobody has explained.

func PostCheckpointWithRetry

func PostCheckpointWithRetry(c *client.Client, ticketID string, phase, sha string, maxAttempts int) error

PostCheckpointWithRetry uses the client's built-in exponential-backoff retry logic with a per-call retry budget. The copy shares the HTTP transport without changing the retry settings used by concurrent requests on the original client.

func ReconstructState

func ReconstructState(ticketDir, worktreePath string, claim *client.ClaimResponse) error

ReconstructState writes state.json and log.jsonl into ticketDir from the data carried in the ClaimResponse. The directory is created if absent. worktreePath is the expected worktree path for the ticket (used by ticket.Load).

func RecoverTicket

func RecoverTicket(ctx context.Context, claim *client.ClaimResponse, cfg *config.Config, setup func(string) error) error

RecoverTicket ensures the local repo is in the correct state for resuming a checkpointed ticket, then reconstructs the ticket's local state files. setup is the adapter's WorktreeSetup, run on a newly created worktree. Idempotent: safe to call on an already-present worktree.

func RecoverTicketForRetry added in v0.1.0

func RecoverTicketForRetry(ctx context.Context, claim *client.ClaimResponse, cfg *config.Config, setup func(string) error) error

RecoverTicketForRetry keeps an existing worktree's uncommitted edits when it is already on this ticket's branch. If the retry lands on another shem with no matching worktree, it falls back to the saved commit checkpoint.

func RestoreDesignDocuments added in v0.1.0

func RestoreDesignDocuments(ticketDir string, claim *client.ClaimResponse) error

RestoreDesignDocuments makes the design documents a resumed ticket's remaining phases read from disk — spec.md for the plan phase, plan.md and spec.md for implementation — exist on this host. A design phase writes its document only into the ticket directory of the host that ran it, so a checkpoint resume on a fresh shem or container used to skip the design phases and implement from a plan that was not there: the implement prompt cats .golem/tickets/<id>/plan.md, gets nothing, and the reviewer later finds no plan.

The orchestrator keeps a copy of each document: the phase posts it as a SPEC/PLAN log entry before validation runs, and every claim carries the ticket's full log. A missing local file is restored from that copy — in manual-approval mode, exactly the text the human approved. A present local file always wins: it is what validation actually ran against. Restored or present, every required document is re-checked for content, the same floor requireDesignDocument applies after a phase.

A required document that exists in neither place fails the resume for brainstorm and plan checkpoints: the next phase exists only to produce or consume that document, and continuing is the silent plan-free run this function exists to remove. Later checkpoints (a crashed implementation or review) restore what they can and only log a gap — those resumes ran without the documents before, and the tickets are already past the phases that read them.

Types

type Agent added in v0.1.0

type Agent struct {
	Adapter    agentrunner.Adapter
	ConfigPath string
	Catalog    models.Catalog
}

Agent is the adapter this shem runs plus the config document its nested golem subcommands read.

func NewAgent added in v0.1.0

func NewAgent(cfg *config.Config) (*Agent, func(), error)

NewAgent builds the configured adapter and writes its backend document. The returned func removes the run directory.

func (*Agent) StageModel added in v0.1.0

func (a *Agent) StageModel(st models.Stage) string

StageModel resolves one stage against this shem's own catalog.

type Decision added in v0.1.0

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

Decision is what the diagnoser decided instead of asking a human.

type Diagnoser added in v0.1.0

type Diagnoser interface {
	Diagnose(context.Context, *client.ClaimResponse, string, string) (Diagnosis, error)
}

Diagnoser returns a second opinion. Routing and dispatch remain worker-owned; a diagnosis cannot override the host policy or the server state guards.

type Diagnosis added in v0.1.0

type Diagnosis struct {
	Route    string `json:"route"`
	Reason   string `json:"reason"`
	Feedback string `json:"feedback"`
	// Decision is set only on route "decide".
	Decision *Decision `json:"decision,omitempty"`
}

Diagnosis is the sole structured output the routing policy accepts.

type Executor

type Executor interface {
	RunTicket(ctx context.Context, cfg *config.Config, c *client.Client, claim *client.ClaimResponse) error
}

Executor is the interface for running a ticket.

type GolemExecutor

type GolemExecutor struct {
	Agent *Agent
	// Forge merges a finished epic child into its run's target ref (plain
	// git in the push mirror). Nil means forge.Git{}; tests substitute a
	// fake. The worker depends on the operation, not on the git CLI.
	Forge forge.Forge
	// contains filtered or unexported fields
}

GolemExecutor runs tickets phase by phase. Per ticket, the spec and the plan are either gated by a human (manual approval) or by automatic validation.

func (*GolemExecutor) IntegrateAssigned added in v0.1.0

func (e *GolemExecutor) IntegrateAssigned(ctx context.Context, cfg *config.Config,
	c *client.Client, claim *client.ClaimResponse, repoPath, branch string)

IntegrateAssigned re-runs the integration lane for one assigned epic child. It is the Worker-facing entry to integrateEpicChild, for the startup sweep, periodic reconciliation and the resume push.

func (*GolemExecutor) RunTicket

func (e *GolemExecutor) RunTicket(ctx context.Context, cfg *config.Config, c *client.Client, claim *client.ClaimResponse) error

RunTicket executes a claimed ticket:

  1. Pre-creates the local ticket with `golem ticket new` (scaffolding only, no agent).
  2. Ensures the repo is initialized and the code graph is current.
  3. Runs three separate agent sessions — brainstorm, plan, implement — pausing between brainstorm→plan and plan→implement for human approval via the orchestrator UI. Tickets are NOT closed automatically; humans close via the UI.

type ModelDiagnoser added in v0.1.0

type ModelDiagnoser struct {
	Runner agentrunner.Runner
	Model  string
}

func (ModelDiagnoser) Diagnose added in v0.1.0

func (d ModelDiagnoser) Diagnose(ctx context.Context, claim *client.ClaimResponse, reason, ticketDir string) (Diagnosis, error)

type Worker

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

Worker polls for available tickets, claims them, and runs them via Executor.

func New

func New(cfg *config.Config, c *client.Client, exec Executor, agent *Agent) *Worker

New creates a new Worker. exec may be nil for testing (skips actual execution).

func (*Worker) HandleMessage

func (w *Worker) HandleMessage(msg ws.WSMessage)

HandleMessage processes a WebSocket push message from the orchestrator.

func (*Worker) SetWSClient

func (w *Worker) SetWSClient(wsc *client.WSClient)

SetWSClient attaches a WebSocket client for heartbeat pings.

func (*Worker) Shutdown

func (w *Worker) Shutdown()

Shutdown signals all running tickets to stop, waits up to 10 minutes for them to exit, then deregisters. Polling stops before cancellation, so it cannot create fresh work while shutdown is waiting.

func (*Worker) Start

func (w *Worker) Start()

Start registers with the orchestrator, resumes any in-progress tickets from before a restart, then begins the poll loop. It does not block.

Jump to

Keyboard shortcuts

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