core

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package core defines protocol-level types shared across Whale subsystems.

Keep this package limited to stable data structures and pure helpers with no filesystem, network, UI, or agent runtime side effects. Business flow belongs in agent/app/tools/tui packages instead of here.

Index

Constants

View Source
const (
	ProposedPlanOpenTag  = "<proposed_plan>"
	ProposedPlanCloseTag = "</proposed_plan>"
)
View Source
const (
	// ToolInputEventsSuffix is the filename suffix for tool input event logs.
	ToolInputEventsSuffix = ".tool_input_events.jsonl"
	// ApprovalEventsSuffix is the filename suffix for approval event logs.
	ApprovalEventsSuffix = ".approval_events.jsonl"
)
View Source
const (
	ToolInputRepairNullOptionalOmitted  = "null_optional_omitted"
	ToolInputRepairStringifiedArray     = "stringified_array"
	ToolInputRepairBareStringToArray    = "bare_string_to_array"
	ToolInputRepairEmptyObjectToArray   = "empty_object_to_array"
	ToolInputRepairMarkdownAutolinkPath = "markdown_autolink_path"
)
View Source
const DefaultMaxToolResultChars = 32 * 1024

Variables

This section is empty.

Functions

func AsAnySlice added in v0.1.24

func AsAnySlice(v any) []any

AsAnySlice extracts a []any value, returning nil on mismatch or nil input.

func AsString added in v0.1.24

func AsString(v any) string

AsString extracts a string value from any type, returning empty string on mismatch.

func ContainsArg added in v0.1.24

func ContainsArg(argv []string, want string) bool

ContainsArg reports whether want is present in argv.

func ExtractProposedPlanText

func ExtractProposedPlanText(text string) (string, bool)

func FirstLine added in v0.1.24

func FirstLine(s string) string

FirstLine returns the first line of s (up to the first newline), trimmed. Returns the full trimmed input if there is no newline.

func FirstNonEmpty added in v0.1.24

func FirstNonEmpty(values ...string) string

FirstNonEmpty returns the first non-empty (after trimming whitespace) variadic string argument. Returns "" if all values are empty.

func FlattenSchemaForModel

func FlattenSchemaForModel(parameters map[string]any) map[string]any

FlattenSchemaForModel flattens nested object properties into dotted keys (for example: payload.path) to reduce nested JSON generation errors.

func IsReadOnlyToolCall

func IsReadOnlyToolCall(spec ToolSpec, call ToolCall) bool

func IsSessionJSONLName added in v0.1.24

func IsSessionJSONLName(name string) bool

IsSessionJSONLName reports whether name is a session JSONL file (not tool input or approval events).

func MarshalToolEnvelope

func MarshalToolEnvelope(env ToolEnvelope) (string, error)

func PathInside added in v0.1.24

func PathInside(path, parent string) (bool, error)

PathInside reports whether path is inside parent (or equal to parent), resolving symlinks through the nearest existing ancestor for accurate boundary checking even when the final path does not exist yet.

func RenestFlatInputForSpec

func RenestFlatInputForSpec(spec ToolSpec, raw string) (string, bool)

RenestFlatInputForSpec turns dotted keys back into nested objects when the tool schema is flattened for model interaction.

func SanitizeSessionID added in v0.1.24

func SanitizeSessionID(v string) string

SanitizeSessionID sanitizes a session ID for use in filenames. Non-alphanumeric characters (except - and _) are replaced with _.

func ShouldFlattenSchema

func ShouldFlattenSchema(parameters map[string]any) bool

ShouldFlattenSchema reports whether a tool schema is deep/wide enough to benefit from flattened argument keys for model-side tool calling.

func SkillNameDisabled added in v0.1.24

func SkillNameDisabled(name string, disabled []string) bool

SkillNameDisabled reports whether name is in the disabled list. Comparison is case-insensitive with whitespace trimmed.

func StripProposedPlanBlocks

func StripProposedPlanBlocks(text string) string

func WithToolResultArchive added in v0.1.21

func WithToolResultArchive(ctx context.Context, dir, sessionID string) context.Context

Types

type FinishReason

type FinishReason string
const (
	FinishReasonEndTurn  FinishReason = "end_turn"
	FinishReasonToolUse  FinishReason = "tool_use"
	FinishReasonCanceled FinishReason = "canceled"
	FinishReasonError    FinishReason = "error"
)

type Message

