api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package api provides event types for the monox event system.

Package api provides the public API types and interfaces for monox plugins. This package is designed to be imported by external plugin developers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	// Local cache configuration
	Local LocalCacheConfig `json:"local,omitempty" yaml:"local,omitempty"`

	// Remote is the remote cache configuration
	Remote *RemoteCacheConfig `json:"remote,omitempty" yaml:"remote,omitempty"`

	// Enabled indicates if caching is enabled (legacy)
	Enabled bool `json:"enabled" yaml:"enabled"`
}

CacheConfig contains cache configuration.

type CacheEntry

type CacheEntry struct {
	// Hash is the unique identifier for this cache entry
	Hash string `json:"hash"`

	// Project is the project this cache entry belongs to
	Project string `json:"project"`

	// Task is the task name
	Task string `json:"task"`

	// Timestamp is when this cache entry was created
	Timestamp time.Time `json:"timestamp"`

	// Duration is how long the original task took
	Duration time.Duration `json:"duration"`

	// ExitCode is the original exit code
	ExitCode int `json:"exitCode"`

	// OutputFiles lists the cached output files
	OutputFiles []string `json:"outputFiles"`

	// Stdout is the captured output
	Stdout string `json:"stdout"`

	// Stderr is the captured error output
	Stderr string `json:"stderr"`

	// Metadata contains additional cache metadata
	Metadata map[string]string `json:"metadata,omitempty"`
}

CacheEntry represents a cached task result.

type Command

type Command struct {
	// Program is the executable to run
	Program string

	// Args are the command-line arguments
	Args []string

	// Env are environment variables (KEY=VALUE format)
	Env []string

	// Dir is the working directory for the command
	Dir string

	// Timeout is the maximum execution time (0 = no timeout)
	Timeout time.Duration
}

Command represents an executable command with all its configuration.

type Dependency

type Dependency struct {
	// Name is the name of the dependency
	Name string `json:"name" yaml:"name"`

	// Version is the version constraint (for external deps)
	Version string `json:"version,omitempty" yaml:"version,omitempty"`

	// Type indicates if this is an internal or external dependency
	Type DependencyType `json:"type" yaml:"type"`

	// Path is the relative path for internal dependencies
	Path string `json:"path,omitempty" yaml:"path,omitempty"`

	// Scope indicates the dependency scope (runtime, dev, test, etc.)
	Scope DependencyScope `json:"scope" yaml:"scope"`
}

Dependency represents a dependency relationship between projects.

type DependencyScope

type DependencyScope string

DependencyScope indicates when a dependency is needed

const (
	DependencyScopeRuntime DependencyScope = "runtime"
	DependencyScopeDev     DependencyScope = "dev"
	DependencyScopeTest    DependencyScope = "test"
	DependencyScopeBuild   DependencyScope = "build"
)

type DependencyType

type DependencyType string

DependencyType indicates whether a dependency is internal or external

const (
	DependencyTypeInternal DependencyType = "internal"
	DependencyTypeExternal DependencyType = "external"
)

type DiscoveryConfig

