Help us shape the future of Go! Take the 2026 Go Developer Survey

customcmd

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolVersion = 1

Variables

View Source
var (
	ErrInvalid     = errors.New("custom command profile is invalid")
	ErrNotApproved = errors.New("custom command profile is not approved")
	ErrProtocol    = errors.New("custom command protocol violation")
	ErrCapacity    = errors.New("custom command profile concurrency exhausted")
	ErrNoProfile   = errors.New("task is not bound to a custom command profile")
)

Functions

func Approved

func Approved(p Profile, now time.Time) bool

func ValidDigest

func ValidDigest(value string) bool

func Validate

func Validate(p Profile) error

Types

type Authorized

type Authorized struct {
	RunID   string      `json:"run_id"`
	Profile ProfileSpec `json:"profile"`
}

type Dispatcher

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

func NewDispatcher

func NewDispatcher(db *store.Store, runners *runner.Service, profiles *Service, budgets *budget.Service) *Dispatcher

func (*Dispatcher) Authorize

func (d *Dispatcher) Authorize(ctx context.Context, credential string) (Authorized, error)

func (*Dispatcher) Report

func (d *Dispatcher) Report(ctx context.Context, credential string, in ReportInput) (Authorized, error)

type Event

type Event struct {
	Type    string          `json:"type"`
	Message string          `json:"message,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
}

type Executor

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

func NewExecutor

func NewExecutor(launcher Launcher) *Executor

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, profile Profile, in Input) (Result, error)

func (*Executor) RunSpec

func (e *Executor) RunSpec(ctx context.Context, spec ProfileSpec, in Input) (Result, error)

type Input

type Input struct {
	JobID      string
	AttemptID  string
	Workspace  sandbox.Workspace
	Request    []byte
	PolicyHash string
}

type Launcher

type Launcher interface {
	Launch(context.Context, Spec) (sandbox.CommandResult, error)
}

type Profile

type Profile struct {
	ID               string     `json:"id"`
	Name             string     `json:"name"`
	Version          int64      `json:"version"`
	ImageDigest      string     `json:"image_digest"`
	Executable       string     `json:"executable"`
	Argv             []string   `json:"argv"`
	ProtocolVersion  int        `json:"protocol_version"`
	MaxWallSeconds   int        `json:"max_wall_seconds"`
	MaxOutputBytes   int64      `json:"max_output_bytes"`
	MaxTurns         int        `json:"max_turns"`
	Concurrency      int        `json:"concurrency"`
	ApprovalEvidence string     `json:"approval_evidence"`
	ApprovedBy       string     `json:"approved_by,omitempty"`
	ApprovedAt       *time.Time `json:"approved_at,omitempty"`
	RevokedAt        *time.Time `json:"revoked_at,omitempty"`
	CreatedAt        time.Time  `json:"created_at"`
}

func (Profile) State

func (p Profile) State() string

type ProfileSpec

type ProfileSpec struct {
	ID              string   `json:"id"`
	Version         int64    `json:"version"`
	ImageDigest     string   `json:"image_digest"`
	Executable      string   `json:"executable"`
	Argv            []string `json:"argv"`
	ProtocolVersion int      `json:"protocol_version"`
	MaxWallSeconds  int      `json:"max_wall_seconds"`
	MaxOutputBytes  int64    `json:"max_output_bytes"`
	MaxTurns        int      `json:"max_turns"`
	Concurrency     int      `json:"concurrency"`
}

func SpecFromProfile

func SpecFromProfile(p Profile) ProfileSpec

type ReportInput

type ReportInput struct {
	RunID  string  `json:"run_id"`
	State  string  `json:"state"`
	Reason string  `json:"reason"`
	Usage  Usage   `json:"usage"`
	Events []Event `json:"events"`
}

type Result

type Result struct {
	State     string  `json:"state"`
	Reason    string  `json:"reason"`
	Output    []byte  `json:"-"`
	Events    []Event `json:"events"`
	Usage     Usage   `json:"usage"`
	Truncated bool    `json:"truncated"`
	ExitCode  int     `json:"exit_code"`
	TimedOut  bool    `json:"timed_out"`
}

type SandboxLauncher

type SandboxLauncher struct {
	Runtime sandbox.SandboxRuntime
}

func (SandboxLauncher) Launch

type Service

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

func New

func New(db *store.Store, identity *auth.Service) *Service

func (*Service) Approve

func (s *Service) Approve(ctx context.Context, session auth.Session, org, id, evidence string, expected int64, request string) (Profile, error)

func (*Service) Bind

func (s *Service) Bind(ctx context.Context, tx pgx.Tx, org, id string, version int64) (Profile, error)

func (*Service) Create

func (s *Service) Create(ctx context.Context, session auth.Session, org string, in Profile, request string) (Profile, error)

func (*Service) Get

func (s *Service) Get(ctx context.Context, session auth.Session, org, id string) (Profile, error)

func (*Service) List

func (s *Service) List(ctx context.Context, session auth.Session, org, cursor string, limit int) (domain.Page[Profile], error)

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, session auth.Session, org, id string, expected int64, request string) (Profile, error)

type Spec

type Spec struct {
	Workspace  sandbox.Workspace
	Executable string
	Args       []string
	Directory  string
	Stdin      []byte
	Timeout    time.Duration
	MaxOutput  int64
}

type Usage

type Usage struct {
	Known        bool  `json:"known"`
	Tokens       int64 `json:"tokens,omitempty"`
	MicroUSD     int64 `json:"micro_usd,omitempty"`
	Milliseconds int64 `json:"milliseconds,omitempty"`
	Requests     int64 `json:"requests,omitempty"`
}

Jump to

Keyboard shortcuts

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