domain

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package domain defines the core domain models and interfaces for the AutoCmd system.

Index

Constants

View Source
const (
	ProviderGoogle   = "google"
	ProviderGitHub   = "github"
	ProviderOpenCode = "opencode"
)

Provider IDs.

View Source
const (
	ShortIDLength       = 8
	MaxCollisionRetries = 100
)

ID Generation Constants.

View Source
const (
	AuthMethodAPIKey = "api_key"
	AuthMethodEnv    = "env"
	AuthFieldAPIKey  = "api_key"
)

Auth Method and Field IDs.

View Source
const (
	NotificationMessageExtraKey = "autocmd/is_notification"
	// ThoughtDurationMsExtraKey is Message.Extra: ms from first reasoning chunk to stream end (persisted for history UI).
	ThoughtDurationMsExtraKey = "autocmd/reasoning_phase_duration_ms"
)

Message metadata keys.

View Source
const (
	AppName       = "autocmd"
	ConfigBaseDir = ".config"
)

Application Metadata.

View Source
const (
	DefaultDirPerm  = 0o755
	DefaultFilePerm = 0o644
	PrivateFilePerm = 0o600
)

Standard Permissions (Unix).

View Source
const ToolErrorCancelled = "execution cancelled"

ToolErrorCancelled is ToolDisplay.Error when Execute returns because the context was cancelled.

View Source
const ToolErrorFailed = "execution failed"

ToolErrorFailed is the generic ToolDisplay.Error for any non-cancellation failures.

View Source
const ToolErrorTimedOut = "execution timed out"

ToolErrorTimedOut is ToolDisplay.Error when Execute returns because the operation took too long.

Variables

This section is empty.

Functions

func GetSessionID

func GetSessionID(ctx context.Context) (string, bool)

GetSessionID returns the session ID from the context if it exists.

func WithSessionID

func WithSessionID(ctx context.Context, sessionID string) context.Context

WithSessionID returns a new context with the session ID attached.

Types

type APIKeyAuthMethod

type APIKeyAuthMethod struct {
	ID     string
	Name   string
	Fields []AuthField
}

APIKeyAuthMethod represents an authentication method that requires user input of text fields.

func (APIKeyAuthMethod) IsAuthMethod

func (APIKeyAuthMethod) IsAuthMethod()

IsAuthMethod marks APIKeyAuthMethod as an implementation of the AuthMethod interface.

type Action

type Action interface {
	// contains filtered or unexported methods
}

Action is the interface for all intents flowing from UI to Workflow.

type AuthErrorEvent

type AuthErrorEvent struct {
	Error string
}

AuthErrorEvent signals an error that occurred during the authentication workflow.

type AuthField

type AuthField struct {
	ID          string `json:"id"`
	Label       string `json:"label"`
	Placeholder string `json:"placeholder"`
	EnvVar      string `json:"env_var,omitempty"` // Fallback environment variable name
	IsSecret    bool   `json:"is_secret"`
}

AuthField defines a single input field required for an authentication method.

type AuthMethod

type AuthMethod interface {
	IsAuthMethod()
}

AuthMethod is a marker interface for authentication data descriptors.

type AuthMethodEvent

type AuthMethodEvent struct {
	ProviderID string
	Methods    []AuthMethod
}

AuthMethodEvent signals that the user needs to select an authentication method from the given list.

type AuthProviderListEvent

type AuthProviderListEvent struct {
	Providers []ProviderSummary
}

AuthProviderListEvent contains the data needed for the auth management UI.

type BashDisplay

type BashDisplay struct {
	TypeField      string `json:"type"`
	Description    string `json:"description"`     // Description from tool (e.g. "Installing dependencies")
	Command        string `json:"command"`         // The command being run (e.g. "npm install")
	Cwd            string `json:"cwd,omitempty"`   // Command working directory
	CapturedOutput string `json:"captured_output"` // Raw output captured after execution (baked)
	Error          string `json:"error,omitempty"`
}

BashDisplay is for bash command execution with streaming output.

func NewBashDisplay

func NewBashDisplay(description, command, cwd, capturedOutput string) BashDisplay

NewBashDisplay creates a new BashDisplay with correct type.

func (BashDisplay) GetError

func (s BashDisplay) GetError() string

GetError returns the error message associated with the display, if any.

func (BashDisplay) Type

func (s BashDisplay) Type() string

Type returns the unique identifier for the bash display type.

func (BashDisplay) WithError

func (s BashDisplay) WithError(err string) ToolDisplay

