Skip to content

Comments

feat: Add pre/post-install script hooks to module installation#38

Merged
mrbrandao merged 9 commits intoRedHatProductSecurity:mainfrom
mrbrandao:bootstrap-script
Feb 10, 2026
Merged

feat: Add pre/post-install script hooks to module installation#38
mrbrandao merged 9 commits intoRedHatProductSecurity:mainfrom
mrbrandao:bootstrap-script

Conversation

@mrbrandao
Copy link
Collaborator

Summary

  • Add install hooks to run custom scripts before/after module installation
  • Useful for checking dependencies, downloading resources, or running verification tests
  • Hooks are optional and fully backward compatible

Three ways to specify hooks:

  1. CLI flags: --pre-install and --post-install
  2. Module metadata: lola.yaml file in the module
  3. Marketplace: hooks field in marketplace module definitions

Precedence: CLI flags > module lola.yaml > marketplace

Example usage:

# Use CLI flags
lola install my-module --pre-install scripts/check-deps.sh

# Or define in module's lola.yaml
hooks:
  pre-install: scripts/check-deps.sh
  post-install: scripts/verify.sh

Scripts receive environment variables like LOLA_MODULE_NAME, LOLA_PROJECT_PATH, LOLA_HOOK for context.

Related Issues

Fixes #37

Checklist

  • Tests pass (pytest)
  • Linting passes (ruff check src tests)
  • Formatting passes (uv run ruff format --check src tests)

AI Disclosure

AI-assisted with Claude Code

mrbrandao and others added 8 commits February 9, 2026 20:11
Add pre_install_hook and post_install_hook fields to Module dataclass.
Add auto-discovery of hooks from lola.yaml file in module content directory.

- Add optional hook fields to Module (default: None)
- Parse lola.yaml and extract hooks.pre-install and hooks.post-install
- Handle malformed YAML gracefully (ignore and continue)
- Support both root and module/ subdirectory layouts
- Add comprehensive tests for hook discovery

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add validation for pre_install_hook and post_install_hook fields.
Ensure hook scripts exist and are within module directory boundary.

- Validate hook script paths exist in content_path
- Prevent path traversal attacks (../../ patterns)
- Add comprehensive security and validation tests
- Handle missing hooks gracefully (None values skip validation)

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add core hook execution function with security validation and timeout.
Execute bash scripts with environment context and proper error handling.

- Add _run_install_hook() to targets/install.py
- Validate script exists and is within module directory
- Set environment variables (LOLA_MODULE_NAME, LOLA_HOOK, etc.)
- Execute with subprocess.run() from project directory
- Handle timeouts (5 minute max)
- Capture and display stdout/stderr
- Raise InstallationError on failure
- Add comprehensive unit tests for all scenarios

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add CLI flags to specify hook scripts during installation.
Implement precedence logic where CLI flags override module metadata.

- Add --pre-install and --post-install options to install command
- Update install_to_assistant() signature to accept hook parameters
- Implement precedence: CLI flags > module lola.yaml
- Add tests for CLI flag acceptance
- Pass effective hooks to install orchestrator

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add pre-install hook execution after module copy, before skill installation.
Implement cleanup on pre-install failure to maintain clean state.

- Execute pre-install hook if provided (after copy_module_to_local)
- Clean up copied module on pre-install failure (shutil.rmtree)
- Re-raise InstallationError to abort installation
- Hook runs before any skills/commands/agents are installed

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add post-install hook execution after registry update.
Show warning on failure but keep installation (no rollback).

- Execute post-install hook if provided (after registry.add)
- Catch InstallationError and display warning
- Do not rollback installation on post-install failure
- Installation is already complete and functional

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Support hooks defined in marketplace YAML module entries.
Implement full precedence: CLI flags > module lola.yaml > marketplace.

- Modify _fetch_from_marketplace() to return module metadata
- Extract marketplace hooks from module dict
- Apply three-level precedence in install_cmd
- Add test for hook precedence
- Marketplace hooks are lowest priority fallback

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive documentation for pre/post-install hooks feature.
Include usage examples, configuration options, and security warnings.

- Document CLI flags and module metadata configuration
- Add marketplace hooks example
- Explain hook environment variables and precedence
- Provide example scripts (sed, python version checks)
- Include security warnings about script execution

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mrbrandao
Copy link
Collaborator Author

cc: @jeremychoi , @SecKatie

Connect stdin/stdout/stderr to terminal so scripts can prompt for user
input and display output in real-time. Remove capture_output=True which
was blocking interactive prompts.

Fixes issue where scripts using read -rp or other interactive commands
didn't show prompts to the user.

Related to RedHatProductSecurity#37

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mrbrandao mrbrandao requested a review from rjeffman February 10, 2026 12:58
@mrbrandao mrbrandao merged commit ea688f3 into RedHatProductSecurity:main Feb 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pre/post-install script hooks to module installation

2 participants