type DiscoveryConfig struct {
	// Include patterns for project discovery
	Include []string `json:"include,omitempty" yaml:"include,omitempty"`

	// Exclude patterns for project discovery
	Exclude []string `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}

DiscoveryConfig configures automatic project discovery.

type Event

type Event struct {
	// Type is the event type
	Type EventType `json:"type"`

	// Timestamp is when the event occurred
	Timestamp time.Time `json:"timestamp"`

	// Data contains event-specific payload
	Data any `json:"data,omitempty"`
}

Event represents a lifecycle event during monox execution.

type EventEmitter

type EventEmitter interface {
	// Emit sends an event to all registered handlers
	Emit(event Event)

	// On registers a handler for a specific event type
	On(eventType EventType, handler EventHandler)

	// OnAll registers a handler for all events
	OnAll(handler EventHandler)

	// Off removes a handler
	Off(eventType EventType, handler EventHandler)
}

EventEmitter emits events to registered handlers.

type EventHandler

type EventHandler func(event Event)

EventHandler is a function that handles events.

type EventType

type EventType string

EventType represents the type of event emitted during execution.

const (
	// Workspace events
	EventWorkspaceLoaded EventType = "workspace:loaded"

	// Graph events
	EventGraphBuilt EventType = "graph:built"

	// Task events
	EventTaskScheduled  EventType = "task:scheduled"
	EventTaskStarted    EventType = "task:started"
	EventTaskOutput     EventType = "task:output"
	EventTaskCompleted  EventType = "task:completed"
	EventTaskFailed     EventType = "task:failed"
	EventTaskSkipped    EventType = "task:skipped"
	EventTaskCacheHit   EventType = "task:cache-hit"
	EventTaskCacheMiss  EventType = "task:cache-miss"
	EventTaskCacheStore EventType = "task:cache-store"

	// Cache events
	EventCacheDownload EventType = "cache:download"
	EventCacheUpload   EventType = "cache:upload"
	EventCacheHit      EventType = "cache:hit"
	EventCacheMiss     EventType = "cache:miss"

	// Run events
	EventRunStarted   EventType = "run:started"
	EventRunCompleted EventType = "run:completed"
	EventRunFailed    EventType = "run:failed"
)

type LanguagePlugin

type LanguagePlugin interface {
	// Name returns the plugin identifier (e.g., "go", "python", "node")
	Name() string

	// DetectProject checks if the given path contains a project of this language
	DetectProject(path string) bool

	// GetDependencies analyzes a project and returns its dependencies
	GetDependencies(ctx context.Context, project *Project, workspaceRoot string) ([]Dependency, error)

	// GetDefaultTasks returns the default task definitions for this language
	GetDefaultTasks(project *Project) []Task

	// InferProjectConfig infers project configuration from the filesystem
	InferProjectConfig(projectPath string, workspaceRoot string) (*Project, error)

	// ValidateProject validates a project configuration
	ValidateProject(project *Project, workspaceRoot string) []error
}

LanguagePlugin is the interface that language-specific plugins must implement. This is the core extension point for adding new language support to monox.

type LocalCacheConfig

type LocalCacheConfig struct {
	// Enabled indicates if local caching is enabled
	Enabled bool `json:"enabled" yaml:"enabled"`

	// Path is the local cache directory
	Path string `json:"path,omitempty" yaml:"path,omitempty"`
}

LocalCacheConfig contains local cache configuration.

type PluginConfig

type PluginConfig struct {
	// Name is the plugin identifier
	Name string `json:"name" yaml:"name"`

	// Path is the path to the plugin binary
	Path string `json:"path,omitempty" yaml:"path,omitempty"`

	// Config is plugin-specific configuration
	Config map[string]any `json:"config,omitempty" yaml:"config,omitempty"`
}

PluginConfig defines an external plugin.

type PluginRegistry

type PluginRegistry interface {
	// Register adds a plugin to the registry
	Register(plugin LanguagePlugin) error

	// Get returns a plugin by name
	Get(name string) (LanguagePlugin, bool)

	// All returns all registered plugins
	All() []LanguagePlugin

	// DetectLanguage detects the language for a given project path
	DetectLanguage(ctx context.Context, projectPath string) (LanguagePlugin, error)
}

PluginRegistry manages registered language plugins.

type Project

type Project struct {
	// Name is the unique identifier for this project
	Name string `json:"name" yaml:"name"`

	// Path is the relative path from workspace root to the project
	Path string `json:"path" yaml:"path"`

	// Type indicates if this is an "application" or "library"
	Type ProjectType `json:"type" yaml:"type"`

	// Language is the primary language of this project (go, python, node, rust, etc.)
	Language string `json:"language" yaml:"language"`

	// Tags are user-defined labels for filtering and grouping
	Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`

	// Metadata contains language-specific additional data
	Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// Dependencies are the project's dependencies
	Dependencies []Dependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`

	// Tasks are the tasks defined for this project
	Tasks []Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`

	// ImplicitDependencies are manually specified dependencies not detected automatically
	ImplicitDependencies []string `json:"implicitDependencies,omitempty" yaml:"implicitDependencies,omitempty"`
}

