service

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 34 Imported by: 1 module, 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 service runs the Blitz service: every workspace a client opens, served over the per-user socket, and the workers' schedules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, o Options) error

Run serves until ctx is done, then lets turns in progress finish for a few seconds and removes the socket. A service already answering on the socket is an error wrapping socket.ErrRunning.

func RunJob

func RunJob(ctx context.Context, j Job, o JobOptions) error

RunJob runs one job's run (JB-10, JB-11): it clones the workspace through the service as the job's owner, runs the job unattended with the organization's models, pushes what it changed to its own branch, keeps what it left in out/ and its log as its artifacts, and tells the service how it ended. The error is why it couldn't, which the service has been told too when it could be.

Types

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (Caller, error)
}

Authenticator says who a request is from, from its credentials (a bearer token, say); an error when it has none or they don't hold.

type Authorizer

type Authorizer interface {
	Authorize(ctx context.Context, c Caller, procedure string) error
}

Authorizer says whether c may call procedure (a Connect procedure, as "/blitz.v1.WorkspaceService/RunTurn", or another path the service serves); an error says why not.

type Caller

type Caller struct {
	ID    string // stable: never an email, which can change
	Email string
	Roles []string
}

Caller is who a request on the network listener is from.

func CallerFrom

func CallerFrom(ctx context.Context) (Caller, bool)

CallerFrom is the caller of a request that came in on the network listener; false on the socket, whose callers are its owner.

type Job

type Job struct {
	// Service is the organization's service; Run and Secret the run's ID
	// and its own secret, traded for access tokens as the job's owner.
	Service, Run, Secret string
	// CloneURL is the workspace's, through the service; Name the job's.
	CloneURL, Name string
	// RunAs is the ID of the person the run acts as, its job's owner, and
	// Artifacts the name its files are kept under (spec_055_urns); either
	// may be unknown to an older service.
	RunAs     string
	Artifacts urn.Name
	// Resume is the session a paused run goes on in (spec_053 EN-43), with
	// the answer to what it asked (approve or deny), its note, and the
	// request answered.
	Resume, Answer, Note string
	Request              *enterprise.Request
	// Deadline is when the run must have ended.
	Deadline time.Time
}

Job is one run of a job the organization's service runs (spec_009_jobs JB-10): what `blitzd run-job` reads from its environment, as the service's runner sets it.

func JobFromEnv

func JobFromEnv(getenv func(string) string) (Job, error)

JobFromEnv is the run getenv describes.

type JobOptions

type JobOptions struct {
	// Config is the configuration's directory ("" for the usual).
	Config string
	// Root is where runs' folders are made (a new temporary one when "",
	// removed after): each run's is jobs/<person>/<job>/<run>/, holding the
	// clone (workspace/) and what it leaves for people (out/).
	Root string
	// Git is the git program ("git").
	Git string
	// Open opens the clone's workspace (engine.Open, trusting it: it's the
	// organization's).
	Open func(ctx context.Context, cfg *config.Config, o engine.Options) (*engine.Workspace, error)
	// Client names the runner to the service.
	Client string
}

JobOptions are how RunJob runs.

type Network

type Network struct {
	// Listener is where it listens; TLS, its certificate.
	Listener net.Listener
	TLS      *tls.Config
	// Plain serves without TLS, HTTP/1.1 and HTTP/2 in cleartext (h2c),
	// for a listener only a front end that ends TLS itself reaches: Cloud
	// Run's, say. TLS is then unused.
	Plain bool
	// Auth says who a request is from; Authz, whether they may make it
	// (nil: anyone Auth accepts may).
	Auth  Authenticator
	Authz Authorizer
	// Routes are the program's own paths on the listener (discovery,
	// health checks, its own sign-in): a request a pattern in Routes
	// matches goes there without Auth, the program checking its callers
	// itself; every other request goes to Blitz's services, guarded.
	Routes *http.ServeMux
	// Wrap, when set, sees every request on the listener first, Routes'
	// and Blitz's alike: a program's own session standing in for the
	// credentials Auth reads (the enterprise admin console's cookie, say).
	Wrap func(http.Handler) http.Handler
}

Network is a listener other machines reach, beside the socket: for a program that runs the service for many people (spec_053_enterprise EN-03). Every request on it needs credentials Auth accepts. blitzd never sets it: the socket is only its owner's, and the service runs commands.

type Options

type Options struct {
	// Socket is where it listens (socket.DefaultSocket when empty).
	Socket string
	// Config is the configuration file ("" for the usual search).
	Config string
	// Version is reported in the diagnostic log and telemetry.
	Version string
	// IdleExit stops the service after this long with nothing to do (no
	// request, turn or background run); 0 never. For a service a client
	// started on demand, not the login item's.
	IdleExit time.Duration
	// ExitWith stops the service when it reads to its end: the stdin of
	// a private service, a pipe from the client that started it, which
	// closes when that client exits, however it exits. Nil: never.
	ExitWith io.Reader
	// Run are one client's settings for every workspace a private service
	// opens (the CLI's flags for that run).
	Run RunOverrides
	// Private marks a service a client started for a run of its own: it
	// serves that client only, and never runs the workers' schedules (the
	// shared service does; a private one would run them twice, and open
	// every workspace with an enabled worker, keeping it from the others).
	Private bool
	// AdoptPath gives the service the user's login shell's PATH at start:
	// blitzd's, started by the tray, launchd or systemd with the system's
	// bare one (spec_021_service SVC-57). A private service has its
	// terminal's already, and tests' services keep theirs.
	AdoptPath bool
	// Network serves the API to other machines too, beside the socket:
	// for a program that runs the service for many people. Nil for
	// blitzd, which never listens on the network.
	Network *Network
}

Options are how the service runs.

type Refusal

type Refusal struct {
	Status  int
	Code    string
	Message string
}

Refusal is an error an Authenticator or Authorizer returns to answer with a status and code of its own rather than 401 unauthenticated or 403 forbidden: 403 terms_required until the person accepts the organization's terms, say.

func (*Refusal) Error

func (r *Refusal) Error() string

Error is the message, for the person.

type RunOverrides

type RunOverrides struct {
	Model, Agent, Agency string
	// PluginDirs load more plugins; AddDirs are more read-write roots
	// (as sandbox.allowed_paths).
	PluginDirs, AddDirs []string
	// SessionDir keeps sessions elsewhere (--no-session-persistence: a
	// folder the CLI removes).
	SessionDir string
	// TrustProject trusts the project's settings for this run.
	TrustProject bool
	// AppendSystemPrompt is added to the agent's instructions.
	AppendSystemPrompt string
}

RunOverrides are a run's settings over the configuration: what the CLI's flags set, for the private service it starts for that run.

Directories

Path Synopsis
Package server serves Blitz's API (proto/blitz/v1) over Connect: one process holding every workspace a user opens, each an engine.Workspace.
Package server serves Blitz's API (proto/blitz/v1) over Connect: one process holding every workspace a user opens, each an engine.Workspace.
Package servicetest runs the Blitz service in a test, for packages outside the service that test against it (the client, the CLI, the desktop app).
Package servicetest runs the Blitz service in a test, for packages outside the service that test against it (the client, the CLI, the desktop app).

Jump to

Keyboard shortcuts

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