The System Executor & Modular Execution Engine¶
While the Orchestrator plans the environment, the execution engine carries it out—writing files, updating configurations, and running shell commands.
To keep the codebase maintainable, secure, and testable, Protostar breaks execution logic into seven focused modules. This separates content generation and security checks from command execution.
The 7-Module Architecture¶
flowchart LR
classDef pure fill:#0f172a,stroke:#3b82f6,stroke-width:1px,color:#e2e8f0;
classDef stateful fill:#334155,stroke:#475569,stroke-width:1px,color:#e2e8f0;
classDef coordinator fill:#1e293b,stroke:#00e5ff,stroke-width:2px,color:#fff;
M[(Environment\nManifest)] --> E(executor.py):::coordinator
subgraph Execution Engine
E --> S(security.py):::pure
E --> T(toml_ast.py):::pure
E --> A(appends.py):::pure
E --> W(workflows.py):::pure
E --> R(registry.py):::stateful
E --> D(dependencies.py):::stateful
E --> I(ide.py):::stateful
end
1. The Thin Orchestrator (executor.py)¶
Role: Stateful execution sequencing and disk I/O.
The SystemExecutor class acts as a thin coordinator. It iterates over the manifest, gathers necessary parameters, invokes the pure content generators, and writes the output to disk using atomic operations. It strictly enforces the chronological order of execution to prevent race conditions (e.g., ensuring uv init completes before attempting to merge pyproject.toml payloads).
2. Pure Content Generation¶
These modules contain pure functions: given the same inputs, they always return the same string or AST without touching the disk or network.
workflows.py: Handles string templating for CI/CD workflows, Justfiles, Dockerfiles, pre-commit configurations, and VCS ignores.appends.py: Resolves language-specific comment syntax and injects hash-delimited marker blocks into existing file strings.toml_ast.py: Parses TOML strings usingtomlkitto manipulate the Abstract Syntax Tree (AST), performing deep merges, header formatting, and array-of-tables (AoT) conflict resolution while preserving your comments.
3. Policy & System Integration¶
These modules interact with external boundaries, but do so predictably.
security.py: Enforces strict boundaries (Pure). Validates that no filesystem operations escape the workspace root (enforce_path_jail) and that no unauthorized shell commands are executed (enforce_binary_safelist).dependencies.py(Stateful): Orchestratesuv addcommands to resolve and install Python packages into their appropriate dependency groups (main, dev, docs).ide.py(Stateful): Verifies the presence of recommended extensions via the IDE's CLI (e.g.,code --list-extensions) and deep-merges telemetry diagnostics and settings into.vscode/settings.json.registry.py: Interacts with the asynchronous static registry to fetch the latest pre-commit hook versions during the execution phase, falling back gracefully to a static mapping (_fallbacks.py) if network access is unavailable. These fallbacks are automatically kept in sync with the live edge CDN prior to every release viascripts/sync_registry_fallbacks.py.
Security & Path Isolation¶
All disk writes and subprocess calls pass through security checks in security.py:
- Path Jailing: Before the executor writes any artifact, it asserts that the
targetpath is physically bounded withinPath.cwd(). This structurally prevents malicious blueprint templates from triggering directory traversal attacks (e.g., writing to/etc/passwd). - Binary Safelisting: Before any shell task is executed (whether pre-install or post-install), the executable command name is verified against
ALLOWED_BINARIES(e.g.,uv,git,npm).
AST Deep Merging & Collision Strategies¶
When merging configuration payloads into existing TOML files, Protostar utilizes tomlkit AST parsing rather than standard dictionary updates or destructive regular expressions.
flowchart TD
classDef artifact fill:#0f172a,stroke:#3b82f6,stroke-width:1px,color:#e2e8f0;
classDef process fill:#334155,stroke:#475569,stroke-width:1px,color:#e2e8f0;
classDef decision fill:#1e293b,stroke:#00e5ff,stroke-width:2px,color:#fff;
classDef format fill:#14532d,stroke:#4ade80,stroke-width:1px,color:#fff;
Base[(Host pyproject.toml)]:::artifact --> ParseHost[Parse AST via tomlkit]:::process
Payload[(Manifest Payload)]:::artifact --> ParsePayload[Parse AST via tomlkit]:::process
ParseHost --> Strategy{Collision\nStrategy}:::decision
ParsePayload --> Strategy
Strategy -- ABORT --> Exit([Halt Operations])
Strategy -- MERGE --> MergeLogic[Union Nodes\nPreserve host scalars]:::process
Strategy -- OVERWRITE --> OverwriteLogic[Union Nodes\nPurge orphaned host scalars]:::process
MergeLogic --> Formatter
OverwriteLogic --> Formatter[Deterministic Formatter\nApply Headers & Sorting]:::format
Formatter --> Write[(Atomic Disk Write)]:::artifact
The merge behavior is governed by the resolved CollisionStrategy:
- Merge (Default): The engine walks the AST, appending missing keys and extending tables. Existing scalar values or sibling tables that are not explicitly targeted by the payload are safely ignored and preserved.
- Overwrite: The engine aggressively prunes the target. If the payload defines a specific table (e.g.,
[tool.ruff]), any existing scalar keys within that table on the host that do not exist in the payload are purged, forcing strict parity with Protostar's baseline.
Subprocess Telemetry¶
Directly calling subprocess.run in a CLI tool often leads to silent failures or messy interleaved terminal output. Protostar routes all system tasks and dependency resolutions through protostar.system.execute_subprocess.
This wrapper executes the command silently while capturing both stdout and stderr, and enforces granular task-level timeouts. If the process returns a non-zero exit code, the executor raises a strictly typed CommandExecutionError. These exceptions preserve the exact upstream streams, ensuring the Orchestrator can catch the failure and present the raw diagnostics to you without destructively flattening the context.
Simulated Subprocess Telemetry Output
When a shell execution fails, the captured streams are formatted to pinpoint the exact failure mechanism:
API Reference¶
Core Interface: SystemExecutor
protostar.executor.SystemExecutor ¶
Executes the materialized environment manifest by mutating the local disk and shell.
Source code in src/protostar/executor.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
interpolation_context
property
¶
Dynamically generates the context for template interpolation.
__init__ ¶
Initializes the executor with the target manifest state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
EnvironmentManifest
|
The centralized state object containing all execution directives. |
required |
config
|
UserConfig
|
The active Protostar configuration instance. |
required |
docker
|
bool
|
If True, scaffolds a .dockerignore from the manifest ignores. |
False
|
Source code in src/protostar/executor.py
record_touch ¶
Records a path as having been modified or created during execution.
Source code in src/protostar/executor.py
add_diagnostic ¶
Queues a diagnostic event for the post-execution summary panel.
Source code in src/protostar/executor.py
execute ¶
Executes the materialized manifest in a deterministic sequence.
Source code in src/protostar/executor.py
Core Interface: execute_subprocess
protostar.system.execute_subprocess ¶
Executes a subprocess silently and captures telemetry on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
The command and its arguments as a list of strings. |
required |
timeout
|
int | None
|
The maximum execution time in seconds. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
CommandTimeoutError
|
If the execution time limit is exceeded. |
CommandExecutionError
|
If the process returns a non-zero exit code. |
Source code in src/protostar/system.py
Related Mechanics & Guides¶
- The Orchestrator: See how the state machine coordinates the planning phase and passes the manifest to the executor.
- The Environment Manifest: Review the structured state container evaluated by the executor.
- The Module Architecture: Explore the polymorphic modules that generate the requirements processed by the executor.