tooltask

package
v0.0.0-...-e2ff964 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package tooltask implements admission and execution of typed background tool tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eligible

func Eligible(name tool.Name) bool

Eligible reports whether a built-in may be reconstructed as durable work. Eligibility is explicit rather than inferred from Definition.ReadOnly.

Types

type Completion

type Completion struct {
	Err            error
	Arguments      tool.Arguments
	TaskID         string
	InvocationID   string
	WrapperCallID  string
	ParentCallID   string
	OwnerSessionID string
	Target         string
	ArgumentsJSON  string
	Result         tool.Result
	SourceSequence int
}

Completion is the canonical target outcome presented to lifecycle hooks.

type CompletionHook

type CompletionHook func(context.Context, *Completion) error

CompletionHook applies assistant lifecycle semantics in the surviving worker.

type Invocation

type Invocation struct {
	ID                string
	WrapperCallID     string
	ParentCallID      string
	OwnerSessionID    string
	CWD               string
	InitiatingEntryID string
	SourceSequence    int
}

Invocation is immutable assistant metadata used for idempotent durable acceptance.

type Service

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

Service admits tasks and reconstructs built-in executors in workers.

func New

func New(
	repository *database.ToolTaskRepository,
	coordinator *tool.Coordinator,
	defaultTimeout time.Duration,
	maxTimeout time.Duration,
	maxOutcomeBytes int,
) *Service

New constructs a background tool task service.

func (*Service) AttachRuntime

func (service *Service) AttachRuntime(runtime *taskruntime.Service)

AttachRuntime connects the scheduler used to wake and cancel task execution.

func (*Service) Cancel

func (service *Service) Cancel(ctx context.Context, owner, taskID string) (*database.ToolTaskEntity, bool, error)

Cancel requests cancellation of an owner-scoped task.

func (*Service) Get

func (service *Service) Get(ctx context.Context, owner, id string) (*database.ToolTaskEntity, bool, error)

Get returns an owner-scoped task snapshot.

func (*Service) Kind

func (service *Service) Kind() string

Kind returns the durable task kind handled by this service.

func (*Service) List

func (service *Service) List(
	ctx context.Context, owner string, states []database.TaskState, limit int,
) ([]database.ToolTaskEntity, error)

List returns an owner's tasks, optionally filtered by state.

func (*Service) RecoverExpired

func (service *Service) RecoverExpired(ctx context.Context, expiresBefore time.Time) error

RecoverExpired interrupts tasks whose worker leases have expired.

func (*Service) ReleaseAdmission

func (service *Service) ReleaseAdmission(taskID string)

ReleaseAdmission abandons any pre-claim reservation that was not consumed.

func (*Service) Run

Run reconstructs and executes a durably admitted tool invocation.

func (*Service) SetCompletionHook

func (service *Service) SetCompletionHook(hook CompletionHook)

SetCompletionHook installs the process lifecycle bridge before workers start.

func (*Service) Settle

func (service *Service) Settle(
	ctx context.Context, finish *database.TaskFinish, outcome taskruntime.Outcome,
) (bool, error)

Settle atomically persists the canonical outcome and terminal transition.

func (*Service) Start

func (service *Service) Start(ctx context.Context, request *StartRequest) (*database.ToolTaskEntity, error)

Start validates and durably admits a background tool invocation.

func (*Service) SubscribeCompletions

func (service *Service) SubscribeCompletions() (events <-chan Completion, cancel func())

SubscribeCompletions follows canonical outcomes after their terminal state is durably committed. Delivery is best effort and never blocks workers; Get remains the authoritative repair path.

func (*Service) TryAdmit

func (service *Service) TryAdmit(ctx context.Context, task *database.TaskEntity) (bool, error)

TryAdmit reserves mutation resources before the authoritative task claim. Saturated resources leave the durable task queued rather than occupying a worker. A true result may accompany an error: admission succeeded, and the caller must continue dispatch so Run can durably settle the reported definition drift.

func (*Service) Wait

func (service *Service) Wait(ctx context.Context, owner, taskID string) (*database.ToolTaskEntity, error)

Wait blocks until a task reaches a terminal state or ctx ends.

type StartRequest

type StartRequest struct {
	Admit      func(context.Context, *StartRequest) error
	Arguments  tool.Arguments
	Target     string
	Invocation Invocation
	Timeout    time.Duration
}

StartRequest requests asynchronous execution of an ordinary built-in tool.

Jump to

Keyboard shortcuts

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