specialist

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const SessionTagSpecialist = sessionTagSpecialist
View Source
const TaskToolName = "Task"

Variables

This section is empty.

Functions

func BuildFinalResult

func BuildFinalResult(events []streamjson.Event, stderrOutput string, processExitCode int, signalDesc string) tools.Result

func FormatList

func FormatList(result LoadResult) string

func FormatMarkdown

func FormatMarkdown(manifest Manifest) string

func FormatPaths

func FormatPaths(paths Paths) string

func FormatShow

func FormatShow(manifest Manifest) string

func ParseStream

func ParseStream(reader io.Reader) ([]streamjson.Event, error)

func ResolveTools

func ResolveTools(selection []string) ([]string, error)

func SplitToolList

func SplitToolList(value string) []string

SplitToolList parses comma- or whitespace-separated specialist tool selections.

func Validate

func Validate(manifest *Manifest) error

func WrapResumePrompt

func WrapResumePrompt(prompt string) string

func WrapSystemPrompt

func WrapSystemPrompt(name string, systemPrompt string, prompt string, description string) string

Types

type BackgroundManagerFunc

type BackgroundManagerFunc func() (*background.Manager, error)

type BuildArgsInput

type BuildArgsInput struct {
	Manifest              Manifest
	Prompt                string
	ParentSessionID       string
	ParentToolUseID       string
	ParentModel           string
	ParentReasoningEffort string
	CurrentDepth          int
	Description           string
	Cwd                   string
	// PermissionMode is the parent's resolved permission mode. Only an explicit
	// unsafe mode runs the child at "--auto high"; empty or any other value is
	// fail-safe "low", so a caller that forgets to wire it never escalates the
	// child to unsafe. Authority is therefore never widened beyond the parent.
	PermissionMode string
	// MemberAutonomy marks a headless swarm member: when set and the parent is
	// non-unsafe, the child runs at "--auto member" (PermissionModeMemberAuto) so
	// it can write/edit + run sandboxed shell IN the workspace, instead of the
	// read-only "--auto low". Off by default, so the Task tool's specialists are
	// unchanged. The sandbox still confines writes to the workspace root.
	MemberAutonomy bool
}

type BuildArgsResult

type BuildArgsResult struct {
	Args      []string
	SessionID string
	// PromptFile is created for large prompts; callers own cleanup after exec finishes.
	PromptFile string
}

type BuildResumeArgsInput

type BuildResumeArgsInput struct {
	SessionID      string
	Prompt         string
	CurrentDepth   int
	Manifest       Manifest
	Cwd            string
	PermissionMode string
}

type ChildRunResult

type ChildRunResult struct {
	Events   []streamjson.Event
	Stderr   string
	ExitCode int
	// Signal is a human-readable description (e.g. "signal: killed") when the child
	// was terminated by a signal rather than exiting normally; empty otherwise. It
	// turns an opaque exit -1 into an actionable reason (SIGKILL ~ out of memory).
	Signal  string
	Started bool
}

type CreateInput

type CreateInput struct {
	Name            string
	Description     string
	SystemPrompt    string
	Extends         string
	Model           string
	ReasoningEffort string
	Tools           []string
	Location        Location
	Overwrite       bool
}

type DeleteInput

type DeleteInput struct {
	Name     string
	Location Location
}

type ExecResult

type ExecResult struct {
	Result    tools.Result
	SessionID string
}

type Executor

type Executor struct {
	NewSessionID          NewSessionIDFunc
	WritePromptFile       WritePromptFileFunc
	PromptFileMaxSize     int
	Load                  LoadFunc
	RunChild              RunChildFunc
	LaunchBackground      LaunchBackgroundFunc
	BinaryPath            string
	Paths                 Paths
	SessionStore          *sessions.Store
	BackgroundManager     *background.Manager
	BackgroundManagerFunc BackgroundManagerFunc
	BackgroundRuntime     *Runtime
}

func (Executor) BuildArgs

func (executor Executor) BuildArgs(input BuildArgsInput) (BuildArgsResult, error)

func (Executor) BuildResumeArgs

func (executor Executor) BuildResumeArgs(input BuildResumeArgsInput) (BuildArgsResult, error)

func (Executor) IsReadOnlySpecialist

func (executor Executor) IsReadOnlySpecialist(name string) bool