WithError returns a copy of the display with the specified error message.

type CallIDer

type CallIDer interface {
	Action
	GetCallID() string
}

CallIDer is implemented by actions correlated to a tool call (e.g. question answers).

type ConnectingEvent

type ConnectingEvent struct{}

ConnectingEvent is emitted when the app is connecting to the provider.

type CreateSessionAction

type CreateSessionAction struct{}

CreateSessionAction is a user intent to start a brand new conversation.

type Credential

type Credential struct {
	Type   string `json:"type"` // e.g., "api_key"
	APIKey string `json:"api_key,omitempty"`

	// Future-proofing for OAuth device flow
	OAuthToken string `json:"oauth_token,omitempty"`
}

Credential represents a stored or resolved credential for an LLM provider.

type CredentialFieldEvent

type CredentialFieldEvent struct {
	Method     AuthMethod
	FieldIndex int
}

CredentialFieldEvent signals that the user needs to provide a value for a specific field in an authentication method.

type DeleteSessionAction

type DeleteSessionAction struct {
	ID string
}

DeleteSessionAction is a user intent to remove a session permanently.

type DiffDisplay

type DiffDisplay struct {
	TypeField   string `json:"type"`
	Description string `json:"description"`
	Target      string `json:"target"`
	Diff        string `json:"diff"`
	Error       string `json:"error,omitempty"`
	Added       int    `json:"added"`
	Removed     int    `json:"removed"`
}

DiffDisplay is for file edit operations with unified diff content.

func NewDiffDisplay

func NewDiffDisplay(description, target string, added, removed int, diff string) DiffDisplay

NewDiffDisplay creates a new DiffDisplay with correct type.

func (DiffDisplay) GetError

func (d DiffDisplay) GetError() string

GetError returns the error message associated with the display, if any.

func (DiffDisplay) Type

func (d DiffDisplay) Type() string

Type returns the unique identifier for the diff display type.

func (DiffDisplay) WithError

func (d DiffDisplay) WithError(err string) ToolDisplay

WithError returns a copy of the display with the specified error message.

type DoneEvent

type DoneEvent struct{}

DoneEvent is emitted when the workflow loop completes.

type EnvVarAuthMethod

type EnvVarAuthMethod struct {
	ID      string
	Name    string
	EnvVars []string
}

EnvVarAuthMethod represents an authentication method that relies purely on environment variables.

func (EnvVarAuthMethod) IsAuthMethod

func (EnvVarAuthMethod) IsAuthMethod()

IsAuthMethod marks EnvVarAuthMethod as an implementation of the AuthMethod interface.

type EnvVarInstructionEvent

type EnvVarInstructionEvent struct {
	EnvVars []string
}

EnvVarInstructionEvent provides instructions on which environment variables are needed for authentication.

type File

type File interface {
	io.Reader
	io.Seeker
	io.Closer
	Stat() (os.FileInfo, error)
}

File defines a generic file handle for reading and seeking.

type HistoryEvent

type HistoryEvent struct {
	ToolDisplays map[string]ToolDisplay
	Messages     []*schema.Message
}

HistoryEvent contains the full conversation history for a session.

type InfoEvent

type InfoEvent struct {
	Model          string
	SessionDisplay string
	Authorized     []string
	SessionTokens  int
	ContextWindow  int
}

InfoEvent contains gathered data for UI display of configuration and state.

type LLM

type LLM interface {
	ID() string
	DisplayName() string
	ContextWindow() int
	Model() model.ToolCallingChatModel
}

LLM is a language model instance powered by Eino.

type LLMInfo

type LLMInfo struct {
	ID            string
	DisplayName   string
	ContextWindow int
}

LLMInfo is metadata for listing language models.

type MCPLoadingEvent

type MCPLoadingEvent struct{}

MCPLoadingEvent is emitted when MCP servers are being loaded.

type ModelListEvent

type ModelListEvent struct {
	ActiveModelID string
	Models        []LLMInfo
}

ModelListEvent contains the data needed for model selection UI.

type OAuthDeviceFlowEvent

type OAuthDeviceFlowEvent struct {
	VerificationURI string
	UserCode        string
}

OAuthDeviceFlowEvent provides the verification URI and user code for OAuth Device Flow authentication.

type OAuthMethod

type OAuthMethod struct {
	ID            string
	Name          string
	ClientID      string
	DeviceAuthURL string
	TokenURL      string
	Scopes        []string
}

OAuthMethod represents an authentication method that follows the OAuth Device Flow.

func (OAuthMethod) IsAuthMethod