Project represents a single project/package within the monorepo.

type ProjectConfig

type ProjectConfig struct {
	// Name overrides the auto-detected project name
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Path is the relative path from workspace root to the project
	Path string `json:"path,omitempty" yaml:"path,omitempty"`

	// Language is the primary language of this project
	Language string `json:"language,omitempty" yaml:"language,omitempty"`

	// Type is the project type (application, library)
	Type ProjectType `json:"type,omitempty" yaml:"type,omitempty"`

	// Tags are labels for filtering
	Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`

	// Tasks are project-specific task configurations
	Tasks map[string]Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`

	// Targets are project-specific target configurations (alias for Tasks)
	Targets map[string]TargetConfig `json:"targets,omitempty" yaml:"targets,omitempty"`

	// Dependencies are the project's dependencies
	Dependencies []Dependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`

	// Metadata contains language-specific additional data
	Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// ImplicitDependencies are manually specified dependencies
	ImplicitDependencies []string `json:"implicitDependencies,omitempty" yaml:"implicitDependencies,omitempty"`

	// IgnoredDependencies are dependencies to ignore in graph
	IgnoredDependencies []string `json:"ignoredDependencies,omitempty" yaml:"ignoredDependencies,omitempty"`
}

ProjectConfig represents per-project configuration (project.yaml).

type ProjectType

type ProjectType string

ProjectType represents the type of a project

const (
	ProjectTypeApplication ProjectType = "application"
	ProjectTypeLibrary     ProjectType = "library"
)

type RemoteCacheConfig

type RemoteCacheConfig struct {
	// Type is the remote cache type (s3, gcs, http)
	Type string `json:"type" yaml:"type"`

	// Bucket is the bucket name for S3/GCS
	Bucket string `json:"bucket,omitempty" yaml:"bucket,omitempty"`

	// Prefix is the key prefix within the bucket
	Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`

	// Region is the AWS region for S3
	Region string `json:"region,omitempty" yaml:"region,omitempty"`

	// Project is the GCP project for GCS
	Project string `json:"project,omitempty" yaml:"project,omitempty"`

	// URL is the endpoint URL for HTTP cache
	URL string `json:"url,omitempty" yaml:"url,omitempty"`

	// Token is the authentication token (can use env var ${VAR})
	Token string `json:"token,omitempty" yaml:"token,omitempty"`

	// ReadOnly indicates if the cache is read-only (for CI)
	ReadOnly bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
}

RemoteCacheConfig contains remote cache configuration.

type RunCompletedEvent

type RunCompletedEvent struct {
	TotalTasks   int           `json:"totalTasks"`
	Succeeded    int           `json:"succeeded"`
	Failed       int           `json:"failed"`
	Cached       int           `json:"cached"`
	Skipped      int           `json:"skipped"`
	Duration     time.Duration `json:"duration"`
	CacheHitRate float64       `json:"cacheHitRate"`
}

RunCompletedEvent is emitted when a run completes.

type RunStartedEvent

type RunStartedEvent struct {
	Tasks       []string `json:"tasks"`
	Projects    []string `json:"projects"`
	Parallelism int      `json:"parallelism"`
}

RunStartedEvent is emitted when a run begins.

type TargetConfig

