Here is the technical documentation for the Core framework packages, analyzing the provided source code.
# Core Framework Package Documentation
## Table of Contents
1. [pkg/build](#package-pkgbuild)
2. [pkg/container](#package-pkgcontainer)
3. [pkg/process](#package-pkgprocess)
4. [pkg/jobrunner](#package-pkgjobrunner)
---
## Package: `pkg/build`
### 1. Overview
The `build` package provides a standardized system for detecting project types, loading build configurations, and packaging artifacts. It is designed around an abstraction of the filesystem (`io.Medium`) to facilitate testing and cross-platform compatibility, handling compression formats (gzip, xz, zip) and SHA256 checksum generation.
### 2. Public API
#### Project Detection & Configuration
```go
// Represents a detected project type (e.g., "go", "wails", "node")
type ProjectType string
// Detects project types in a directory based on marker files
func Discover(fs io.Medium, dir string) ([]ProjectType, error)
func PrimaryType(fs io.Medium, dir string) (ProjectType, error)
// Helper predicates for detection
func IsGoProject(fs io.Medium, dir string) bool
func IsWailsProject(fs io.Medium, dir string) bool
func IsNodeProject(fs io.Medium, dir string) bool
func IsPHPProject(fs io.Medium, dir string) bool
func IsCPPProject(fs io.Medium, dir string) bool
// Loads configuration from .core/build.yaml
func LoadConfig(fs io.Medium, dir string) (*BuildConfig, error)
***Filesystem Abstraction**: Heavily relies on dependency injection via `io.Medium` rather than direct `os` calls, enabling safe unit testing of file operations.
***Strategy Pattern**: The `Builder` interface allows different build logic (Go, Docker, Node) to be swapped dynamically based on detection.
***Priority Detection**: `Discovery` uses an ordered slice of markers (`markers` var) to handle hybrid projects (e.g., Wails is detected before Go).
***Configuration Overlay**: Uses `mapstructure` to parse YAML config, applying sensible defaults via `applyDefaults` if fields are missing.
### 4. Dependencies
*`archive/tar`, `archive/zip`, `compress/gzip`: Standard library for archiving.
*`github.com/Snider/Borg/pkg/compress`: External dependency for XZ compression support.
***Mocking IO**: Tests must implement a mock `io.Medium` to simulate file existence (`Detect`) and write operations (`Archive`) without touching the disk.
***Format Specifics**: Verify that Windows builds automatically default to `.zip` regardless of the requested format in `ArchiveWithFormat`.
***Config Parsing**: Test `LoadConfig` with malformed YAML and missing fields to ensure defaults are applied correctly.
### 6. Integration Points
***CLI Build Commands**: This package is the backend for any `core build` CLI command.
***CI Pipelines**: Used to generate release artifacts and `CHECKSUMS.txt` files for releases.
---
## Package: `pkg/container`
### 1. Overview
This package manages the lifecycle of local LinuxKit virtual machines. It abstracts underlying hypervisors (QEMU on Linux, Hyperkit on macOS) to provide a container-like experience (start, stop, logs, exec) for running VM images.
***Dev Environments**: Used to spin up isolated development environments defined by LinuxKit YAMLs.
***Testing**: Can be used to launch disposable VMs for integration testing.
---
## Package: `pkg/process`
### 1. Overview
A sophisticated wrapper around `os/exec` that integrates with the Core framework's event bus. It features output streaming, ring-buffer capturing, dependency-based task execution (DAG), and a global singleton service for ease of use.
***Event Sourcing**: Instead of just logging, the service broadcasts events (`ActionProcessStarted`, `ActionProcessOutput`) via `framework.Core`. This allows UI frontends to subscribe to real-time output.
***Ring Buffer**: Uses a fixed-size circular buffer (`RingBuffer`) to store logs, preventing memory exhaustion from long-running processes.
***DAG Execution**: The `Runner.RunAll` method implements a dependency graph resolver to run tasks in parallel waves based on the `After` field.
***Global Singleton**: Uses `atomic.Pointer` for a thread-safe global `Default()` service instance.
***Concurrency**: The `Runner` needs tests for race conditions during parallel execution.
***Dependency Resolution**: Test circular dependencies (deadlock detection) and skip logic when a dependency fails.
***Buffer Overflow**: Verify `RingBuffer` overwrites old data correctly when full.
### 6. Integration Points
***Task Runners**: The `Runner` struct is the engine for tools like `make` or `Taskfile`.
***UI/TUI**: The Action-based output streaming is designed to feed data into a TUI or Web frontend in real-time.
---
## Package: `pkg/jobrunner`
### 1. Overview
A polling-based workflow engine designed to ingest "signals" (e.g., GitHub Issues/PRs), match them to specific handlers, and record execution results in a structured journal. It implements a "dry-run" capability and detailed audit logging.
### 2. Public API
#### Poller
```go
type Poller struct { ... }
type PollerConfig struct {
Sources []JobSource
Handlers []JobHandler
Journal *Journal
// ... interval, dryRun
}
func NewPoller(cfg PollerConfig) *Poller
func (p *Poller) Run(ctx context.Context) error
func (p *Poller) AddSource(s JobSource)
func (p *Poller) AddHandler(h JobHandler)
```
#### Journaling
```go
type Journal struct { ... }
func NewJournal(baseDir string) (*Journal, error)
func (j *Journal) Append(signal *PipelineSignal, result *ActionResult) error
Report(ctx context.Context, result *ActionResult) error
}
type JobHandler interface {
Match(signal *PipelineSignal) bool
Execute(ctx context.Context, signal *PipelineSignal) (*ActionResult, error)
}
```
### 3. Internal Design
***Poller Loop**: Runs a continuous loop (ticker-based) that snapshots sources and handlers at the start of every cycle to allow dynamic registration.
***Data Models**: Defines rigid structures (`PipelineSignal`, `ActionResult`) to decouple data sources (GitHub) from logic handlers.
***Journaling**: Writes `jsonl` (JSON Lines) files partitioned by repository and date (`baseDir/owner/repo/YYYY-MM-DD.jsonl`), ensuring an append-only audit trail.