func (OAuthMethod) IsAuthMethod()

IsAuthMethod marks OAuthMethod as an implementation of the AuthMethod interface.

type PermissionDecisionAction

type PermissionDecisionAction struct {
	CallID   string
	Approved bool
}

PermissionDecisionAction is sent by the prompt UI to approve or deny a tool permission request.

func (PermissionDecisionAction) GetCallID

func (a PermissionDecisionAction) GetCallID() string

GetCallID implements CallIDer for action routing.

type Provider

type Provider interface {
	ID() string
	SupportedAuthMethods() []AuthMethod
	List() []LLMInfo
	GetLLM(ctx context.Context, cred *Credential, info LLMInfo) (LLM, error)
}

Provider represents an LLM service (e.g., Google, OpenAI). It acts as a factory and metadata source for authentication and model listing.

type ProviderInfo

type ProviderInfo struct {
	Credential *Credential
	ID         string
}

ProviderInfo contains a provider's ID and its resolved credential (if any).

type ProviderSummary

type ProviderSummary struct {
	ID         string
	AuthMethod string
	Authorized bool
}

ProviderSummary provides a snapshot of a provider's auth status.

type QuestionAnswerAction

type QuestionAnswerAction struct {
	CallID  string
	Answers [][]string // per-question selected labels and/or custom text; order matches Questions
}

QuestionAnswerAction is sent by the prompt UI after the user submits or cancels the question toolbox.

func (QuestionAnswerAction) GetCallID

func (a QuestionAnswerAction) GetCallID() string

GetCallID implements CallIDer for action routing.

type QuestionDisplay

type QuestionDisplay struct {
	TypeField string         `json:"type"`
	Error     string         `json:"error,omitempty"`
	Questions []QuestionInfo `json:"questions"`
}

QuestionDisplay is the tool UI payload for the question tool (preview and final baked state).

func NewQuestionDisplay

func NewQuestionDisplay(questions []QuestionInfo) QuestionDisplay

NewQuestionDisplay returns a QuestionDisplay with type "question".

func (QuestionDisplay) GetError

func (d QuestionDisplay) GetError() string

GetError returns the error message associated with the display, if any.

func (QuestionDisplay) Type

func (d QuestionDisplay) Type() string

Type returns the unique identifier for the question display type.

func (QuestionDisplay) WithError

func (d QuestionDisplay) WithError(err string) ToolDisplay

WithError returns a copy of the display with the specified error message.

type QuestionInfo

type QuestionInfo struct {
	Question    string   `json:"question"`
	Options     []string `json:"options"`
	MultiSelect bool     `json:"multiSelect,omitempty"`
}

QuestionInfo describes one question in the question toolbox. Free-text answers are always offered by the UI (not part of this payload).

type RemoveAuthAction

type RemoveAuthAction struct {
	ProviderID string
}

RemoveAuthAction is a user intent to remove authentication for a provider.

type RenameSessionAction

type RenameSessionAction struct {
	ID   string
	Name string
}

RenameSessionAction is a user intent to change a session's title.

type SavedCommand

type SavedCommand struct {
	Name        string `json:"name"`
	Command     string `json:"command"`
	Description string `json:"description,omitempty"`
	CreatedAt   int64  `json:"createdAt"`
	UpdatedAt   int64  `json:"updatedAt"`
}

SavedCommand represents a command saved by the AI agent for later reuse.

type SelectAuthMethodAction

type SelectAuthMethodAction struct {
	ID string
}

SelectAuthMethodAction is a user intent to select a specific authentication method for a provider.

type SelectModelAction

type SelectModelAction struct {
	ID string
}

SelectModelAction is a user intent to switch the current model.

type SelectProviderAction

type SelectProviderAction struct {
	ID string
}

SelectProviderAction is a user intent to select an LLM provider for authentication.

type SelectSessionAction

type SelectSessionAction struct {
	ID string
}

SelectSessionAction is a user intent to choose a session from the list.

type Session

Session is the composite session type that bundles all three parts. Use Store.GetSession() to load a full session.

func (*Session) TotalTokens

func (s *Session) TotalTokens() int

TotalTokens returns the factual total tokens in the session as of the last model response.

type SessionDisplays

type SessionDisplays struct {
	ToolDisplays map[string]ToolDisplay
}

SessionDisplays contains the tool displays stored in displays.json.

func (*SessionDisplays) UnmarshalJSON

func (d *SessionDisplays) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for the polymorphic ToolDisplay map.

type SessionListEvent