type TargetConfig struct {
	// Command is the shell command to execute
	Command string `json:"command,omitempty" yaml:"command,omitempty"`

	// Commands is a list of commands to execute
	Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"`

	// Args are additional arguments to pass to the command
	Args []string `json:"args,omitempty" yaml:"args,omitempty"`

	// Env are environment variables to set
	Env map[string]string `json:"env,omitempty" yaml:"env,omitempty"`

	// DependsOn lists task dependencies
	DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

	// Inputs are glob patterns for files that affect the task hash
	Inputs []string `json:"inputs,omitempty" yaml:"inputs,omitempty"`

	// Outputs are glob patterns for files produced by the task
	Outputs []string `json:"outputs,omitempty" yaml:"outputs,omitempty"`

	// Cache indicates whether this task's outputs should be cached
	Cache bool `json:"cache" yaml:"cache"`

	// Persistent indicates if this is a long-running task
	Persistent bool `json:"persistent,omitempty" yaml:"persistent,omitempty"`

	// Interactive indicates if this task requires TTY/stdin
	Interactive bool `json:"interactive,omitempty" yaml:"interactive,omitempty"`

	// Executor specifies a custom executor (e.g., "docker", "sandbox")
	Executor string `json:"executor,omitempty" yaml:"executor,omitempty"`
}

TargetConfig represents a build target configuration.

type Task

type Task struct {
	// Name is the task identifier (build, test, lint, etc.)
	Name string `json:"name" yaml:"name"`

	// Command is the shell command to execute
	Command string `json:"command" yaml:"command"`

	// Args are additional arguments to pass to the command
	Args []string `json:"args,omitempty" yaml:"args,omitempty"`

	// Env are environment variables to set
	Env map[string]string `json:"env,omitempty" yaml:"env,omitempty"`

	// DependsOn lists task dependencies (format: "task" or "^task" for deps)
	DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

	// Inputs are glob patterns for files that affect the task hash
	Inputs []string `json:"inputs,omitempty" yaml:"inputs,omitempty"`

	// Outputs are glob patterns for files produced by the task
	Outputs []string `json:"outputs,omitempty" yaml:"outputs,omitempty"`

	// Cache indicates whether this task's outputs should be cached
	Cache bool `json:"cache" yaml:"cache"`

	// Persistent indicates if this is a long-running task (dev server, watch, etc.)
	Persistent bool `json:"persistent,omitempty" yaml:"persistent,omitempty"`

	// Interactive indicates if this task requires TTY/stdin
	Interactive bool `json:"interactive,omitempty" yaml:"interactive,omitempty"`
}

Task represents a task that can be executed within a project.

type TaskCompletedEvent

type TaskCompletedEvent struct {
	ProjectName string        `json:"projectName"`
	TaskName    string        `json:"taskName"`
	Hash        string        `json:"hash"`
	Duration    time.Duration `json:"duration"`
	CacheHit    bool          `json:"cacheHit"`
}

TaskCompletedEvent is emitted when a task finishes successfully.

type TaskDefinition

type TaskDefinition struct {
	Task
	// Priority determines which plugin's task definition takes precedence
	Priority int `json:"priority" yaml:"priority"`
}

TaskDefinition is a default task definition provided by a language plugin

type TaskEvent

type TaskEvent struct {
	Type      TaskEventType
	TaskID    string
	Project   string
	Task      string
	Duration  time.Duration
	Error     error
	Stdout    string
	Stderr    string
	Timestamp time.Time
}

TaskEvent represents an event in the task execution lifecycle.

type TaskEventType

type TaskEventType string

TaskEventType represents the type of task event.

const (
	TaskStarted   TaskEventType = "started"
	TaskCompleted TaskEventType = "completed"
	TaskFailed    TaskEventType = "failed"
	TaskCached    TaskEventType = "cached"
)

type TaskFailedEvent

type TaskFailedEvent struct {
	ProjectName string        `json:"projectName"`
	TaskName    string        `json:"taskName"`
	Hash        string        `json:"hash"`
	Duration    time.Duration `json:"duration"`
	ExitCode    int           `json:"exitCode"`
	Error       string        `json:"error"`
}

TaskFailedEvent is emitted when a task fails.

type TaskOutputEvent

type TaskOutputEvent struct {
	ProjectName string `json:"projectName"`
	TaskName    string `json:"taskName"`
	Stream      string `json:"stream"` // "stdout" or "stderr"
	Data        string `json:"data"`
}

TaskOutputEvent is emitted when a task produces output.