type Message struct {
	ID           string
	SessionID    string
	Role         Role
	Text         string
	Hidden       bool
	Reasoning    string
	ToolCalls    []ToolCall
	ToolResults  []ToolResult
	FinishReason FinishReason
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type ProposedPlanParser

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

func (*ProposedPlanParser) Finish

func (*ProposedPlanParser) Parse

func (p *ProposedPlanParser) Parse(delta string) []ProposedPlanSegment

type ProposedPlanSegment

type ProposedPlanSegment struct {
	Kind ProposedPlanSegmentKind
	Text string
}

type ProposedPlanSegmentKind

type ProposedPlanSegmentKind string
const (
	ProposedPlanSegmentNormal ProposedPlanSegmentKind = "normal"
	ProposedPlanSegmentStart  ProposedPlanSegmentKind = "start"
	ProposedPlanSegmentDelta  ProposedPlanSegmentKind = "delta"
	ProposedPlanSegmentEnd    ProposedPlanSegmentKind = "end"
)

type Role

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type SubagentStep added in v0.1.24

type SubagentStep struct {
	ToolName string `json:"tool_name,omitempty"`
	Status   string `json:"status,omitempty"`
	Summary  string `json:"summary,omitempty"`
}

type Tool

type Tool interface {
	Name() string
	Run(ctx context.Context, call ToolCall) (ToolResult, error)
}

type ToolApprovalHint

type ToolApprovalHint interface {
	ApprovalHint() string
}

type ToolCall

type ToolCall struct {
	ID    string
	Name  string
	Input string
}

type ToolCapabilities

type ToolCapabilities interface {
	Capabilities() []string
}

type ToolDescriber

type ToolDescriber interface {
	Description() string
}

type ToolEnvelope

type ToolEnvelope struct {
	OK        bool           `json:"ok"`
	Success   bool           `json:"success"`
	Error     string         `json:"error,omitempty"`
	Message   string         `json:"message,omitempty"`
	Code      string         `json:"code,omitempty"`
	Summary   string         `json:"summary,omitempty"`
	Data      map[string]any `json:"data,omitempty"`
	Truncated bool           `json:"truncated,omitempty"`
	Meta      map[string]any `json:"meta,omitempty"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

func NewToolErrorEnvelope

func NewToolErrorEnvelope(code, message string) ToolEnvelope

func NewToolSuccessEnvelope

func NewToolSuccessEnvelope(data map[string]any) ToolEnvelope

func ParseToolEnvelope

func ParseToolEnvelope(raw string) (ToolEnvelope, bool)

type ToolInputRepair added in v0.1.10

type ToolInputRepair struct {
	Kind       string
	Path       string
	BeforeType string
	AfterType  string
}

func RepairToolInputForSpec added in v0.1.10

func RepairToolInputForSpec(spec ToolSpec, raw string) (string, []ToolInputRepair)

RepairToolInputForSpec applies narrowly scoped, schema-guided repairs to common tool-call argument shape mistakes. Valid inputs are returned unchanged.

type ToolParamSpec

type ToolParamSpec interface {
	Parameters() map[string]any
}

type ToolPreviewer added in v0.1.2

type ToolPreviewer interface {
	Preview(ctx context.Context, call ToolCall) (map[string]any, error)
}

type ToolProgress added in v0.1.5

type ToolProgress struct {
	ToolCallID       string
	ToolName         string
	Status           string
	Summary          string
	Role             string
	Model            string
	Count            int
	DurationMS       int64
	Metadata         map[string]any
	ProgressMessages []SubagentStep
}

type ToolProgressRunner added in v0.1.5

type ToolProgressRunner interface {
	RunWithProgress(ctx context.Context, call ToolCall, progress func(ToolProgress)) (ToolResult, error)
}

type ToolReadOnly

type ToolReadOnly interface {
	ReadOnly() bool
}

type ToolReadOnlyCheck

type ToolReadOnlyCheck interface {
	ReadOnlyCheck(args map[string]any) bool
}

type ToolRegistry

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

func NewToolRegistry

func NewToolRegistry(tools []Tool) *ToolRegistry

func NewToolRegistryChecked

func NewToolRegistryChecked(tools []Tool) (*ToolRegistry, error)

func (*ToolRegistry) Dispatch

func (r *ToolRegistry) Dispatch(ctx context.Context, call ToolCall) (ToolResult, error)

func (*ToolRegistry) DispatchWithProgress added in v0.1.5

func (r *ToolRegistry) DispatchWithProgress(ctx context.Context, call ToolCall, progress func(ToolProgress)) (ToolResult, error)

func (*ToolRegistry) Get

func (r *ToolRegistry) Get(name string) Tool

func (*ToolRegistry) ReplaceTools added in v0.1.6

func (r *ToolRegistry) ReplaceTools(tools []Tool) error

func (*ToolRegistry) SetMaxResultChars

func (r *ToolRegistry) SetMaxResultChars(limit int)

func (*ToolRegistry) Snapshot added in v0.1.23

func (r *ToolRegistry) Snapshot() *ToolRegistry

func (*ToolRegistry) Spec

func (r *ToolRegistry) Spec(name string) (ToolSpec, bool)

func (*ToolRegistry) Specs

func (r *ToolRegistry) Specs() []ToolSpec

func (*ToolRegistry) Tools

func (r *ToolRegistry) Tools() []Tool

type ToolResult

type ToolResult struct {
	ToolCallID string
	Name       string
	Content    string
	Metadata   map[string]any `json:"metadata,omitempty"`
	IsError    bool
}

type ToolSpec

type ToolSpec struct {
	Name             string
	Description      string
	Parameters       map[string]any
	ReadOnly         bool
	ReadOnlyCheck    func(args map[string]any) bool
	Capabilities     []string
	ApprovalHint     string
	SupportsParallel bool
}

func DescribeTool

func DescribeTool(t Tool) ToolSpec

type ToolSupportsParallel

type ToolSupportsParallel interface {
	SupportsParallel() bool
}

type UserInputAnswer

type UserInputAnswer struct {
	ID      string `json:"id"`
	Label   string `json:"label"`
	Value   string `json:"value"`
	IsOther bool   `json:"is_other,omitempty"`
}

type UserInputOption

type UserInputOption struct {
	Label       string `json:"label"`
	Description string `json:"description"`
}

type UserInputQuestion

type UserInputQuestion struct {
	Header   string            `json:"header"`
	ID       string            `json:"id"`
	Question string            `json:"question"`
	Options  []UserInputOption `json:"options"`
}

type UserInputRequest

type UserInputRequest struct {
	Questions []UserInputQuestion `json:"questions"`
}

type UserInputResponse

type UserInputResponse struct {
	Answers []UserInputAnswer `json:"answers"`
}

Jump to

Keyboard shortcuts

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