IsReadOnlySpecialist reports whether the named specialist resolves to a read-only tool set. Unknown names and load errors return false, so a caller (the Task tool's permission gate) stays on the safe prompt path when in doubt.

func (Executor) Run

func (executor Executor) Run(ctx context.Context, params TaskParameters, options TaskRunOptions) (ExecResult, error)

type GenerateTool

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

func NewGenerateTool

func NewGenerateTool(storage *Storage) *GenerateTool

func (*GenerateTool) Description

func (tool *GenerateTool) Description() string

func (*GenerateTool) Name

func (tool *GenerateTool) Name() string

func (*GenerateTool) Parameters

func (tool *GenerateTool) Parameters() tools.Schema

func (*GenerateTool) Run

func (tool *GenerateTool) Run(ctx context.Context, args map[string]any) tools.Result

func (*GenerateTool) Safety

func (tool *GenerateTool) Safety() tools.Safety

type LaunchBackgroundFunc

type LaunchBackgroundFunc func(binaryPath string, args []string, outputFile string, onExit func(exitCode int)) (int, error)

type LoadFunc

type LoadFunc func(LoadOptions) (LoadResult, error)

type LoadOptions

type LoadOptions struct {
	Paths Paths
}

type LoadResult

type LoadResult struct {
	Paths       Paths      `json:"paths"`
	Specialists []Manifest `json:"specialists"`
	Warnings    []string   `json:"warnings,omitempty"`
}

func Load

func Load(options LoadOptions) (LoadResult, error)

type Location

type Location string
const (
	LocationBuiltin Location = "builtin"
	LocationUser    Location = "user"
	LocationProject Location = "project"
)

type Manifest

type Manifest struct {
	Metadata      Metadata  `json:"metadata"`
	SystemPrompt  string    `json:"systemPrompt"`
	ResolvedTools []string  `json:"resolvedTools,omitempty"`
	Location      Location  `json:"location"`
	FilePath      string    `json:"filePath"`
	LastModified  time.Time `json:"lastModified,omitempty"`
	Warnings      []string  `json:"warnings,omitempty"`
}

func Builtins

func Builtins() []Manifest

func Find

func Find(result LoadResult, name string) (Manifest, bool)

func ParseMarkdown

func ParseMarkdown(content string) (Manifest, error)

type Metadata

type Metadata struct {
	Name            string   `json:"name"`
	Description     string   `json:"description"`
	Extends         string   `json:"extends,omitempty"`
	Model           string   `json:"model,omitempty"`
	ReasoningEffort string   `json:"reasoningEffort,omitempty"`
	Tools           []string `json:"tools,omitempty"`
}

type NewSessionIDFunc

type NewSessionIDFunc func() (string, error)

type OutputTool

type OutputTool struct {
	SessionStore   *sessions.Store
	PollInterval   time.Duration
	DefaultTimeout time.Duration
	MaxTimeout     time.Duration
	// contains filtered or unexported fields
}

func NewOutputTool

func NewOutputTool(manager *background.Manager) *OutputTool

func (*OutputTool) Description

func (tool *OutputTool) Description() string

func (*OutputTool) Name

func (tool *OutputTool) Name() string

func (*OutputTool) Parameters

func (tool *OutputTool) Parameters() tools.Schema

func (*OutputTool) Run

func (tool *OutputTool) Run(ctx context.Context, args map[string]any) tools.Result

func (*OutputTool) Safety

func (tool *OutputTool) Safety() tools.Safety

type Paths

type Paths struct {
	UserDir    string `json:"userDir"`
	ProjectDir string `json:"projectDir,omitempty"`
}

func DefaultPaths

func DefaultPaths(workspaceRoot string) (Paths, error)

type RunChildFunc

type RunChildFunc func(ctx context.Context, binaryPath string, args []string, progress func(streamjson.Event)) (ChildRunResult, error)

type Runtime

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

func NewRuntime

func NewRuntime(options RuntimeOptions) *Runtime

func RegisterTools

func RegisterTools(registry *tools.Registry, executor Executor) (*Runtime, error)

func (*Runtime) Close

func (runtime *Runtime) Close() error

func (*Runtime) Manager

func (runtime *Runtime) Manager() (*background.Manager, error)

func (*Runtime) TrackPromptFile

func (runtime *Runtime) TrackPromptFile(taskID string, promptFile string)

func (*Runtime) UntrackPromptFile

func (runtime *Runtime) UntrackPromptFile(taskID string)

type RuntimeOptions

type RuntimeOptions struct {
	Manager     *background.Manager
	ManagerFunc BackgroundManagerFunc
}

type StopTool

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

func NewStopTool

func NewStopTool(manager *background.Manager) *StopTool

func (*StopTool) Description

func (tool *StopTool) Description() string

func (*StopTool) Name

func (tool *StopTool) Name() string

func (*StopTool) Parameters

func (tool *StopTool) Parameters() tools.Schema

func (*StopTool) Run

func (tool *StopTool) Run(ctx context.Context, args map[string]any) tools.Result

func (*StopTool) Safety

func (tool *StopTool) Safety() tools.Safety

type Storage

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

func NewStorage

func NewStorage(paths Paths) *Storage

func (*Storage) Create

func (storage *Storage) Create(input CreateInput) (Manifest, error)

func (*Storage) Delete

func (storage *Storage) Delete(input DeleteInput) (string, error)

func (*Storage) Path

func (storage *Storage) Path(name string, location Location) (string, error)

type StreamResult

type StreamResult struct {
	Events    []streamjson.Event
	RunID     string
	SessionID string
	Text      string
	Tools     []string
	Errors    []string
	Status    string
	ExitCode  int
	Usage     StreamUsage
}

func SummarizeStream

func SummarizeStream(events []streamjson.Event, processExitCode int) StreamResult

type StreamUsage

type StreamUsage struct {
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
	Events           int
}

func (StreamUsage) EffectiveTotalTokens

func (usage StreamUsage) EffectiveTotalTokens() int

func (StreamUsage) HasUsage

func (usage StreamUsage) HasUsage() bool

type Summary

type Summary struct {
	Name            string   `json:"name"`
	Description     string   `json:"description"`
	Extends         string   `json:"extends,omitempty"`
	Model           string   `json:"model,omitempty"`
	ReasoningEffort string   `json:"reasoningEffort,omitempty"`
	Tools           []string `json:"tools,omitempty"`
	ResolvedTools   []string `json:"resolvedTools,omitempty"`
	Location        Location `json:"location"`
	FilePath        string   `json:"filePath"`
	Warnings        []string `json:"warnings,omitempty"`
}

func Summaries

func Summaries(manifests []Manifest) []Summary

type TaskParameters

type TaskParameters struct {
	Name            string
	Prompt          string
	Description     string
	RunInBackground bool
	Resume          string
	// Manifest, when non-nil, supplies the specialist definition inline instead
	// of resolving Name against the specialist registry. It is validated before
	// use. The swarm launcher sets this so a swarm member can run from its own
	// agent definition (e.g. "subagent"/"teammate"), which is not a registered
	// specialist and would otherwise fail the name lookup.
	Manifest *Manifest
}

type TaskRunOptions

type TaskRunOptions struct {
	ToolCallID            string
	ParentSessionID       string
	ParentModel           string
	ParentReasoningEffort string
	CurrentDepth          int
	Cwd                   string
	// PermissionMode propagates the parent's resolved permission mode to the
	// child. Only an explicit unsafe mode runs the child unsafe; empty or any
	// other value is fail-safe "low", so the child never gains more authority
	// than the parent.
	PermissionMode string
	// MemberAutonomy marks a headless swarm member so it can write/edit + run
	// sandboxed shell in the workspace (see BuildArgsInput.MemberAutonomy). Off
	// for Task-tool specialists.
	MemberAutonomy bool
	// Progress, when set, is called with each stream-json event emitted by the
	// child process while it runs. nil is a no-op.
	Progress func(streamjson.Event)
}

type TaskTool

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

func NewTaskTool

func NewTaskTool(executor Executor) *TaskTool

func (*TaskTool) Description

func (tool *TaskTool) Description() string

func (*TaskTool) Name

func (tool *TaskTool) Name() string

func (*TaskTool) Parameters

func (tool *TaskTool) Parameters() tools.Schema

func (*TaskTool) PermissionForArgs

func (tool *TaskTool) PermissionForArgs(args map[string]any) tools.Permission

PermissionForArgs auto-approves delegating to a READ-ONLY specialist — it can only read the workspace, so spawning it is harmless — while keeping the static prompt for write-capable specialists (e.g. worker) and for resume. This lets the orchestrator delegate exploration/review off a normal prompt without an approval wall. Implements tools.ArgsPermissioner.

func (*TaskTool) Run

func (tool *TaskTool) Run(ctx context.Context, args map[string]any) tools.Result

func (*TaskTool) RunWithOptions

func (tool *TaskTool) RunWithOptions(ctx context.Context, args map[string]any, options tools.RunOptions) tools.Result

func (*TaskTool) Safety

func (tool *TaskTool) Safety() tools.Safety

type WritePromptFileFunc

type WritePromptFileFunc func(prompt string) (string, error)

Jump to

Keyboard shortcuts

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