Business logic and state management for wish
Project description
wish-core
Core business logic and state management for the wish penetration testing support system.
Overview
wish-core provides the central business logic, state management, and event processing capabilities for wish. It acts as the coordination layer between the AI components, tools, and user interface.
Key Features
- State Management: Centralized management of engagement state and session data
- Event System: Event-driven architecture for component communication
- Tool Coordination: Integration layer for penetration testing tools
- Workflow Management: Handles the flow between different testing phases
- Job Management: Asynchronous job execution and monitoring
Installation
# Install dependencies in development environment
uv sync --dev
# Install as package (future release)
pip install wish-core
Quick Start
Basic Usage Example
from wish_core import StateManager, EventBus, JobManager
from wish_models import EngagementState, SessionMetadata
# Initialize core components
state_manager = StateManager()
event_bus = EventBus()
job_manager = JobManager()
# Create and manage engagement state
session = SessionMetadata(engagement_name="Example Pentest")
engagement = EngagementState(name="Internal Network Assessment", session_metadata=session)
state_manager.set_engagement(engagement)
# Subscribe to events
@event_bus.subscribe("host.discovered")
async def on_host_discovered(event):
print(f"New host discovered: {event.data['ip_address']}")
# Execute tools asynchronously
job = await job_manager.execute_tool(
tool_name="nmap",
command="nmap -sS -p- 192.168.1.0/24",
callback=lambda result: process_nmap_results(result)
)
# Monitor job progress
status = await job_manager.get_job_status(job.id)
print(f"Job {job.id} status: {status}")
Architecture
Core Components
StateManager
Manages the central engagement state and provides thread-safe access to shared data.
from wish_core import StateManager
manager = StateManager()
# Get current state
state = manager.get_current_state()
# Update specific parts
manager.update_hosts(new_hosts)
manager.add_finding(finding)
# Transaction support
with manager.transaction():
manager.update_hosts(hosts)
manager.update_services(services)
EventBus
Provides event-driven communication between components.
from wish_core import EventBus
bus = EventBus()
# Subscribe to events
@bus.subscribe("tool.completed")
async def handle_tool_completion(event):
print(f"Tool {event.data['tool']} completed")
# Publish events
await bus.publish("scan.started", {"target": "192.168.1.0/24"})
JobManager
Handles asynchronous execution of tools and long-running operations.
from wish_core import JobManager
job_manager = JobManager()
# Execute tool
job = await job_manager.execute_tool(
tool_name="nikto",
command="nikto -h http://target.com",
timeout=300
)
# Check status
status = await job_manager.get_job_status(job.id)
# Cancel job
await job_manager.cancel_job(job.id)
Development Guide
Running Tests
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=src --cov-report=html
# Run specific test file
uv run pytest tests/test_state_manager.py
# Run with verbose output
uv run pytest -v
Code Quality Checks
# Run linting
uv run ruff check src/ tests/
# Format code
uv run ruff format src/ tests/
# Type checking
uv run mypy src/
Project Structure
packages/wish-core/
├── src/wish_core/
│ ├── __init__.py # Package exports
│ ├── state_manager.py # State management
│ ├── event_bus.py # Event system
│ ├── job_manager.py # Job execution
│ ├── workflow/ # Workflow management
│ │ ├── __init__.py
│ │ └── coordinator.py
│ └── utils/ # Utility functions
│ ├── __init__.py
│ └── threading.py
├── tests/
│ ├── test_state_manager.py
│ ├── test_event_bus.py
│ ├── test_job_manager.py
│ └── test_workflow.py
└── README.md
API Reference
StateManager API
get_current_state(): Get the current engagement stateset_engagement(engagement): Set a new engagementupdate_hosts(hosts): Update host informationadd_finding(finding): Add a new findingtransaction(): Context manager for atomic updates
EventBus API
subscribe(event_type, handler): Subscribe to an event typeunsubscribe(event_type, handler): Unsubscribe from eventspublish(event_type, data): Publish an eventclear(): Clear all subscriptions
JobManager API
execute_tool(tool_name, command, **kwargs): Execute a toolget_job_status(job_id): Get job statuscancel_job(job_id): Cancel a running jobget_job_logs(job_id): Get job output logslist_active_jobs(): List all active jobs
License
This project is published under [appropriate license].
Related Packages
wish-models: Core data models and validationwish-ai: AI-driven inference enginewish-tools: Pentest tool integrationwish-knowledge: Knowledge base managementwish-c2: C2 server integrationwish-cli: Command line interface
Support
If you have issues or questions, you can get support through:
- Issues: Bug reports and feature requests
- Discussions: General questions and discussions
- Documentation: Review API documentation and examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wish_core-0.7.0.tar.gz.
File metadata
- Download URL: wish_core-0.7.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c412edce72dc3287e4c051fbc991289a8163eb739e7e31e7d2f6c09442c2925
|
|
| MD5 |
68f6a8c848d329a85823ff6e49481838
|
|
| BLAKE2b-256 |
bcbddaf28ab7989264cf5796a95b79355f573ed14e3f240bd03e32a21e5bf037
|
File details
Details for the file wish_core-0.7.0-py3-none-any.whl.
File metadata
- Download URL: wish_core-0.7.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14c295918f46bd5b69fcda4dc02c0dc55277f1f9c6e2a180cf0a0c636815d9d2
|
|
| MD5 |
3719b5ffe0deca1fc4c5f59e8cb8a72a
|
|
| BLAKE2b-256 |
9ec0ba65bfe801884dcfa8cddd81b075aa64f0615ba38f434e650ab30863d5a4
|