grove core grove core
grove-core is a Go library that provides shared packages and utilities for tools in the Grove ecosystem.
Role in the Ecosystem
All executable tools in the Grove ecosystem import grove-core as a Go module. This provides a consistent implementation for command-line interaction, configuration file loading, logging, and error handling, which reduces duplicated code.
How It Works
A Grove tool uses the cli package to create a cobra command with standard flags (--config, --json, --verbose). The config package then loads and merges grove.yml files from a series of locations: a global directory, an optional parent ecosystem directory, the current project directory, and local override files. The logging package uses this configuration to set up a logger. Functions like logging.NewLogger("component") create log entries tagged with a component name, which are then written to standard output, standard error, or a file as configured.
Packages
cli
Provides functions for building command-line interfaces with cobra.
NewStandardCommandcreates a command with a standard set of persistent flags (--verbose,--json,--config).GetLoggerandGetOptionsinitialize a logger and retrieve common options from command-line flags.- An error handler presents messages for predefined error types.
NewVersionCommandcreates a command that displays build information.
command
Executes external commands with validation.
- A
SafeBuildercreatesexec.Cmdinstances and can validate arguments against predefined patterns for filenames or Git references. - Integrates with Go’s
contextpackage for command timeouts and cancellation.
config
Manages grove.yml configuration files.
- Loads and merges configuration from multiple sources in order: global, ecosystem, project, and override files.
- Captures non-standard top-level keys in an
Extensionsmap for use by other tools. - Replaces
${VAR}or${VAR:-default}syntax with environment variable values. - Validates
grove.ymlagainst an embedded JSON schema.
conventional
Parses Conventional Commit messages.
- Parses commit messages into a structured format.
- Generates changelogs from a list of commits.
errors
Defines a structured error type for the ecosystem.
GroveErrorcontains a machine-readableErrorCode(e.g.,CONFIG_NOT_FOUND), a message, and a map of contextual details.- Provides constructor functions for common error conditions such as
ServiceNotFoundorConfigInvalid.
fs
Provides filesystem utilities.
- Contains functions to copy single files and recursively copy directories.
git
Interacts with Git repositories by executing git commands.
- Functions to get repository information such as current branch, repository root, remote URL, and status.
- A
WorktreeManagerto create, list, and remove Git worktrees. - An interface for installing and uninstalling Git hooks.
logging
Provides a centralized logging system built on Logrus.
NewLogger("component-name")creates a logger that tags messages with a component name.- Log level, format (text or JSON), and file output are configured in
grove.yml. - The
UnifiedLoggerwrites a log event to both a structured format for machine processing and a styled format for terminal output. - Provides functions to show or hide log output from specific components based on configuration rules.
pkg/alias
Resolves workspace aliases to absolute file paths.
- Translates project aliases like
"ecosystem:repo:worktree"into an absolute path. - Translates notebook resource aliases that are prefixed with
nb:.
pkg/models
Contains shared data structures for Grove services.
- Includes types for sessions, events, tool executions, transcripts, and notifications.
pkg/process
Provides process utilities.
- Includes a function
IsProcessAliveto check if a process with a given PID is running.
pkg/profiling
Provides performance profiling utilities for command-line applications.
- Integrates with Cobra commands to add flags for enabling CPU and memory profiling.
- Includes a hierarchical timer for measuring the duration of nested function calls.
pkg/repo
Manages local clones of remote git repositories.
- Clones repositories as bare repos and checks out specific versions into worktrees.
- Maintains a manifest of managed repositories and their worktrees.
pkg/sessions
Manages metadata for live, stateful sessions.
- A filesystem-based registry tracks running processes and their associated session metadata.
pkg/tmux
A Go client for managing tmux sessions, windows, and panes.
- Functions to create, check for existence, kill, and list tmux sessions.
- Functions to create windows, split panes, send keys, and capture pane content.
- A function to block execution until a specified tmux session closes.
pkg/workspace
Discovers and classifies Grove workspaces on the filesystem.
DiscoveryServicescans configured directories to find ecosystems, projects, and worktrees.- Classifies entities based on
grove.ymlcontent and filesystem markers, assigning aWorkspaceKind. GetProjectByPathfinds the containing workspace for a given directory path without performing a full scan.- The
Providerholds a snapshot of discovered workspaces for in-memory lookups.
schema
Manages JSON schema for grove.yml configuration files.
- Contains an embedded base schema for core
grove.ymlproperties. - Provides a validator to check configuration data against the schema.
- Includes a manifest of extension schemas used for composing a unified schema.
starship
Provides commands for integration with the Starship shell prompt.
- An
installcommand modifiesstarship.tomlto add a custom module. - A
statuscommand, used by the prompt, queries registered providers for status strings to display.
state
Manages local workspace state.
- Loads from and saves key-value data to a
.grove/state.ymlfile in the current workspace.
tui
Provides reusable components for building terminal user interfaces with Bubble Tea.
navigator: A component for browsing projects and files.logviewer: A component for tailing and viewing log files.jsontree: A component for interactively exploring JSON data.help: A component for displaying keybindings.theme: A theming system with color palettes and icons.keymap: A standardized set of keybindings.
util/pathutil
Provides path expansion and normalization utilities.
- Expands home directory (
~), environment variables, and git variables in path strings. - Normalizes paths for case-insensitive filesystem comparisons by resolving symlinks and converting to lowercase on macOS and Windows.
util/sanitize
Sanitizes strings for various technical contexts.
- Functions to format strings for use as Docker labels, domain names, filenames, and environment variables.
version
Embeds build information into binaries.
- Contains variables that are populated by Go linker flags for version, commit, branch, and build date.
Installation
Grove-core is a Go library. Add it to your project:
go get github.com/mattsolo1/grove-coreImport in your Go code:
import "github.com/mattsolo1/grove-core/cli"See the Grove Development Guide for development setup.