type SessionListEvent struct {
	CurrentSessionID string
	Sessions         []SessionMetadata
	WorkingDir       string
}

SessionListEvent contains the data needed for session selection UI.

type SessionMessages

type SessionMessages struct {
	Messages []*schema.Message
}

SessionMessages contains the messages stored in messages.json.

type SessionMetadata

type SessionMetadata struct {
	ID           string
	Name         string
	MessageCount int
	TokenCount   int
	Created      time.Time
	Updated      time.Time
	WorkingDir   string
	Active       bool
}

SessionMetadata contains the metadata fields stored in metadata.json.

type SessionSelectedEvent

type SessionSelectedEvent struct {
	ID             string
	SwitchRequired bool
	TargetDir      string
}

SessionSelectedEvent is emitted when a session is chosen, indicating if a directory switch is required.

type State

type State struct {
	Model string `json:"model"`
}

State holds application persistent state loaded from disk.

type StopAction

type StopAction struct{}

StopAction is a user intent to cancel the current workflow.

type StringDisplay

type StringDisplay struct {
	TypeField   string `json:"type"`
	Description string `json:"description"`
	Content     string `json:"content"`
	Error       string `json:"error,omitempty"`
}

StringDisplay is for simple text output (most tools).

func NewStringDisplay

func NewStringDisplay(description, content string) StringDisplay

NewStringDisplay creates a new StringDisplay with correct type.

func (StringDisplay) GetError

func (s StringDisplay) GetError() string

GetError returns the error message associated with the display, if any.

func (StringDisplay) Type

func (s StringDisplay) Type() string

Type returns the unique identifier for the string display type.

func (StringDisplay) WithError

func (s StringDisplay) WithError(err string) ToolDisplay

WithError returns a copy of the display with the specified error message.

type SubmitCredentialAction

type SubmitCredentialAction struct {
	Credential Credential
}

SubmitCredentialAction is a user intent to submit a complete set of credentials.

type SubmitFieldAction

type SubmitFieldAction struct {
	Value string
}

SubmitFieldAction is a user intent to submit a value for a single authentication field.

type SummaryCompactionEndEvent

type SummaryCompactionEndEvent struct {
	Error string
}

SummaryCompactionEndEvent is emitted when context compaction completes. Error is empty on success.

type SummaryCompactionStartEvent

type SummaryCompactionStartEvent struct{}

SummaryCompactionStartEvent is emitted when context compaction begins.

type SystemNotificationEvent

type SystemNotificationEvent struct {
	Content string
}

SystemNotificationEvent is emitted when a system notification is injected.

type TaskResult

type TaskResult struct {
	ID          string `xml:"task-id"`
	Status      string `xml:"status"`
	Description string `xml:"description"`
	Command     string `xml:"command"`
	ExitCode    int    `xml:"exit-code"`
	Error       string `xml:"error,omitempty"`
	LogPath     string `xml:"log-file"`
	Cwd         string `xml:"cwd"`
}

TaskResult represents the result of a completed background task.

type TextEvent

type TextEvent struct {
	Text      string
	IsThought bool
}

TextEvent is emitted when the LLM produces text output.

type ToolApprovalRequestEvent

type ToolApprovalRequestEvent struct {
	CallID string
}

ToolApprovalRequestEvent marks a running tool as awaiting explicit user approval.

type ToolDisplay

type ToolDisplay interface {
	Type() string

	GetError() string
	WithError(err string) ToolDisplay
	// contains filtered or unexported methods
}

ToolDisplay is implemented by all display types returned from tools. The UI uses type switches to render each type appropriately. Must be in domain so tools can implement without importing workflow.

type ToolEndEvent

type ToolEndEvent struct {
	Display ToolDisplay
	CallID  string
}

ToolEndEvent is emitted when tool execution completes with the final baked ToolDisplay.

type ToolStartEvent

type ToolStartEvent struct {
	Display ToolDisplay
	CallID  string
}

ToolStartEvent is sent by preview middleware using the ToolDisplay returned from tool Preview.

type ToolStreamEvent

type ToolStreamEvent struct {
	CallID string
	Chunk  string
}

ToolStreamEvent is emitted for streaming tool output (bash.commands).

type UIUpdate

type UIUpdate interface {
	// contains filtered or unexported methods
}

UIUpdate is the interface for all events flowing from Workflow to UI.

type WaitingForNamingEvent

type WaitingForNamingEvent struct{}

WaitingForNamingEvent is emitted when the app is waiting for auto session naming.

Jump to

Keyboard shortcuts

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