type TaskPipelineConfig

type TaskPipelineConfig struct {
	// DependsOn lists tasks that must run before this task
	DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

	// Cache indicates whether outputs should be cached
	Cache bool `json:"cache,omitempty" yaml:"cache,omitempty"`
}

TaskPipelineConfig defines task execution dependencies.

type TaskResult

type TaskResult struct {
	// TaskID is the unique identifier for this task run
	TaskID string `json:"taskId"`

	// ProjectName is the project this task belongs to
	ProjectName string `json:"projectName"`

	// TaskName is the name of the task
	TaskName string `json:"taskName"`

	// Status is the execution status
	Status TaskStatus `json:"status"`

	// ExitCode is the process exit code
	ExitCode int `json:"exitCode"`

	// Duration is how long the task took
	Duration time.Duration `json:"duration"`

	// CacheHit indicates if result was restored from cache
	CacheHit bool `json:"cacheHit"`

	// Hash is the computed hash for this task
	Hash string `json:"hash"`

	// Stdout is the captured standard output
	Stdout string `json:"stdout,omitempty"`

	// Stderr is the captured standard error
	Stderr string `json:"stderr,omitempty"`

	// Error contains error details if the task failed
	Error string `json:"error,omitempty"`

	// StartTime is when the task started
	StartTime time.Time `json:"startTime"`

	// EndTime is when the task completed
	EndTime time.Time `json:"endTime"`
}

TaskResult represents the outcome of a task execution.

type TaskStartedEvent

type TaskStartedEvent struct {
	ProjectName string `json:"projectName"`
	TaskName    string `json:"taskName"`
	Hash        string `json:"hash"`
	Command     string `json:"command"`
}

TaskStartedEvent is emitted when a task begins execution.

type TaskStatus

type TaskStatus string

TaskStatus represents the current status of a task

const (
	TaskStatusPending   TaskStatus = "pending"
	TaskStatusRunning   TaskStatus = "running"
	TaskStatusSuccess   TaskStatus = "success"
	TaskStatusFailed    TaskStatus = "failed"
	TaskStatusSkipped   TaskStatus = "skipped"
	TaskStatusCacheHit  TaskStatus = "cache-hit"
	TaskStatusCancelled TaskStatus = "cancelled"
)

type WorkspaceConfig

type WorkspaceConfig struct {
	// Version is the config schema version
	Version int `json:"version" yaml:"version"`

	// Name is the workspace name
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Projects defines explicit project configurations
	Projects []ProjectConfig `json:"projects,omitempty" yaml:"projects,omitempty"`

	// Discovery configures project auto-discovery
	Discovery DiscoveryConfig `json:"discovery,omitempty" yaml:"discovery,omitempty"`

	// Tasks defines global task configurations
	Tasks map[string]Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`

	// TaskPipeline defines task execution order
	TaskPipeline map[string]TaskPipelineConfig `json:"taskPipeline,omitempty" yaml:"taskPipeline,omitempty"`

	// Cache configuration
	Cache CacheConfig `json:"cache,omitempty" yaml:"cache,omitempty"`

	// TargetDefaults are default configurations for tasks by name
	TargetDefaults map[string]Task `json:"targetDefaults,omitempty" yaml:"targetDefaults,omitempty"`

	// GlobalInputs are files that affect all tasks
	GlobalInputs []string `json:"globalInputs,omitempty" yaml:"globalInputs,omitempty"`

	// ImplicitDependencies are always considered changed
	ImplicitDependencies []string `json:"implicitDependencies,omitempty" yaml:"implicitDependencies,omitempty"`

	// Plugins lists additional plugins to load
	Plugins []PluginConfig `json:"plugins,omitempty" yaml:"plugins,omitempty"`

	// Parallel is the default parallelism level (0 = auto)
	Parallel int `json:"parallel,omitempty" yaml:"parallel,omitempty"`
}

WorkspaceConfig represents the root monox.yaml configuration.

Jump to

Keyboard shortcuts

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