Extending Protostar¶
Protostar's architecture strictly isolates state definition from execution. This guarantees that you can add entirely new languages, tools, or domain workflows without altering the core orchestrator or the system executor.
Building a Custom Bootstrap Module¶
Bootstrap modules define the structural environment footprint. To create a new module, subclass BootstrapModule from protostar.modules.base.
You must define its CLI flags, a human-readable name, and the build method. You can also optionally define pre_flight checks, collision_markers, and required_languages to enforce strict footprint constraints.
Dynamic CLI Registration
The CLI parser dynamically reads the cli_flags and cli_help attributes at runtime. Once you append your module to the TOOLING_MODULES tuple in protostar/modules/__init__.py, it will automatically appear in the protostar init --help output.
Here is a complete example of a module that scaffolds a justfile (a modern Makefile alternative):
from pathlib import Path
from protostar.modules import BootstrapModule
from protostar.manifest import EnvironmentManifest
class JustModule(BootstrapModule):
"""Configures a justfile for project task execution."""
cli_flags = ("--just",)
cli_help = "Scaffold a standard justfile for project tasks"
config_key = "just"
@property
def name(self) -> str:
return "Just"
@property
def collision_markers(self) -> list[Path]:
return [Path("justfile")]
def pre_flight(self) -> None:
import shutil
if not shutil.which("just"):
from protostar.errors import MissingDependencyError
raise MissingDependencyError("just", purpose="task runner", hint="Install: brew install just")
def build(self, manifest: EnvironmentManifest) -> None:
content = r"""default:
\t@just --list
lint:
\tuv run ruff check .
\tuv run ruff format --check .
test:
\tuv run pytest
"""
manifest.filesystem.add_file_injection("justfile", content)
Core Interface: BootstrapModule
protostar.modules.base.BootstrapModule ¶
Bases: ABC
Appends module-specific requirements to the environment manifest.
Source code in src/protostar/modules/base.py
cli_flags
class-attribute
¶
The CLI flags to trigger this module (e.g., ('-p', '--python')).
config_key
class-attribute
¶
The global configuration key used to evaluate if this module is active.
required_metadata
class-attribute
¶
The metadata keys that MUST be resolved for this module to function.
optional_metadata
class-attribute
¶
The metadata keys that are nice to have but not strictly required.
collision_markers
property
¶
Returns a list of critical filesystem paths to evaluate for collisions during pre-flight.
Returns:
| Type | Description |
|---|---|
list[Path]
|
A list of Path objects representing critical configuration files or directories |
list[Path]
|
managed by this module. Defaults to an empty list. |
pre_flight ¶
Verifies system prerequisites before manifest building begins.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a critical dependency (e.g., 'uv', 'cargo') is missing. |
build
abstractmethod
¶
Appends module-specific requirements to the environment manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
EnvironmentManifest
|
The centralized state object. |
required |
Deep Dive: Pre-flight vs Build
pre_flight(): Executes before any state changes occur. Ifshutil.which("just")fails here, the orchestrator immediately halts, guaranteeing the environment remains untouched.build(): Only queues state changes. Notice how we usemanifest.filesystem.add_file_injection()instead ofPath("justfile").write_text().
The Manifest API¶
No Direct Disk I/O
Never call subprocess.run or write to disk inside a module's build() method. Modules must strictly communicate via the EnvironmentManifest to ensure the Orchestrator maintains atomicity.
The manifest exposes the following methods across its domain slices to queue state changes:
| Method Signature | Execution Behavior |
|---|---|
manifest.dependencies.add(package: str) |
Queues a standard package for resolution. |
manifest.dependencies.add_dev(package: str) |
Queues a development or tooling package. |
manifest.dependencies.add_docs(package: str) |
Queues a documentation dependency for installation. |
manifest.filesystem.add_directory(path: str) |
Queues a relative directory path to be scaffolded. |
manifest.filesystem.add_file_injection(path: str, content: str) |
Queues a complete file write. Fails if the file exists unless explicitly marked for overwrite. |
manifest.filesystem.add_file_append(path: str, content: str) |
Queues a string payload for late-binding concatenation or TOML AST deep-merging. |
manifest.filesystem.add_vcs_ignore(path: str) |
Appends a tracking exclusion entry to the version control ignore manifest (e.g., .gitignore). |
manifest.tasks.add_system_task(command: list[str], timeout: int | None = 30, description: str | None = None) |
Queues a subprocess command to execute after the disk scaffolding phase is complete. Allows an optional execution timeout and UI description. |
manifest.tasks.add_post_install_task(command: list[str], timeout: int | None = 30, description: str | None = None) |
Queues a subprocess command to execute after all dependencies have been installed. Allows an optional execution timeout and UI description. |
Next Steps¶
- Testing Architecture & Philosophy: Best practices for writing isolated unit tests and mocking subprocesses.
- The Module Architecture: Deep dive into the layering model and module resolution sequence.
- API Reference: Complete class documentation for
BootstrapModuleandEnvironmentManifest.