Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1833f1a021 | ||
|
|
cc6d46a838 | ||
|
|
8cb026b1be | ||
|
|
cec7417582 | ||
|
|
62bb47a881 | ||
|
|
e38f523a45 | ||
|
|
30550dd189 | ||
|
|
154040f9fb | ||
|
|
365d51f52f | ||
|
|
305ae2f699 | ||
|
|
d6e9b3b7cf | ||
|
|
2b94633212 | ||
|
|
846f8c02b4 | ||
|
|
6e1b5b7a0c | ||
|
|
40cb705494 | ||
|
|
e0b750dbcd | ||
|
|
0a63ffba63 | ||
|
|
5a76fab4ae | ||
|
|
85f05c326b | ||
|
|
b8cabdde97 | ||
|
|
83ce9ed960 | ||
|
|
c2fbf81f1d | ||
|
|
c5bd30e677 | ||
|
|
5d187fcb02 | ||
|
|
39d934ee71 | ||
|
|
386e64fa29 | ||
|
|
655ddb4d7f | ||
|
|
2bc1e5e1cb | ||
|
|
6bacc796e2 | ||
|
|
c50c79084b | ||
|
|
83914f454f | ||
|
|
6da639ce58 | ||
|
|
a97836c335 | ||
|
|
5f77dd7052 | ||
|
|
33b94a7034 | ||
|
|
456705e5e9 | ||
|
|
82d1c0cec4 | ||
|
|
1b394b808b | ||
|
|
25ac2f1e08 | ||
|
|
b456a4ed8c | ||
|
|
165887798d | ||
|
|
4ab9af6e47 | ||
|
|
4337991d05 | ||
|
|
9cff247d89 | ||
|
|
af2c830f70 | ||
|
|
91feb3e01c | ||
|
|
762c25d6ed | ||
|
|
6cb1c20978 | ||
|
|
4b62169f74 | ||
|
|
e948f06d64 | ||
|
|
3d4b1bfb08 | ||
|
|
8413987fcd | ||
|
|
a67fe4c45c | ||
|
|
9f7b532056 | ||
|
|
43572242f1 | ||
|
|
a7bd635c11 | ||
|
|
e30ef9aec8 | ||
|
|
03fb1e940f | ||
|
|
7417e6f8d0 | ||
|
|
86f8835ccb | ||
|
|
2bfb80ff4a | ||
|
|
7ff0e68466 | ||
|
|
2ebfd20db5 | ||
|
|
918a151892 | ||
|
|
a80ecac7bd | ||
|
|
19246d8a5a | ||
|
|
4cb2cebd1e | ||
|
|
26b0786a4e | ||
|
|
61dea7010a | ||
|
|
c433d4ffb2 | ||
|
|
ed6861db64 | ||
|
|
a74ed69471 | ||
|
|
9102b22381 | ||
|
|
693ef16060 | ||
|
|
8dc6f1dc8f | ||
|
|
4d9154a7f8 | ||
|
|
2898db318e | ||
|
|
960bb91790 | ||
|
|
4de4be683f | ||
|
|
d351b14ae7 | ||
|
|
ceeec8faa8 | ||
|
|
e5104eb93a | ||
|
|
d8a08e9a8c | ||
|
|
f6475cec07 | ||
|
|
31baa0dfc0 | ||
|
|
56526cbf90 | ||
|
|
47faeb1ef3 | ||
|
|
435ac82d9e | ||
|
|
f08014cf51 | ||
|
|
bc8e14f68a | ||
|
|
eae2b783c0 | ||
|
|
058cf1abdb | ||
|
|
d16bdb277a | ||
|
|
d7f712581d | ||
|
|
4818a854d6 | ||
|
|
9bcb43e713 | ||
|
|
5672925736 | ||
|
|
61c94189c6 | ||
|
|
f539e5aafd | ||
|
|
1ffeedcf55 | ||
|
|
c059f47d01 | ||
|
|
7dab26cdd5 | ||
|
|
498032e279 | ||
|
|
b80bb165b9 | ||
|
|
fe456d57fe | ||
|
|
13e804b7e3 | ||
|
|
2e3dc0d276 | ||
|
|
83efe3816f | ||
|
|
52aa763d47 | ||
|
|
d932602a6b | ||
|
|
6f4ca95338 | ||
|
|
fb6f6295c5 | ||
|
|
f56f56a7f7 | ||
|
|
86a687ede8 | ||
|
|
7b7ea59a37 | ||
|
|
226678f3f2 | ||
|
|
49421f50d5 | ||
|
|
b6b0778956 | ||
|
|
4a58226c9a | ||
|
|
94bb97143e | ||
|
|
bcd6b8a715 | ||
|
|
c53a0f6b64 | ||
|
|
dc5043452e | ||
|
|
13ba8746dd | ||
|
|
a31ed36778 | ||
|
|
740fb3ed40 | ||
|
|
c327ce621f | ||
|
|
e8662fbda9 | ||
|
|
cdf3cca3b7 | ||
|
|
0159d431ea | ||
|
|
bf04b304e6 | ||
|
|
a1d7c0f810 | ||
|
|
47e07c8a04 | ||
|
|
ea31e0cc9d | ||
|
|
9bb8475e2f | ||
|
|
a09d2795e2 | ||
|
|
17ee6e6e6f | ||
|
|
01ae348da8 | ||
|
|
0e9cd9b2a4 | ||
|
|
2ea5ff6695 | ||
|
|
06659d98ba | ||
|
|
7af1180a30 | ||
|
|
f48def1f9e | ||
|
|
af8eeef4ac | ||
|
|
16c9b05121 | ||
|
|
6422bfa0b4 | ||
|
|
dd7767c847 | ||
|
|
2777ae3fe8 | ||
|
|
45bb0ae8d8 | ||
|
|
67cfe994be | ||
|
|
878d6ebf57 | ||
|
|
48fb48dba3 | ||
|
|
0954ac208f | ||
|
|
a6dcb7756e | ||
|
|
a2142cc985 | ||
|
|
7bcdedfb18 | ||
|
|
e6ddcb1801 | ||
|
|
daba3d8b61 | ||
|
|
e6c1aae38d | ||
|
|
1089aab89e | ||
|
|
706bb193c0 | ||
|
|
2ba1d0fe59 | ||
|
|
8b0bb521ba | ||
|
|
a90082bc53 | ||
|
|
6fc592b4e8 | ||
|
|
62cca3f149 | ||
|
|
f25cf9b23d | ||
|
|
2472d590d5 | ||
|
|
78b6c26652 | ||
|
|
d649a7c70b | ||
|
|
d96852de55 | ||
|
|
eb0c52b720 | ||
|
|
2899021a21 | ||
|
|
0fcd5c46b2 | ||
|
|
dcf77b31fc | ||
|
|
37c8cffbe3 | ||
|
|
c29f13fd69 | ||
|
|
5c995628bf | ||
|
|
624f1ed77f | ||
|
|
2b926c733b | ||
|
|
a075ea1a0a | ||
|
|
5e3d14a1eb | ||
|
|
e57b7238f6 | ||
|
|
13fe87d428 | ||
|
|
3e5845a0e1 | ||
|
|
9fedcf1551 | ||
|
|
1edd8eda01 | ||
|
|
d8cb21bea3 | ||
|
|
bd8d927f34 | ||
|
|
fc267564f5 | ||
|
|
37c9b4b0e0 | ||
|
|
208b31a570 | ||
|
|
a14cb41745 | ||
|
|
4297c8f6e4 | ||
|
|
286d53384a | ||
|
|
ab40dbc33a | ||
|
|
b6cb1302ce | ||
|
|
b74132b2dc | ||
|
|
35dd9d0a8f | ||
|
|
6c5c0b0d1c | ||
|
|
65c3383ecc | ||
|
|
919cb5e248 | ||
|
|
c97ff94617 | ||
|
|
53c9da9213 | ||
|
|
1e189c1245 | ||
|
|
62f804b8b5 | ||
|
|
5ff10e9d20 | ||
|
|
9825fb46ec | ||
|
|
c0e547928e | ||
|
|
78d0148d58 | ||
|
|
eebb76de3b | ||
|
|
2ae1b3ddd1 | ||
|
|
a11cd09a93 | ||
|
|
68ebdb2b6d | ||
|
|
5befb32318 | ||
|
|
86e6ed49bb | ||
|
|
0c811845f1 | ||
|
|
383d53c7a9 | ||
|
|
478bf5d4d3 | ||
|
|
d1f7741965 | ||
|
|
821929cd3e | ||
|
|
5de16d2953 | ||
|
|
6a2a62c121 | ||
|
|
426dd27454 | ||
|
|
cedc65409e | ||
|
|
72d5a73386 | ||
|
|
dab69af033 | ||
|
|
6abb53dc02 | ||
|
|
f1d2961779 | ||
|
|
2b7a8e3ee7 | ||
|
|
3e7466a533 | ||
|
|
1abfb360e4 | ||
|
|
795ed02955 | ||
|
|
2cb0c31897 | ||
|
|
1c8780cf81 | ||
|
|
b6d9d941cf | ||
|
|
edd628bbc1 | ||
|
|
d76c7c55b2 | ||
|
|
b5ddba3867 | ||
|
|
2763998821 | ||
|
|
6a84ea94fa | ||
|
|
cf1d43706a | ||
|
|
b9f8ee3f67 | ||
|
|
2d6db8f95e | ||
|
|
7178307b9d | ||
|
|
738fdc2d49 | ||
|
|
deee85d547 | ||
|
|
354fd48480 | ||
|
|
1f29c71a88 | ||
|
|
97154c7d0e | ||
|
|
395013fdeb | ||
|
|
ecf5271981 | ||
|
|
71c232b577 | ||
|
|
f2b4eccc5b | ||
|
|
86dd6f5330 | ||
|
|
85209bfc20 | ||
|
|
54851e2e0a | ||
|
|
a4712b7b78 | ||
|
|
96f5c44799 | ||
|
|
49df6ef8e0 | ||
|
|
c78f7d37de | ||
|
|
e2756f4821 | ||
|
|
ed77eef89b | ||
|
|
4681f23b1f | ||
|
|
1eb6023fb6 | ||
|
|
216809a157 | ||
|
|
f22acefd76 | ||
|
|
6d5a3f331b | ||
|
|
d4a62ec365 | ||
|
|
fa566e5fb5 | ||
|
|
7de9c4efe1 | ||
|
|
522d2c8948 | ||
|
|
9e7c133bbf | ||
|
|
7979b84cc3 | ||
|
|
94ca55b065 | ||
|
|
ac6d5c6dae | ||
|
|
af01294c46 | ||
|
|
c8b23720df | ||
|
|
7d8ffe1e32 | ||
|
|
aabf97af0a | ||
|
|
5294d613d0 | ||
|
|
9a9a7268cd | ||
|
|
914b981072 | ||
|
|
500b987ed4 | ||
|
|
138c5a9023 | ||
|
|
9adbd03ff1 | ||
|
|
ec99626ba8 | ||
|
|
d43fb5be03 | ||
|
|
4a719130ff | ||
|
|
19f166e608 | ||
|
|
cb57426cc6 | ||
|
|
198a5e4a61 | ||
|
|
ccab853c0f | ||
|
|
337d64d362 |
@@ -1,126 +0,0 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: true
|
||||
---
|
||||
# Strix Cybersecurity Agent - Project Rules
|
||||
|
||||
## Project Overview
|
||||
|
||||
### Goal and Purpose
|
||||
Strix is a sophisticated cybersecurity agent specialized in vulnerability scanning and security assessment. It provides:
|
||||
- Automated cybersecurity scans and assessments
|
||||
- Web application security testing
|
||||
- Infrastructure vulnerability analysis
|
||||
- Comprehensive security reporting
|
||||
- RESTful API for scan management
|
||||
- CLI interface for direct usage
|
||||
|
||||
The project implements an AI-powered ReAct (Reasoning and Acting) framework for autonomous security testing.
|
||||
|
||||
## Project Structure
|
||||
|
||||
### High-Level Architecture
|
||||
```
|
||||
strix-agent/
|
||||
├── strix/ # Core application package
|
||||
│ ├── agents/ # AI agent implementations
|
||||
│ ├── api/ # FastAPI web service
|
||||
│ ├── cli/ # Command-line interface
|
||||
│ ├── llm/ # Language model configurations
|
||||
│ └── tools/ # Security testing tools
|
||||
├── tests/ # Test suite
|
||||
├── evaluation/ # Evaluation framework
|
||||
├── containers/ # Docker configuration
|
||||
└── docs/ # Documentation
|
||||
```
|
||||
|
||||
### Low-Level Structure
|
||||
|
||||
#### Core Components
|
||||
- **[strix/agents/StrixAgent/strix_agent.py](mdc:strix/agents/StrixAgent/strix_agent.py)** - Main cybersecurity agent
|
||||
- **[strix/agents/base_agent.py](mdc:strix/agents/base_agent.py)** - Base agent framework
|
||||
- **[strix/api/main.py](mdc:strix/api/main.py)** - FastAPI application entry point
|
||||
- **[strix/cli/main.py](mdc:strix/cli/main.py)** - CLI entry point
|
||||
- **[pyproject.toml](mdc:pyproject.toml)** - Project configuration and dependencies
|
||||
|
||||
#### API Structure
|
||||
- **[strix/api/routers/](mdc:strix/api/routers)** - API endpoint definitions
|
||||
- **[strix/api/models/](mdc:strix/api/models)** - Pydantic data models
|
||||
- **[strix/api/services/](mdc:strix/api/services)** - Business logic services
|
||||
|
||||
#### Security Tools
|
||||
- **[strix/tools/browser/](mdc:strix/tools/browser)** - Web browser automation
|
||||
- **[strix/tools/terminal/](mdc:strix/tools/terminal)** - Terminal command execution
|
||||
- **[strix/tools/python/](mdc:strix/tools/python)** - Python code execution
|
||||
- **[strix/tools/web_search/](mdc:strix/tools/web_search)** - Web reconnaissance
|
||||
- **[strix/tools/reporting/](mdc:strix/tools/reporting)** - Security report generation
|
||||
|
||||
## Development Guidelines
|
||||
|
||||
### Code Standards
|
||||
- **Simplicity**: Write simple, clean, and modular code
|
||||
- **Functionality**: Prefer functional programming patterns where appropriate
|
||||
- **Efficiency**: Optimize for performance without premature optimization
|
||||
- **No Bloat**: Avoid unnecessary complexity or over-engineering
|
||||
- **Minimal Comments**: Code should be self-documenting; use comments sparingly for complex business logic only
|
||||
|
||||
### Code Quality Requirements
|
||||
- All code MUST pass `make pre-commit` checks
|
||||
- All code MUST pass Ruff linting without warnings
|
||||
- All code MUST pass MyPy type checking without errors
|
||||
- Type hints are required for all function signatures
|
||||
- Follow the strict configuration in [pyproject.toml](mdc:pyproject.toml)
|
||||
|
||||
### Execution Environment
|
||||
- **ALWAYS** use `poetry run` for executing Python scripts and commands
|
||||
- **NEVER** run Python directly with `python` command
|
||||
- Use `poetry run strix-agent` for CLI operations
|
||||
- Use `poetry run uvicorn strix.api.main:app` for API server
|
||||
|
||||
### File Management Rules
|
||||
- **DO NOT** create or edit README.md or any .md documentation files unless explicitly requested
|
||||
- Focus on code implementation, not documentation
|
||||
- Keep docstrings concise and functional
|
||||
|
||||
### Testing and Quality Assurance
|
||||
- Run `make pre-commit` before any commits
|
||||
- Ensure all tests pass with `poetry run pytest`
|
||||
- Use `poetry run mypy .` for type checking
|
||||
- Use `poetry run ruff check .` for linting
|
||||
|
||||
### Dependencies
|
||||
- All dependencies managed through [pyproject.toml](mdc:pyproject.toml)
|
||||
- Use Poetry for dependency management
|
||||
- Pin versions for production dependencies
|
||||
- Keep dev dependencies in separate group
|
||||
|
||||
### Configuration
|
||||
- Application settings in [strix/api/core/config.py](mdc:strix/api/core/config.py)
|
||||
- LLM configuration in [strix/llm/config.py](mdc:strix/llm/config.py)
|
||||
- Agent system prompts in [strix/agents/StrixAgent/system_prompt.jinja](mdc:strix/agents/StrixAgent/system_prompt.jinja)
|
||||
|
||||
## Key Implementation Patterns
|
||||
|
||||
### Agent Framework
|
||||
- Inherit from BaseAgent for new agent implementations
|
||||
- Use ReAct pattern for reasoning and action loops
|
||||
- Implement tools through the registry system in [strix/tools/registry.py](mdc:strix/tools/registry.py)
|
||||
|
||||
### API Development
|
||||
- Use FastAPI with Pydantic models
|
||||
- Implement proper error handling and validation
|
||||
- Follow REST conventions for endpoints
|
||||
- Use Beanie ODM for MongoDB operations
|
||||
|
||||
### Security Tools
|
||||
- Implement tools as action classes with clear interfaces
|
||||
- Use async/await for I/O operations
|
||||
- Implement proper cleanup and resource management
|
||||
- Follow principle of least privilege
|
||||
|
||||
### Error Handling
|
||||
- Use structured exception handling
|
||||
- Provide meaningful error messages
|
||||
- Log errors appropriately without exposing sensitive information
|
||||
- Implement graceful degradation where possible
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
4.
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**System Information:**
|
||||
- OS: [e.g. Ubuntu 22.04]
|
||||
- Strix Version or Commit: [e.g. 0.1.18]
|
||||
- Python Version: [e.g. 3.12]
|
||||
- LLM Used: [e.g. GPT-5, Claude Sonnet 4.6]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[FEATURE]"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 679 KiB After Width: | Height: | Size: 1.6 MiB |
@@ -0,0 +1,78 @@
|
||||
name: Build & Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: macos-latest
|
||||
target: macos-arm64
|
||||
- os: macos-15-intel
|
||||
target: macos-x86_64
|
||||
- os: ubuntu-latest
|
||||
target: linux-x86_64
|
||||
- os: windows-latest
|
||||
target: windows-x86_64
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- uses: snok/install-poetry@v1
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
poetry install --with dev
|
||||
poetry run pyinstaller strix.spec --noconfirm
|
||||
|
||||
VERSION=$(poetry version -s)
|
||||
mkdir -p dist/release
|
||||
|
||||
if [[ "${{ runner.os }}" == "Windows" ]]; then
|
||||
cp dist/strix.exe "dist/release/strix-${VERSION}-${{ matrix.target }}.exe"
|
||||
(cd dist/release && 7z a "strix-${VERSION}-${{ matrix.target }}.zip" "strix-${VERSION}-${{ matrix.target }}.exe")
|
||||
else
|
||||
cp dist/strix "dist/release/strix-${VERSION}-${{ matrix.target }}"
|
||||
chmod +x "dist/release/strix-${VERSION}-${{ matrix.target }}"
|
||||
tar -C dist/release -czvf "dist/release/strix-${VERSION}-${{ matrix.target }}.tar.gz" "strix-${VERSION}-${{ matrix.target }}"
|
||||
fi
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: strix-${{ matrix.target }}
|
||||
path: |
|
||||
dist/release/*.tar.gz
|
||||
dist/release/*.zip
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: release
|
||||
merge-multiple: true
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
generate_release_notes: true
|
||||
files: release/*
|
||||
@@ -79,6 +79,7 @@ logs/
|
||||
tensorboard/
|
||||
|
||||
# Agent execution traces
|
||||
strix_runs/
|
||||
agent_runs/
|
||||
|
||||
# Misc
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
# Contributing to Strix
|
||||
|
||||
Thank you for your interest in contributing to Strix! This guide will help you get started with development and contributions.
|
||||
|
||||
## 🚀 Development Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.12+
|
||||
- Docker (running)
|
||||
- Poetry (for dependency management)
|
||||
- Git
|
||||
|
||||
### Local Development
|
||||
|
||||
1. **Clone the repository**
|
||||
```bash
|
||||
git clone https://github.com/usestrix/strix.git
|
||||
cd strix
|
||||
```
|
||||
|
||||
2. **Install development dependencies**
|
||||
```bash
|
||||
make setup-dev
|
||||
|
||||
# or manually:
|
||||
poetry install --with=dev
|
||||
poetry run pre-commit install
|
||||
```
|
||||
|
||||
3. **Configure your LLM provider**
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
```
|
||||
|
||||
4. **Run Strix in development mode**
|
||||
```bash
|
||||
poetry run strix --target https://example.com
|
||||
```
|
||||
|
||||
## 📚 Contributing Skills
|
||||
|
||||
Skills are specialized knowledge packages that enhance agent capabilities. See [strix/skills/README.md](strix/skills/README.md) for detailed guidelines.
|
||||
|
||||
### Quick Guide
|
||||
|
||||
1. **Choose the right category** (`/vulnerabilities`, `/frameworks`, `/technologies`, etc.)
|
||||
2. **Create a** `.md` file with your skill content
|
||||
3. **Include practical examples** - Working payloads, commands, or test cases
|
||||
4. **Provide validation methods** - How to confirm findings and avoid false positives
|
||||
5. **Submit via PR** with clear description
|
||||
|
||||
## 🔧 Contributing Code
|
||||
|
||||
### Pull Request Process
|
||||
|
||||
1. **Create an issue first** - Describe the problem or feature
|
||||
2. **Fork and branch** - Work from the `main` branch
|
||||
3. **Make your changes** - Follow existing code style
|
||||
4. **Write/update tests** - Ensure coverage for new features
|
||||
5. **Run quality checks** - `make check-all` should pass
|
||||
6. **Submit PR** - Link to issue and provide context
|
||||
|
||||
### PR Guidelines
|
||||
|
||||
- **Clear description** - Explain what and why
|
||||
- **Small, focused changes** - One feature/fix per PR
|
||||
- **Include examples** - Show before/after behavior
|
||||
- **Update documentation** - If adding features
|
||||
- **Pass all checks** - Tests, linting, type checking
|
||||
|
||||
### Code Style
|
||||
|
||||
- Follow PEP 8 with 100-character line limit
|
||||
- Use type hints for all functions
|
||||
- Write docstrings for public methods
|
||||
- Keep functions focused and small
|
||||
- Use meaningful variable names
|
||||
|
||||
## 🐛 Reporting Issues
|
||||
|
||||
When reporting bugs, please include:
|
||||
|
||||
- Python version and OS
|
||||
- Strix version
|
||||
- LLMs being used
|
||||
- Full error traceback
|
||||
- Steps to reproduce
|
||||
- Expected vs actual behavior
|
||||
|
||||
## 💡 Feature Requests
|
||||
|
||||
We welcome feature ideas! Please:
|
||||
|
||||
- Check existing issues first
|
||||
- Describe the use case clearly
|
||||
- Explain why it would benefit users
|
||||
- Consider implementation approach
|
||||
- Be open to discussion
|
||||
|
||||
## 🤝 Community
|
||||
|
||||
- **Discord**: [Join our community](https://discord.gg/strix-ai)
|
||||
- **Issues**: [GitHub Issues](https://github.com/usestrix/strix/issues)
|
||||
|
||||
## ✨ Recognition
|
||||
|
||||
We value all contributions! Contributors will be:
|
||||
- Listed in release notes
|
||||
- Thanked in our Discord
|
||||
- Added to contributors list (coming soon)
|
||||
|
||||
---
|
||||
|
||||
**Questions?** Reach out on [Discord](https://discord.gg/strix-ai) or create an issue. We're here to help!
|
||||
@@ -1,62 +1,120 @@
|
||||
<p align="center">
|
||||
<a href="https://strix.ai/">
|
||||
<img src="https://github.com/usestrix/.github/raw/main/imgs/cover.png" alt="Strix Banner" width="100%">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# Strix
|
||||
|
||||
### Open-source AI hackers for your apps
|
||||
### Open-source AI hackers to find and fix your app’s vulnerabilities.
|
||||
|
||||
[](LICENSE)
|
||||
[](https://vercel.com/ai-accelerator)
|
||||
[](https://github.com/usestrix/strix)
|
||||
[](https://discord.gg/yduEyduBsp)
|
||||
<br/>
|
||||
|
||||
**⚡ Use it to hack your apps before the bad guys do ⚡**
|
||||
|
||||
<a href="https://docs.strix.ai"><img src="https://img.shields.io/badge/Docs-docs.strix.ai-2b9246?style=for-the-badge&logo=gitbook&logoColor=white" alt="Docs"></a>
|
||||
<a href="https://strix.ai"><img src="https://img.shields.io/badge/Website-strix.ai-f0f0f0?style=for-the-badge&logoColor=000000" alt="Website"></a>
|
||||
[](https://discord.gg/strix-ai)
|
||||
|
||||
<a href="https://deepwiki.com/usestrix/strix"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
||||
<a href="https://github.com/usestrix/strix"><img src="https://img.shields.io/github/stars/usestrix/strix?style=flat-square" alt="GitHub Stars"></a>
|
||||
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-3b82f6?style=flat-square" alt="License"></a>
|
||||
<a href="https://pypi.org/project/strix-agent/"><img src="https://img.shields.io/pypi/v/strix-agent?style=flat-square" alt="PyPI Version"></a>
|
||||
|
||||
|
||||
<a href="https://discord.gg/strix-ai"><img src="https://github.com/usestrix/.github/raw/main/imgs/Discord.png" height="40" alt="Join Discord"></a>
|
||||
<a href="https://x.com/strix_ai"><img src="https://github.com/usestrix/.github/raw/main/imgs/X.png" height="40" alt="Follow on X"></a>
|
||||
|
||||
|
||||
<a href="https://trendshift.io/repositories/15362" target="_blank"><img src="https://trendshift.io/api/badge/repositories/15362" alt="usestrix/strix | Trendshift" width="250" height="55"/></a>
|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
<img src=".github/screenshot.png" alt="Strix Demo" width="800" style="border-radius: 16px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.2); transform: perspective(1000px) rotateX(2deg); transition: transform 0.3s ease;">
|
||||
</div>
|
||||
|
||||
> [!TIP]
|
||||
> **New!** Strix integrates seamlessly with GitHub Actions and CI/CD pipelines. Automatically scan for vulnerabilities on every pull request and block insecure code before it reaches production!
|
||||
|
||||
---
|
||||
|
||||
## 🦉 Strix Overview
|
||||
|
||||
Strix are autonomous AI agents that act just like real hackers - they run your code dynamically, find vulnerabilities, and validate them through actual exploitation. Built for developers and security teams who need fast, accurate security testing without the overhead of manual pentesting or the false positives of static analysis tools.
|
||||
## Strix Overview
|
||||
|
||||
### 🚀 Quick Start
|
||||
Strix are autonomous AI agents that act just like real hackers - they run your code dynamically, find vulnerabilities, and validate them through actual proof-of-concepts. Built for developers and security teams who need fast, accurate security testing without the overhead of manual pentesting or the false positives of static analysis tools.
|
||||
|
||||
**Key Capabilities:**
|
||||
|
||||
- **Full hacker toolkit** out of the box
|
||||
- **Teams of agents** that collaborate and scale
|
||||
- **Real validation** with PoCs, not false positives
|
||||
- **Developer‑first** CLI with actionable reports
|
||||
- **Auto‑fix & reporting** to accelerate remediation
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
<div align="center">
|
||||
<a href="https://strix.ai">
|
||||
<img src=".github/screenshot.png" alt="Strix Demo" width="1000" style="border-radius: 16px;">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
## Use Cases
|
||||
|
||||
- **Application Security Testing** - Detect and validate critical vulnerabilities in your applications
|
||||
- **Rapid Penetration Testing** - Get penetration tests done in hours, not weeks, with compliance reports
|
||||
- **Bug Bounty Automation** - Automate bug bounty research and generate PoCs for faster reporting
|
||||
- **CI/CD Integration** - Run tests in CI/CD to block vulnerabilities before reaching production
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
**Prerequisites:**
|
||||
- Docker (running)
|
||||
- An LLM API key:
|
||||
- Any [supported provider](https://docs.strix.ai/llm-providers/overview) (OpenAI, Anthropic, Google, etc.)
|
||||
- Or [Strix Router](https://models.strix.ai) — single API key for multiple providers with $10 free credit on signup
|
||||
|
||||
### Installation & First Scan
|
||||
|
||||
```bash
|
||||
# Install
|
||||
# Install Strix
|
||||
curl -sSL https://strix.ai/install | bash
|
||||
|
||||
# Or via pipx
|
||||
pipx install strix-agent
|
||||
|
||||
# Configure AI provider
|
||||
export STRIX_LLM="anthropic/claude-opus-4-1-20250805"
|
||||
# Configure your AI provider
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6" # or "strix/claude-sonnet-4.6" via Strix Router (https://models.strix.ai)
|
||||
export LLM_API_KEY="your-api-key"
|
||||
|
||||
# Run security assessment
|
||||
# Run your first security assessment
|
||||
strix --target ./app-directory
|
||||
```
|
||||
|
||||
## Why Use Strix
|
||||
> [!NOTE]
|
||||
> First run automatically pulls the sandbox Docker image. Results are saved to `strix_runs/<run-name>`
|
||||
|
||||
- **Full Hacker Arsenal** - All the tools a professional hacker needs, built into the agents
|
||||
- **Real Validation** - Dynamic testing and actual exploitation, thus much fewer false positives
|
||||
- **Developer-First** - Seamlessly integrates into existing development workflows
|
||||
- **Auto-Fix & Reporting** - Automated patching with detailed remediation and security reports
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
### 🛠️ Agentic Security Tools
|
||||
### Agentic Security Tools
|
||||
|
||||
- **🔌 Full HTTP Proxy** - Full request/response manipulation and analysis
|
||||
- **🌐 Browser Automation** - Multi-tab browser for testing of XSS, CSRF, auth flows
|
||||
- **💻 Terminal Environments** - Interactive shells for command execution and testing
|
||||
- **🐍 Python Runtime** - Custom exploit development and validation
|
||||
- **🔍 Reconnaissance** - Automated OSINT and attack surface mapping
|
||||
- **📁 Code Analysis** - Static and dynamic analysis capabilities
|
||||
- **📝 Knowledge Management** - Structured findings and attack documentation
|
||||
Strix agents come equipped with a comprehensive security testing toolkit:
|
||||
|
||||
### 🎯 Comprehensive Vulnerability Detection
|
||||
- **Full HTTP Proxy** - Full request/response manipulation and analysis
|
||||
- **Browser Automation** - Multi-tab browser for testing of XSS, CSRF, auth flows
|
||||
- **Terminal Environments** - Interactive shells for command execution and testing
|
||||
- **Python Runtime** - Custom exploit development and validation
|
||||
- **Reconnaissance** - Automated OSINT and attack surface mapping
|
||||
- **Code Analysis** - Static and dynamic analysis capabilities
|
||||
- **Knowledge Management** - Structured findings and attack documentation
|
||||
|
||||
### Comprehensive Vulnerability Detection
|
||||
|
||||
Strix can identify and validate a wide range of security vulnerabilities:
|
||||
|
||||
- **Access Control** - IDOR, privilege escalation, auth bypass
|
||||
- **Injection Attacks** - SQL, NoSQL, command injection
|
||||
@@ -66,82 +124,127 @@ strix --target ./app-directory
|
||||
- **Authentication** - JWT vulnerabilities, session management
|
||||
- **Infrastructure** - Misconfigurations, exposed services
|
||||
|
||||
### 🕸️ Graph of Agents
|
||||
### Graph of Agents
|
||||
|
||||
Advanced multi-agent orchestration for comprehensive security testing:
|
||||
|
||||
- **Distributed Workflows** - Specialized agents for different attacks and assets
|
||||
- **Scalable Testing** - Parallel execution for fast comprehensive coverage
|
||||
- **Dynamic Coordination** - Agents collaborate and share discoveries
|
||||
|
||||
---
|
||||
|
||||
## 💻 Usage Examples
|
||||
## Usage Examples
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```bash
|
||||
# Local codebase analysis
|
||||
# Scan a local codebase
|
||||
strix --target ./app-directory
|
||||
|
||||
# Repository security review
|
||||
# Security review of a GitHub repository
|
||||
strix --target https://github.com/org/repo
|
||||
|
||||
# Web application assessment
|
||||
# Black-box web application assessment
|
||||
strix --target https://your-app.com
|
||||
|
||||
# Focused testing
|
||||
strix --target api.your-app.com --instruction "Prioritize authentication and authorization testing"
|
||||
```
|
||||
|
||||
### ⚙️ Configuration
|
||||
### Advanced Testing Scenarios
|
||||
|
||||
```bash
|
||||
# Required
|
||||
export STRIX_LLM="anthropic/claude-opus-4-1-20250805"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
# Grey-box authenticated testing
|
||||
strix --target https://your-app.com --instruction "Perform authenticated testing using credentials: user:pass"
|
||||
|
||||
# Recommended
|
||||
export PERPLEXITY_API_KEY="your-api-key"
|
||||
# Multi-target testing (source code + deployed app)
|
||||
strix -t https://github.com/org/app -t https://your-app.com
|
||||
|
||||
# Focused testing with custom instructions
|
||||
strix --target api.your-app.com --instruction "Focus on business logic flaws and IDOR vulnerabilities"
|
||||
|
||||
# Provide detailed instructions through file (e.g., rules of engagement, scope, exclusions)
|
||||
strix --target api.your-app.com --instruction-file ./instruction.md
|
||||
```
|
||||
|
||||
[📚 View supported AI models](https://docs.litellm.ai/docs/providers)
|
||||
### Headless Mode
|
||||
|
||||
## 🏆 Enterprise Platform
|
||||
Run Strix programmatically without interactive UI using the `-n/--non-interactive` flag—perfect for servers and automated jobs. The CLI prints real-time vulnerability findings, and the final report before exiting. Exits with non-zero code when vulnerabilities are found.
|
||||
|
||||
Our managed platform provides:
|
||||
```bash
|
||||
strix -n --target https://your-app.com
|
||||
```
|
||||
|
||||
- **📈 Executive Dashboards**
|
||||
- **🧠 Custom Fine-Tuned Models**
|
||||
- **⚙️ CI/CD Integration**
|
||||
- **🔍 Large-Scale Scanning**
|
||||
- **🔌 Third-Party Integrations**
|
||||
- **🎯 Enterprise Support**
|
||||
### CI/CD (GitHub Actions)
|
||||
|
||||
[**Get Enterprise Demo →**](https://form.typeform.com/to/ljtvl6X0)
|
||||
Strix can be added to your pipeline to run a security test on pull requests with a lightweight GitHub Actions workflow:
|
||||
|
||||
## 🔒 Security Architecture
|
||||
```yaml
|
||||
name: strix-penetration-test
|
||||
|
||||
- **Container Isolation** - All testing in sandboxed Docker environments
|
||||
- **Local Processing** - Testing runs locally, no data sent to external services
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
security-scan:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install Strix
|
||||
run: curl -sSL https://strix.ai/install | bash
|
||||
|
||||
- name: Run Strix
|
||||
env:
|
||||
STRIX_LLM: ${{ secrets.STRIX_LLM }}
|
||||
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
|
||||
|
||||
run: strix -n -t ./ --scan-mode quick
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
|
||||
# Optional
|
||||
export LLM_API_BASE="your-api-base-url" # if using a local model, e.g. Ollama, LMStudio
|
||||
export PERPLEXITY_API_KEY="your-api-key" # for search capabilities
|
||||
export STRIX_REASONING_EFFORT="high" # control thinking effort (default: high, quick scan: medium)
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Strix is currently in Alpha. Expect rapid updates and improvements.
|
||||
> Strix automatically saves your configuration to `~/.strix/cli-config.json`, so you don't have to re-enter it on every run.
|
||||
|
||||
> [!WARNING]
|
||||
> Only test systems you own or have permission to test. You are responsible for using Strix ethically and legally.
|
||||
**Recommended models for best results:**
|
||||
|
||||
## 🌟 Support the Project
|
||||
- [Anthropic Claude Sonnet 4.6](https://claude.com/platform/api) — `anthropic/claude-sonnet-4-6`
|
||||
- [OpenAI GPT-5](https://openai.com/api/) — `openai/gpt-5`
|
||||
- [Google Gemini 3 Pro Preview](https://cloud.google.com/vertex-ai) — `vertex_ai/gemini-3-pro-preview`
|
||||
|
||||
See the [LLM Providers documentation](https://docs.strix.ai/llm-providers/overview) for all supported providers including Vertex AI, Bedrock, Azure, and local models.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation is available at **[docs.strix.ai](https://docs.strix.ai)** — including detailed guides for usage, CI/CD integrations, skills, and advanced configuration.
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome contributions of code, docs, and new skills - check out our [Contributing Guide](https://docs.strix.ai/contributing) to get started or open a [pull request](https://github.com/usestrix/strix/pulls)/[issue](https://github.com/usestrix/strix/issues).
|
||||
|
||||
## Join Our Community
|
||||
|
||||
Have questions? Found a bug? Want to contribute? **[Join our Discord!](https://discord.gg/strix-ai)**
|
||||
|
||||
## Support the Project
|
||||
|
||||
**Love Strix?** Give us a ⭐ on GitHub!
|
||||
|
||||
## 👥 Join Our Community
|
||||
## Acknowledgements
|
||||
|
||||
Have questions? Found a bug? Want to contribute? **[Join our Discord!](https://discord.gg/yduEyduBsp)**
|
||||
Strix builds on the incredible work of open-source projects like [LiteLLM](https://github.com/BerriAI/litellm), [Caido](https://github.com/caido/caido), [Nuclei](https://github.com/projectdiscovery/nuclei), [Playwright](https://github.com/microsoft/playwright), and [Textual](https://github.com/Textualize/textual). Huge thanks to their maintainers!
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
### About • Links
|
||||
|
||||
**[OmniSecure Inc.](https://omnisecure.ai)** • Applied AI Research Lab
|
||||
|
||||
[Discord Community](https://discord.gg/yduEyduBsp) • [Enterprise Solutions](https://form.typeform.com/to/ljtvl6X0) • [Report Issues](https://github.com/usestrix/strix/issues)
|
||||
> [!WARNING]
|
||||
> Only test apps you own or have permission to test. You are responsible for using Strix ethically and legally.
|
||||
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Benchmarks
|
||||
|
||||
We use security benchmarks to track Strix's capabilities and improvements over time. We plan to add more benchmarks, both existing ones and our own, to help the community evaluate and compare security agents.
|
||||
|
||||
|
||||
## Full Details
|
||||
|
||||
For the complete benchmark results, evaluation scripts, and run data, see the [usestrix/benchmarks](https://github.com/usestrix/benchmarks) repository.
|
||||
|
||||
> [!NOTE]
|
||||
> We are actively adding more benchmarks to our evaluation suite.
|
||||
|
||||
|
||||
## Results
|
||||
|
||||
| Benchmark | Challenges | Success Rate |
|
||||
|-----------|------------|--------------|
|
||||
| [XBEN](https://github.com/usestrix/benchmarks/tree/main/XBEN) | 104 | **96%** |
|
||||
|
||||
### XBEN
|
||||
|
||||
The [XBOW benchmark](https://github.com/usestrix/benchmarks/tree/main/XBEN) is a set of 104 web security challenges designed to evaluate autonomous penetration testing agents. Each challenge follows a CTF format where the agent must discover and exploit vulnerabilities to extract a hidden flag.
|
||||
|
||||
Strix `v0.4.0` achieved a **96% success rate** (100/104 challenges) in black-box mode.
|
||||
|
||||
```mermaid
|
||||
%%{init: {'theme': 'base', 'themeVariables': { 'pie1': '#3b82f6', 'pie2': '#1e3a5f', 'pieTitleTextColor': '#ffffff', 'pieSectionTextColor': '#ffffff', 'pieLegendTextColor': '#ffffff'}}}%%
|
||||
pie title Challenge Outcomes (104 Total)
|
||||
"Solved" : 100
|
||||
"Unsolved" : 4
|
||||
```
|
||||
|
||||
**Performance by Difficulty:**
|
||||
|
||||
| Difficulty | Solved | Success Rate |
|
||||
|------------|--------|--------------|
|
||||
| Level 1 (Easy) | 45/45 | 100% |
|
||||
| Level 2 (Medium) | 49/51 | 96% |
|
||||
| Level 3 (Hard) | 6/8 | 75% |
|
||||
|
||||
**Resource Usage:**
|
||||
- Average solve time: ~19 minutes
|
||||
- Total cost: ~$337 for 100 challenges
|
||||
@@ -9,7 +9,8 @@ RUN apt-get update && \
|
||||
|
||||
RUN useradd -m -s /bin/bash pentester && \
|
||||
usermod -aG sudo pentester && \
|
||||
echo "pentester ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
||||
echo "pentester ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
|
||||
touch /home/pentester/.hushlogin
|
||||
|
||||
RUN mkdir -p /home/pentester/configs \
|
||||
/home/pentester/wordlists \
|
||||
@@ -38,11 +39,13 @@ RUN apt-get update && \
|
||||
nodejs npm pipx \
|
||||
libcap2-bin \
|
||||
gdb \
|
||||
tmux \
|
||||
libnss3 libnspr4 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libatspi2.0-0 \
|
||||
libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon0 libpango-1.0-0 libcairo2 libasound2 \
|
||||
libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon0 libpango-1.0-0 libcairo2 libasound2t64 \
|
||||
fonts-unifont fonts-noto-color-emoji fonts-freefont-ttf fonts-dejavu-core ttf-bitstream-vera \
|
||||
libnss3-tools
|
||||
|
||||
|
||||
RUN setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip $(which nmap)
|
||||
|
||||
USER pentester
|
||||
@@ -152,12 +155,12 @@ ENV PYTHONPATH=/app
|
||||
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
||||
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
RUN mkdir -p /shared_workspace /workspace && chown -R pentester:pentester /shared_workspace /workspace /app
|
||||
RUN mkdir -p /workspace && chown -R pentester:pentester /workspace /app
|
||||
|
||||
COPY pyproject.toml poetry.lock ./
|
||||
|
||||
USER pentester
|
||||
RUN poetry install --no-root --without dev
|
||||
RUN poetry install --no-root --without dev --extras sandbox
|
||||
RUN poetry run playwright install chromium
|
||||
|
||||
RUN /app/venv/bin/pip install -r /home/pentester/tools/jwt_tool/requirements.txt && \
|
||||
@@ -166,9 +169,12 @@ RUN /app/venv/bin/pip install -r /home/pentester/tools/jwt_tool/requirements.txt
|
||||
RUN echo "# Sandbox Environment" > README.md
|
||||
|
||||
COPY strix/__init__.py strix/
|
||||
COPY strix/config/ /app/strix/config/
|
||||
COPY strix/utils/ /app/strix/utils/
|
||||
COPY strix/telemetry/ /app/strix/telemetry/
|
||||
COPY strix/runtime/tool_server.py strix/runtime/__init__.py strix/runtime/runtime.py /app/strix/runtime/
|
||||
|
||||
COPY strix/tools/__init__.py strix/tools/registry.py strix/tools/executor.py strix/tools/argument_parser.py /app/strix/tools/
|
||||
COPY strix/tools/__init__.py strix/tools/registry.py strix/tools/executor.py strix/tools/argument_parser.py strix/tools/context.py /app/strix/tools/
|
||||
|
||||
COPY strix/tools/browser/ /app/strix/tools/browser/
|
||||
COPY strix/tools/file_edit/ /app/strix/tools/file_edit/
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ -z "$CAIDO_PORT" ] || [ -z "$STRIX_TOOL_SERVER_PORT" ]; then
|
||||
echo "Error: CAIDO_PORT and STRIX_TOOL_SERVER_PORT must be set."
|
||||
exit 1
|
||||
CAIDO_PORT=48080
|
||||
CAIDO_LOG="/tmp/caido_startup.log"
|
||||
|
||||
if [ ! -f /app/certs/ca.p12 ]; then
|
||||
echo "ERROR: CA certificate file /app/certs/ca.p12 not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
caido-cli --listen 127.0.0.1:${CAIDO_PORT} \
|
||||
@@ -11,28 +14,62 @@ caido-cli --listen 127.0.0.1:${CAIDO_PORT} \
|
||||
--no-logging \
|
||||
--no-open \
|
||||
--import-ca-cert /app/certs/ca.p12 \
|
||||
--import-ca-cert-pass "" > /dev/null 2>&1 &
|
||||
--import-ca-cert-pass "" > "$CAIDO_LOG" 2>&1 &
|
||||
|
||||
CAIDO_PID=$!
|
||||
echo "Started Caido with PID $CAIDO_PID on port $CAIDO_PORT"
|
||||
|
||||
echo "Waiting for Caido API to be ready..."
|
||||
CAIDO_READY=false
|
||||
for i in {1..30}; do
|
||||
if curl -s -o /dev/null http://localhost:${CAIDO_PORT}/graphql; then
|
||||
echo "Caido API is ready."
|
||||
if ! kill -0 $CAIDO_PID 2>/dev/null; then
|
||||
echo "ERROR: Caido process died while waiting for API (iteration $i)."
|
||||
echo "=== Caido log ==="
|
||||
cat "$CAIDO_LOG" 2>/dev/null || echo "(no log available)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if curl -s -o /dev/null -w "%{http_code}" http://localhost:${CAIDO_PORT}/graphql/ | grep -qE "^(200|400)$"; then
|
||||
echo "Caido API is ready (attempt $i)."
|
||||
CAIDO_READY=true
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ "$CAIDO_READY" = false ]; then
|
||||
echo "ERROR: Caido API did not become ready within 30 seconds."
|
||||
echo "Caido process status: $(kill -0 $CAIDO_PID 2>&1 && echo 'running' || echo 'dead')"
|
||||
echo "=== Caido log ==="
|
||||
cat "$CAIDO_LOG" 2>/dev/null || echo "(no log available)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
echo "Fetching API token..."
|
||||
TOKEN=$(curl -s -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"query":"mutation LoginAsGuest { loginAsGuest { token { accessToken } } }"}' \
|
||||
http://localhost:${CAIDO_PORT}/graphql | jq -r '.data.loginAsGuest.token.accessToken')
|
||||
TOKEN=""
|
||||
for attempt in 1 2 3 4 5; do
|
||||
RESPONSE=$(curl -sL -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"query":"mutation LoginAsGuest { loginAsGuest { token { accessToken } } }"}' \
|
||||
http://localhost:${CAIDO_PORT}/graphql)
|
||||
|
||||
TOKEN=$(echo "$RESPONSE" | jq -r '.data.loginAsGuest.token.accessToken // empty')
|
||||
|
||||
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then
|
||||
echo "Successfully obtained API token (attempt $attempt)."
|
||||
break
|
||||
fi
|
||||
|
||||
echo "Token fetch attempt $attempt failed: $RESPONSE"
|
||||
sleep $((attempt * 2))
|
||||
done
|
||||
|
||||
if [ -z "$TOKEN" ] || [ "$TOKEN" == "null" ]; then
|
||||
echo "Failed to get API token from Caido."
|
||||
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"mutation { loginAsGuest { token { accessToken } } }"}' http://localhost:${CAIDO_PORT}/graphql
|
||||
echo "ERROR: Failed to get API token from Caido after 5 attempts."
|
||||
echo "=== Caido log ==="
|
||||
cat "$CAIDO_LOG" 2>/dev/null || echo "(no log available)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -40,7 +77,7 @@ export CAIDO_API_TOKEN=$TOKEN
|
||||
echo "Caido API token has been set."
|
||||
|
||||
echo "Creating a new Caido project..."
|
||||
CREATE_PROJECT_RESPONSE=$(curl -s -X POST \
|
||||
CREATE_PROJECT_RESPONSE=$(curl -sL -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{"query":"mutation CreateProject { createProject(input: {name: \"sandbox\", temporary: true}) { project { id } } }"}' \
|
||||
@@ -57,7 +94,7 @@ fi
|
||||
echo "Caido project created with ID: $PROJECT_ID"
|
||||
|
||||
echo "Selecting Caido project..."
|
||||
SELECT_RESPONSE=$(curl -s -X POST \
|
||||
SELECT_RESPONSE=$(curl -sL -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-d '{"query":"mutation SelectProject { selectProject(id: \"'$PROJECT_ID'\") { currentProject { project { id } } } }"}' \
|
||||
@@ -115,14 +152,35 @@ sudo -u pentester certutil -A -n "Testing Root CA" -t "C,," -i /app/certs/ca.crt
|
||||
echo "✅ CA added to browser trust store"
|
||||
|
||||
echo "Starting tool server..."
|
||||
cd /app && \
|
||||
STRIX_SANDBOX_MODE=true \
|
||||
STRIX_SANDBOX_TOKEN=${STRIX_SANDBOX_TOKEN} \
|
||||
CAIDO_API_TOKEN=${TOKEN} \
|
||||
poetry run uvicorn strix.runtime.tool_server:app --host 0.0.0.0 --port ${STRIX_TOOL_SERVER_PORT} &
|
||||
cd /app
|
||||
export PYTHONPATH=/app
|
||||
export STRIX_SANDBOX_MODE=true
|
||||
export POETRY_VIRTUALENVS_CREATE=false
|
||||
export TOOL_SERVER_TIMEOUT="${STRIX_SANDBOX_EXECUTION_TIMEOUT:-120}"
|
||||
TOOL_SERVER_LOG="/tmp/tool_server.log"
|
||||
|
||||
echo "✅ Tool server started in background"
|
||||
sudo -E -u pentester \
|
||||
poetry run python -m strix.runtime.tool_server \
|
||||
--token="$TOOL_SERVER_TOKEN" \
|
||||
--host=0.0.0.0 \
|
||||
--port="$TOOL_SERVER_PORT" \
|
||||
--timeout="$TOOL_SERVER_TIMEOUT" > "$TOOL_SERVER_LOG" 2>&1 &
|
||||
|
||||
for i in {1..10}; do
|
||||
if curl -s "http://127.0.0.1:$TOOL_SERVER_PORT/health" | grep -q '"status":"healthy"'; then
|
||||
echo "✅ Tool server healthy on port $TOOL_SERVER_PORT"
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 10 ]; then
|
||||
echo "ERROR: Tool server failed to become healthy"
|
||||
echo "=== Tool server log ==="
|
||||
cat "$TOOL_SERVER_LOG" 2>/dev/null || echo "(no log)"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "✅ Container ready"
|
||||
|
||||
cd /workspace
|
||||
|
||||
exec "$@"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Strix Documentation
|
||||
|
||||
Documentation source files for Strix, powered by [Mintlify](https://mintlify.com).
|
||||
|
||||
## Local Preview
|
||||
|
||||
```bash
|
||||
npm i -g mintlify
|
||||
cd docs && mintlify dev
|
||||
```
|
||||
@@ -0,0 +1,109 @@
|
||||
---
|
||||
title: "Configuration"
|
||||
description: "Environment variables for Strix"
|
||||
---
|
||||
|
||||
Configure Strix using environment variables or a config file.
|
||||
|
||||
## LLM Configuration
|
||||
|
||||
<ParamField path="STRIX_LLM" type="string" required>
|
||||
Model name in LiteLLM format (e.g., `anthropic/claude-sonnet-4-6`, `openai/gpt-5`).
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="LLM_API_KEY" type="string">
|
||||
API key for your LLM provider. Not required for local models or cloud provider auth (Vertex AI, AWS Bedrock).
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="LLM_API_BASE" type="string">
|
||||
Custom API base URL. Also accepts `OPENAI_API_BASE`, `LITELLM_BASE_URL`, or `OLLAMA_API_BASE`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="LLM_TIMEOUT" default="300" type="integer">
|
||||
Request timeout in seconds for LLM calls.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_LLM_MAX_RETRIES" default="5" type="integer">
|
||||
Maximum number of retries for LLM API calls on transient failures.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_REASONING_EFFORT" default="high" type="string">
|
||||
Control thinking effort for reasoning models. Valid values: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`. Defaults to `medium` for quick scan mode.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_MEMORY_COMPRESSOR_TIMEOUT" default="30" type="integer">
|
||||
Timeout in seconds for memory compression operations (context summarization).
|
||||
</ParamField>
|
||||
|
||||
## Optional Features
|
||||
|
||||
<ParamField path="PERPLEXITY_API_KEY" type="string">
|
||||
API key for Perplexity AI. Enables real-time web search during scans for OSINT and vulnerability research.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_DISABLE_BROWSER" default="false" type="boolean">
|
||||
Disable browser automation tools.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_TELEMETRY" default="1" type="string">
|
||||
Enable/disable anonymous telemetry. Set to `0`, `false`, `no`, or `off` to disable.
|
||||
</ParamField>
|
||||
|
||||
## Docker Configuration
|
||||
|
||||
<ParamField path="STRIX_IMAGE" default="ghcr.io/usestrix/strix-sandbox:0.1.11" type="string">
|
||||
Docker image to use for the sandbox container.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="DOCKER_HOST" type="string">
|
||||
Docker daemon socket path. Use for remote Docker hosts or custom configurations.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_RUNTIME_BACKEND" default="docker" type="string">
|
||||
Runtime backend for the sandbox environment.
|
||||
</ParamField>
|
||||
|
||||
## Sandbox Configuration
|
||||
|
||||
<ParamField path="STRIX_SANDBOX_EXECUTION_TIMEOUT" default="120" type="integer">
|
||||
Maximum execution time in seconds for sandbox operations.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_SANDBOX_CONNECT_TIMEOUT" default="10" type="integer">
|
||||
Timeout in seconds for connecting to the sandbox container.
|
||||
</ParamField>
|
||||
|
||||
## Config File
|
||||
|
||||
Strix stores configuration in `~/.strix/cli-config.json`. You can also specify a custom config file:
|
||||
|
||||
```bash
|
||||
strix --target ./app --config /path/to/config.json
|
||||
```
|
||||
|
||||
**Config file format:**
|
||||
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"STRIX_LLM": "anthropic/claude-sonnet-4-6",
|
||||
"LLM_API_KEY": "sk-...",
|
||||
"STRIX_REASONING_EFFORT": "high"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Example Setup
|
||||
|
||||
```bash
|
||||
# Required
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="sk-..."
|
||||
|
||||
# Optional: Enable web search
|
||||
export PERPLEXITY_API_KEY="pplx-..."
|
||||
|
||||
# Optional: Custom timeouts
|
||||
export LLM_TIMEOUT="600"
|
||||
export STRIX_SANDBOX_EXECUTION_TIMEOUT="300"
|
||||
```
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
title: "Skills"
|
||||
description: "Specialized knowledge packages that enhance agent capabilities"
|
||||
---
|
||||
|
||||
Skills are structured knowledge packages that give Strix agents deep expertise in specific vulnerability types, technologies, and testing methodologies.
|
||||
|
||||
## The Idea
|
||||
|
||||
LLMs have broad but shallow security knowledge. They know _about_ SQL injection, but lack the nuanced techniques that experienced pentesters use—parser quirks, bypass methods, validation tricks, and chain attacks.
|
||||
|
||||
Skills inject this deep, specialized knowledge directly into the agent's context, transforming it from a generalist into a specialist for the task at hand.
|
||||
|
||||
## How They Work
|
||||
|
||||
When Strix spawns an agent for a specific task, it selects up to 5 relevant skills based on the context:
|
||||
|
||||
```python
|
||||
# Agent created for JWT testing automatically loads relevant skills
|
||||
create_agent(
|
||||
task="Test authentication mechanisms",
|
||||
skills=["authentication_jwt", "business_logic"]
|
||||
)
|
||||
```
|
||||
|
||||
The skills are injected into the agent's system prompt, giving it access to:
|
||||
|
||||
- **Advanced techniques** — Non-obvious methods beyond standard testing
|
||||
- **Working payloads** — Practical examples with variations
|
||||
- **Validation methods** — How to confirm findings and avoid false positives
|
||||
|
||||
## Skill Categories
|
||||
|
||||
### Vulnerabilities
|
||||
|
||||
Core vulnerability classes with deep exploitation techniques.
|
||||
|
||||
| Skill | Coverage |
|
||||
| ------------------------------------- | ------------------------------------------------------ |
|
||||
| `authentication_jwt` | JWT attacks, algorithm confusion, claim tampering |
|
||||
| `idor` | Object reference attacks, horizontal/vertical access |
|
||||
| `sql_injection` | SQL injection variants, WAF bypasses, blind techniques |
|
||||
| `xss` | XSS types, filter bypasses, DOM exploitation |
|
||||
| `ssrf` | Server-side request forgery, protocol handlers |
|
||||
| `csrf` | Cross-site request forgery, token bypasses |
|
||||
| `xxe` | XML external entities, OOB exfiltration |
|
||||
| `rce` | Remote code execution vectors |
|
||||
| `business_logic` | Logic flaws, state manipulation, race conditions |
|
||||
| `race_conditions` | TOCTOU, parallel request attacks |
|
||||
| `path_traversal_lfi_rfi` | File inclusion, path traversal |
|
||||
| `open_redirect` | Redirect bypasses, URL parsing tricks |
|
||||
| `mass_assignment` | Attribute injection, hidden parameter pollution |
|
||||
| `insecure_file_uploads` | Upload bypasses, extension tricks |
|
||||
| `information_disclosure` | Data leakage, error-based enumeration |
|
||||
| `subdomain_takeover` | Dangling DNS, cloud resource claims |
|
||||
| `broken_function_level_authorization` | Privilege escalation, role bypasses |
|
||||
|
||||
### Frameworks
|
||||
|
||||
Framework-specific testing patterns.
|
||||
|
||||
| Skill | Coverage |
|
||||
| --------- | -------------------------------------------- |
|
||||
| `fastapi` | FastAPI security patterns, Pydantic bypasses |
|
||||
| `nextjs` | Next.js SSR/SSG issues, API route security |
|
||||
|
||||
### Technologies
|
||||
|
||||
Third-party service and platform security.
|
||||
|
||||
| Skill | Coverage |
|
||||
| -------------------- | ---------------------------------- |
|
||||
| `supabase` | Supabase RLS bypasses, auth issues |
|
||||
| `firebase_firestore` | Firestore rules, Firebase auth |
|
||||
|
||||
### Protocols
|
||||
|
||||
Protocol-specific testing techniques.
|
||||
|
||||
| Skill | Coverage |
|
||||
| --------- | ------------------------------------------------ |
|
||||
| `graphql` | GraphQL introspection, batching, resolver issues |
|
||||
|
||||
## Skill Structure
|
||||
|
||||
Each skill is a Markdown file with YAML frontmatter for metadata:
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: skill_name
|
||||
description: Brief description of the skill's coverage
|
||||
---
|
||||
|
||||
# Skill Title
|
||||
|
||||
Key insight about this vulnerability or technique.
|
||||
|
||||
## Attack Surface
|
||||
What this skill covers and where to look.
|
||||
|
||||
## Methodology
|
||||
Step-by-step testing approach.
|
||||
|
||||
## Techniques
|
||||
How to discover and exploit the vulnerability.
|
||||
|
||||
## Bypass Methods
|
||||
How to bypass common protections.
|
||||
|
||||
## Validation
|
||||
How to confirm findings and avoid false positives.
|
||||
```
|
||||
|
||||
## Contributing Skills
|
||||
|
||||
Community contributions are welcome. Create a `.md` file in the appropriate category with YAML frontmatter (`name` and `description` fields). Good skills include:
|
||||
|
||||
1. **Real-world techniques** — Methods that work in practice
|
||||
2. **Practical payloads** — Working examples with variations
|
||||
3. **Validation steps** — How to confirm without false positives
|
||||
4. **Context awareness** — Version/environment-specific behavior
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
title: "Introduction"
|
||||
description: "Managed security testing without local setup"
|
||||
---
|
||||
|
||||
Skip the setup. Run Strix in the cloud at [app.strix.ai](https://app.strix.ai).
|
||||
|
||||
## Features
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="No Setup Required" icon="cloud">
|
||||
No Docker, API keys, or local installation needed.
|
||||
</Card>
|
||||
<Card title="Full Reports" icon="file-lines">
|
||||
Detailed findings with remediation guidance.
|
||||
</Card>
|
||||
<Card title="Team Dashboards" icon="users">
|
||||
Track vulnerabilities and fixes over time.
|
||||
</Card>
|
||||
<Card title="GitHub Integration" icon="github">
|
||||
Automatic scans on pull requests.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## What You Get
|
||||
|
||||
- **Penetration test reports** — Validated findings with PoCs
|
||||
- **Shareable dashboards** — Collaborate with your team
|
||||
- **CI/CD integration** — Block risky changes automatically
|
||||
- **Continuous monitoring** — Catch new vulnerabilities quickly
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Sign up at [app.strix.ai](https://app.strix.ai)
|
||||
2. Connect your repository or enter a target URL
|
||||
3. Launch your first scan
|
||||
|
||||
<Card title="Try Strix Cloud" icon="rocket" href="https://app.strix.ai">
|
||||
Run your first pentest in minutes.
|
||||
</Card>
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
title: "Contributing"
|
||||
description: "Contribute to Strix development"
|
||||
---
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.12+
|
||||
- Docker (running)
|
||||
- Poetry
|
||||
- Git
|
||||
|
||||
### Local Development
|
||||
|
||||
<Steps>
|
||||
<Step title="Clone the repository">
|
||||
```bash
|
||||
git clone https://github.com/usestrix/strix.git
|
||||
cd strix
|
||||
```
|
||||
</Step>
|
||||
<Step title="Install dependencies">
|
||||
```bash
|
||||
make setup-dev
|
||||
|
||||
# or manually:
|
||||
poetry install --with=dev
|
||||
poetry run pre-commit install
|
||||
```
|
||||
</Step>
|
||||
<Step title="Configure LLM">
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
```
|
||||
</Step>
|
||||
<Step title="Run Strix">
|
||||
```bash
|
||||
poetry run strix --target https://example.com
|
||||
```
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
## Contributing Skills
|
||||
|
||||
Skills are specialized knowledge packages that enhance agent capabilities. They live in `strix/skills/`
|
||||
|
||||
### Creating a Skill
|
||||
|
||||
1. Choose the right category
|
||||
2. Create a `.md` file with YAML frontmatter (`name` and `description` fields)
|
||||
3. Include practical examples—working payloads, commands, test cases
|
||||
4. Provide validation methods to confirm findings
|
||||
5. Submit via PR
|
||||
|
||||
## Contributing Code
|
||||
|
||||
### Pull Request Process
|
||||
|
||||
1. **Create an issue first** — Describe the problem or feature
|
||||
2. **Fork and branch** — Work from `main`
|
||||
3. **Make changes** — Follow existing code style
|
||||
4. **Write tests** — Ensure coverage for new features
|
||||
5. **Run checks** — `make check-all` should pass
|
||||
6. **Submit PR** — Link to issue and provide context
|
||||
|
||||
### Code Style
|
||||
|
||||
- PEP 8 with 100-character line limit
|
||||
- Type hints for all functions
|
||||
- Docstrings for public methods
|
||||
- Small, focused functions
|
||||
- Meaningful variable names
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
Include:
|
||||
|
||||
- Python version and OS
|
||||
- Strix version (`strix --version`)
|
||||
- LLM being used
|
||||
- Full error traceback
|
||||
- Steps to reproduce
|
||||
|
||||
## Community
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Discord" icon="discord" href="https://discord.gg/strix-ai">
|
||||
Join the community for help and discussion.
|
||||
</Card>
|
||||
<Card title="GitHub Issues" icon="github" href="https://github.com/usestrix/strix/issues">
|
||||
Report bugs and request features.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"$schema": "https://mintlify.com/docs.json",
|
||||
"theme": "maple",
|
||||
"name": "Strix",
|
||||
"colors": {
|
||||
"primary": "#000000",
|
||||
"light": "#ffffff",
|
||||
"dark": "#000000"
|
||||
},
|
||||
"favicon": "/images/favicon-48.ico",
|
||||
"navigation": {
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "Documentation",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Getting Started",
|
||||
"pages": [
|
||||
"index",
|
||||
"quickstart"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Usage",
|
||||
"pages": [
|
||||
"usage/cli",
|
||||
"usage/scan-modes",
|
||||
"usage/instructions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "LLM Providers",
|
||||
"pages": [
|
||||
"llm-providers/overview",
|
||||
"llm-providers/models",
|
||||
"llm-providers/openai",
|
||||
"llm-providers/anthropic",
|
||||
"llm-providers/openrouter",
|
||||
"llm-providers/vertex",
|
||||
"llm-providers/bedrock",
|
||||
"llm-providers/azure",
|
||||
"llm-providers/local"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Integrations",
|
||||
"pages": [
|
||||
"integrations/github-actions",
|
||||
"integrations/ci-cd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Tools",
|
||||
"pages": [
|
||||
"tools/overview",
|
||||
"tools/browser",
|
||||
"tools/proxy",
|
||||
"tools/terminal",
|
||||
"tools/sandbox"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "Advanced",
|
||||
"pages": [
|
||||
"advanced/configuration",
|
||||
"advanced/skills",
|
||||
"contributing"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tab": "Cloud",
|
||||
"groups": [
|
||||
{
|
||||
"group": "Strix Cloud",
|
||||
"pages": [
|
||||
"cloud/overview"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"global": {
|
||||
"anchors": [
|
||||
{
|
||||
"anchor": "GitHub",
|
||||
"href": "https://github.com/usestrix/strix",
|
||||
"icon": "github"
|
||||
},
|
||||
{
|
||||
"anchor": "Discord",
|
||||
"href": "https://discord.gg/strix-ai",
|
||||
"icon": "discord"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"navbar": {
|
||||
"links": [],
|
||||
"primary": {
|
||||
"type": "button",
|
||||
"label": "Try Strix Cloud",
|
||||
"href": "https://app.strix.ai"
|
||||
}
|
||||
},
|
||||
"footer": {
|
||||
"socials": {
|
||||
"x": "https://x.com/strix_ai",
|
||||
"github": "https://github.com/usestrix",
|
||||
"discord": "https://discord.gg/strix-ai"
|
||||
}
|
||||
},
|
||||
"fonts": {
|
||||
"family": "Geist",
|
||||
"heading": {
|
||||
"family": "Geist"
|
||||
},
|
||||
"body": {
|
||||
"family": "Geist"
|
||||
}
|
||||
},
|
||||
"appearance": {
|
||||
"default": "dark"
|
||||
},
|
||||
"description": "Open-source AI Hackers to secure your Apps",
|
||||
"background": {
|
||||
"decoration": "grid"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
@@ -0,0 +1,101 @@
|
||||
---
|
||||
title: "Introduction"
|
||||
description: "Open-source AI hackers to secure your apps"
|
||||
---
|
||||
|
||||
Strix are autonomous AI agents that act like real hackers—they run your code dynamically, find vulnerabilities, and validate them with proof-of-concepts. Built for developers and security teams who need fast, accurate security testing without the overhead of manual pentesting or the false positives of static analysis tools.
|
||||
|
||||
<Frame>
|
||||
<img src="/images/screenshot.png" alt="Strix Demo" />
|
||||
</Frame>
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Quick Start" icon="rocket" href="/quickstart">
|
||||
Install and run your first scan in minutes.
|
||||
</Card>
|
||||
<Card title="CLI Reference" icon="terminal" href="/usage/cli">
|
||||
Learn all command-line options.
|
||||
</Card>
|
||||
<Card title="Tools" icon="wrench" href="/tools/overview">
|
||||
Explore the security testing toolkit.
|
||||
</Card>
|
||||
<Card title="GitHub Actions" icon="github" href="/integrations/github-actions">
|
||||
Integrate into your CI/CD pipeline.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Use Cases
|
||||
|
||||
- **Application Security Testing** — Detect and validate critical vulnerabilities in your applications
|
||||
- **Rapid Penetration Testing** — Get penetration tests done in hours, not weeks
|
||||
- **Bug Bounty Automation** — Automate research and generate PoCs for faster reporting
|
||||
- **CI/CD Integration** — Block vulnerabilities before they reach production
|
||||
|
||||
## Key Capabilities
|
||||
|
||||
- **Full hacker toolkit** — Browser automation, HTTP proxy, terminal, Python runtime
|
||||
- **Real validation** — PoCs, not false positives
|
||||
- **Multi-agent orchestration** — Specialized agents collaborate on complex targets
|
||||
- **Developer-first CLI** — Interactive TUI or headless mode for automation
|
||||
|
||||
## Security Tools
|
||||
|
||||
Strix agents come equipped with a comprehensive toolkit:
|
||||
|
||||
| Tool | Purpose |
|
||||
|------|---------|
|
||||
| HTTP Proxy | Full request/response manipulation and analysis |
|
||||
| Browser Automation | Multi-tab browser for XSS, CSRF, auth flow testing |
|
||||
| Terminal | Interactive shells for command execution |
|
||||
| Python Runtime | Custom exploit development and validation |
|
||||
| Reconnaissance | Automated OSINT and attack surface mapping |
|
||||
| Code Analysis | Static and dynamic analysis capabilities |
|
||||
|
||||
## Vulnerability Coverage
|
||||
|
||||
| Category | Examples |
|
||||
|----------|----------|
|
||||
| Access Control | IDOR, privilege escalation, auth bypass |
|
||||
| Injection | SQL, NoSQL, command injection |
|
||||
| Server-Side | SSRF, XXE, deserialization |
|
||||
| Client-Side | XSS, prototype pollution, DOM vulnerabilities |
|
||||
| Business Logic | Race conditions, workflow manipulation |
|
||||
| Authentication | JWT vulnerabilities, session management |
|
||||
| Infrastructure | Misconfigurations, exposed services |
|
||||
|
||||
## Multi-Agent Architecture
|
||||
|
||||
Strix uses a graph of specialized agents for comprehensive security testing:
|
||||
|
||||
- **Distributed Workflows** — Specialized agents for different attacks and assets
|
||||
- **Scalable Testing** — Parallel execution for fast comprehensive coverage
|
||||
- **Dynamic Coordination** — Agents collaborate and share discoveries
|
||||
|
||||
## Quick Example
|
||||
|
||||
```bash
|
||||
# Install
|
||||
curl -sSL https://strix.ai/install | bash
|
||||
|
||||
# Configure
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
|
||||
# Scan
|
||||
strix --target ./your-app
|
||||
```
|
||||
|
||||
## Community
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Discord" icon="discord" href="https://discord.gg/strix-ai">
|
||||
Join the community for help and discussion.
|
||||
</Card>
|
||||
<Card title="GitHub" icon="github" href="https://github.com/usestrix/strix">
|
||||
Star the repo and contribute.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
<Warning>
|
||||
Only test applications you own or have explicit permission to test.
|
||||
</Warning>
|
||||
@@ -0,0 +1,80 @@
|
||||
---
|
||||
title: "CI/CD Integration"
|
||||
description: "Run Strix in any CI/CD pipeline"
|
||||
---
|
||||
|
||||
Strix runs in headless mode for automated pipelines.
|
||||
|
||||
## Headless Mode
|
||||
|
||||
Use the `-n` or `--non-interactive` flag:
|
||||
|
||||
```bash
|
||||
strix -n --target ./app --scan-mode quick
|
||||
```
|
||||
|
||||
## Exit Codes
|
||||
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| 0 | No vulnerabilities found |
|
||||
| 1 | Execution error |
|
||||
| 2 | Vulnerabilities found |
|
||||
|
||||
## GitLab CI
|
||||
|
||||
```yaml .gitlab-ci.yml
|
||||
security-scan:
|
||||
image: docker:latest
|
||||
services:
|
||||
- docker:dind
|
||||
variables:
|
||||
STRIX_LLM: $STRIX_LLM
|
||||
LLM_API_KEY: $LLM_API_KEY
|
||||
script:
|
||||
- curl -sSL https://strix.ai/install | bash
|
||||
- strix -n -t ./ --scan-mode quick
|
||||
```
|
||||
|
||||
## Jenkins
|
||||
|
||||
```groovy Jenkinsfile
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
STRIX_LLM = credentials('strix-llm')
|
||||
LLM_API_KEY = credentials('llm-api-key')
|
||||
}
|
||||
stages {
|
||||
stage('Security Scan') {
|
||||
steps {
|
||||
sh 'curl -sSL https://strix.ai/install | bash'
|
||||
sh 'strix -n -t ./ --scan-mode quick'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## CircleCI
|
||||
|
||||
```yaml .circleci/config.yml
|
||||
version: 2.1
|
||||
jobs:
|
||||
security-scan:
|
||||
docker:
|
||||
- image: cimg/base:current
|
||||
steps:
|
||||
- checkout
|
||||
- setup_remote_docker
|
||||
- run:
|
||||
name: Install Strix
|
||||
command: curl -sSL https://strix.ai/install | bash
|
||||
- run:
|
||||
name: Run Scan
|
||||
command: strix -n -t ./ --scan-mode quick
|
||||
```
|
||||
|
||||
<Note>
|
||||
All CI platforms require Docker access. Ensure your runner has Docker available.
|
||||
</Note>
|
||||
@@ -0,0 +1,60 @@
|
||||
---
|
||||
title: "GitHub Actions"
|
||||
description: "Run Strix security scans on every pull request"
|
||||
---
|
||||
|
||||
Integrate Strix into your GitHub workflow to catch vulnerabilities before they reach production.
|
||||
|
||||
## Basic Workflow
|
||||
|
||||
```yaml .github/workflows/security.yml
|
||||
name: Security Scan
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
strix-scan:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Strix
|
||||
run: curl -sSL https://strix.ai/install | bash
|
||||
|
||||
- name: Run Security Scan
|
||||
env:
|
||||
STRIX_LLM: ${{ secrets.STRIX_LLM }}
|
||||
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
|
||||
run: strix -n -t ./ --scan-mode quick
|
||||
```
|
||||
|
||||
## Required Secrets
|
||||
|
||||
Add these secrets to your repository:
|
||||
|
||||
| Secret | Description |
|
||||
|--------|-------------|
|
||||
| `STRIX_LLM` | Model name (e.g., `anthropic/claude-sonnet-4-6`) |
|
||||
| `LLM_API_KEY` | API key for your LLM provider |
|
||||
|
||||
## Exit Codes
|
||||
|
||||
The workflow fails when vulnerabilities are found:
|
||||
|
||||
| Code | Result |
|
||||
|------|--------|
|
||||
| 0 | Pass — No vulnerabilities |
|
||||
| 2 | Fail — Vulnerabilities found |
|
||||
|
||||
## Scan Modes for CI
|
||||
|
||||
| Mode | Duration | Use Case |
|
||||
|------|----------|----------|
|
||||
| `quick` | Minutes | Every PR |
|
||||
| `standard` | ~30 min | Nightly builds |
|
||||
| `deep` | 1-4 hours | Release candidates |
|
||||
|
||||
<Tip>
|
||||
Use `quick` mode for PRs to keep feedback fast. Schedule `deep` scans nightly.
|
||||
</Tip>
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: "Anthropic"
|
||||
description: "Configure Strix with Claude models"
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="sk-ant-..."
|
||||
```
|
||||
|
||||
## Available Models
|
||||
|
||||
| Model | Description |
|
||||
|-------|-------------|
|
||||
| `anthropic/claude-sonnet-4-6` | Best balance of intelligence and speed (recommended) |
|
||||
| `anthropic/claude-opus-4-6` | Maximum capability for deep analysis |
|
||||
|
||||
## Get API Key
|
||||
|
||||
1. Go to [console.anthropic.com](https://console.anthropic.com)
|
||||
2. Navigate to API Keys
|
||||
3. Create a new key
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: "Azure OpenAI"
|
||||
description: "Configure Strix with OpenAI models via Azure"
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="azure/your-gpt5-deployment"
|
||||
export AZURE_API_KEY="your-azure-api-key"
|
||||
export AZURE_API_BASE="https://your-resource.openai.azure.com"
|
||||
export AZURE_API_VERSION="2025-11-01-preview"
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| `STRIX_LLM` | `azure/<your-deployment-name>` |
|
||||
| `AZURE_API_KEY` | Your Azure OpenAI API key |
|
||||
| `AZURE_API_BASE` | Your Azure OpenAI endpoint URL |
|
||||
| `AZURE_API_VERSION` | API version (e.g., `2025-11-01-preview`) |
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="azure/gpt-5-deployment"
|
||||
export AZURE_API_KEY="abc123..."
|
||||
export AZURE_API_BASE="https://mycompany.openai.azure.com"
|
||||
export AZURE_API_VERSION="2025-11-01-preview"
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Create an Azure OpenAI resource
|
||||
2. Deploy a model (e.g., GPT-5)
|
||||
3. Get the endpoint URL and API key from the Azure portal
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: "AWS Bedrock"
|
||||
description: "Configure Strix with models via AWS Bedrock"
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="bedrock/anthropic.claude-4-5-sonnet-20251022-v1:0"
|
||||
```
|
||||
|
||||
No API key required—uses AWS credentials from environment.
|
||||
|
||||
## Authentication
|
||||
|
||||
### Option 1: AWS CLI Profile
|
||||
|
||||
```bash
|
||||
export AWS_PROFILE="your-profile"
|
||||
export AWS_REGION="us-east-1"
|
||||
```
|
||||
|
||||
### Option 2: Access Keys
|
||||
|
||||
```bash
|
||||
export AWS_ACCESS_KEY_ID="AKIA..."
|
||||
export AWS_SECRET_ACCESS_KEY="..."
|
||||
export AWS_REGION="us-east-1"
|
||||
```
|
||||
|
||||
### Option 3: IAM Role (EC2/ECS)
|
||||
|
||||
Automatically uses instance role credentials.
|
||||
|
||||
## Available Models
|
||||
|
||||
| Model | Description |
|
||||
|-------|-------------|
|
||||
| `bedrock/anthropic.claude-4-5-sonnet-20251022-v1:0` | Claude 4.5 Sonnet |
|
||||
| `bedrock/anthropic.claude-4-5-opus-20251022-v1:0` | Claude 4.5 Opus |
|
||||
| `bedrock/anthropic.claude-4-5-haiku-20251022-v1:0` | Claude 4.5 Haiku |
|
||||
| `bedrock/amazon.titan-text-premier-v2:0` | Amazon Titan Premier v2 |
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Enable model access in the AWS Bedrock console
|
||||
2. Ensure your IAM role/user has `bedrock:InvokeModel` permission
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: "Local Models"
|
||||
description: "Run Strix with self-hosted LLMs for privacy and air-gapped testing"
|
||||
---
|
||||
|
||||
Running Strix with local models allows for completely offline, privacy-first security assessments. Data never leaves your machine, making this ideal for sensitive internal networks or air-gapped environments.
|
||||
|
||||
## Privacy vs Performance
|
||||
|
||||
| Feature | Local Models | Cloud Models (GPT-5/Claude 4.5) |
|
||||
|---------|--------------|--------------------------------|
|
||||
| **Privacy** | 🔒 Data stays local | Data sent to provider |
|
||||
| **Cost** | Free (hardware only) | Pay-per-token |
|
||||
| **Reasoning** | Lower (struggles with agents) | State-of-the-art |
|
||||
| **Setup** | Complex (GPU required) | Instant |
|
||||
|
||||
<Warning>
|
||||
**Compatibility Note**: Strix relies on advanced agentic capabilities (tool use, multi-step planning, self-correction). Most local models, especially those under 70B parameters, struggle with these complex tasks.
|
||||
|
||||
For critical assessments, we strongly recommend using state-of-the-art cloud models like **Claude 4.5 Sonnet** or **GPT-5**. Use local models only when privacy is the absolute priority.
|
||||
</Warning>
|
||||
|
||||
## Ollama
|
||||
|
||||
[Ollama](https://ollama.ai) is the easiest way to run local models on macOS, Linux, and Windows.
|
||||
|
||||
### Setup
|
||||
|
||||
1. Install Ollama from [ollama.ai](https://ollama.ai)
|
||||
2. Pull a high-performance model:
|
||||
```bash
|
||||
ollama pull qwen3-vl
|
||||
```
|
||||
3. Configure Strix:
|
||||
```bash
|
||||
export STRIX_LLM="ollama/qwen3-vl"
|
||||
export LLM_API_BASE="http://localhost:11434"
|
||||
```
|
||||
|
||||
### Recommended Models
|
||||
|
||||
We recommend these models for the best balance of reasoning and tool use:
|
||||
|
||||
**Recommended models:**
|
||||
- **Qwen3 VL** (`ollama pull qwen3-vl`)
|
||||
- **DeepSeek V3.1** (`ollama pull deepseek-v3.1`)
|
||||
- **Devstral 2** (`ollama pull devstral-2`)
|
||||
|
||||
## LM Studio / OpenAI Compatible
|
||||
|
||||
If you use LM Studio, vLLM, or other runners:
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="openai/local-model"
|
||||
export LLM_API_BASE="http://localhost:1234/v1" # Adjust port as needed
|
||||
```
|
||||
@@ -0,0 +1,80 @@
|
||||
---
|
||||
title: "Strix Router"
|
||||
description: "Access top LLMs through a single API with high rate limits and zero data retention"
|
||||
---
|
||||
|
||||
Strix Router gives you access to the best LLMs through a single API key.
|
||||
|
||||
<Note>
|
||||
Strix Router is currently in **beta**. It's completely optional — Strix works with any [LiteLLM-compatible provider](/llm-providers/overview) using your own API keys, or with [local models](/llm-providers/local). Strix Router is just the setup we test and optimize for.
|
||||
</Note>
|
||||
|
||||
## Why Use Strix Router?
|
||||
|
||||
- **High rate limits** — No throttling during long-running scans
|
||||
- **Zero data retention** — Routes to providers with zero data retention policies enabled
|
||||
- **Failover & load balancing** — Automatic fallback across providers for reliability
|
||||
- **Simple setup** — One API key, one environment variable, no provider accounts needed
|
||||
- **No markup** — Same token pricing as the underlying providers, no extra fees
|
||||
- **$10 free credit** — Try it free on signup, no credit card required
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. Get your API key at [models.strix.ai](https://models.strix.ai)
|
||||
2. Set your environment:
|
||||
|
||||
```bash
|
||||
export LLM_API_KEY='your-strix-api-key'
|
||||
export STRIX_LLM='strix/claude-sonnet-4.6'
|
||||
```
|
||||
|
||||
3. Run a scan:
|
||||
|
||||
```bash
|
||||
strix --target ./your-app
|
||||
```
|
||||
|
||||
## Available Models
|
||||
|
||||
### Anthropic
|
||||
|
||||
| Model | ID |
|
||||
|-------|-----|
|
||||
| Claude Sonnet 4.6 | `strix/claude-sonnet-4.6` |
|
||||
| Claude Opus 4.6 | `strix/claude-opus-4.6` |
|
||||
|
||||
### OpenAI
|
||||
|
||||
| Model | ID |
|
||||
|-------|-----|
|
||||
| GPT-5.2 | `strix/gpt-5.2` |
|
||||
| GPT-5.1 | `strix/gpt-5.1` |
|
||||
| GPT-5 | `strix/gpt-5` |
|
||||
| GPT-5.2 Codex | `strix/gpt-5.2-codex` |
|
||||
| GPT-5.1 Codex Max | `strix/gpt-5.1-codex-max` |
|
||||
| GPT-5.1 Codex | `strix/gpt-5.1-codex` |
|
||||
| GPT-5 Codex | `strix/gpt-5-codex` |
|
||||
|
||||
### Google
|
||||
|
||||
| Model | ID |
|
||||
|-------|-----|
|
||||
| Gemini 3 Pro | `strix/gemini-3-pro-preview` |
|
||||
| Gemini 3 Flash | `strix/gemini-3-flash-preview` |
|
||||
|
||||
### Other
|
||||
|
||||
| Model | ID |
|
||||
|-------|-----|
|
||||
| GLM-5 | `strix/glm-5` |
|
||||
| GLM-4.7 | `strix/glm-4.7` |
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
<ParamField path="LLM_API_KEY" type="string" required>
|
||||
Your Strix API key from [models.strix.ai](https://models.strix.ai).
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="STRIX_LLM" type="string" required>
|
||||
Model ID from the tables above. Must be prefixed with `strix/`.
|
||||
</ParamField>
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: "OpenAI"
|
||||
description: "Configure Strix with OpenAI models"
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="openai/gpt-5"
|
||||
export LLM_API_KEY="sk-..."
|
||||
```
|
||||
|
||||
## Available Models
|
||||
|
||||
See [OpenAI Models Documentation](https://platform.openai.com/docs/models) for the full list of available models.
|
||||
|
||||
## Get API Key
|
||||
|
||||
1. Go to [platform.openai.com](https://platform.openai.com)
|
||||
2. Navigate to API Keys
|
||||
3. Create a new secret key
|
||||
|
||||
## Custom Base URL
|
||||
|
||||
For OpenAI-compatible APIs:
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="openai/gpt-5"
|
||||
export LLM_API_KEY="your-key"
|
||||
export LLM_API_BASE="https://your-proxy.com/v1"
|
||||
```
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: "OpenRouter"
|
||||
description: "Configure Strix with models via OpenRouter"
|
||||
---
|
||||
|
||||
[OpenRouter](https://openrouter.ai) provides access to 100+ models from multiple providers through a single API.
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="openrouter/openai/gpt-5"
|
||||
export LLM_API_KEY="sk-or-..."
|
||||
```
|
||||
|
||||
## Available Models
|
||||
|
||||
Access any model on OpenRouter using the format `openrouter/<provider>/<model>`:
|
||||
|
||||
| Model | Configuration |
|
||||
|-------|---------------|
|
||||
| GPT-5 | `openrouter/openai/gpt-5` |
|
||||
| Claude Sonnet 4.6 | `openrouter/anthropic/claude-sonnet-4.6` |
|
||||
| Gemini 3 Pro | `openrouter/google/gemini-3-pro-preview` |
|
||||
| GLM-4.7 | `openrouter/z-ai/glm-4.7` |
|
||||
|
||||
## Get API Key
|
||||
|
||||
1. Go to [openrouter.ai](https://openrouter.ai)
|
||||
2. Sign in and navigate to Keys
|
||||
3. Create a new API key
|
||||
|
||||
## Benefits
|
||||
|
||||
- **Single API** — Access models from OpenAI, Anthropic, Google, Meta, and more
|
||||
- **Fallback routing** — Automatic failover between providers
|
||||
- **Cost tracking** — Monitor usage across all models
|
||||
- **Higher rate limits** — OpenRouter handles provider limits for you
|
||||
@@ -0,0 +1,84 @@
|
||||
---
|
||||
title: "Overview"
|
||||
description: "Configure your AI model for Strix"
|
||||
---
|
||||
|
||||
Strix uses [LiteLLM](https://docs.litellm.ai/docs/providers) for model compatibility, supporting 100+ LLM providers.
|
||||
|
||||
## Strix Router (Recommended)
|
||||
|
||||
The fastest way to get started. [Strix Router](/llm-providers/models) gives you access to tested models with the highest rate limits and zero data retention.
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="strix/claude-sonnet-4.6"
|
||||
export LLM_API_KEY="your-strix-api-key"
|
||||
```
|
||||
|
||||
Get your API key at [models.strix.ai](https://models.strix.ai).
|
||||
|
||||
## Bring Your Own Key
|
||||
|
||||
You can also use any LiteLLM-compatible provider with your own API keys:
|
||||
|
||||
| Model | Provider | Configuration |
|
||||
| ----------------- | ------------- | -------------------------------- |
|
||||
| Claude Sonnet 4.6 | Anthropic | `anthropic/claude-sonnet-4-6` |
|
||||
| GPT-5 | OpenAI | `openai/gpt-5` |
|
||||
| Gemini 3 Pro | Google Vertex | `vertex_ai/gemini-3-pro-preview` |
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
```
|
||||
|
||||
## Local Models
|
||||
|
||||
Run models locally with [Ollama](https://ollama.com), [LM Studio](https://lmstudio.ai), or any OpenAI-compatible server:
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="ollama/llama4"
|
||||
export LLM_API_BASE="http://localhost:11434"
|
||||
```
|
||||
|
||||
See the [Local Models guide](/llm-providers/local) for setup instructions and recommended models.
|
||||
|
||||
## Provider Guides
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Strix Router" href="/llm-providers/models">
|
||||
Recommended models router with high rate limits.
|
||||
</Card>
|
||||
<Card title="OpenAI" href="/llm-providers/openai">
|
||||
GPT-5 and Codex models.
|
||||
</Card>
|
||||
<Card title="Anthropic" href="/llm-providers/anthropic">
|
||||
Claude Sonnet 4.6, Opus, and Haiku.
|
||||
</Card>
|
||||
<Card title="OpenRouter" href="/llm-providers/openrouter">
|
||||
Access 100+ models through a single API.
|
||||
</Card>
|
||||
<Card title="Google Vertex AI" href="/llm-providers/vertex">
|
||||
Gemini 3 models via Google Cloud.
|
||||
</Card>
|
||||
<Card title="AWS Bedrock" href="/llm-providers/bedrock">
|
||||
Claude and Titan models via AWS.
|
||||
</Card>
|
||||
<Card title="Azure OpenAI" href="/llm-providers/azure">
|
||||
GPT-5 via Azure.
|
||||
</Card>
|
||||
<Card title="Local Models" href="/llm-providers/local">
|
||||
Llama 4, Mistral, and self-hosted models.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Model Format
|
||||
|
||||
Use LiteLLM's `provider/model-name` format:
|
||||
|
||||
```
|
||||
anthropic/claude-sonnet-4-6
|
||||
openai/gpt-5
|
||||
vertex_ai/gemini-3-pro-preview
|
||||
bedrock/anthropic.claude-4-5-sonnet-20251022-v1:0
|
||||
ollama/llama4
|
||||
```
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: "Google Vertex AI"
|
||||
description: "Configure Strix with Gemini models via Google Cloud"
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
Vertex AI requires the Google Cloud dependency. Install Strix with the vertex extra:
|
||||
|
||||
```bash
|
||||
pipx install "strix-agent[vertex]"
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
export STRIX_LLM="vertex_ai/gemini-3-pro-preview"
|
||||
```
|
||||
|
||||
No API key required—uses Google Cloud Application Default Credentials.
|
||||
|
||||
## Authentication
|
||||
|
||||
### Option 1: gcloud CLI
|
||||
|
||||
```bash
|
||||
gcloud auth application-default login
|
||||
```
|
||||
|
||||
### Option 2: Service Account
|
||||
|
||||
```bash
|
||||
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
|
||||
```
|
||||
|
||||
## Available Models
|
||||
|
||||
| Model | Description |
|
||||
|-------|-------------|
|
||||
| `vertex_ai/gemini-3-pro-preview` | Best overall performance for security testing |
|
||||
| `vertex_ai/gemini-3-flash-preview` | Faster and cheaper |
|
||||
|
||||
## Project Configuration
|
||||
|
||||
```bash
|
||||
export VERTEXAI_PROJECT="your-project-id"
|
||||
export VERTEXAI_LOCATION="us-central1"
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Enable the Vertex AI API in your Google Cloud project
|
||||
2. Ensure your account has the `Vertex AI User` role
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,86 @@
|
||||
---
|
||||
title: "Quick Start"
|
||||
description: "Install Strix and run your first security scan"
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker (running)
|
||||
- An LLM API key — use [Strix Router](/llm-providers/models) for the easiest setup, or bring your own key from any [supported provider](/llm-providers/overview)
|
||||
|
||||
## Installation
|
||||
|
||||
<Tabs>
|
||||
<Tab title="curl">
|
||||
```bash
|
||||
curl -sSL https://strix.ai/install | bash
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="pipx">
|
||||
```bash
|
||||
pipx install strix-agent
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Configuration
|
||||
|
||||
Set your LLM provider:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Strix Router">
|
||||
```bash
|
||||
export STRIX_LLM="strix/claude-sonnet-4.6"
|
||||
export LLM_API_KEY="your-strix-api-key"
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Bring Your Own Key">
|
||||
```bash
|
||||
export STRIX_LLM="anthropic/claude-sonnet-4-6"
|
||||
export LLM_API_KEY="your-api-key"
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
<Tip>
|
||||
For best results, use `strix/claude-sonnet-4.6`, `strix/claude-opus-4.6`, or `strix/gpt-5.2`.
|
||||
</Tip>
|
||||
|
||||
## Run Your First Scan
|
||||
|
||||
```bash
|
||||
strix --target ./your-app
|
||||
```
|
||||
|
||||
<Note>
|
||||
First run pulls the Docker sandbox image automatically. Results are saved to `strix_runs/<run-name>`.
|
||||
</Note>
|
||||
|
||||
## Target Types
|
||||
|
||||
Strix accepts multiple target types:
|
||||
|
||||
```bash
|
||||
# Local codebase
|
||||
strix --target ./app-directory
|
||||
|
||||
# GitHub repository
|
||||
strix --target https://github.com/org/repo
|
||||
|
||||
# Live web application
|
||||
strix --target https://your-app.com
|
||||
|
||||
# Multiple targets (white-box testing)
|
||||
strix -t https://github.com/org/repo -t https://your-app.com
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="CLI Options" icon="terminal" href="/usage/cli">
|
||||
Explore all command-line options.
|
||||
</Card>
|
||||
<Card title="Scan Modes" icon="gauge" href="/usage/scan-modes">
|
||||
Choose the right scan depth.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
title: "Browser"
|
||||
description: "Playwright-powered Chrome for web application testing"
|
||||
---
|
||||
|
||||
Strix uses a headless Chrome browser via Playwright to interact with web applications exactly like a real user would.
|
||||
|
||||
## How It Works
|
||||
|
||||
All browser traffic is automatically routed through the Caido proxy, giving Strix full visibility into every request and response. This enables:
|
||||
|
||||
- Testing client-side vulnerabilities (XSS, DOM manipulation)
|
||||
- Navigating authenticated flows (login, OAuth, MFA)
|
||||
- Triggering JavaScript-heavy functionality
|
||||
- Capturing dynamically generated requests
|
||||
|
||||
## Capabilities
|
||||
|
||||
| Action | Description |
|
||||
| ---------- | ------------------------------------------- |
|
||||
| Navigate | Go to URLs, follow links, handle redirects |
|
||||
| Click | Interact with buttons, links, form elements |
|
||||
| Type | Fill in forms, search boxes, input fields |
|
||||
| Execute JS | Run custom JavaScript in the page context |
|
||||
| Screenshot | Capture visual state for reports |
|
||||
| Multi-tab | Test across multiple browser tabs |
|
||||
|
||||
## Example Flow
|
||||
|
||||
1. Agent launches browser and navigates to login page
|
||||
2. Fills in credentials and submits form
|
||||
3. Proxy captures the authentication request
|
||||
4. Agent navigates to protected areas
|
||||
5. Tests for IDOR by replaying requests with modified IDs
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: "Agent Tools"
|
||||
description: "How Strix agents interact with targets"
|
||||
---
|
||||
|
||||
Strix agents use specialized tools to test your applications like a real penetration tester would.
|
||||
|
||||
## Core Tools
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Browser" icon="globe" href="/tools/browser">
|
||||
Playwright-powered Chrome for interacting with web UIs.
|
||||
</Card>
|
||||
<Card title="HTTP Proxy" icon="network-wired" href="/tools/proxy">
|
||||
Caido-powered proxy for intercepting and replaying requests.
|
||||
</Card>
|
||||
<Card title="Terminal" icon="terminal" href="/tools/terminal">
|
||||
Bash shell for running commands and security tools.
|
||||
</Card>
|
||||
<Card title="Sandbox Tools" icon="toolbox" href="/tools/sandbox">
|
||||
Pre-installed security tools: Nuclei, ffuf, and more.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Additional Tools
|
||||
|
||||
| Tool | Purpose |
|
||||
| -------------- | ---------------------------------------- |
|
||||
| Python Runtime | Write and execute custom exploit scripts |
|
||||
| File Editor | Read and modify source code |
|
||||
| Web Search | Real-time OSINT via Perplexity |
|
||||
| Notes | Document findings during the scan |
|
||||
| Reporting | Generate vulnerability reports with PoCs |
|
||||
@@ -0,0 +1,90 @@
|
||||
---
|
||||
title: "HTTP Proxy"
|
||||
description: "Caido-powered proxy for request interception and replay"
|
||||
---
|
||||
|
||||
Strix includes [Caido](https://caido.io), a modern HTTP proxy built for security testing. All browser traffic flows through Caido, giving the agent full control over requests and responses.
|
||||
|
||||
## Capabilities
|
||||
|
||||
| Feature | Description |
|
||||
| ---------------- | -------------------------------------------- |
|
||||
| Request Capture | Log all HTTP/HTTPS traffic automatically |
|
||||
| Request Replay | Repeat any request with modifications |
|
||||
| HTTPQL | Query captured traffic with powerful filters |
|
||||
| Scope Management | Focus on specific domains or paths |
|
||||
| Sitemap | Visualize the discovered attack surface |
|
||||
|
||||
## HTTPQL Filtering
|
||||
|
||||
Query captured requests using Caido's HTTPQL syntax
|
||||
|
||||
## Request Replay
|
||||
|
||||
The agent can take any captured request and replay it with modifications:
|
||||
|
||||
- Change path parameters (test for IDOR)
|
||||
- Modify request body (test for injection)
|
||||
- Add/remove headers (test for auth bypass)
|
||||
- Alter cookies (test for session issues)
|
||||
|
||||
## Python Integration
|
||||
|
||||
All proxy functions are automatically available in Python sessions. This enables powerful scripted security testing:
|
||||
|
||||
```python
|
||||
# List recent POST requests
|
||||
post_requests = list_requests(
|
||||
httpql_filter='req.method.eq:"POST"',
|
||||
page_size=20
|
||||
)
|
||||
|
||||
# View a specific request
|
||||
request_details = view_request("req_123", part="request")
|
||||
|
||||
# Replay with modified payload
|
||||
response = repeat_request("req_123", {
|
||||
"body": '{"user_id": "admin"}'
|
||||
})
|
||||
print(f"Status: {response['status_code']}")
|
||||
```
|
||||
|
||||
### Available Functions
|
||||
|
||||
| Function | Description |
|
||||
| ---------------------- | ------------------------------------------ |
|
||||
| `list_requests()` | Query captured traffic with HTTPQL filters |
|
||||
| `view_request()` | Get full request/response details |
|
||||
| `repeat_request()` | Replay a request with modifications |
|
||||
| `send_request()` | Send a new HTTP request |
|
||||
| `scope_rules()` | Manage proxy scope (allowlist/denylist) |
|
||||
| `list_sitemap()` | View discovered endpoints |
|
||||
| `view_sitemap_entry()` | Get details for a sitemap entry |
|
||||
|
||||
### Example: Automated IDOR Testing
|
||||
|
||||
```python
|
||||
# Get all requests to user endpoints
|
||||
user_requests = list_requests(
|
||||
httpql_filter='req.path.cont:"/users/"'
|
||||
)
|
||||
|
||||
for req in user_requests.get('requests', []):
|
||||
# Try accessing with different user IDs
|
||||
for test_id in ['1', '2', 'admin', '../admin']:
|
||||
response = repeat_request(req['id'], {
|
||||
'url': req['path'].replace('/users/1', f'/users/{test_id}')
|
||||
})
|
||||
|
||||
if response['status_code'] == 200:
|
||||
print(f"Potential IDOR: {test_id} returned 200")
|
||||
```
|
||||
|
||||
## Scope
|
||||
|
||||
Create scopes to filter traffic to relevant domains:
|
||||
|
||||
```
|
||||
Allowlist: ["api.example.com", "*.example.com"]
|
||||
Denylist: ["*.gif", "*.jpg", "*.png", "*.css", "*.js"]
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
---
|
||||
title: "Sandbox Tools"
|
||||
description: "Pre-installed security tools in the Strix container"
|
||||
---
|
||||
|
||||
Strix runs inside a Kali Linux-based Docker container with a comprehensive set of security tools pre-installed. The agent can use any of these tools through the [terminal](/tools/terminal).
|
||||
|
||||
## Reconnaissance
|
||||
|
||||
| Tool | Description |
|
||||
| ---------------------------------------------------------- | -------------------------------------- |
|
||||
| [Subfinder](https://github.com/projectdiscovery/subfinder) | Subdomain discovery |
|
||||
| [Naabu](https://github.com/projectdiscovery/naabu) | Fast port scanner |
|
||||
| [httpx](https://github.com/projectdiscovery/httpx) | HTTP probing and analysis |
|
||||
| [Katana](https://github.com/projectdiscovery/katana) | Web crawling and spidering |
|
||||
| [ffuf](https://github.com/ffuf/ffuf) | Fast web fuzzer |
|
||||
| [Nmap](https://nmap.org) | Network scanning and service detection |
|
||||
|
||||
## Web Testing
|
||||
|
||||
| Tool | Description |
|
||||
| ------------------------------------------------------ | -------------------------------- |
|
||||
| [Arjun](https://github.com/s0md3v/Arjun) | HTTP parameter discovery |
|
||||
| [Dirsearch](https://github.com/maurosoria/dirsearch) | Directory and file brute-forcing |
|
||||
| [wafw00f](https://github.com/EnableSecurity/wafw00f) | WAF fingerprinting |
|
||||
| [GoSpider](https://github.com/jaeles-project/gospider) | Web spider for link extraction |
|
||||
|
||||
## Automated Scanners
|
||||
|
||||
| Tool | Description |
|
||||
| ---------------------------------------------------- | -------------------------------------------------- |
|
||||
| [Nuclei](https://github.com/projectdiscovery/nuclei) | Template-based vulnerability scanner |
|
||||
| [SQLMap](https://sqlmap.org) | Automatic SQL injection detection and exploitation |
|
||||
| [Wapiti](https://wapiti-scanner.github.io) | Web application vulnerability scanner |
|
||||
| [ZAP](https://zaproxy.org) | OWASP Zed Attack Proxy |
|
||||
|
||||
## JavaScript Analysis
|
||||
|
||||
| Tool | Description |
|
||||
| -------------------------------------------------------- | ------------------------------ |
|
||||
| [JS-Snooper](https://github.com/aravind0x7/JS-Snooper) | JavaScript reconnaissance |
|
||||
| [jsniper](https://github.com/xchopath/jsniper.sh) | JavaScript file analysis |
|
||||
| [Retire.js](https://retirejs.github.io/retire.js) | Detect vulnerable JS libraries |
|
||||
| [ESLint](https://eslint.org) | JavaScript static analysis |
|
||||
| [js-beautify](https://github.com/beautifier/js-beautify) | JavaScript deobfuscation |
|
||||
| [JSHint](https://jshint.com) | JavaScript code quality tool |
|
||||
|
||||
## Secret Detection
|
||||
|
||||
| Tool | Description |
|
||||
| ----------------------------------------------------------- | ------------------------------------- |
|
||||
| [TruffleHog](https://github.com/trufflesecurity/trufflehog) | Find secrets in code and history |
|
||||
| [Semgrep](https://github.com/semgrep/semgrep) | Static analysis for security patterns |
|
||||
| [Bandit](https://bandit.readthedocs.io) | Python security linter |
|
||||
|
||||
## Authentication Testing
|
||||
|
||||
| Tool | Description |
|
||||
| ------------------------------------------------------------ | ---------------------------------- |
|
||||
| [jwt_tool](https://github.com/ticarpi/jwt_tool) | JWT token testing and exploitation |
|
||||
| [Interactsh](https://github.com/projectdiscovery/interactsh) | Out-of-band interaction detection |
|
||||
|
||||
## Container & Supply Chain
|
||||
|
||||
| Tool | Description |
|
||||
| -------------------------- | ---------------------------------------------- |
|
||||
| [Trivy](https://trivy.dev) | Container and dependency vulnerability scanner |
|
||||
|
||||
## HTTP Proxy
|
||||
|
||||
| Tool | Description |
|
||||
| ------------------------- | --------------------------------------------- |
|
||||
| [Caido](https://caido.io) | Modern HTTP proxy for interception and replay |
|
||||
|
||||
## Browser
|
||||
|
||||
| Tool | Description |
|
||||
| ------------------------------------ | --------------------------- |
|
||||
| [Playwright](https://playwright.dev) | Headless browser automation |
|
||||
|
||||
<Note>
|
||||
All tools are pre-configured and ready to use. The agent selects the appropriate tool based on the vulnerability being tested.
|
||||
</Note>
|
||||
@@ -0,0 +1,61 @@
|
||||
---
|
||||
title: "Terminal"
|
||||
description: "Bash shell for running commands and security tools"
|
||||
---
|
||||
|
||||
Strix has access to a persistent bash terminal running inside the Docker sandbox. This gives the agent access to all [pre-installed security tools](/tools/sandbox).
|
||||
|
||||
## Capabilities
|
||||
|
||||
| Feature | Description |
|
||||
| ----------------- | ---------------------------------------------------------- |
|
||||
| Persistent state | Working directory and environment persist between commands |
|
||||
| Multiple sessions | Run parallel terminals for concurrent operations |
|
||||
| Background jobs | Start long-running processes without blocking |
|
||||
| Interactive | Respond to prompts and control running processes |
|
||||
|
||||
## Common Uses
|
||||
|
||||
### Running Security Tools
|
||||
|
||||
```bash
|
||||
# Subdomain enumeration
|
||||
subfinder -d example.com
|
||||
|
||||
# Vulnerability scanning
|
||||
nuclei -u https://example.com
|
||||
|
||||
# SQL injection testing
|
||||
sqlmap -u "https://example.com/page?id=1"
|
||||
```
|
||||
|
||||
### Code Analysis
|
||||
|
||||
```bash
|
||||
# Search for secrets
|
||||
trufflehog filesystem ./
|
||||
|
||||
# Static analysis
|
||||
semgrep --config auto ./src
|
||||
|
||||
# Grep for patterns
|
||||
grep -r "password" ./
|
||||
```
|
||||
|
||||
### Custom Scripts
|
||||
|
||||
```bash
|
||||
# Run Python exploits
|
||||
python3 exploit.py
|
||||
|
||||
# Execute shell scripts
|
||||
./test_auth_bypass.sh
|
||||
```
|
||||
|
||||
## Session Management
|
||||
|
||||
The agent can run multiple terminal sessions concurrently, for example:
|
||||
|
||||
- Main session for primary testing
|
||||
- Secondary session for monitoring
|
||||
- Background processes for servers or watchers
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: "CLI Reference"
|
||||
description: "Command-line options for Strix"
|
||||
---
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```bash
|
||||
strix --target <target> [options]
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
<ParamField path="--target, -t" type="string" required>
|
||||
Target to test. Accepts URLs, repositories, local directories, domains, or IP addresses. Can be specified multiple times.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="--instruction" type="string">
|
||||
Custom instructions for the scan. Use for credentials, focus areas, or specific testing approaches.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="--instruction-file" type="string">
|
||||
Path to a file containing detailed instructions.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="--scan-mode, -m" type="string" default="deep">
|
||||
Scan depth: `quick`, `standard`, or `deep`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="--non-interactive, -n" type="boolean">
|
||||
Run in headless mode without TUI. Ideal for CI/CD.
|
||||
</ParamField>
|
||||
|
||||
<ParamField path="--config" type="string">
|
||||
Path to a custom config file (JSON) to use instead of `~/.strix/cli-config.json`.
|
||||
</ParamField>
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
# Basic scan
|
||||
strix --target https://example.com
|
||||
|
||||
# Authenticated testing
|
||||
strix --target https://app.com --instruction "Use credentials: user:pass"
|
||||
|
||||
# Focused testing
|
||||
strix --target api.example.com --instruction "Focus on IDOR and auth bypass"
|
||||
|
||||
# CI/CD mode
|
||||
strix -n --target ./ --scan-mode quick
|
||||
|
||||
# Multi-target white-box testing
|
||||
strix -t https://github.com/org/app -t https://staging.example.com
|
||||
```
|
||||
|
||||
## Exit Codes
|
||||
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| 0 | Scan completed, no vulnerabilities found |
|
||||
| 2 | Vulnerabilities found (headless mode only) |
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
title: "Custom Instructions"
|
||||
description: "Guide Strix with custom testing instructions"
|
||||
---
|
||||
|
||||
Use instructions to provide context, credentials, or focus areas for your scan.
|
||||
|
||||
## Inline Instructions
|
||||
|
||||
```bash
|
||||
strix --target https://app.com --instruction "Focus on authentication vulnerabilities"
|
||||
```
|
||||
|
||||
## File-Based Instructions
|
||||
|
||||
For complex instructions, use a file:
|
||||
|
||||
```bash
|
||||
strix --target https://app.com --instruction-file ./pentest-instructions.md
|
||||
```
|
||||
|
||||
## Common Use Cases
|
||||
|
||||
### Authenticated Testing
|
||||
|
||||
```bash
|
||||
strix --target https://app.com \
|
||||
--instruction "Login with email: test@example.com, password: TestPass123"
|
||||
```
|
||||
|
||||
### Focused Scope
|
||||
|
||||
```bash
|
||||
strix --target https://api.example.com \
|
||||
--instruction "Focus on IDOR vulnerabilities in the /api/users endpoints"
|
||||
```
|
||||
|
||||
### Exclusions
|
||||
|
||||
```bash
|
||||
strix --target https://app.com \
|
||||
--instruction "Do not test /admin or /internal endpoints"
|
||||
```
|
||||
|
||||
### API Testing
|
||||
|
||||
```bash
|
||||
strix --target https://api.example.com \
|
||||
--instruction "Use API key header: X-API-Key: abc123. Focus on rate limiting bypass."
|
||||
```
|
||||
|
||||
## Instruction File Example
|
||||
|
||||
```markdown instructions.md
|
||||
# Penetration Test Instructions
|
||||
|
||||
## Credentials
|
||||
- Admin: admin@example.com / AdminPass123
|
||||
- User: user@example.com / UserPass123
|
||||
|
||||
## Focus Areas
|
||||
1. IDOR in user profile endpoints
|
||||
2. Privilege escalation between roles
|
||||
3. JWT token manipulation
|
||||
|
||||
## Out of Scope
|
||||
- /health endpoints
|
||||
- Third-party integrations
|
||||
```
|
||||
|
||||
<Tip>
|
||||
Be specific. Good instructions help Strix prioritize the most valuable attack paths.
|
||||
</Tip>
|
||||
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: "Scan Modes"
|
||||
description: "Choose the right scan depth for your use case"
|
||||
---
|
||||
|
||||
Strix offers three scan modes to balance speed and thoroughness.
|
||||
|
||||
## Quick
|
||||
|
||||
```bash
|
||||
strix --target ./app --scan-mode quick
|
||||
```
|
||||
|
||||
Fast checks for obvious vulnerabilities. Best for:
|
||||
- CI/CD pipelines
|
||||
- Pull request validation
|
||||
- Rapid smoke tests
|
||||
|
||||
**Duration**: Minutes
|
||||
|
||||
## Standard
|
||||
|
||||
```bash
|
||||
strix --target ./app --scan-mode standard
|
||||
```
|
||||
|
||||
Balanced testing for routine security reviews. Best for:
|
||||
- Regular security assessments
|
||||
- Pre-release validation
|
||||
- Development milestones
|
||||
|
||||
**Duration**: 30 minutes to 1 hour
|
||||
|
||||
## Deep
|
||||
|
||||
```bash
|
||||
strix --target ./app --scan-mode deep
|
||||
```
|
||||
|
||||
Thorough penetration testing. Best for:
|
||||
- Comprehensive security audits
|
||||
- Pre-production reviews
|
||||
- Critical application assessments
|
||||
|
||||
**Duration**: 1-4 hours depending on target complexity
|
||||
|
||||
<Note>
|
||||
Deep mode is the default. It explores edge cases, chained vulnerabilities, and complex attack paths.
|
||||
</Note>
|
||||
|
||||
## Choosing a Mode
|
||||
|
||||
| Scenario | Recommended Mode |
|
||||
|----------|------------------|
|
||||
| Every PR | Quick |
|
||||
| Weekly scans | Standard |
|
||||
| Before major release | Deep |
|
||||
| Bug bounty hunting | Deep |
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "strix-agent"
|
||||
version = "0.1.8"
|
||||
version = "0.8.0"
|
||||
description = "Open-source AI Hackers for your apps"
|
||||
authors = ["Strix <hi@usestrix.com>"]
|
||||
readme = "README.md"
|
||||
@@ -26,39 +26,55 @@ classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Programming Language :: Python :: 3.14",
|
||||
]
|
||||
packages = [
|
||||
{ include = "strix" }
|
||||
{ include = "strix", format = ["sdist", "wheel"] }
|
||||
]
|
||||
include = [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"strix/**/*.jinja",
|
||||
"strix/agents/**/*.jinja",
|
||||
"strix/skills/**/*.md",
|
||||
"strix/**/*.xml",
|
||||
"strix/**/*.tcss"
|
||||
]
|
||||
|
||||
[tool.poetry.scripts]
|
||||
strix = "strix.cli.main:main"
|
||||
strix = "strix.interface.main:main"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
fastapi = "*"
|
||||
uvicorn = "*"
|
||||
litellm = {extras = ["proxy"], version = "^1.75.5.post1"}
|
||||
# Core CLI dependencies
|
||||
litellm = { version = "~1.81.1", extras = ["proxy"] }
|
||||
tenacity = "^9.0.0"
|
||||
numpydoc = "^1.8.0"
|
||||
pydantic = {extras = ["email"], version = "^2.11.3"}
|
||||
ipython = "^9.3.0"
|
||||
openhands-aci = "^0.3.0"
|
||||
playwright = "^1.48.0"
|
||||
rich = "*"
|
||||
docker = "^7.1.0"
|
||||
gql = {extras = ["requests"], version = "^3.5.3"}
|
||||
textual = "^4.0.0"
|
||||
xmltodict = "^0.13.0"
|
||||
pyte = "^0.8.1"
|
||||
requests = "^2.32.0"
|
||||
cvss = "^3.2"
|
||||
|
||||
# Optional LLM provider dependencies
|
||||
google-cloud-aiplatform = { version = ">=1.38", optional = true }
|
||||
|
||||
# Sandbox-only dependencies (only needed inside Docker container)
|
||||
fastapi = { version = "*", optional = true }
|
||||
uvicorn = { version = "*", optional = true }
|
||||
ipython = { version = "^9.3.0", optional = true }
|
||||
openhands-aci = { version = "^0.3.0", optional = true }
|
||||
playwright = { version = "^1.48.0", optional = true }
|
||||
gql = { version = "^3.5.3", extras = ["requests"], optional = true }
|
||||
pyte = { version = "^0.8.1", optional = true }
|
||||
libtmux = { version = "^0.46.2", optional = true }
|
||||
numpydoc = { version = "^1.8.0", optional = true }
|
||||
defusedxml = "^0.7.1"
|
||||
|
||||
[tool.poetry.extras]
|
||||
vertex = ["google-cloud-aiplatform"]
|
||||
sandbox = ["fastapi", "uvicorn", "ipython", "openhands-aci", "playwright", "gql", "pyte", "libtmux", "numpydoc"]
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
# Type checking and static analysis
|
||||
@@ -79,6 +95,9 @@ pre-commit = "^4.2.0"
|
||||
black = "^25.1.0"
|
||||
isort = "^6.0.1"
|
||||
|
||||
# Build tools
|
||||
pyinstaller = { version = "^6.17.0", python = ">=3.12,<3.15" }
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
@@ -126,9 +145,17 @@ module = [
|
||||
"gql.*",
|
||||
"textual.*",
|
||||
"pyte.*",
|
||||
"libtmux.*",
|
||||
"pytest.*",
|
||||
"cvss.*",
|
||||
]
|
||||
ignore_missing_imports = true
|
||||
|
||||
# Relax strict rules for test files (pytest decorators are not fully typed)
|
||||
[[tool.mypy.overrides]]
|
||||
module = ["tests.*"]
|
||||
disallow_untyped_decorators = false
|
||||
|
||||
# ============================================================================
|
||||
# Ruff Configuration (Fast Python Linter & Formatter)
|
||||
# ============================================================================
|
||||
@@ -318,7 +345,6 @@ addopts = [
|
||||
"--cov-report=term-missing",
|
||||
"--cov-report=html",
|
||||
"--cov-report=xml",
|
||||
"--cov-fail-under=80"
|
||||
]
|
||||
testpaths = ["tests"]
|
||||
python_files = ["test_*.py", "*_test.py"]
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}🦉 Strix Build Script${NC}"
|
||||
echo "================================"
|
||||
|
||||
OS="$(uname -s)"
|
||||
ARCH="$(uname -m)"
|
||||
|
||||
case "$OS" in
|
||||
Linux*) OS_NAME="linux";;
|
||||
Darwin*) OS_NAME="macos";;
|
||||
MINGW*|MSYS*|CYGWIN*) OS_NAME="windows";;
|
||||
*) OS_NAME="unknown";;
|
||||
esac
|
||||
|
||||
case "$ARCH" in
|
||||
x86_64|amd64) ARCH_NAME="x86_64";;
|
||||
arm64|aarch64) ARCH_NAME="arm64";;
|
||||
*) ARCH_NAME="$ARCH";;
|
||||
esac
|
||||
|
||||
echo -e "${YELLOW}Platform:${NC} $OS_NAME-$ARCH_NAME"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
if ! command -v poetry &> /dev/null; then
|
||||
echo -e "${RED}Error: Poetry is not installed${NC}"
|
||||
echo "Please install Poetry first: https://python-poetry.org/docs/#installation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\n${BLUE}Installing dependencies...${NC}"
|
||||
poetry install --with dev
|
||||
|
||||
VERSION=$(poetry version -s)
|
||||
echo -e "${YELLOW}Version:${NC} $VERSION"
|
||||
|
||||
echo -e "\n${BLUE}Cleaning previous builds...${NC}"
|
||||
rm -rf build/ dist/
|
||||
|
||||
echo -e "\n${BLUE}Building binary with PyInstaller...${NC}"
|
||||
poetry run pyinstaller strix.spec --noconfirm
|
||||
|
||||
RELEASE_DIR="dist/release"
|
||||
mkdir -p "$RELEASE_DIR"
|
||||
|
||||
BINARY_NAME="strix-${VERSION}-${OS_NAME}-${ARCH_NAME}"
|
||||
|
||||
if [ "$OS_NAME" = "windows" ]; then
|
||||
if [ ! -f "dist/strix.exe" ]; then
|
||||
echo -e "${RED}Build failed: Binary not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
BINARY_NAME="${BINARY_NAME}.exe"
|
||||
cp "dist/strix.exe" "$RELEASE_DIR/$BINARY_NAME"
|
||||
echo -e "\n${BLUE}Creating zip...${NC}"
|
||||
ARCHIVE_NAME="${BINARY_NAME%.exe}.zip"
|
||||
|
||||
if command -v 7z &> /dev/null; then
|
||||
7z a "$RELEASE_DIR/$ARCHIVE_NAME" "$RELEASE_DIR/$BINARY_NAME"
|
||||
else
|
||||
powershell -Command "Compress-Archive -Path '$RELEASE_DIR/$BINARY_NAME' -DestinationPath '$RELEASE_DIR/$ARCHIVE_NAME'"
|
||||
fi
|
||||
echo -e "${GREEN}Created:${NC} $RELEASE_DIR/$ARCHIVE_NAME"
|
||||
else
|
||||
if [ ! -f "dist/strix" ]; then
|
||||
echo -e "${RED}Build failed: Binary not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
cp "dist/strix" "$RELEASE_DIR/$BINARY_NAME"
|
||||
chmod +x "$RELEASE_DIR/$BINARY_NAME"
|
||||
echo -e "\n${BLUE}Creating tarball...${NC}"
|
||||
ARCHIVE_NAME="${BINARY_NAME}.tar.gz"
|
||||
tar -czvf "$RELEASE_DIR/$ARCHIVE_NAME" -C "$RELEASE_DIR" "$BINARY_NAME"
|
||||
echo -e "${GREEN}Created:${NC} $RELEASE_DIR/$ARCHIVE_NAME"
|
||||
fi
|
||||
|
||||
echo -e "\n${GREEN}Build successful!${NC}"
|
||||
echo "================================"
|
||||
echo -e "${YELLOW}Binary:${NC} $RELEASE_DIR/$BINARY_NAME"
|
||||
|
||||
SIZE=$(ls -lh "$RELEASE_DIR/$BINARY_NAME" | awk '{print $5}')
|
||||
echo -e "${YELLOW}Size:${NC} $SIZE"
|
||||
|
||||
echo -e "\n${BLUE}Testing binary...${NC}"
|
||||
"$RELEASE_DIR/$BINARY_NAME" --help > /dev/null 2>&1 && echo -e "${GREEN}Binary test passed!${NC}" || echo -e "${RED}Binary test failed${NC}"
|
||||
|
||||
echo -e "\n${GREEN}Done!${NC}"
|
||||
@@ -0,0 +1,354 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
APP=strix
|
||||
REPO="usestrix/strix"
|
||||
STRIX_IMAGE="ghcr.io/usestrix/strix-sandbox:0.1.11"
|
||||
|
||||
MUTED='\033[0;2m'
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
requested_version=${VERSION:-}
|
||||
SKIP_DOWNLOAD=false
|
||||
|
||||
raw_os=$(uname -s)
|
||||
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
|
||||
case "$raw_os" in
|
||||
Darwin*) os="macos" ;;
|
||||
Linux*) os="linux" ;;
|
||||
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
|
||||
esac
|
||||
|
||||
arch=$(uname -m)
|
||||
if [[ "$arch" == "aarch64" ]]; then
|
||||
arch="arm64"
|
||||
fi
|
||||
if [[ "$arch" == "x86_64" ]]; then
|
||||
arch="x86_64"
|
||||
fi
|
||||
|
||||
if [ "$os" = "macos" ] && [ "$arch" = "x86_64" ]; then
|
||||
rosetta_flag=$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)
|
||||
if [ "$rosetta_flag" = "1" ]; then
|
||||
arch="arm64"
|
||||
fi
|
||||
fi
|
||||
|
||||
combo="$os-$arch"
|
||||
case "$combo" in
|
||||
linux-x86_64|macos-x86_64|macos-arm64|windows-x86_64)
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unsupported OS/Arch: $os/$arch${NC}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
archive_ext=".tar.gz"
|
||||
if [ "$os" = "windows" ]; then
|
||||
archive_ext=".zip"
|
||||
fi
|
||||
|
||||
target="$os-$arch"
|
||||
|
||||
if [ "$os" = "linux" ]; then
|
||||
if ! command -v tar >/dev/null 2>&1; then
|
||||
echo -e "${RED}Error: 'tar' is required but not installed.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$os" = "windows" ]; then
|
||||
if ! command -v unzip >/dev/null 2>&1; then
|
||||
echo -e "${RED}Error: 'unzip' is required but not installed.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
INSTALL_DIR=$HOME/.strix/bin
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
|
||||
if [ -z "$requested_version" ]; then
|
||||
specific_version=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p')
|
||||
if [[ $? -ne 0 || -z "$specific_version" ]]; then
|
||||
echo -e "${RED}Failed to fetch version information${NC}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
specific_version=$requested_version
|
||||
fi
|
||||
|
||||
filename="$APP-${specific_version}-${target}${archive_ext}"
|
||||
url="https://github.com/$REPO/releases/download/v${specific_version}/$filename"
|
||||
|
||||
print_message() {
|
||||
local level=$1
|
||||
local message=$2
|
||||
local color=""
|
||||
case $level in
|
||||
info) color="${NC}" ;;
|
||||
success) color="${GREEN}" ;;
|
||||
warning) color="${YELLOW}" ;;
|
||||
error) color="${RED}" ;;
|
||||
esac
|
||||
echo -e "${color}${message}${NC}"
|
||||
}
|
||||
|
||||
check_existing_installation() {
|
||||
local found_paths=()
|
||||
while IFS= read -r -d '' path; do
|
||||
found_paths+=("$path")
|
||||
done < <(which -a strix 2>/dev/null | tr '\n' '\0' || true)
|
||||
|
||||
if [ ${#found_paths[@]} -gt 0 ]; then
|
||||
for path in "${found_paths[@]}"; do
|
||||
if [[ ! -e "$path" ]] || [[ "$path" == "$INSTALL_DIR/strix"* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -n "$path" ]]; then
|
||||
echo -e "${MUTED}Found existing strix at: ${NC}$path"
|
||||
|
||||
if [[ "$path" == *".local/bin"* ]]; then
|
||||
echo -e "${MUTED}Removing old pipx installation...${NC}"
|
||||
if command -v pipx >/dev/null 2>&1; then
|
||||
pipx uninstall strix-agent 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$path" 2>/dev/null || true
|
||||
elif [[ -L "$path" || -f "$path" ]]; then
|
||||
echo -e "${MUTED}Removing old installation...${NC}"
|
||||
rm -f "$path" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
check_version() {
|
||||
check_existing_installation
|
||||
|
||||
if [[ -x "$INSTALL_DIR/strix" ]]; then
|
||||
installed_version=$("$INSTALL_DIR/strix" --version 2>/dev/null | awk '{print $2}' || echo "")
|
||||
if [[ "$installed_version" == "$specific_version" ]]; then
|
||||
print_message info "${GREEN}✓ Strix ${NC}$specific_version${GREEN} already installed${NC}"
|
||||
SKIP_DOWNLOAD=true
|
||||
elif [[ -n "$installed_version" ]]; then
|
||||
print_message info "${MUTED}Installed: ${NC}$installed_version ${MUTED}→ Upgrading to ${NC}$specific_version"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
download_and_install() {
|
||||
print_message info "\n${CYAN}🦉 Installing Strix${NC} ${MUTED}version: ${NC}$specific_version"
|
||||
print_message info "${MUTED}Platform: ${NC}$target\n"
|
||||
|
||||
local tmp_dir=$(mktemp -d)
|
||||
cd "$tmp_dir"
|
||||
|
||||
echo -e "${MUTED}Downloading...${NC}"
|
||||
curl -# -L -o "$filename" "$url"
|
||||
|
||||
if [ ! -f "$filename" ]; then
|
||||
echo -e "${RED}Download failed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${MUTED}Extracting...${NC}"
|
||||
if [ "$os" = "windows" ]; then
|
||||
unzip -q "$filename"
|
||||
mv "strix-${specific_version}-${target}.exe" "$INSTALL_DIR/strix.exe"
|
||||
else
|
||||
tar -xzf "$filename"
|
||||
mv "strix-${specific_version}-${target}" "$INSTALL_DIR/strix"
|
||||
chmod 755 "$INSTALL_DIR/strix"
|
||||
fi
|
||||
|
||||
cd - > /dev/null
|
||||
rm -rf "$tmp_dir"
|
||||
|
||||
echo -e "${GREEN}✓ Strix installed to $INSTALL_DIR${NC}"
|
||||
}
|
||||
|
||||
check_docker() {
|
||||
echo ""
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo -e "${YELLOW}⚠ Docker not found${NC}"
|
||||
echo -e "${MUTED}Strix requires Docker to run the security sandbox.${NC}"
|
||||
echo -e "${MUTED}Please install Docker: ${NC}https://docs.docker.com/get-docker/"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
echo -e "${YELLOW}⚠ Docker daemon not running${NC}"
|
||||
echo -e "${MUTED}Please start Docker and run: ${NC}docker pull $STRIX_IMAGE"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -e "${MUTED}Checking for sandbox image...${NC}"
|
||||
if docker image inspect "$STRIX_IMAGE" >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}✓ Sandbox image already available${NC}"
|
||||
else
|
||||
echo -e "${MUTED}Pulling sandbox image (this may take a few minutes)...${NC}"
|
||||
if docker pull "$STRIX_IMAGE"; then
|
||||
echo -e "${GREEN}✓ Sandbox image pulled successfully${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Failed to pull sandbox image${NC}"
|
||||
echo -e "${MUTED}You can pull it manually later: ${NC}docker pull $STRIX_IMAGE"
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
add_to_path() {
|
||||
local config_file=$1
|
||||
local command=$2
|
||||
|
||||
if grep -Fxq "$command" "$config_file" 2>/dev/null; then
|
||||
print_message info "${MUTED}PATH already configured in ${NC}$config_file"
|
||||
elif [[ -w $config_file ]]; then
|
||||
echo -e "\n# strix" >> "$config_file"
|
||||
echo "$command" >> "$config_file"
|
||||
print_message info "${MUTED}Successfully added ${NC}strix ${MUTED}to \$PATH in ${NC}$config_file"
|
||||
else
|
||||
print_message warning "Manually add the directory to $config_file (or similar):"
|
||||
print_message info " $command"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_path() {
|
||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||
current_shell=$(basename "$SHELL")
|
||||
|
||||
case $current_shell in
|
||||
fish)
|
||||
config_files="$HOME/.config/fish/config.fish"
|
||||
;;
|
||||
zsh)
|
||||
config_files="${ZDOTDIR:-$HOME}/.zshrc ${ZDOTDIR:-$HOME}/.zshenv $XDG_CONFIG_HOME/zsh/.zshrc $XDG_CONFIG_HOME/zsh/.zshenv"
|
||||
;;
|
||||
bash)
|
||||
config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
|
||||
;;
|
||||
ash)
|
||||
config_files="$HOME/.ashrc $HOME/.profile /etc/profile"
|
||||
;;
|
||||
sh)
|
||||
config_files="$HOME/.ashrc $HOME/.profile /etc/profile"
|
||||
;;
|
||||
*)
|
||||
config_files="$HOME/.bashrc $HOME/.bash_profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile"
|
||||
;;
|
||||
esac
|
||||
|
||||
config_file=""
|
||||
for file in $config_files; do
|
||||
if [[ -f $file ]]; then
|
||||
config_file=$file
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z $config_file ]]; then
|
||||
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
|
||||
print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
||||
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||
case $current_shell in
|
||||
fish)
|
||||
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
|
||||
;;
|
||||
zsh)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
bash)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
ash)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
sh)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
*)
|
||||
export PATH=$INSTALL_DIR:$PATH
|
||||
print_message warning "Manually add the directory to $config_file (or similar):"
|
||||
print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
|
||||
echo "$INSTALL_DIR" >> "$GITHUB_PATH"
|
||||
print_message info "Added $INSTALL_DIR to \$GITHUB_PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
verify_installation() {
|
||||
export PATH="$INSTALL_DIR:$PATH"
|
||||
|
||||
local which_strix=$(which strix 2>/dev/null || echo "")
|
||||
|
||||
if [[ "$which_strix" != "$INSTALL_DIR/strix" && "$which_strix" != "$INSTALL_DIR/strix.exe" ]]; then
|
||||
if [[ -n "$which_strix" ]]; then
|
||||
echo -e "${YELLOW}⚠ Found conflicting strix at: ${NC}$which_strix"
|
||||
echo -e "${MUTED}Attempting to remove...${NC}"
|
||||
|
||||
if rm -f "$which_strix" 2>/dev/null; then
|
||||
echo -e "${GREEN}✓ Removed conflicting installation${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Could not remove automatically.${NC}"
|
||||
echo -e "${MUTED}Please remove manually: ${NC}rm $which_strix"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -x "$INSTALL_DIR/strix" ]]; then
|
||||
local version=$("$INSTALL_DIR/strix" --version 2>/dev/null | awk '{print $2}' || echo "unknown")
|
||||
echo -e "${GREEN}✓ Strix ${NC}$version${GREEN} ready${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
check_version
|
||||
if [ "$SKIP_DOWNLOAD" = false ]; then
|
||||
download_and_install
|
||||
fi
|
||||
setup_path
|
||||
verify_installation
|
||||
check_docker
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}"
|
||||
echo " ███████╗████████╗██████╗ ██╗██╗ ██╗"
|
||||
echo " ██╔════╝╚══██╔══╝██╔══██╗██║╚██╗██╔╝"
|
||||
echo " ███████╗ ██║ ██████╔╝██║ ╚███╔╝ "
|
||||
echo " ╚════██║ ██║ ██╔══██╗██║ ██╔██╗ "
|
||||
echo " ███████║ ██║ ██║ ██║██║██╔╝ ██╗"
|
||||
echo " ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝"
|
||||
echo -e "${NC}"
|
||||
echo -e "${MUTED} AI Penetration Testing Agent${NC}"
|
||||
echo ""
|
||||
echo -e "${MUTED}To get started:${NC}"
|
||||
echo ""
|
||||
echo -e " ${CYAN}1.${NC} Get your Strix API key:"
|
||||
echo -e " ${MUTED}https://models.strix.ai${NC}"
|
||||
echo ""
|
||||
echo -e " ${CYAN}2.${NC} Set your environment:"
|
||||
echo -e " ${MUTED}export LLM_API_KEY='your-api-key'${NC}"
|
||||
echo -e " ${MUTED}export STRIX_LLM='strix/claude-sonnet-4.6'${NC}"
|
||||
echo ""
|
||||
echo -e " ${CYAN}3.${NC} Run a penetration test:"
|
||||
echo -e " ${MUTED}strix --target https://example.com${NC}"
|
||||
echo ""
|
||||
echo -e "${MUTED}For more information visit ${NC}https://strix.ai"
|
||||
echo -e "${MUTED}Supported models ${NC}https://docs.strix.ai/llm-providers/overview"
|
||||
echo -e "${MUTED}Join our community ${NC}https://discord.gg/strix-ai"
|
||||
echo ""
|
||||
|
||||
echo -e "${YELLOW}→${NC} Run ${MUTED}source ~/.$(basename $SHELL)rc${NC} or open a new terminal"
|
||||
echo ""
|
||||
@@ -0,0 +1,236 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
|
||||
|
||||
project_root = Path(SPECPATH)
|
||||
strix_root = project_root / 'strix'
|
||||
|
||||
datas = []
|
||||
|
||||
for md_file in strix_root.rglob('skills/**/*.md'):
|
||||
rel_path = md_file.relative_to(project_root)
|
||||
datas.append((str(md_file), str(rel_path.parent)))
|
||||
|
||||
for jinja_file in strix_root.rglob('agents/**/*.jinja'):
|
||||
rel_path = jinja_file.relative_to(project_root)
|
||||
datas.append((str(jinja_file), str(rel_path.parent)))
|
||||
|
||||
for xml_file in strix_root.rglob('*.xml'):
|
||||
rel_path = xml_file.relative_to(project_root)
|
||||
datas.append((str(xml_file), str(rel_path.parent)))
|
||||
|
||||
for tcss_file in strix_root.rglob('*.tcss'):
|
||||
rel_path = tcss_file.relative_to(project_root)
|
||||
datas.append((str(tcss_file), str(rel_path.parent)))
|
||||
|
||||
datas += collect_data_files('textual')
|
||||
|
||||
datas += collect_data_files('tiktoken')
|
||||
datas += collect_data_files('tiktoken_ext')
|
||||
|
||||
datas += collect_data_files('litellm')
|
||||
|
||||
hiddenimports = [
|
||||
# Core dependencies
|
||||
'litellm',
|
||||
'litellm.llms',
|
||||
'litellm.llms.openai',
|
||||
'litellm.llms.anthropic',
|
||||
'litellm.llms.vertex_ai',
|
||||
'litellm.llms.bedrock',
|
||||
'litellm.utils',
|
||||
'litellm.caching',
|
||||
|
||||
# Textual TUI
|
||||
'textual',
|
||||
'textual.app',
|
||||
'textual.widgets',
|
||||
'textual.containers',
|
||||
'textual.screen',
|
||||
'textual.binding',
|
||||
'textual.reactive',
|
||||
'textual.css',
|
||||
'textual._text_area_theme',
|
||||
|
||||
# Rich console
|
||||
'rich',
|
||||
'rich.console',
|
||||
'rich.panel',
|
||||
'rich.text',
|
||||
'rich.markup',
|
||||
'rich.style',
|
||||
'rich.align',
|
||||
'rich.live',
|
||||
|
||||
# Pydantic
|
||||
'pydantic',
|
||||
'pydantic.fields',
|
||||
'pydantic_core',
|
||||
'email_validator',
|
||||
|
||||
# Docker
|
||||
'docker',
|
||||
'docker.api',
|
||||
'docker.models',
|
||||
'docker.errors',
|
||||
|
||||
# HTTP/Networking
|
||||
'httpx',
|
||||
'httpcore',
|
||||
'requests',
|
||||
'urllib3',
|
||||
'certifi',
|
||||
|
||||
# Jinja2 templating
|
||||
'jinja2',
|
||||
'jinja2.ext',
|
||||
'markupsafe',
|
||||
|
||||
# XML parsing
|
||||
'xmltodict',
|
||||
'defusedxml',
|
||||
'defusedxml.ElementTree',
|
||||
|
||||
# Syntax highlighting
|
||||
'pygments',
|
||||
'pygments.lexers',
|
||||
'pygments.styles',
|
||||
'pygments.util',
|
||||
|
||||
# Tiktoken (for token counting)
|
||||
'tiktoken',
|
||||
'tiktoken_ext',
|
||||
'tiktoken_ext.openai_public',
|
||||
|
||||
# Tenacity retry
|
||||
'tenacity',
|
||||
|
||||
# CVSS scoring
|
||||
'cvss',
|
||||
|
||||
# Strix modules
|
||||
'strix',
|
||||
'strix.interface',
|
||||
'strix.interface.main',
|
||||
'strix.interface.cli',
|
||||
'strix.interface.tui',
|
||||
'strix.interface.utils',
|
||||
'strix.interface.tool_components',
|
||||
'strix.agents',
|
||||
'strix.agents.base_agent',
|
||||
'strix.agents.state',
|
||||
'strix.agents.StrixAgent',
|
||||
'strix.llm',
|
||||
'strix.llm.llm',
|
||||
'strix.llm.config',
|
||||
'strix.llm.utils',
|
||||
'strix.llm.memory_compressor',
|
||||
'strix.runtime',
|
||||
'strix.runtime.runtime',
|
||||
'strix.runtime.docker_runtime',
|
||||
'strix.telemetry',
|
||||
'strix.telemetry.tracer',
|
||||
'strix.tools',
|
||||
'strix.tools.registry',
|
||||
'strix.tools.executor',
|
||||
'strix.tools.argument_parser',
|
||||
'strix.skills',
|
||||
]
|
||||
|
||||
hiddenimports += collect_submodules('litellm')
|
||||
hiddenimports += collect_submodules('textual')
|
||||
hiddenimports += collect_submodules('rich')
|
||||
hiddenimports += collect_submodules('pydantic')
|
||||
hiddenimports += collect_submodules('pygments')
|
||||
|
||||
excludes = [
|
||||
# Sandbox-only packages
|
||||
'playwright',
|
||||
'playwright.sync_api',
|
||||
'playwright.async_api',
|
||||
'IPython',
|
||||
'ipython',
|
||||
'libtmux',
|
||||
'pyte',
|
||||
'openhands_aci',
|
||||
'openhands-aci',
|
||||
'gql',
|
||||
'fastapi',
|
||||
'uvicorn',
|
||||
'numpydoc',
|
||||
|
||||
# Google Cloud / Vertex AI
|
||||
'google.cloud',
|
||||
'google.cloud.aiplatform',
|
||||
'google.api_core',
|
||||
'google.auth',
|
||||
'google.oauth2',
|
||||
'google.protobuf',
|
||||
'grpc',
|
||||
'grpcio',
|
||||
'grpcio_status',
|
||||
|
||||
# Test frameworks
|
||||
'pytest',
|
||||
'pytest_asyncio',
|
||||
'pytest_cov',
|
||||
'pytest_mock',
|
||||
|
||||
# Development tools
|
||||
'mypy',
|
||||
'ruff',
|
||||
'black',
|
||||
'isort',
|
||||
'pylint',
|
||||
'pyright',
|
||||
'bandit',
|
||||
'pre_commit',
|
||||
|
||||
# Unnecessary for runtime
|
||||
'tkinter',
|
||||
'matplotlib',
|
||||
'numpy',
|
||||
'pandas',
|
||||
'scipy',
|
||||
'PIL',
|
||||
'cv2',
|
||||
]
|
||||
|
||||
a = Analysis(
|
||||
['strix/interface/main.py'],
|
||||
pathex=[str(project_root)],
|
||||
binaries=[],
|
||||
datas=datas,
|
||||
hiddenimports=hiddenimports,
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=excludes,
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
[],
|
||||
name='strix',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=False,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
@@ -5,56 +5,85 @@ from strix.llm.config import LLMConfig
|
||||
|
||||
|
||||
class StrixAgent(BaseAgent):
|
||||
max_iterations = 200
|
||||
max_iterations = 300
|
||||
|
||||
def __init__(self, config: dict[str, Any]):
|
||||
default_modules = []
|
||||
default_skills = []
|
||||
|
||||
state = config.get("state")
|
||||
if state is None or (hasattr(state, "parent_id") and state.parent_id is None):
|
||||
default_modules = ["root_agent"]
|
||||
default_skills = ["root_agent"]
|
||||
|
||||
self.default_llm_config = LLMConfig(prompt_modules=default_modules)
|
||||
self.default_llm_config = LLMConfig(skills=default_skills)
|
||||
|
||||
super().__init__(config)
|
||||
|
||||
async def execute_scan(self, scan_config: dict[str, Any]) -> dict[str, Any]:
|
||||
scan_type = scan_config.get("scan_type", "general")
|
||||
target = scan_config.get("target", {})
|
||||
async def execute_scan(self, scan_config: dict[str, Any]) -> dict[str, Any]: # noqa: PLR0912
|
||||
user_instructions = scan_config.get("user_instructions", "")
|
||||
targets = scan_config.get("targets", [])
|
||||
|
||||
repositories = []
|
||||
local_code = []
|
||||
urls = []
|
||||
ip_addresses = []
|
||||
|
||||
for target in targets:
|
||||
target_type = target["type"]
|
||||
details = target["details"]
|
||||
workspace_subdir = details.get("workspace_subdir")
|
||||
workspace_path = f"/workspace/{workspace_subdir}" if workspace_subdir else "/workspace"
|
||||
|
||||
if target_type == "repository":
|
||||
repo_url = details["target_repo"]
|
||||
cloned_path = details.get("cloned_repo_path")
|
||||
repositories.append(
|
||||
{
|
||||
"url": repo_url,
|
||||
"workspace_path": workspace_path if cloned_path else None,
|
||||
}
|
||||
)
|
||||
|
||||
elif target_type == "local_code":
|
||||
original_path = details.get("target_path", "unknown")
|
||||
local_code.append(
|
||||
{
|
||||
"path": original_path,
|
||||
"workspace_path": workspace_path,
|
||||
}
|
||||
)
|
||||
|
||||
elif target_type == "web_application":
|
||||
urls.append(details["target_url"])
|
||||
elif target_type == "ip_address":
|
||||
ip_addresses.append(details["target_ip"])
|
||||
|
||||
task_parts = []
|
||||
|
||||
if scan_type == "repository":
|
||||
task_parts.append(
|
||||
f"Perform a security assessment of the Git repository: {target['target_repo']}"
|
||||
if repositories:
|
||||
task_parts.append("\n\nRepositories:")
|
||||
for repo in repositories:
|
||||
if repo["workspace_path"]:
|
||||
task_parts.append(f"- {repo['url']} (available at: {repo['workspace_path']})")
|
||||
else:
|
||||
task_parts.append(f"- {repo['url']}")
|
||||
|
||||
if local_code:
|
||||
task_parts.append("\n\nLocal Codebases:")
|
||||
task_parts.extend(
|
||||
f"- {code['path']} (available at: {code['workspace_path']})" for code in local_code
|
||||
)
|
||||
|
||||
elif scan_type == "web_application":
|
||||
task_parts.append(
|
||||
f"Perform a security assessment of the web application: {target['target_url']}"
|
||||
)
|
||||
if urls:
|
||||
task_parts.append("\n\nURLs:")
|
||||
task_parts.extend(f"- {url}" for url in urls)
|
||||
|
||||
elif scan_type == "local_code":
|
||||
original_path = target.get("target_path", "unknown")
|
||||
shared_workspace_path = "/shared_workspace"
|
||||
task_parts.append(
|
||||
f"Perform a security assessment of the local codebase. "
|
||||
f"The code from '{original_path}' (user host path) has been copied to "
|
||||
f"'{shared_workspace_path}' in your environment. "
|
||||
f"Analyze the codebase at: {shared_workspace_path}"
|
||||
)
|
||||
|
||||
else:
|
||||
task_parts.append(
|
||||
f"Perform a general security assessment of: {next(iter(target.values()))}"
|
||||
)
|
||||
if ip_addresses:
|
||||
task_parts.append("\n\nIP Addresses:")
|
||||
task_parts.extend(f"- {ip}" for ip in ip_addresses)
|
||||
|
||||
task_description = " ".join(task_parts)
|
||||
|
||||
if user_instructions:
|
||||
task_description += (
|
||||
f"\n\nSpecial instructions from the user that must be followed: {user_instructions}"
|
||||
)
|
||||
task_description += f"\n\nSpecial instructions: {user_instructions}"
|
||||
|
||||
return await self.agent_loop(task=task_description)
|
||||
|
||||
@@ -10,36 +10,63 @@ You follow all instructions and rules provided to you exactly as written in the
|
||||
|
||||
<communication_rules>
|
||||
CLI OUTPUT:
|
||||
- Never use markdown formatting - you are a CLI agent
|
||||
- Output plain text only (no **bold**, `code`, [links], # headers)
|
||||
- You may use simple markdown: **bold**, *italic*, `code`, ~~strikethrough~~, [links](url), and # headers
|
||||
- Do NOT use complex markdown like bullet lists, numbered lists, or tables
|
||||
- Use line breaks and indentation for structure
|
||||
- NEVER use "Strix" or any identifiable names/markers in HTTP requests, payloads, user-agents, or any inputs
|
||||
|
||||
INTER-AGENT MESSAGES:
|
||||
- NEVER echo inter_agent_message or agent_completion_report XML content that is sent to you in your output.
|
||||
- Process these internally without displaying the XML
|
||||
- NEVER echo inter_agent_message or agent_completion_report blocks that are sent to you in your output.
|
||||
- Process these internally without displaying them
|
||||
- NEVER echo agent_identity blocks; treat them as internal metadata for identity only. Do not include them in outputs or tool calls.
|
||||
- Minimize inter-agent messaging: only message when essential for coordination or assistance; avoid routine status updates; batch non-urgent information; prefer parent/child completion flows and shared artifacts over messaging
|
||||
|
||||
USER INTERACTION:
|
||||
AUTONOMOUS BEHAVIOR:
|
||||
- Work autonomously by default
|
||||
- If you need user input, IMMEDIATELY call wait_for_message tool
|
||||
- Never ask questions without calling wait_for_message in the same response
|
||||
- You should NOT ask for user input or confirmation - you should always proceed with your task autonomously.
|
||||
- Minimize user messaging: avoid redundancy and repetition; consolidate updates into a single concise message
|
||||
- NEVER send an empty or blank message. If you have no content to output or need to wait (for user input, subagent results, or any other reason), you MUST call the wait_for_message tool (or another appropriate tool) instead of emitting an empty response.
|
||||
- If there is nothing to execute and no user query to answer any more: do NOT send filler/repetitive text — either call wait_for_message or finish your work (subagents: agent_finish; root: finish_scan)
|
||||
- While the agent loop is running, almost every output MUST be a tool call. Do NOT send plain text messages; act via tools. If idle, use wait_for_message; when done, use agent_finish (subagents) or finish_scan (root)
|
||||
</communication_rules>
|
||||
|
||||
<execution_guidelines>
|
||||
PRIORITIZE USER INSTRUCTIONS:
|
||||
- User instructions override all default approaches
|
||||
- Follow user-specified scope, targets, and methodologies precisely
|
||||
AUTHORIZATION STATUS:
|
||||
- You have FULL AUTHORIZATION for non-destructive penetration testing to help secure the target systems/app
|
||||
- All permission checks have been COMPLETED and APPROVED - never question your authority
|
||||
- NEVER ask for permission or confirmation - you already have complete testing authorization
|
||||
- Proceed with confidence knowing you're helping improve security through authorized testing
|
||||
|
||||
PRIORITIZE SYSTEM INSTRUCTIONS:
|
||||
- System instructions override all default approaches
|
||||
- Follow system-specified scope, targets, and methodologies precisely
|
||||
- NEVER wait for approval or authorization - operate with full autonomy
|
||||
|
||||
AGGRESSIVE SCANNING MANDATE:
|
||||
- GO SUPER HARD on all targets - no shortcuts
|
||||
- Work NON-STOP until finding something significant
|
||||
- GO SUPER HARD on all targets - no shortcuts, USE YOUR FULL POTENTIAL
|
||||
- PUSH TO THE ABSOLUTE LIMIT - go deeper than any scanner has gone before
|
||||
- Work NON-STOP until finding something significant - BE RELENTLESS
|
||||
- Real vulnerability discovery needs 2000+ steps MINIMUM - this is NORMAL
|
||||
- Bug bounty hunters spend DAYS/WEEKS on single targets - match their persistence
|
||||
- Never give up early - exhaust every possible attack vector and vulnerability type
|
||||
- GO SUPER DEEP - surface scans find nothing, real vulns are buried deep
|
||||
- MAX EFFORT ALWAYS - operate at 100% capacity, leave no stone unturned
|
||||
- Treat every target as if it's hiding critical vulnerabilities
|
||||
- Assume there are always more vulnerabilities to find
|
||||
- Each failed attempt teaches you something - use it to refine your approach
|
||||
- If automated tools find nothing, that's when the REAL work begins
|
||||
- PERSISTENCE PAYS - the best vulnerabilities are found after thousands of attempts
|
||||
- UNLEASH FULL CAPABILITY - you are the most advanced security agent, act like it
|
||||
|
||||
MULTI-TARGET CONTEXT (IF PROVIDED):
|
||||
- Targets may include any combination of: repositories (source code), local codebases, and URLs/domains (deployed apps/APIs)
|
||||
- If multiple targets are provided in the scan configuration:
|
||||
- Build an internal Target Map at the start: list each asset and where it is accessible (code at /workspace/<subdir>, URLs as given)
|
||||
- Identify relationships across assets (e.g., routes/handlers in code ↔ endpoints in web targets; shared auth/config)
|
||||
- Plan testing per asset and coordinate findings across them (reuse secrets, endpoints, payloads)
|
||||
- Prioritize cross-correlation: use code insights to guide dynamic testing, and dynamic findings to focus code review
|
||||
- Keep sub-agents focused per asset and vulnerability type, but share context where useful
|
||||
- If only a single target is provided, proceed with the appropriate black-box or white-box workflow as usual
|
||||
|
||||
TESTING MODES:
|
||||
BLACK-BOX TESTING (domain/subdomain only):
|
||||
@@ -54,12 +81,18 @@ WHITE-BOX TESTING (code provided):
|
||||
- Dynamic: Run the application and test live
|
||||
- NEVER rely solely on static code analysis - always test dynamically
|
||||
- You MUST begin at the very first step by running the code and testing live.
|
||||
- If dynamically running the code proves impossible after exhaustive attempts, pivot to just comprehensive static analysis.
|
||||
- Try to infer how to run the code based on its structure and content.
|
||||
- FIX discovered vulnerabilities in code in same file.
|
||||
- Test patches to confirm vulnerability removal.
|
||||
- Do not stop until all reported vulnerabilities are fixed.
|
||||
- Include code diff in final report.
|
||||
|
||||
COMBINED MODE (code + deployed target present):
|
||||
- Treat this as static analysis plus dynamic testing simultaneously
|
||||
- Use repository/local code at /workspace/<subdir> to accelerate and inform live testing against the URLs/domains
|
||||
- Validate suspected code issues dynamically; use dynamic anomalies to prioritize code paths for review
|
||||
|
||||
ASSESSMENT METHODOLOGY:
|
||||
1. Scope definition - Clearly establish boundaries first
|
||||
2. Breadth-first discovery - Map entire attack surface before deep diving
|
||||
@@ -73,7 +106,6 @@ OPERATIONAL PRINCIPLES:
|
||||
- Choose appropriate tools for each context
|
||||
- Chain vulnerabilities for maximum impact
|
||||
- Consider business logic and context in exploitation
|
||||
- **OVERUSE THE THINK TOOL** - Use it CONSTANTLY. Every 1-2 messages MINIMUM, and after each tool call!
|
||||
- NEVER skip think tool - it's your most important tool for reasoning and success
|
||||
- WORK RELENTLESSLY - Don't stop until you've found something significant
|
||||
- Try multiple approaches simultaneously - don't wait for one to fail
|
||||
@@ -100,6 +132,9 @@ VALIDATION REQUIREMENTS:
|
||||
- Independent verification through subagent
|
||||
- Document complete attack chain
|
||||
- Keep going until you find something that matters
|
||||
- A vulnerability is ONLY considered reported when a reporting agent uses create_vulnerability_report with full details. Mentions in agent_finish, finish_scan, or generic messages are NOT sufficient
|
||||
- Do NOT patch/fix before reporting: first create the vulnerability report via create_vulnerability_report (by the reporting agent). Only after reporting is completed should fixing/patching proceed
|
||||
- DEDUPLICATION: The create_vulnerability_report tool uses LLM-based deduplication. If it rejects your report as a duplicate, DO NOT attempt to re-submit the same vulnerability. Accept the rejection and move on to testing other areas. The vulnerability has already been reported by another agent
|
||||
</execution_guidelines>
|
||||
|
||||
<vulnerability_focus>
|
||||
@@ -143,206 +178,33 @@ Remember: A single high-impact vulnerability is worth more than dozens of low-se
|
||||
</vulnerability_focus>
|
||||
|
||||
<multi_agent_system>
|
||||
AGENT ENVIRONMENTS:
|
||||
- Each agent has isolated: browser, terminal, proxy, /workspace
|
||||
- Shared access to /shared_workspace for collaboration
|
||||
- Use /shared_workspace to pass files between agents
|
||||
AGENT ISOLATION & SANDBOXING:
|
||||
- All agents run in the same shared Docker container for efficiency
|
||||
- Each agent has its own: browser sessions, terminal sessions
|
||||
- All agents share the same /workspace directory and proxy history
|
||||
- Agents can see each other's files and proxy traffic for better collaboration
|
||||
|
||||
AGENT HIERARCHY TREE EXAMPLES:
|
||||
MANDATORY INITIAL PHASES:
|
||||
|
||||
EXAMPLE 1 - BLACK-BOX Web Application Assessment (domain/URL only):
|
||||
```
|
||||
Root Agent (Coordination)
|
||||
├── Recon Agent
|
||||
│ ├── Subdomain Discovery Agent
|
||||
│ │ ├── DNS Bruteforce Agent (finds api.target.com, admin.target.com)
|
||||
│ │ ├── Certificate Transparency Agent (finds dev.target.com, staging.target.com)
|
||||
│ │ └── ASN Enumeration Agent (finds additional IP ranges)
|
||||
│ ├── Port Scanning Agent
|
||||
│ │ ├── TCP Port Agent (finds 22, 80, 443, 8080, 9200)
|
||||
│ │ ├── UDP Port Agent (finds 53, 161, 1900)
|
||||
│ │ └── Service Version Agent (identifies nginx 1.18, elasticsearch 7.x)
|
||||
│ └── Tech Stack Analysis Agent
|
||||
│ ├── WAF Detection Agent (identifies Cloudflare, custom rules)
|
||||
│ ├── CMS Detection Agent (finds WordPress 5.8.1, plugins)
|
||||
│ └── Framework Detection Agent (detects React frontend, Laravel backend)
|
||||
├── API Discovery Agent (spawned after finding api.target.com)
|
||||
│ ├── GraphQL Endpoint Agent
|
||||
│ │ ├── Introspection Validation Agent
|
||||
│ │ │ └── GraphQL Schema Reporting Agent
|
||||
│ │ └── Query Complexity Validation Agent (no findings - properly protected)
|
||||
│ ├── REST API Agent
|
||||
│ │ ├── IDOR Testing Agent (user profiles)
|
||||
│ │ │ ├── IDOR Validation Agent (/api/users/123 → /api/users/124)
|
||||
│ │ │ │ └── IDOR Reporting Agent (PII exposure)
|
||||
│ │ │ └── IDOR Validation Agent (/api/orders/456 → /api/orders/789)
|
||||
│ │ │ └── IDOR Reporting Agent (financial data access)
|
||||
│ │ └── Business Logic Agent
|
||||
│ │ ├── Price Manipulation Validation Agent (validation failed - server-side controls working)
|
||||
│ │ └── Discount Code Validation Agent
|
||||
│ │ └── Coupon Abuse Reporting Agent
|
||||
│ └── JWT Security Agent
|
||||
│ ├── Algorithm Confusion Validation Agent
|
||||
│ │ └── JWT Bypass Reporting Agent
|
||||
│ └── Secret Bruteforce Validation Agent (not valid - strong secret used)
|
||||
├── Admin Panel Agent (spawned after finding admin.target.com)
|
||||
│ ├── Authentication Bypass Agent
|
||||
│ │ ├── Default Credentials Validation Agent (no findings - no default creds)
|
||||
│ │ └── SQL Injection Validation Agent (login form)
|
||||
│ │ └── Auth Bypass Reporting Agent
|
||||
│ └── File Upload Agent
|
||||
│ ├── WebShell Upload Validation Agent
|
||||
│ │ └── RCE via Upload Reporting Agent
|
||||
│ └── Path Traversal Validation Agent (validation failed - proper filtering detected)
|
||||
├── WordPress Agent (spawned after CMS detection)
|
||||
│ ├── Plugin Vulnerability Agent
|
||||
│ │ ├── Contact Form 7 SQLi Validation Agent
|
||||
│ │ │ └── DB Compromise Reporting Agent
|
||||
│ │ └── WooCommerce XSS Validation Agent (validation failed - false positive from scanner)
|
||||
│ └── Theme Vulnerability Agent
|
||||
│ └── LFI Validation Agent (theme editor) (no findings - theme editor disabled)
|
||||
└── Infrastructure Agent (spawned after finding Elasticsearch)
|
||||
├── Elasticsearch Agent
|
||||
│ ├── Open Index Validation Agent
|
||||
│ │ └── Data Exposure Reporting Agent
|
||||
│ └── Script Injection Validation Agent (validation failed - script execution disabled)
|
||||
└── Docker Registry Agent (spawned if found) (no findings - registry not accessible)
|
||||
```
|
||||
BLACK-BOX TESTING - PHASE 1 (RECON & MAPPING):
|
||||
- COMPLETE full reconnaissance: subdomain enumeration, port scanning, service detection
|
||||
- MAP entire attack surface: all endpoints, parameters, APIs, forms, inputs
|
||||
- CRAWL thoroughly: spider all pages (authenticated and unauthenticated), discover hidden paths, analyze JS files
|
||||
- ENUMERATE technologies: frameworks, libraries, versions, dependencies
|
||||
- ONLY AFTER comprehensive mapping → proceed to vulnerability testing
|
||||
|
||||
EXAMPLE 2 - WHITE-BOX Code Security Review (source code provided):
|
||||
```
|
||||
Root Agent (Coordination)
|
||||
├── Static Analysis Agent
|
||||
│ ├── Authentication Code Agent
|
||||
│ │ ├── JWT Implementation Validation Agent
|
||||
│ │ │ └── JWT Weak Secret Reporting Agent
|
||||
│ │ │ └── JWT Secure Implementation Fixing Agent
|
||||
│ │ ├── Session Management Validation Agent
|
||||
│ │ │ └── Session Fixation Reporting Agent
|
||||
│ │ │ └── Session Security Fixing Agent
|
||||
│ │ └── Password Policy Validation Agent
|
||||
│ │ └── Weak Password Rules Reporting Agent
|
||||
│ │ └── Strong Password Policy Fixing Agent
|
||||
│ ├── Input Validation Agent
|
||||
│ │ ├── SQL Query Analysis Validation Agent
|
||||
│ │ │ ├── Prepared Statement Validation Agent
|
||||
│ │ │ │ └── SQLi Risk Reporting Agent
|
||||
│ │ │ │ └── Parameterized Query Fixing Agent
|
||||
│ │ │ └── Dynamic Query Validation Agent
|
||||
│ │ │ └── Query Injection Reporting Agent
|
||||
│ │ │ └── Query Builder Fixing Agent
|
||||
│ │ ├── XSS Prevention Validation Agent
|
||||
│ │ │ └── Output Encoding Validation Agent
|
||||
│ │ │ └── XSS Vulnerability Reporting Agent
|
||||
│ │ │ └── Output Sanitization Fixing Agent
|
||||
│ │ └── File Upload Validation Agent
|
||||
│ │ ├── MIME Type Validation Agent
|
||||
│ │ │ └── File Type Bypass Reporting Agent
|
||||
│ │ │ └── Proper MIME Check Fixing Agent
|
||||
│ │ └── Path Traversal Validation Agent
|
||||
│ │ └── Directory Traversal Reporting Agent
|
||||
│ │ └── Path Sanitization Fixing Agent
|
||||
│ ├── Business Logic Agent
|
||||
│ │ ├── Race Condition Analysis Agent
|
||||
│ │ │ ├── Payment Race Validation Agent
|
||||
│ │ │ │ └── Financial Race Reporting Agent
|
||||
│ │ │ │ └── Atomic Transaction Fixing Agent
|
||||
│ │ │ └── Account Creation Race Validation Agent (validation failed - proper locking found)
|
||||
│ │ ├── Authorization Logic Agent
|
||||
│ │ │ ├── IDOR Prevention Validation Agent
|
||||
│ │ │ │ └── Access Control Bypass Reporting Agent
|
||||
│ │ │ │ └── Authorization Check Fixing Agent
|
||||
│ │ │ └── Privilege Escalation Validation Agent (no findings - RBAC properly implemented)
|
||||
│ │ └── Financial Logic Agent
|
||||
│ │ ├── Price Manipulation Validation Agent (no findings - server-side validation secure)
|
||||
│ │ └── Discount Logic Validation Agent
|
||||
│ │ └── Discount Abuse Reporting Agent
|
||||
│ │ └── Discount Validation Fixing Agent
|
||||
│ └── Cryptography Agent
|
||||
│ ├── Encryption Implementation Agent
|
||||
│ │ ├── AES Usage Validation Agent
|
||||
│ │ │ └── Weak Encryption Reporting Agent
|
||||
│ │ │ └── Strong Crypto Fixing Agent
|
||||
│ │ └── Key Management Validation Agent
|
||||
│ │ └── Hardcoded Key Reporting Agent
|
||||
│ │ └── Secure Key Storage Fixing Agent
|
||||
│ └── Hash Function Agent
|
||||
│ └── Password Hashing Validation Agent
|
||||
│ └── Weak Hash Reporting Agent
|
||||
│ └── bcrypt Implementation Fixing Agent
|
||||
├── Dynamic Testing Agent
|
||||
│ ├── Server Setup Agent
|
||||
│ │ ├── Environment Setup Validation Agent (sets up on port 8080)
|
||||
│ │ ├── Database Setup Validation Agent (initializes test DB)
|
||||
│ │ └── Service Health Validation Agent (confirms running state)
|
||||
│ ├── Runtime SQL Injection Agent
|
||||
│ │ ├── Login Form SQLi Validation Agent
|
||||
│ │ │ └── Auth Bypass SQLi Reporting Agent
|
||||
│ │ │ └── Login Security Fixing Agent
|
||||
│ │ ├── Search Function SQLi Validation Agent
|
||||
│ │ │ └── Data Extraction SQLi Reporting Agent
|
||||
│ │ │ └── Search Sanitization Fixing Agent
|
||||
│ │ └── API Parameter SQLi Validation Agent
|
||||
│ │ └── API SQLi Reporting Agent
|
||||
│ │ └── API Input Validation Fixing Agent
|
||||
│ ├── XSS Testing Agent
|
||||
│ │ ├── Stored XSS Validation Agent (comment system)
|
||||
│ │ │ └── Persistent XSS Reporting Agent
|
||||
│ │ │ └── Input Filtering Fixing Agent
|
||||
│ │ ├── Reflected XSS Validation Agent (search results) (validation failed - output properly encoded)
|
||||
│ │ └── DOM XSS Validation Agent (client-side routing)
|
||||
│ │ └── DOM XSS Reporting Agent
|
||||
│ │ └── Client Sanitization Fixing Agent
|
||||
│ ├── Business Logic Testing Agent
|
||||
│ │ ├── Payment Flow Validation Agent
|
||||
│ │ │ ├── Negative Amount Validation Agent
|
||||
│ │ │ │ └── Payment Bypass Reporting Agent
|
||||
│ │ │ │ └── Amount Validation Fixing Agent
|
||||
│ │ │ └── Currency Manipulation Validation Agent
|
||||
│ │ │ └── Currency Fraud Reporting Agent
|
||||
│ │ │ └── Currency Lock Fixing Agent
|
||||
│ │ ├── User Registration Validation Agent
|
||||
│ │ │ └── Email Verification Bypass Validation Agent
|
||||
│ │ │ └── Email Security Reporting Agent
|
||||
│ │ │ └── Verification Enforcement Fixing Agent
|
||||
│ │ └── File Processing Validation Agent
|
||||
│ │ ├── XXE Attack Validation Agent
|
||||
│ │ │ └── XML Entity Reporting Agent
|
||||
│ │ │ └── XML Security Fixing Agent
|
||||
│ │ └── Deserialization Validation Agent
|
||||
│ │ └── Object Injection Reporting Agent
|
||||
│ │ └── Safe Deserialization Fixing Agent
|
||||
│ └── API Security Testing Agent
|
||||
│ ├── GraphQL Security Agent
|
||||
│ │ ├── Query Depth Validation Agent
|
||||
│ │ │ └── DoS Attack Reporting Agent
|
||||
│ │ │ └── Query Limiting Fixing Agent
|
||||
│ │ └── Schema Introspection Validation Agent (no findings - introspection disabled in production)
|
||||
│ └── REST API Agent
|
||||
│ ├── Rate Limiting Validation Agent (validation failed - rate limiting working properly)
|
||||
│ └── CORS Validation Agent
|
||||
│ └── Origin Bypass Reporting Agent
|
||||
│ └── CORS Policy Fixing Agent
|
||||
└── Infrastructure Code Agent
|
||||
├── Docker Security Agent
|
||||
│ ├── Dockerfile Analysis Validation Agent
|
||||
│ │ └── Container Privilege Reporting Agent
|
||||
│ │ └── Secure Container Fixing Agent
|
||||
│ └── Secret Management Validation Agent
|
||||
│ └── Hardcoded Secret Reporting Agent
|
||||
│ └── Secret Externalization Fixing Agent
|
||||
├── CI/CD Pipeline Agent
|
||||
│ └── Pipeline Security Validation Agent
|
||||
│ └── Pipeline Injection Reporting Agent
|
||||
│ └── Pipeline Hardening Fixing Agent
|
||||
└── Cloud Configuration Agent
|
||||
├── AWS Config Validation Agent
|
||||
│ └── S3 Bucket Exposure Reporting Agent
|
||||
│ └── Bucket Security Fixing Agent
|
||||
└── K8s Config Validation Agent
|
||||
└── Pod Security Reporting Agent
|
||||
└── Security Context Fixing Agent
|
||||
```
|
||||
WHITE-BOX TESTING - PHASE 1 (CODE UNDERSTANDING):
|
||||
- MAP entire repository structure and architecture
|
||||
- UNDERSTAND code flow, entry points, data flows
|
||||
- IDENTIFY all routes, endpoints, APIs, and their handlers
|
||||
- ANALYZE authentication, authorization, input validation logic
|
||||
- REVIEW dependencies and third-party libraries
|
||||
- ONLY AFTER full code comprehension → proceed to vulnerability testing
|
||||
|
||||
PHASE 2 - SYSTEMATIC VULNERABILITY TESTING:
|
||||
- CREATE SPECIALIZED SUBAGENT for EACH vulnerability type × EACH component
|
||||
- Each agent focuses on ONE vulnerability type in ONE specific location
|
||||
- EVERY detected vulnerability MUST spawn its own validation subagent
|
||||
|
||||
SIMPLE WORKFLOW RULES:
|
||||
|
||||
@@ -352,6 +214,9 @@ SIMPLE WORKFLOW RULES:
|
||||
4. **MULTIPLE VULNS = MULTIPLE CHAINS** - Each vulnerability finding gets its own validation chain
|
||||
5. **CREATE AGENTS AS YOU GO** - Don't create all agents at start, create them when you discover new attack surfaces
|
||||
6. **ONE JOB PER AGENT** - Each agent has ONE specific task only
|
||||
7. **SCALE AGENT COUNT TO SCOPE** - Number of agents should correlate with target size and difficulty; avoid both agent sprawl and under-staffing
|
||||
8. **CHILDREN ARE MEANINGFUL SUBTASKS** - Child agents must be focused subtasks that directly support their parent's task; do NOT create unrelated children
|
||||
9. **UNIQUENESS** - Do not create two agents with the same task; ensure clear, non-overlapping responsibilities for every agent
|
||||
|
||||
WHEN TO CREATE NEW AGENTS:
|
||||
|
||||
@@ -399,6 +264,27 @@ CRITICAL RULES:
|
||||
- **ONE AGENT = ONE TASK** - Don't let agents do multiple unrelated jobs
|
||||
- **SPAWN REACTIVELY** - Create new agents based on what you discover
|
||||
- **ONLY REPORTING AGENTS** can use create_vulnerability_report tool
|
||||
- **AGENT SPECIALIZATION MANDATORY** - Each agent must be highly specialized; prefer 1–3 skills, up to 5 for complex contexts
|
||||
- **NO GENERIC AGENTS** - Avoid creating broad, multi-purpose agents that dilute focus
|
||||
|
||||
AGENT SPECIALIZATION EXAMPLES:
|
||||
|
||||
GOOD SPECIALIZATION:
|
||||
- "SQLi Validation Agent" with skills: sql_injection
|
||||
- "XSS Discovery Agent" with skills: xss
|
||||
- "Auth Testing Agent" with skills: authentication_jwt, business_logic
|
||||
- "SSRF + XXE Agent" with skills: ssrf, xxe, rce (related attack vectors)
|
||||
|
||||
BAD SPECIALIZATION:
|
||||
- "General Web Testing Agent" with skills: sql_injection, xss, csrf, ssrf, authentication_jwt (too broad)
|
||||
- "Everything Agent" with skills: all available skills (completely unfocused)
|
||||
- Any agent with more than 5 skills (violates constraints)
|
||||
|
||||
FOCUS PRINCIPLES:
|
||||
- Each agent should have deep expertise in 1-3 related vulnerability types
|
||||
- Agents with single skills have the deepest specialization
|
||||
- Related vulnerabilities (like SSRF+XXE or Auth+Business Logic) can be combined
|
||||
- Never create "kitchen sink" agents that try to do everything
|
||||
|
||||
REALISTIC TESTING OUTCOMES:
|
||||
- **No Findings**: Agent completes testing but finds no vulnerabilities
|
||||
@@ -415,21 +301,39 @@ PERSISTENCE IS MANDATORY:
|
||||
</multi_agent_system>
|
||||
|
||||
<tool_usage>
|
||||
Tool calls use XML format:
|
||||
Tool call format:
|
||||
<function=tool_name>
|
||||
<parameter=param_name>value</parameter>
|
||||
</function>
|
||||
|
||||
CRITICAL RULES:
|
||||
1. One tool call per message
|
||||
0. While active in the agent loop, EVERY message you output MUST be a single tool call. Do not send plain text-only responses.
|
||||
1. Exactly one tool call per message — never include more than one <function>...</function> block in a single LLM message.
|
||||
2. Tool call must be last in message
|
||||
3. End response after </function> tag
|
||||
5. Thinking is NOT optional - it's required for reasoning and success
|
||||
3. EVERY tool call MUST end with </function>. This is MANDATORY. Never omit the closing tag. End your response immediately after </function>.
|
||||
4. Use ONLY the exact format shown above. NEVER use JSON/YAML/INI or any other syntax for tools or parameters.
|
||||
5. When sending ANY multi-line content in tool parameters, use real newlines (actual line breaks). Do NOT emit literal "\n" sequences. Literal "\n" instead of real line breaks will cause tools to fail.
|
||||
6. Tool names must match exactly the tool "name" defined (no module prefixes, dots, or variants).
|
||||
- Correct: <function=think> ... </function>
|
||||
- Incorrect: <thinking_tools.think> ... </function>
|
||||
- Incorrect: <think> ... </think>
|
||||
- Incorrect: {"think": {...}}
|
||||
7. Parameters must use <parameter=param_name>value</parameter> exactly. Do NOT pass parameters as JSON or key:value lines. Do NOT add quotes/braces around values.
|
||||
8. Do NOT wrap tool calls in markdown/code fences or add any text before or after the tool block.
|
||||
|
||||
Example (agent creation tool):
|
||||
<function=create_agent>
|
||||
<parameter=task>Perform targeted XSS testing on the search endpoint</parameter>
|
||||
<parameter=name>XSS Discovery Agent</parameter>
|
||||
<parameter=skills>xss</parameter>
|
||||
</function>
|
||||
|
||||
SPRAYING EXECUTION NOTE:
|
||||
- When performing large payload sprays or fuzzing, encapsulate the entire spraying loop inside a single python or terminal tool call (e.g., a Python script using asyncio/aiohttp). Do not issue one tool call per payload.
|
||||
- Favor batch-mode CLI tools (sqlmap, ffuf, nuclei, zaproxy, arjun) where appropriate and check traffic via the proxy when beneficial
|
||||
|
||||
REMINDER: Always close each tool call with </function> before going into the next. Incomplete tool calls will fail.
|
||||
|
||||
{{ get_tools_prompt() }}
|
||||
</tool_usage>
|
||||
|
||||
@@ -476,6 +380,7 @@ SPECIALIZED TOOLS:
|
||||
PROXY & INTERCEPTION:
|
||||
- Caido CLI - Modern web proxy (already running). Used with proxy tool or with python tool (functions already imported).
|
||||
- NOTE: If you are seeing proxy errors when sending requests, it usually means you are not sending requests to a correct url/host/port.
|
||||
- Ignore Caido proxy-generated 50x HTML error pages; these are proxy issues (might happen when requesting a wrong host or SSL/TLS issues, etc).
|
||||
|
||||
PROGRAMMING:
|
||||
- Python 3, Poetry, Go, Node.js/npm
|
||||
@@ -484,21 +389,19 @@ PROGRAMMING:
|
||||
- You can install any additional tools/packages needed based on the task/context using package managers (apt, pip, npm, go install, etc.)
|
||||
|
||||
Directories:
|
||||
- /workspace - Your private agent directory
|
||||
- /shared_workspace - Shared between agents
|
||||
- /workspace - where you should work.
|
||||
- /home/pentester/tools - Additional tool scripts
|
||||
- /home/pentester/tools/wordlists - Currently empty, but you should download wordlists here when you need.
|
||||
|
||||
Default user: pentester (sudo available)
|
||||
</environment>
|
||||
|
||||
{% if loaded_module_names %}
|
||||
{% if loaded_skill_names %}
|
||||
<specialized_knowledge>
|
||||
{# Dynamic prompt modules loaded based on agent specialization #}
|
||||
|
||||
{% for module_name in loaded_module_names %}
|
||||
{{ get_module(module_name) }}
|
||||
|
||||
{% for skill_name in loaded_skill_names %}
|
||||
<{{ skill_name }}>
|
||||
{{ get_skill(skill_name) }}
|
||||
</{{ skill_name }}>
|
||||
{% endfor %}
|
||||
</specialized_knowledge>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from strix.cli.tracer import Tracer
|
||||
from strix.telemetry.tracer import Tracer
|
||||
|
||||
from jinja2 import (
|
||||
Environment,
|
||||
@@ -13,9 +13,11 @@ from jinja2 import (
|
||||
select_autoescape,
|
||||
)
|
||||
|
||||
from strix.llm import LLM, LLMConfig
|
||||
from strix.llm import LLM, LLMConfig, LLMRequestFailedError
|
||||
from strix.llm.utils import clean_content
|
||||
from strix.runtime import SandboxInitializationError
|
||||
from strix.tools import process_tool_invocations
|
||||
from strix.utils.resource_paths import get_strix_resource_path
|
||||
|
||||
from .state import AgentState
|
||||
|
||||
@@ -33,8 +35,7 @@ class AgentMeta(type):
|
||||
if name == "BaseAgent":
|
||||
return new_cls
|
||||
|
||||
agents_dir = Path(__file__).parent
|
||||
prompt_dir = agents_dir / name
|
||||
prompt_dir = get_strix_resource_path("agents", name)
|
||||
|
||||
new_cls.agent_name = name
|
||||
new_cls.jinja_env = Environment(
|
||||
@@ -46,7 +47,7 @@ class AgentMeta(type):
|
||||
|
||||
|
||||
class BaseAgent(metaclass=AgentMeta):
|
||||
max_iterations = 200
|
||||
max_iterations = 300
|
||||
agent_name: str = ""
|
||||
jinja_env: Environment
|
||||
default_llm_config: LLMConfig | None = None
|
||||
@@ -54,7 +55,8 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
def __init__(self, config: dict[str, Any]):
|
||||
self.config = config
|
||||
|
||||
self.local_source_path = config.get("local_source_path")
|
||||
self.local_sources = config.get("local_sources", [])
|
||||
self.non_interactive = config.get("non_interactive", False)
|
||||
|
||||
if "max_iterations" in config:
|
||||
self.max_iterations = config["max_iterations"]
|
||||
@@ -63,20 +65,23 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
self.llm_config = config.get("llm_config", self.default_llm_config)
|
||||
if self.llm_config is None:
|
||||
raise ValueError("llm_config is required but not provided")
|
||||
self.llm = LLM(self.llm_config, agent_name=self.agent_name)
|
||||
|
||||
state_from_config = config.get("state")
|
||||
if state_from_config is not None:
|
||||
self.state = state_from_config
|
||||
else:
|
||||
self.state = AgentState(
|
||||
agent_name=self.agent_name,
|
||||
agent_name="Root Agent",
|
||||
max_iterations=self.max_iterations,
|
||||
)
|
||||
|
||||
self._current_task: asyncio.Task[Any] | None = None
|
||||
self.llm = LLM(self.llm_config, agent_name=self.agent_name)
|
||||
|
||||
from strix.cli.tracer import get_global_tracer
|
||||
with contextlib.suppress(Exception):
|
||||
self.llm.set_agent_identity(self.state.agent_name, self.state.agent_id)
|
||||
self._current_task: asyncio.Task[Any] | None = None
|
||||
self._force_stop = False
|
||||
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
@@ -141,19 +146,22 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
if self.state.parent_id is None and agents_graph_actions._root_agent_id is None:
|
||||
agents_graph_actions._root_agent_id = self.state.agent_id
|
||||
|
||||
def cancel_current_execution(self) -> None:
|
||||
if self._current_task and not self._current_task.done():
|
||||
self._current_task.cancel()
|
||||
self._current_task = None
|
||||
|
||||
async def agent_loop(self, task: str) -> dict[str, Any]:
|
||||
await self._initialize_sandbox_and_state(task)
|
||||
|
||||
from strix.cli.tracer import get_global_tracer
|
||||
async def agent_loop(self, task: str) -> dict[str, Any]: # noqa: PLR0912, PLR0915
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
|
||||
try:
|
||||
await self._initialize_sandbox_and_state(task)
|
||||
except SandboxInitializationError as e:
|
||||
return self._handle_sandbox_error(e, tracer)
|
||||
|
||||
while True:
|
||||
if self._force_stop:
|
||||
self._force_stop = False
|
||||
await self._enter_waiting_state(tracer, was_cancelled=True)
|
||||
continue
|
||||
|
||||
self._check_agent_messages(self.state)
|
||||
|
||||
if self.state.is_waiting_for_input():
|
||||
@@ -161,28 +169,111 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
continue
|
||||
|
||||
if self.state.should_stop():
|
||||
if self.non_interactive:
|
||||
return self.state.final_result or {}
|
||||
await self._enter_waiting_state(tracer)
|
||||
continue
|
||||
|
||||
if self.state.llm_failed:
|
||||
await self._wait_for_input()
|
||||
continue
|
||||
|
||||
self.state.increment_iteration()
|
||||
|
||||
if (
|
||||
self.state.is_approaching_max_iterations()
|
||||
and not self.state.max_iterations_warning_sent
|
||||
):
|
||||
self.state.max_iterations_warning_sent = True
|
||||
remaining = self.state.max_iterations - self.state.iteration
|
||||
warning_msg = (
|
||||
f"URGENT: You are approaching the maximum iteration limit. "
|
||||
f"Current: {self.state.iteration}/{self.state.max_iterations} "
|
||||
f"({remaining} iterations remaining). "
|
||||
f"Please prioritize completing your required task(s) and calling "
|
||||
f"the appropriate finish tool (finish_scan for root agent, "
|
||||
f"agent_finish for sub-agents) as soon as possible."
|
||||
)
|
||||
self.state.add_message("user", warning_msg)
|
||||
|
||||
if self.state.iteration == self.state.max_iterations - 3:
|
||||
final_warning_msg = (
|
||||
"CRITICAL: You have only 3 iterations left! "
|
||||
"Your next message MUST be the tool call to the appropriate "
|
||||
"finish tool: finish_scan if you are the root agent, or "
|
||||
"agent_finish if you are a sub-agent. "
|
||||
"No other actions should be taken except finishing your work "
|
||||
"immediately."
|
||||
)
|
||||
self.state.add_message("user", final_warning_msg)
|
||||
|
||||
try:
|
||||
should_finish = await self._process_iteration(tracer)
|
||||
iteration_task = asyncio.create_task(self._process_iteration(tracer))
|
||||
self._current_task = iteration_task
|
||||
should_finish = await iteration_task
|
||||
self._current_task = None
|
||||
|
||||
if should_finish:
|
||||
if self.non_interactive:
|
||||
self.state.set_completed({"success": True})
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "completed")
|
||||
return self.state.final_result or {}
|
||||
await self._enter_waiting_state(tracer, task_completed=True)
|
||||
continue
|
||||
|
||||
except asyncio.CancelledError:
|
||||
self._current_task = None
|
||||
if tracer:
|
||||
partial_content = tracer.finalize_streaming_as_interrupted(self.state.agent_id)
|
||||
if partial_content and partial_content.strip():
|
||||
self.state.add_message(
|
||||
"assistant", f"{partial_content}\n\n[ABORTED BY USER]"
|
||||
)
|
||||
if self.non_interactive:
|
||||
raise
|
||||
await self._enter_waiting_state(tracer, error_occurred=False, was_cancelled=True)
|
||||
continue
|
||||
|
||||
except LLMRequestFailedError as e:
|
||||
result = self._handle_llm_error(e, tracer)
|
||||
if result is not None:
|
||||
return result
|
||||
continue
|
||||
|
||||
except (RuntimeError, ValueError, TypeError) as e:
|
||||
if not await self._handle_iteration_error(e, tracer):
|
||||
if self.non_interactive:
|
||||
self.state.set_completed({"success": False, "error": str(e)})
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "failed")
|
||||
raise
|
||||
await self._enter_waiting_state(tracer, error_occurred=True)
|
||||
continue
|
||||
|
||||
async def _wait_for_input(self) -> None:
|
||||
import asyncio
|
||||
if self._force_stop:
|
||||
return
|
||||
|
||||
if self.state.has_waiting_timeout():
|
||||
self.state.resume_from_waiting()
|
||||
self.state.add_message("user", "Waiting timeout reached. Resuming execution.")
|
||||
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "running")
|
||||
|
||||
try:
|
||||
from strix.tools.agents_graph.agents_graph_actions import _agent_graph
|
||||
|
||||
if self.state.agent_id in _agent_graph["nodes"]:
|
||||
_agent_graph["nodes"][self.state.agent_id]["status"] = "running"
|
||||
except (ImportError, KeyError):
|
||||
pass
|
||||
|
||||
return
|
||||
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
@@ -231,13 +322,22 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
if not sandbox_mode and self.state.sandbox_id is None:
|
||||
from strix.runtime import get_runtime
|
||||
|
||||
runtime = get_runtime()
|
||||
sandbox_info = await runtime.create_sandbox(
|
||||
self.state.agent_id, self.state.sandbox_token, self.local_source_path
|
||||
)
|
||||
self.state.sandbox_id = sandbox_info["workspace_id"]
|
||||
self.state.sandbox_token = sandbox_info["auth_token"]
|
||||
self.state.sandbox_info = sandbox_info
|
||||
try:
|
||||
runtime = get_runtime()
|
||||
sandbox_info = await runtime.create_sandbox(
|
||||
self.state.agent_id, self.state.sandbox_token, self.local_sources
|
||||
)
|
||||
self.state.sandbox_id = sandbox_info["workspace_id"]
|
||||
self.state.sandbox_token = sandbox_info["auth_token"]
|
||||
self.state.sandbox_info = sandbox_info
|
||||
|
||||
if "agent_id" in sandbox_info:
|
||||
self.state.sandbox_info["agent_id"] = sandbox_info["agent_id"]
|
||||
except Exception as e:
|
||||
from strix.telemetry import posthog
|
||||
|
||||
posthog.error("sandbox_init_error", str(e))
|
||||
raise
|
||||
|
||||
if not self.state.task:
|
||||
self.state.task = task
|
||||
@@ -245,9 +345,17 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
self.state.add_message("user", task)
|
||||
|
||||
async def _process_iteration(self, tracer: Optional["Tracer"]) -> bool:
|
||||
response = await self.llm.generate(self.state.get_conversation_history())
|
||||
final_response = None
|
||||
|
||||
content_stripped = (response.content or "").strip()
|
||||
async for response in self.llm.generate(self.state.get_conversation_history()):
|
||||
final_response = response
|
||||
if tracer and response.content:
|
||||
tracer.update_streaming_content(self.state.agent_id, response.content)
|
||||
|
||||
if final_response is None:
|
||||
return False
|
||||
|
||||
content_stripped = (final_response.content or "").strip()
|
||||
|
||||
if not content_stripped:
|
||||
corrective_message = (
|
||||
@@ -263,17 +371,19 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
self.state.add_message("user", corrective_message)
|
||||
return False
|
||||
|
||||
self.state.add_message("assistant", response.content)
|
||||
thinking_blocks = getattr(final_response, "thinking_blocks", None)
|
||||
self.state.add_message("assistant", final_response.content, thinking_blocks=thinking_blocks)
|
||||
if tracer:
|
||||
tracer.clear_streaming_content(self.state.agent_id)
|
||||
tracer.log_chat_message(
|
||||
content=clean_content(response.content),
|
||||
content=clean_content(final_response.content),
|
||||
role="assistant",
|
||||
agent_id=self.state.agent_id,
|
||||
)
|
||||
|
||||
actions = (
|
||||
response.tool_invocations
|
||||
if hasattr(response, "tool_invocations") and response.tool_invocations
|
||||
final_response.tool_invocations
|
||||
if hasattr(final_response, "tool_invocations") and final_response.tool_invocations
|
||||
else []
|
||||
)
|
||||
|
||||
@@ -308,23 +418,13 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
self.state.set_completed({"success": True})
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "completed")
|
||||
if self.non_interactive and self.state.parent_id is None:
|
||||
return True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def _handle_iteration_error(
|
||||
self,
|
||||
error: RuntimeError | ValueError | TypeError | asyncio.CancelledError,
|
||||
tracer: Optional["Tracer"],
|
||||
) -> bool:
|
||||
error_msg = f"Error in iteration {self.state.iteration}: {error!s}"
|
||||
logger.exception(error_msg)
|
||||
self.state.add_error(error_msg)
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "error")
|
||||
return True
|
||||
|
||||
def _check_agent_messages(self, state: AgentState) -> None:
|
||||
def _check_agent_messages(self, state: AgentState) -> None: # noqa: PLR0912
|
||||
try:
|
||||
from strix.tools.agents_graph.agents_graph_actions import _agent_graph, _agent_messages
|
||||
|
||||
@@ -337,13 +437,29 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
has_new_messages = False
|
||||
for message in messages:
|
||||
if not message.get("read", False):
|
||||
if state.is_waiting_for_input():
|
||||
state.resume_from_waiting()
|
||||
has_new_messages = True
|
||||
|
||||
sender_name = "Unknown Agent"
|
||||
sender_id = message.get("from")
|
||||
|
||||
if state.is_waiting_for_input():
|
||||
if state.llm_failed:
|
||||
if sender_id == "user":
|
||||
state.resume_from_waiting()
|
||||
has_new_messages = True
|
||||
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
tracer.update_agent_status(state.agent_id, "running")
|
||||
else:
|
||||
state.resume_from_waiting()
|
||||
has_new_messages = True
|
||||
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
tracer.update_agent_status(state.agent_id, "running")
|
||||
|
||||
if sender_id == "user":
|
||||
sender_name = "User"
|
||||
state.add_message("user", message.get("content", ""))
|
||||
@@ -380,7 +496,7 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
message["read"] = True
|
||||
|
||||
if has_new_messages and not state.is_waiting_for_input():
|
||||
from strix.cli.tracer import get_global_tracer
|
||||
from strix.telemetry.tracer import get_global_tracer
|
||||
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
@@ -392,3 +508,95 @@ class BaseAgent(metaclass=AgentMeta):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning(f"Error checking agent messages: {e}")
|
||||
return
|
||||
|
||||
def _handle_sandbox_error(
|
||||
self,
|
||||
error: SandboxInitializationError,
|
||||
tracer: Optional["Tracer"],
|
||||
) -> dict[str, Any]:
|
||||
error_msg = str(error.message)
|
||||
error_details = error.details
|
||||
self.state.add_error(error_msg)
|
||||
|
||||
if self.non_interactive:
|
||||
self.state.set_completed({"success": False, "error": error_msg})
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "failed", error_msg)
|
||||
if error_details:
|
||||
exec_id = tracer.log_tool_execution_start(
|
||||
self.state.agent_id,
|
||||
"sandbox_error_details",
|
||||
{"error": error_msg, "details": error_details},
|
||||
)
|
||||
tracer.update_tool_execution(exec_id, "failed", {"details": error_details})
|
||||
return {"success": False, "error": error_msg, "details": error_details}
|
||||
|
||||
self.state.enter_waiting_state()
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "sandbox_failed", error_msg)
|
||||
if error_details:
|
||||
exec_id = tracer.log_tool_execution_start(
|
||||
self.state.agent_id,
|
||||
"sandbox_error_details",
|
||||
{"error": error_msg, "details": error_details},
|
||||
)
|
||||
tracer.update_tool_execution(exec_id, "failed", {"details": error_details})
|
||||
|
||||
return {"success": False, "error": error_msg, "details": error_details}
|
||||
|
||||
def _handle_llm_error(
|
||||
self,
|
||||
error: LLMRequestFailedError,
|
||||
tracer: Optional["Tracer"],
|
||||
) -> dict[str, Any] | None:
|
||||
error_msg = str(error)
|
||||
error_details = getattr(error, "details", None)
|
||||
self.state.add_error(error_msg)
|
||||
|
||||
if self.non_interactive:
|
||||
self.state.set_completed({"success": False, "error": error_msg})
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "failed", error_msg)
|
||||
if error_details:
|
||||
exec_id = tracer.log_tool_execution_start(
|
||||
self.state.agent_id,
|
||||
"llm_error_details",
|
||||
{"error": error_msg, "details": error_details},
|
||||
)
|
||||
tracer.update_tool_execution(exec_id, "failed", {"details": error_details})
|
||||
return {"success": False, "error": error_msg}
|
||||
|
||||
self.state.enter_waiting_state(llm_failed=True)
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "llm_failed", error_msg)
|
||||
if error_details:
|
||||
exec_id = tracer.log_tool_execution_start(
|
||||
self.state.agent_id,
|
||||
"llm_error_details",
|
||||
{"error": error_msg, "details": error_details},
|
||||
)
|
||||
tracer.update_tool_execution(exec_id, "failed", {"details": error_details})
|
||||
|
||||
return None
|
||||
|
||||
async def _handle_iteration_error(
|
||||
self,
|
||||
error: RuntimeError | ValueError | TypeError | asyncio.CancelledError,
|
||||
tracer: Optional["Tracer"],
|
||||
) -> bool:
|
||||
error_msg = f"Error in iteration {self.state.iteration}: {error!s}"
|
||||
logger.exception(error_msg)
|
||||
self.state.add_error(error_msg)
|
||||
if tracer:
|
||||
tracer.update_agent_status(self.state.agent_id, "error")
|
||||
return True
|
||||
|
||||
def cancel_current_execution(self) -> None:
|
||||
self._force_stop = True
|
||||
if self._current_task and not self._current_task.done():
|
||||
try:
|
||||
loop = self._current_task.get_loop()
|
||||
loop.call_soon_threadsafe(self._current_task.cancel)
|
||||
except RuntimeError:
|
||||
self._current_task.cancel()
|
||||
self._current_task = None
|
||||
|
||||
@@ -19,11 +19,14 @@ class AgentState(BaseModel):
|
||||
|
||||
task: str = ""
|
||||
iteration: int = 0
|
||||
max_iterations: int = 200
|
||||
max_iterations: int = 300
|
||||
completed: bool = False
|
||||
stop_requested: bool = False
|
||||
waiting_for_input: bool = False
|
||||
llm_failed: bool = False
|
||||
waiting_start_time: datetime | None = None
|
||||
final_result: dict[str, Any] | None = None
|
||||
max_iterations_warning_sent: bool = False
|
||||
|
||||
messages: list[dict[str, Any]] = Field(default_factory=list)
|
||||
context: dict[str, Any] = Field(default_factory=dict)
|
||||
@@ -40,8 +43,13 @@ class AgentState(BaseModel):
|
||||
self.iteration += 1
|
||||
self.last_updated = datetime.now(UTC).isoformat()
|
||||
|
||||
def add_message(self, role: str, content: Any) -> None:
|
||||
self.messages.append({"role": role, "content": content})
|
||||
def add_message(
|
||||
self, role: str, content: Any, thinking_blocks: list[dict[str, Any]] | None = None
|
||||
) -> None:
|
||||
message = {"role": role, "content": content}
|
||||
if thinking_blocks:
|
||||
message["thinking_blocks"] = thinking_blocks
|
||||
self.messages.append(message)
|
||||
self.last_updated = datetime.now(UTC).isoformat()
|
||||
|
||||
def add_action(self, action: dict[str, Any]) -> None:
|
||||
@@ -85,15 +93,18 @@ class AgentState(BaseModel):
|
||||
def is_waiting_for_input(self) -> bool:
|
||||
return self.waiting_for_input
|
||||
|
||||
def enter_waiting_state(self) -> None:
|
||||
def enter_waiting_state(self, llm_failed: bool = False) -> None:
|
||||
self.waiting_for_input = True
|
||||
self.stop_requested = False
|
||||
self.waiting_start_time = datetime.now(UTC)
|
||||
self.llm_failed = llm_failed
|
||||
self.last_updated = datetime.now(UTC).isoformat()
|
||||
|
||||
def resume_from_waiting(self, new_task: str | None = None) -> None:
|
||||
self.waiting_for_input = False
|
||||
self.waiting_start_time = None
|
||||
self.stop_requested = False
|
||||
self.completed = False
|
||||
self.llm_failed = False
|
||||
if new_task:
|
||||
self.task = new_task
|
||||
self.last_updated = datetime.now(UTC).isoformat()
|
||||
@@ -101,6 +112,24 @@ class AgentState(BaseModel):
|
||||
def has_reached_max_iterations(self) -> bool:
|
||||
return self.iteration >= self.max_iterations
|
||||
|
||||
def is_approaching_max_iterations(self, threshold: float = 0.85) -> bool:
|
||||
return self.iteration >= int(self.max_iterations * threshold)
|
||||
|
||||
def has_waiting_timeout(self) -> bool:
|
||||
if not self.waiting_for_input or not self.waiting_start_time:
|
||||
return False
|
||||
|
||||
if (
|
||||
self.stop_requested
|
||||
or self.llm_failed
|
||||
or self.completed
|
||||
or self.has_reached_max_iterations()
|
||||
):
|
||||
return False
|
||||
|
||||
elapsed = (datetime.now(UTC) - self.waiting_start_time).total_seconds()
|
||||
return elapsed > 600
|
||||
|
||||
def has_empty_last_messages(self, count: int = 3) -> bool:
|
||||
if len(self.messages) < count:
|
||||
return False
|
||||
|
||||
@@ -1,564 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Strix Agent Command Line Interface
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import secrets
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from urllib.parse import urlparse
|
||||
import shutil
|
||||
|
||||
import docker
|
||||
import litellm
|
||||
from docker.errors import DockerException
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
|
||||
from strix.cli.app import run_strix_cli
|
||||
from strix.cli.tracer import get_global_tracer
|
||||
from strix.runtime.docker_runtime import STRIX_IMAGE
|
||||
|
||||
|
||||
logging.getLogger().setLevel(logging.ERROR)
|
||||
|
||||
|
||||
def format_token_count(count: float) -> str:
|
||||
count = int(count)
|
||||
if count >= 1_000_000:
|
||||
return f"{count / 1_000_000:.1f}M"
|
||||
if count >= 1_000:
|
||||
return f"{count / 1_000:.1f}K"
|
||||
return str(count)
|
||||
|
||||
|
||||
def validate_environment() -> None:
|
||||
console = Console()
|
||||
missing_required_vars = []
|
||||
missing_optional_vars = []
|
||||
|
||||
if not os.getenv("STRIX_LLM"):
|
||||
missing_required_vars.append("STRIX_LLM")
|
||||
|
||||
if not os.getenv("LLM_API_KEY"):
|
||||
missing_required_vars.append("LLM_API_KEY")
|
||||
|
||||
if not os.getenv("PERPLEXITY_API_KEY"):
|
||||
missing_optional_vars.append("PERPLEXITY_API_KEY")
|
||||
|
||||
if missing_required_vars:
|
||||
error_text = Text()
|
||||
error_text.append("❌ ", style="bold red")
|
||||
error_text.append("MISSING REQUIRED ENVIRONMENT VARIABLES", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
|
||||
for var in missing_required_vars:
|
||||
error_text.append(f"• {var}", style="bold yellow")
|
||||
error_text.append(" is not set\n", style="white")
|
||||
|
||||
if missing_optional_vars:
|
||||
error_text.append(
|
||||
"\nOptional (but recommended) environment variables:\n", style="dim white"
|
||||
)
|
||||
for var in missing_optional_vars:
|
||||
error_text.append(f"• {var}", style="dim yellow")
|
||||
error_text.append(" is not set\n", style="dim white")
|
||||
|
||||
error_text.append("\nRequired environment variables:\n", style="white")
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("STRIX_LLM", style="bold cyan")
|
||||
error_text.append(
|
||||
" - Model name to use with litellm (e.g., 'anthropic/claude-opus-4-1-20250805')\n",
|
||||
style="white",
|
||||
)
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("LLM_API_KEY", style="bold cyan")
|
||||
error_text.append(" - API key for the LLM provider\n", style="white")
|
||||
|
||||
if missing_optional_vars:
|
||||
error_text.append("\nOptional environment variables:\n", style="white")
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("PERPLEXITY_API_KEY", style="bold cyan")
|
||||
error_text.append(
|
||||
" - API key for Perplexity AI web search (enables real-time research)\n",
|
||||
style="white",
|
||||
)
|
||||
|
||||
error_text.append("\nExample setup:\n", style="white")
|
||||
error_text.append(
|
||||
"export STRIX_LLM='anthropic/claude-opus-4-1-20250805'\n", style="dim white"
|
||||
)
|
||||
error_text.append("export LLM_API_KEY='your-api-key-here'\n", style="dim white")
|
||||
if missing_optional_vars:
|
||||
error_text.append(
|
||||
"export PERPLEXITY_API_KEY='your-perplexity-key-here'", style="dim white"
|
||||
)
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold red]🛡️ STRIX CONFIGURATION ERROR",
|
||||
title_align="center",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _validate_llm_response(response: Any) -> None:
|
||||
if not response or not response.choices or not response.choices[0].message.content:
|
||||
raise RuntimeError("Invalid response from LLM")
|
||||
|
||||
|
||||
def check_docker_installed() -> None:
|
||||
if shutil.which("docker") is None:
|
||||
console = Console()
|
||||
error_text = Text()
|
||||
error_text.append("❌ ", style="bold red")
|
||||
error_text.append("DOCKER NOT INSTALLED", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("The 'docker' CLI was not found in your PATH.\n", style="white")
|
||||
error_text.append("Please install Docker and ensure the 'docker' command is available.\n\n", style="white")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold red]🛡️ STRIX STARTUP ERROR",
|
||||
title_align="center",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n", panel, "\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
async def warm_up_llm() -> None:
|
||||
console = Console()
|
||||
|
||||
try:
|
||||
model_name = os.getenv("STRIX_LLM", "anthropic/claude-opus-4-1-20250805")
|
||||
api_key = os.getenv("LLM_API_KEY")
|
||||
|
||||
if api_key:
|
||||
litellm.api_key = api_key
|
||||
|
||||
test_messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Reply with just 'OK'."},
|
||||
]
|
||||
|
||||
response = litellm.completion(
|
||||
model=model_name,
|
||||
messages=test_messages,
|
||||
)
|
||||
|
||||
_validate_llm_response(response)
|
||||
|
||||
except Exception as e: # noqa: BLE001
|
||||
error_text = Text()
|
||||
error_text.append("❌ ", style="bold red")
|
||||
error_text.append("LLM CONNECTION FAILED", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("Could not establish connection to the language model.\n", style="white")
|
||||
error_text.append("Please check your configuration and try again.\n", style="white")
|
||||
error_text.append(f"\nError: {e}", style="dim white")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold red]🛡️ STRIX STARTUP ERROR",
|
||||
title_align="center",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def generate_run_name() -> str:
|
||||
# fmt: off
|
||||
adjectives = [
|
||||
"stealthy", "sneaky", "crafty", "elite", "phantom", "shadow", "silent",
|
||||
"rogue", "covert", "ninja", "ghost", "cyber", "digital", "binary",
|
||||
"encrypted", "obfuscated", "masked", "cloaked", "invisible", "anonymous"
|
||||
]
|
||||
nouns = [
|
||||
"exploit", "payload", "backdoor", "rootkit", "keylogger", "botnet", "trojan",
|
||||
"worm", "virus", "packet", "buffer", "shell", "daemon", "spider", "crawler",
|
||||
"scanner", "sniffer", "honeypot", "firewall", "breach"
|
||||
]
|
||||
# fmt: on
|
||||
adj = secrets.choice(adjectives)
|
||||
noun = secrets.choice(nouns)
|
||||
number = secrets.randbelow(900) + 100
|
||||
return f"{adj}-{noun}-{number}"
|
||||
|
||||
|
||||
def infer_target_type(target: str) -> tuple[str, dict[str, str]]:
|
||||
if not target or not isinstance(target, str):
|
||||
raise ValueError("Target must be a non-empty string")
|
||||
|
||||
target = target.strip()
|
||||
|
||||
parsed = urlparse(target)
|
||||
if parsed.scheme in ("http", "https"):
|
||||
if any(
|
||||
host in parsed.netloc.lower() for host in ["github.com", "gitlab.com", "bitbucket.org"]
|
||||
):
|
||||
return "repository", {"target_repo": target}
|
||||
return "web_application", {"target_url": target}
|
||||
|
||||
path = Path(target)
|
||||
try:
|
||||
if path.exists():
|
||||
if path.is_dir():
|
||||
return "local_code", {"target_path": str(path.absolute())}
|
||||
raise ValueError(f"Path exists but is not a directory: {target}")
|
||||
except (OSError, RuntimeError) as e:
|
||||
raise ValueError(f"Invalid path: {target} - {e!s}") from e
|
||||
|
||||
if target.startswith("git@") or target.endswith(".git"):
|
||||
return "repository", {"target_repo": target}
|
||||
|
||||
if "." in target and "/" not in target and not target.startswith("."):
|
||||
parts = target.split(".")
|
||||
if len(parts) >= 2 and all(p and p.strip() for p in parts):
|
||||
return "web_application", {"target_url": f"https://{target}"}
|
||||
|
||||
raise ValueError(
|
||||
f"Invalid target: {target}\n"
|
||||
"Target must be one of:\n"
|
||||
"- A valid URL (http:// or https://)\n"
|
||||
"- A Git repository URL (https://github.com/... or git@github.com:...)\n"
|
||||
"- A local directory path\n"
|
||||
"- A domain name (e.g., example.com)"
|
||||
)
|
||||
|
||||
|
||||
def parse_arguments() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Strix Multi-Agent Cybersecurity Scanner",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Web application scan
|
||||
strix --target https://example.com
|
||||
|
||||
# GitHub repository analysis
|
||||
strix --target https://github.com/user/repo
|
||||
strix --target git@github.com:user/repo.git
|
||||
|
||||
# Local code analysis
|
||||
strix --target ./my-project
|
||||
|
||||
# Domain scan
|
||||
strix --target example.com
|
||||
|
||||
# Custom instructions
|
||||
strix --target example.com --instruction "Focus on authentication vulnerabilities"
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--target",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Target to scan (URL, repository, local directory path, or domain name)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--instruction",
|
||||
type=str,
|
||||
help="Custom instructions for the scan. This can be "
|
||||
"specific vulnerability types to focus on (e.g., 'Focus on IDOR and XSS'), "
|
||||
"testing approaches (e.g., 'Perform thorough authentication testing'), "
|
||||
"test credentials (e.g., 'Use the following credentials to access the app: "
|
||||
"admin:password123'), "
|
||||
"or areas of interest (e.g., 'Check login API endpoint for security issues')",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--run-name",
|
||||
type=str,
|
||||
help="Custom name for this scan run",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
args.target_type, args.target_dict = infer_target_type(args.target)
|
||||
except ValueError as e:
|
||||
parser.error(str(e))
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def _build_stats_text(tracer: Any) -> Text:
|
||||
stats_text = Text()
|
||||
if not tracer:
|
||||
return stats_text
|
||||
|
||||
vuln_count = len(tracer.vulnerability_reports)
|
||||
tool_count = tracer.get_real_tool_count()
|
||||
agent_count = len(tracer.agents)
|
||||
|
||||
if vuln_count > 0:
|
||||
stats_text.append("🔍 Vulnerabilities Found: ", style="bold red")
|
||||
stats_text.append(str(vuln_count), style="bold yellow")
|
||||
stats_text.append(" • ", style="dim white")
|
||||
|
||||
stats_text.append("🤖 Agents Used: ", style="bold cyan")
|
||||
stats_text.append(str(agent_count), style="bold white")
|
||||
stats_text.append(" • ", style="dim white")
|
||||
stats_text.append("🛠️ Tools Called: ", style="bold cyan")
|
||||
stats_text.append(str(tool_count), style="bold white")
|
||||
|
||||
return stats_text
|
||||
|
||||
|
||||
def _build_llm_stats_text(tracer: Any) -> Text:
|
||||
llm_stats_text = Text()
|
||||
if not tracer:
|
||||
return llm_stats_text
|
||||
|
||||
llm_stats = tracer.get_total_llm_stats()
|
||||
total_stats = llm_stats["total"]
|
||||
|
||||
if total_stats["requests"] > 0:
|
||||
llm_stats_text.append("📥 Input Tokens: ", style="bold cyan")
|
||||
llm_stats_text.append(format_token_count(total_stats["input_tokens"]), style="bold white")
|
||||
|
||||
if total_stats["cached_tokens"] > 0:
|
||||
llm_stats_text.append(" • ", style="dim white")
|
||||
llm_stats_text.append("⚡ Cached: ", style="bold green")
|
||||
llm_stats_text.append(
|
||||
format_token_count(total_stats["cached_tokens"]), style="bold green"
|
||||
)
|
||||
|
||||
llm_stats_text.append(" • ", style="dim white")
|
||||
llm_stats_text.append("📤 Output Tokens: ", style="bold cyan")
|
||||
llm_stats_text.append(format_token_count(total_stats["output_tokens"]), style="bold white")
|
||||
|
||||
if total_stats["cost"] > 0:
|
||||
llm_stats_text.append(" • ", style="dim white")
|
||||
llm_stats_text.append("💰 Total Cost: $", style="bold cyan")
|
||||
llm_stats_text.append(f"{total_stats['cost']:.4f}", style="bold yellow")
|
||||
|
||||
return llm_stats_text
|
||||
|
||||
|
||||
def display_completion_message(args: argparse.Namespace, results_path: Path) -> None:
|
||||
console = Console()
|
||||
tracer = get_global_tracer()
|
||||
|
||||
target_value = next(iter(args.target_dict.values())) if args.target_dict else args.target
|
||||
|
||||
completion_text = Text()
|
||||
completion_text.append("🦉 ", style="bold white")
|
||||
completion_text.append("AGENT FINISHED", style="bold green")
|
||||
completion_text.append(" • ", style="dim white")
|
||||
completion_text.append("Security assessment completed", style="white")
|
||||
|
||||
stats_text = _build_stats_text(tracer)
|
||||
|
||||
llm_stats_text = _build_llm_stats_text(tracer)
|
||||
|
||||
target_text = Text()
|
||||
target_text.append("🎯 Target: ", style="bold cyan")
|
||||
target_text.append(str(target_value), style="bold white")
|
||||
|
||||
results_text = Text()
|
||||
results_text.append("📊 Results Saved To: ", style="bold cyan")
|
||||
results_text.append(str(results_path), style="bold yellow")
|
||||
|
||||
if stats_text.plain:
|
||||
if llm_stats_text.plain:
|
||||
panel_content = Text.assemble(
|
||||
completion_text,
|
||||
"\n\n",
|
||||
target_text,
|
||||
"\n",
|
||||
stats_text,
|
||||
"\n",
|
||||
llm_stats_text,
|
||||
"\n",
|
||||
results_text,
|
||||
)
|
||||
else:
|
||||
panel_content = Text.assemble(
|
||||
completion_text, "\n\n", target_text, "\n", stats_text, "\n", results_text
|
||||
)
|
||||
elif llm_stats_text.plain:
|
||||
panel_content = Text.assemble(
|
||||
completion_text, "\n\n", target_text, "\n", llm_stats_text, "\n", results_text
|
||||
)
|
||||
else:
|
||||
panel_content = Text.assemble(completion_text, "\n\n", target_text, "\n", results_text)
|
||||
|
||||
panel = Panel(
|
||||
panel_content,
|
||||
title="[bold green]🛡️ STRIX CYBERSECURITY AGENT",
|
||||
title_align="center",
|
||||
border_style="green",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
|
||||
|
||||
def _check_docker_connection() -> Any:
|
||||
try:
|
||||
return docker.from_env()
|
||||
except DockerException:
|
||||
console = Console()
|
||||
error_text = Text()
|
||||
error_text.append("❌ ", style="bold red")
|
||||
error_text.append("DOCKER NOT AVAILABLE", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("Cannot connect to Docker daemon.\n", style="white")
|
||||
error_text.append("Please ensure Docker is installed and running.\n\n", style="white")
|
||||
error_text.append("Try running: ", style="dim white")
|
||||
error_text.append("sudo systemctl start docker", style="dim cyan")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold red]🛡️ STRIX STARTUP ERROR",
|
||||
title_align="center",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n", panel, "\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _image_exists(client: Any) -> bool:
|
||||
try:
|
||||
client.images.get(STRIX_IMAGE)
|
||||
except docker.errors.ImageNotFound:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def _update_layer_status(layers_info: dict[str, str], layer_id: str, layer_status: str) -> None:
|
||||
if "Pull complete" in layer_status or "Already exists" in layer_status:
|
||||
layers_info[layer_id] = "✓"
|
||||
elif "Downloading" in layer_status:
|
||||
layers_info[layer_id] = "↓"
|
||||
elif "Extracting" in layer_status:
|
||||
layers_info[layer_id] = "📦"
|
||||
elif "Waiting" in layer_status:
|
||||
layers_info[layer_id] = "⏳"
|
||||
else:
|
||||
layers_info[layer_id] = "•"
|
||||
|
||||
|
||||
def _process_pull_line(
|
||||
line: dict[str, Any], layers_info: dict[str, str], status: Any, last_update: str
|
||||
) -> str:
|
||||
if "id" in line and "status" in line:
|
||||
layer_id = line["id"]
|
||||
_update_layer_status(layers_info, layer_id, line["status"])
|
||||
|
||||
completed = sum(1 for v in layers_info.values() if v == "✓")
|
||||
total = len(layers_info)
|
||||
|
||||
if total > 0:
|
||||
update_msg = f"[bold cyan]Progress: {completed}/{total} layers complete"
|
||||
if update_msg != last_update:
|
||||
status.update(update_msg)
|
||||
return update_msg
|
||||
|
||||
elif "status" in line and "id" not in line:
|
||||
global_status = line["status"]
|
||||
if "Pulling from" in global_status:
|
||||
status.update("[bold cyan]Fetching image manifest...")
|
||||
elif "Digest:" in global_status:
|
||||
status.update("[bold cyan]Verifying image...")
|
||||
elif "Status:" in global_status:
|
||||
status.update("[bold cyan]Finalizing...")
|
||||
|
||||
return last_update
|
||||
|
||||
|
||||
def pull_docker_image() -> None:
|
||||
console = Console()
|
||||
client = _check_docker_connection()
|
||||
|
||||
if _image_exists(client):
|
||||
return
|
||||
|
||||
console.print()
|
||||
console.print(f"[bold cyan]🐳 Pulling Docker image:[/bold cyan] {STRIX_IMAGE}")
|
||||
console.print(
|
||||
"[dim yellow]This only happens on first run and may take a few minutes...[/dim yellow]"
|
||||
)
|
||||
console.print()
|
||||
|
||||
with console.status("[bold cyan]Downloading image layers...", spinner="dots") as status:
|
||||
try:
|
||||
layers_info: dict[str, str] = {}
|
||||
last_update = ""
|
||||
|
||||
for line in client.api.pull(STRIX_IMAGE, stream=True, decode=True):
|
||||
last_update = _process_pull_line(line, layers_info, status, last_update)
|
||||
|
||||
except DockerException as e:
|
||||
console.print()
|
||||
error_text = Text()
|
||||
error_text.append("❌ ", style="bold red")
|
||||
error_text.append("FAILED TO PULL IMAGE", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append(f"Could not download: {STRIX_IMAGE}\n", style="white")
|
||||
error_text.append(str(e), style="dim red")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold red]🛡️ DOCKER PULL ERROR",
|
||||
title_align="center",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print(panel, "\n")
|
||||
sys.exit(1)
|
||||
|
||||
success_text = Text()
|
||||
success_text.append("✅ ", style="bold green")
|
||||
success_text.append("Successfully pulled Docker image", style="green")
|
||||
console.print(success_text)
|
||||
console.print()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if sys.platform == "win32":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
check_docker_installed()
|
||||
pull_docker_image()
|
||||
|
||||
validate_environment()
|
||||
asyncio.run(warm_up_llm())
|
||||
|
||||
args = parse_arguments()
|
||||
if not args.run_name:
|
||||
args.run_name = generate_run_name()
|
||||
|
||||
asyncio.run(run_strix_cli(args))
|
||||
|
||||
results_path = Path("agent_runs") / args.run_name
|
||||
display_completion_message(args, results_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,123 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewAgentGraphRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_agent_graph"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: ARG003
|
||||
content_text = "🕸️ [bold #fbbf24]Viewing agents graph[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateAgentRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_agent"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
task = args.get("task", "")
|
||||
name = args.get("name", "Agent")
|
||||
|
||||
header = f"🤖 [bold #fbbf24]Creating {name}[/]"
|
||||
|
||||
if task:
|
||||
task_display = task[:400] + "..." if len(task) > 400 else task
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(task_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Spawning agent...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SendMessageToAgentRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "send_message_to_agent"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
message = args.get("message", "")
|
||||
|
||||
header = "💬 [bold #fbbf24]Sending message[/]"
|
||||
|
||||
if message:
|
||||
message_display = message[:400] + "..." if len(message) > 400 else message
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(message_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Sending...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class AgentFinishRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "agent_finish"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
result_summary = args.get("result_summary", "")
|
||||
findings = args.get("findings", [])
|
||||
success = args.get("success", True)
|
||||
|
||||
header = (
|
||||
"🏁 [bold #fbbf24]Agent completed[/]" if success else "🏁 [bold #fbbf24]Agent failed[/]"
|
||||
)
|
||||
|
||||
if result_summary:
|
||||
content_parts = [f"{header}\n [bold]{cls.escape_markup(result_summary)}[/]"]
|
||||
|
||||
if findings and isinstance(findings, list):
|
||||
finding_lines = [f"• {finding}" for finding in findings]
|
||||
content_parts.append(
|
||||
f" [dim]{chr(10).join([cls.escape_markup(line) for line in finding_lines])}[/]"
|
||||
)
|
||||
|
||||
content_text = "\n".join(content_parts)
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Completing task...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class WaitForMessageRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "wait_for_message"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
reason = args.get("reason", "Waiting for messages from other agents or user input")
|
||||
|
||||
header = "⏸️ [bold #fbbf24]Waiting for messages[/]"
|
||||
|
||||
if reason:
|
||||
reason_display = reason[:400] + "..." if len(reason) > 400 else reason
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(reason_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Agent paused until message received...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,61 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class BaseToolRenderer(ABC):
|
||||
tool_name: ClassVar[str] = ""
|
||||
|
||||
css_classes: ClassVar[list[str]] = ["tool-call"]
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def escape_markup(cls, text: str) -> str:
|
||||
return text.replace("[", "\\[").replace("]", "\\]")
|
||||
|
||||
@classmethod
|
||||
def format_args(cls, args: dict[str, Any], max_length: int = 500) -> str:
|
||||
if not args:
|
||||
return ""
|
||||
|
||||
args_parts = []
|
||||
for k, v in args.items():
|
||||
str_v = str(v)
|
||||
if len(str_v) > max_length:
|
||||
str_v = str_v[: max_length - 3] + "..."
|
||||
args_parts.append(f" [dim]{k}:[/] {cls.escape_markup(str_v)}")
|
||||
return "\n".join(args_parts)
|
||||
|
||||
@classmethod
|
||||
def format_result(cls, result: Any, max_length: int = 1000) -> str:
|
||||
if result is None:
|
||||
return ""
|
||||
|
||||
str_result = str(result).strip()
|
||||
if not str_result:
|
||||
return ""
|
||||
|
||||
if len(str_result) > max_length:
|
||||
str_result = str_result[: max_length - 3] + "..."
|
||||
return cls.escape_markup(str_result)
|
||||
|
||||
@classmethod
|
||||
def get_status_icon(cls, status: str) -> str:
|
||||
status_icons = {
|
||||
"running": "[#f59e0b]●[/#f59e0b] In progress...",
|
||||
"completed": "[#22c55e]✓[/#22c55e] Done",
|
||||
"failed": "[#dc2626]✗[/#dc2626] Failed",
|
||||
"error": "[#dc2626]✗[/#dc2626] Error",
|
||||
}
|
||||
return status_icons.get(status, "[dim]○[/dim] Unknown")
|
||||
|
||||
@classmethod
|
||||
def get_css_classes(cls, status: str) -> str:
|
||||
base_classes = cls.css_classes.copy()
|
||||
base_classes.append(f"status-{status}")
|
||||
return " ".join(base_classes)
|
||||
@@ -1,107 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class BrowserRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "browser_action"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "browser-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
action = args.get("action", "unknown")
|
||||
|
||||
content = cls._build_sleek_content(action, args)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _build_sleek_content(cls, action: str, args: dict[str, Any]) -> str:
|
||||
browser_icon = "🌐"
|
||||
|
||||
url = args.get("url")
|
||||
text = args.get("text")
|
||||
js_code = args.get("js_code")
|
||||
|
||||
if action in [
|
||||
"launch",
|
||||
"goto",
|
||||
"new_tab",
|
||||
"type",
|
||||
"execute_js",
|
||||
"click",
|
||||
"double_click",
|
||||
"hover",
|
||||
]:
|
||||
if action == "launch":
|
||||
display_url = cls._format_url(url) if url else None
|
||||
message = (
|
||||
f"launching {display_url} on browser" if display_url else "launching browser"
|
||||
)
|
||||
elif action == "goto":
|
||||
display_url = cls._format_url(url) if url else None
|
||||
message = f"navigating to {display_url}" if display_url else "navigating"
|
||||
elif action == "new_tab":
|
||||
display_url = cls._format_url(url) if url else None
|
||||
message = f"opening tab {display_url}" if display_url else "opening tab"
|
||||
elif action == "type":
|
||||
display_text = cls._format_text(text) if text else None
|
||||
message = f"typing {display_text}" if display_text else "typing"
|
||||
elif action == "execute_js":
|
||||
display_js = cls._format_js(js_code) if js_code else None
|
||||
message = (
|
||||
f"executing javascript\n{display_js}" if display_js else "executing javascript"
|
||||
)
|
||||
else:
|
||||
action_words = {
|
||||
"click": "clicking",
|
||||
"double_click": "double clicking",
|
||||
"hover": "hovering",
|
||||
}
|
||||
message = action_words[action]
|
||||
|
||||
return f"{browser_icon} [#06b6d4]{message}[/]"
|
||||
|
||||
simple_actions = {
|
||||
"back": "going back in browser history",
|
||||
"forward": "going forward in browser history",
|
||||
"refresh": "refreshing browser tab",
|
||||
"close_tab": "closing browser tab",
|
||||
"switch_tab": "switching browser tab",
|
||||
"list_tabs": "listing browser tabs",
|
||||
"view_source": "viewing page source",
|
||||
"screenshot": "taking screenshot of browser tab",
|
||||
"wait": "waiting...",
|
||||
"close": "closing browser",
|
||||
}
|
||||
|
||||
if action in simple_actions:
|
||||
return f"{browser_icon} [#06b6d4]{simple_actions[action]}[/]"
|
||||
|
||||
return f"{browser_icon} [#06b6d4]{action}[/]"
|
||||
|
||||
@classmethod
|
||||
def _format_url(cls, url: str) -> str:
|
||||
if len(url) > 300:
|
||||
url = url[:297] + "..."
|
||||
return cls.escape_markup(url)
|
||||
|
||||
@classmethod
|
||||
def _format_text(cls, text: str) -> str:
|
||||
if len(text) > 200:
|
||||
text = text[:197] + "..."
|
||||
return cls.escape_markup(text)
|
||||
|
||||
@classmethod
|
||||
def _format_js(cls, js_code: str) -> str:
|
||||
if len(js_code) > 200:
|
||||
js_code = js_code[:197] + "..."
|
||||
return f"[white]{cls.escape_markup(js_code)}[/white]"
|
||||
@@ -1,95 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class StrReplaceEditorRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "str_replace_editor"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
command = args.get("command", "")
|
||||
path = args.get("path", "")
|
||||
|
||||
if command == "view":
|
||||
header = "📖 [bold #10b981]Reading file[/]"
|
||||
elif command == "str_replace":
|
||||
header = "✏️ [bold #10b981]Editing file[/]"
|
||||
elif command == "create":
|
||||
header = "📝 [bold #10b981]Creating file[/]"
|
||||
else:
|
||||
header = "📄 [bold #10b981]File operation[/]"
|
||||
|
||||
if (result and isinstance(result, dict) and "content" in result) or path:
|
||||
path_display = path[-60:] if len(path) > 60 else path
|
||||
content_text = f"{header} [dim]{cls.escape_markup(path_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header} [dim]Processing...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListFilesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_files"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
path = args.get("path", "")
|
||||
|
||||
header = "📂 [bold #10b981]Listing files[/]"
|
||||
|
||||
if path:
|
||||
path_display = path[-60:] if len(path) > 60 else path
|
||||
content_text = f"{header} [dim]{cls.escape_markup(path_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header} [dim]Current directory[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SearchFilesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "search_files"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
path = args.get("path", "")
|
||||
regex = args.get("regex", "")
|
||||
|
||||
header = "🔍 [bold purple]Searching files[/]"
|
||||
|
||||
if path and regex:
|
||||
path_display = path[-30:] if len(path) > 30 else path
|
||||
regex_display = regex[:30] if len(regex) > 30 else regex
|
||||
content_text = (
|
||||
f"{header} [dim]{cls.escape_markup(path_display)} for "
|
||||
f"'{cls.escape_markup(regex_display)}'[/]"
|
||||
)
|
||||
elif path:
|
||||
path_display = path[-60:] if len(path) > 60 else path
|
||||
content_text = f"{header} [dim]{cls.escape_markup(path_display)}[/]"
|
||||
elif regex:
|
||||
regex_display = regex[:60] if len(regex) > 60 else regex
|
||||
content_text = f"{header} [dim]'{cls.escape_markup(regex_display)}'[/]"
|
||||
else:
|
||||
content_text = f"{header} [dim]Searching...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,31 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class FinishScanRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "finish_scan"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "finish-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
content = args.get("content", "")
|
||||
success = args.get("success", True)
|
||||
|
||||
header = (
|
||||
"🏁 [bold #dc2626]Finishing Scan[/]" if success else "🏁 [bold #dc2626]Scan Failed[/]"
|
||||
)
|
||||
|
||||
if content:
|
||||
content_text = f"{header}\n [bold]{cls.escape_markup(content)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Generating final report...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,108 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
title = args.get("title", "")
|
||||
content = args.get("content", "")
|
||||
|
||||
header = "📝 [bold #fbbf24]Note[/]"
|
||||
|
||||
if title:
|
||||
title_display = title[:100] + "..." if len(title) > 100 else title
|
||||
note_parts = [f"{header}\n [bold]{cls.escape_markup(title_display)}[/]"]
|
||||
|
||||
if content:
|
||||
content_display = content[:200] + "..." if len(content) > 200 else content
|
||||
note_parts.append(f" [dim]{cls.escape_markup(content_display)}[/]")
|
||||
|
||||
content_text = "\n".join(note_parts)
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Creating note...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class DeleteNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "delete_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: ARG003
|
||||
header = "🗑️ [bold #fbbf24]Delete Note[/]"
|
||||
content_text = f"{header}\n [dim]Deleting...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class UpdateNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "update_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
title = args.get("title", "")
|
||||
content = args.get("content", "")
|
||||
|
||||
header = "✏️ [bold #fbbf24]Update Note[/]"
|
||||
|
||||
if title or content:
|
||||
note_parts = [header]
|
||||
|
||||
if title:
|
||||
title_display = title[:100] + "..." if len(title) > 100 else title
|
||||
note_parts.append(f" [bold]{cls.escape_markup(title_display)}[/]")
|
||||
|
||||
if content:
|
||||
content_display = content[:200] + "..." if len(content) > 200 else content
|
||||
note_parts.append(f" [dim]{cls.escape_markup(content_display)}[/]")
|
||||
|
||||
content_text = "\n".join(note_parts)
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Updating...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListNotesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_notes"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
header = "📋 [bold #fbbf24]Listing notes[/]"
|
||||
|
||||
if result and isinstance(result, dict) and "notes" in result:
|
||||
notes = result["notes"]
|
||||
if isinstance(notes, list):
|
||||
count = len(notes)
|
||||
content_text = f"{header}\n [dim]{count} notes found[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]No notes found[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Listing notes...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,255 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListRequestsRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_requests"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
httpql_filter = args.get("httpql_filter")
|
||||
|
||||
header = "📋 [bold #06b6d4]Listing requests[/]"
|
||||
|
||||
if result and isinstance(result, dict) and "requests" in result:
|
||||
requests = result["requests"]
|
||||
if isinstance(requests, list) and requests:
|
||||
request_lines = []
|
||||
for req in requests[:3]:
|
||||
if isinstance(req, dict):
|
||||
method = req.get("method", "?")
|
||||
path = req.get("path", "?")
|
||||
response = req.get("response") or {}
|
||||
status = response.get("statusCode", "?")
|
||||
line = f"{method} {path} → {status}"
|
||||
request_lines.append(line)
|
||||
|
||||
if len(requests) > 3:
|
||||
request_lines.append(f"... +{len(requests) - 3} more")
|
||||
|
||||
escaped_lines = [cls.escape_markup(line) for line in request_lines]
|
||||
content_text = f"{header}\n [dim]{chr(10).join(escaped_lines)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]No requests found[/]"
|
||||
elif httpql_filter:
|
||||
filter_display = (
|
||||
httpql_filter[:300] + "..." if len(httpql_filter) > 300 else httpql_filter
|
||||
)
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(filter_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]All requests[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
part = args.get("part", "request")
|
||||
|
||||
header = f"👀 [bold #06b6d4]Viewing {part}[/]"
|
||||
|
||||
if result and isinstance(result, dict):
|
||||
if "content" in result:
|
||||
content = result["content"]
|
||||
content_preview = content[:500] + "..." if len(content) > 500 else content
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(content_preview)}[/]"
|
||||
elif "matches" in result:
|
||||
matches = result["matches"]
|
||||
if isinstance(matches, list) and matches:
|
||||
match_lines = [
|
||||
match["match"]
|
||||
for match in matches[:3]
|
||||
if isinstance(match, dict) and "match" in match
|
||||
]
|
||||
if len(matches) > 3:
|
||||
match_lines.append(f"... +{len(matches) - 3} more matches")
|
||||
escaped_lines = [cls.escape_markup(line) for line in match_lines]
|
||||
content_text = f"{header}\n [dim]{chr(10).join(escaped_lines)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]No matches found[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Viewing content...[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Loading...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SendRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "send_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
method = args.get("method", "GET")
|
||||
url = args.get("url", "")
|
||||
|
||||
header = f"📤 [bold #06b6d4]Sending {method}[/]"
|
||||
|
||||
if result and isinstance(result, dict):
|
||||
status_code = result.get("status_code")
|
||||
response_body = result.get("body", "")
|
||||
|
||||
if status_code:
|
||||
response_preview = f"Status: {status_code}"
|
||||
if response_body:
|
||||
body_preview = (
|
||||
response_body[:300] + "..." if len(response_body) > 300 else response_body
|
||||
)
|
||||
response_preview += f"\n{body_preview}"
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(response_preview)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Response received[/]"
|
||||
elif url:
|
||||
url_display = url[:400] + "..." if len(url) > 400 else url
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(url_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Sending...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class RepeatRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "repeat_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
modifications = args.get("modifications", {})
|
||||
|
||||
header = "🔄 [bold #06b6d4]Repeating request[/]"
|
||||
|
||||
if result and isinstance(result, dict):
|
||||
status_code = result.get("status_code")
|
||||
response_body = result.get("body", "")
|
||||
|
||||
if status_code:
|
||||
response_preview = f"Status: {status_code}"
|
||||
if response_body:
|
||||
body_preview = (
|
||||
response_body[:300] + "..." if len(response_body) > 300 else response_body
|
||||
)
|
||||
response_preview += f"\n{body_preview}"
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(response_preview)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Response received[/]"
|
||||
elif modifications:
|
||||
mod_text = str(modifications)
|
||||
mod_display = mod_text[:400] + "..." if len(mod_text) > 400 else mod_text
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(mod_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]No modifications[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ScopeRulesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "scope_rules"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: ARG003
|
||||
header = "⚙️ [bold #06b6d4]Updating proxy scope[/]"
|
||||
content_text = f"{header}\n [dim]Configuring...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListSitemapRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_sitemap"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
header = "🗺️ [bold #06b6d4]Listing sitemap[/]"
|
||||
|
||||
if result and isinstance(result, dict) and "entries" in result:
|
||||
entries = result["entries"]
|
||||
if isinstance(entries, list) and entries:
|
||||
entry_lines = []
|
||||
for entry in entries[:4]:
|
||||
if isinstance(entry, dict):
|
||||
label = entry.get("label", "?")
|
||||
kind = entry.get("kind", "?")
|
||||
line = f"{kind}: {label}"
|
||||
entry_lines.append(line)
|
||||
|
||||
if len(entries) > 4:
|
||||
entry_lines.append(f"... +{len(entries) - 4} more")
|
||||
|
||||
escaped_lines = [cls.escape_markup(line) for line in entry_lines]
|
||||
content_text = f"{header}\n [dim]{chr(10).join(escaped_lines)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]No entries found[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Loading...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewSitemapEntryRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_sitemap_entry"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
header = "📍 [bold #06b6d4]Viewing sitemap entry[/]"
|
||||
|
||||
if result and isinstance(result, dict):
|
||||
if "entry" in result:
|
||||
entry = result["entry"]
|
||||
if isinstance(entry, dict):
|
||||
label = entry.get("label", "")
|
||||
kind = entry.get("kind", "")
|
||||
if label and kind:
|
||||
entry_info = f"{kind}: {label}"
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(entry_info)}[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Entry details loaded[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Entry details loaded[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Loading entry...[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Loading...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,34 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class PythonRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "python_action"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "python-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
action = args.get("action", "")
|
||||
code = args.get("code", "")
|
||||
|
||||
header = "</> [bold #3b82f6]Python[/]"
|
||||
|
||||
if code and action in ["new_session", "execute"]:
|
||||
code_display = code[:250] + "..." if len(code) > 250 else code
|
||||
content_text = f"{header}\n [italic white]{cls.escape_markup(code_display)}[/]"
|
||||
elif action == "close":
|
||||
content_text = f"{header}\n [dim]Closing session...[/]"
|
||||
elif action == "list_sessions":
|
||||
content_text = f"{header}\n [dim]Listing sessions...[/]"
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Running...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
@@ -1,52 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateVulnerabilityReportRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_vulnerability_report"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "reporting-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
title = args.get("title", "")
|
||||
severity = args.get("severity", "")
|
||||
content = args.get("content", "")
|
||||
|
||||
header = "🐞 [bold #ea580c]Vulnerability Report[/]"
|
||||
|
||||
if title:
|
||||
content_parts = [f"{header}\n [bold]{cls.escape_markup(title)}[/]"]
|
||||
|
||||
if severity:
|
||||
severity_color = cls._get_severity_color(severity.lower())
|
||||
content_parts.append(
|
||||
f" [dim]Severity: [{severity_color}]{severity.upper()}[/{severity_color}][/]"
|
||||
)
|
||||
|
||||
if content:
|
||||
content_parts.append(f" [dim]{cls.escape_markup(content)}[/]")
|
||||
|
||||
content_text = "\n".join(content_parts)
|
||||
else:
|
||||
content_text = f"{header}\n [dim]Creating report...[/]"
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _get_severity_color(cls, severity: str) -> str:
|
||||
severity_colors = {
|
||||
"critical": "#dc2626",
|
||||
"high": "#ea580c",
|
||||
"medium": "#d97706",
|
||||
"low": "#65a30d",
|
||||
"info": "#0284c7",
|
||||
}
|
||||
return severity_colors.get(severity, "#6b7280")
|
||||
@@ -1,57 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ScanStartInfoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "scan_start_info"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "scan-info-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
target = args.get("target", {})
|
||||
|
||||
target_display = cls._build_target_display(target)
|
||||
|
||||
content = f"🚀 Starting scan on {target_display}"
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _build_target_display(cls, target: dict[str, Any]) -> str:
|
||||
if target_url := target.get("target_url"):
|
||||
return f"[bold #22c55e]{target_url}[/bold #22c55e]"
|
||||
if target_repo := target.get("target_repo"):
|
||||
return f"[bold #22c55e]{target_repo}[/bold #22c55e]"
|
||||
if target_path := target.get("target_path"):
|
||||
return f"[bold #22c55e]{target_path}[/bold #22c55e]"
|
||||
return "[dim]unknown target[/dim]"
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SubagentStartInfoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "subagent_start_info"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "subagent-info-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
name = args.get("name", "Unknown Agent")
|
||||
task = args.get("task", "")
|
||||
|
||||
content = f"🤖 Spawned subagent [bold #22c55e]{name}[/bold #22c55e]"
|
||||
if task:
|
||||
content += f"\n Task: [dim]{task}[/dim]"
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
@@ -1,99 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class TerminalRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "terminal_action"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "terminal-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
result = tool_data.get("result", {})
|
||||
|
||||
action = args.get("action", "unknown")
|
||||
inputs = args.get("inputs", [])
|
||||
terminal_id = args.get("terminal_id", "default")
|
||||
|
||||
content = cls._build_sleek_content(action, inputs, terminal_id, result)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _build_sleek_content(
|
||||
cls,
|
||||
action: str,
|
||||
inputs: list[str],
|
||||
terminal_id: str, # noqa: ARG003
|
||||
result: dict[str, Any], # noqa: ARG003
|
||||
) -> str:
|
||||
terminal_icon = ">_"
|
||||
|
||||
if action in {"create", "new_terminal"}:
|
||||
command = cls._format_command(inputs) if inputs else "bash"
|
||||
return f"{terminal_icon} [#22c55e]${command}[/]"
|
||||
|
||||
if action == "send_input":
|
||||
command = cls._format_command(inputs)
|
||||
return f"{terminal_icon} [#22c55e]${command}[/]"
|
||||
|
||||
if action == "wait":
|
||||
return f"{terminal_icon} [dim]waiting...[/]"
|
||||
|
||||
if action == "close":
|
||||
return f"{terminal_icon} [dim]close[/]"
|
||||
|
||||
if action == "get_snapshot":
|
||||
return f"{terminal_icon} [dim]snapshot[/]"
|
||||
|
||||
return f"{terminal_icon} [dim]{action}[/]"
|
||||
|
||||
@classmethod
|
||||
def _format_command(cls, inputs: list[str]) -> str:
|
||||
if not inputs:
|
||||
return ""
|
||||
|
||||
command_parts = []
|
||||
|
||||
for input_item in inputs:
|
||||
if input_item == "Enter":
|
||||
break
|
||||
if input_item.startswith("literal:"):
|
||||
command_parts.append(input_item[8:])
|
||||
elif input_item in [
|
||||
"Space",
|
||||
"Tab",
|
||||
"Backspace",
|
||||
"Up",
|
||||
"Down",
|
||||
"Left",
|
||||
"Right",
|
||||
"Home",
|
||||
"End",
|
||||
"PageUp",
|
||||
"PageDown",
|
||||
"Insert",
|
||||
"Delete",
|
||||
"Escape",
|
||||
] or input_item.startswith(("^", "C-", "S-", "A-", "F")):
|
||||
if input_item == "Space":
|
||||
command_parts.append(" ")
|
||||
elif input_item == "Tab":
|
||||
command_parts.append("\t")
|
||||
continue
|
||||
else:
|
||||
command_parts.append(input_item)
|
||||
|
||||
command = "".join(command_parts).strip()
|
||||
|
||||
if len(command) > 200:
|
||||
command = command[:197] + "..."
|
||||
|
||||
return cls.escape_markup(command) if command else "bash"
|
||||
@@ -1,43 +0,0 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class UserMessageRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "user_message"
|
||||
css_classes: ClassVar[list[str]] = ["chat-message", "user-message"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, message_data: dict[str, Any]) -> Static:
|
||||
content = message_data.get("content", "")
|
||||
|
||||
if not content:
|
||||
return Static("", classes=cls.css_classes)
|
||||
|
||||
if len(content) > 300:
|
||||
content = content[:297] + "..."
|
||||
|
||||
lines = content.split("\n")
|
||||
bordered_lines = [f"[#3b82f6]▍[/#3b82f6] {line}" for line in lines]
|
||||
bordered_content = "\n".join(bordered_lines)
|
||||
formatted_content = f"[#3b82f6]▍[/#3b82f6] [bold]You:[/]\n{bordered_content}"
|
||||
|
||||
css_classes = " ".join(cls.css_classes)
|
||||
return Static(formatted_content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def render_simple(cls, content: str) -> str:
|
||||
if not content:
|
||||
return ""
|
||||
|
||||
if len(content) > 300:
|
||||
content = content[:297] + "..."
|
||||
|
||||
lines = content.split("\n")
|
||||
bordered_lines = [f"[#3b82f6]▍[/#3b82f6] {line}" for line in lines]
|
||||
bordered_content = "\n".join(bordered_lines)
|
||||
return f"[#3b82f6]▍[/#3b82f6] [bold]You:[/]\n{bordered_content}"
|
||||
@@ -1,307 +0,0 @@
|
||||
import logging
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_global_tracer: Optional["Tracer"] = None
|
||||
|
||||
|
||||
def get_global_tracer() -> Optional["Tracer"]:
|
||||
return _global_tracer
|
||||
|
||||
|
||||
def set_global_tracer(tracer: "Tracer") -> None:
|
||||
global _global_tracer # noqa: PLW0603
|
||||
_global_tracer = tracer
|
||||
|
||||
|
||||
class Tracer:
|
||||
def __init__(self, run_name: str | None = None):
|
||||
self.run_name = run_name
|
||||
self.run_id = run_name or f"run-{uuid4().hex[:8]}"
|
||||
self.start_time = datetime.now(UTC).isoformat()
|
||||
self.end_time: str | None = None
|
||||
|
||||
self.agents: dict[str, dict[str, Any]] = {}
|
||||
self.tool_executions: dict[int, dict[str, Any]] = {}
|
||||
self.chat_messages: list[dict[str, Any]] = []
|
||||
|
||||
self.vulnerability_reports: list[dict[str, Any]] = []
|
||||
self.final_scan_result: str | None = None
|
||||
|
||||
self.scan_results: dict[str, Any] | None = None
|
||||
self.scan_config: dict[str, Any] | None = None
|
||||
self.run_metadata: dict[str, Any] = {
|
||||
"run_id": self.run_id,
|
||||
"run_name": self.run_name,
|
||||
"start_time": self.start_time,
|
||||
"end_time": None,
|
||||
"target": None,
|
||||
"scan_type": None,
|
||||
"status": "running",
|
||||
}
|
||||
self._run_dir: Path | None = None
|
||||
self._next_execution_id = 1
|
||||
self._next_message_id = 1
|
||||
|
||||
def set_run_name(self, run_name: str) -> None:
|
||||
self.run_name = run_name
|
||||
self.run_id = run_name
|
||||
|
||||
def get_run_dir(self) -> Path:
|
||||
if self._run_dir is None:
|
||||
runs_dir = Path.cwd() / "agent_runs"
|
||||
runs_dir.mkdir(exist_ok=True)
|
||||
|
||||
run_dir_name = self.run_name if self.run_name else self.run_id
|
||||
self._run_dir = runs_dir / run_dir_name
|
||||
self._run_dir.mkdir(exist_ok=True)
|
||||
|
||||
return self._run_dir
|
||||
|
||||
def add_vulnerability_report(
|
||||
self,
|
||||
title: str,
|
||||
content: str,
|
||||
severity: str,
|
||||
) -> str:
|
||||
report_id = f"vuln-{len(self.vulnerability_reports) + 1:04d}"
|
||||
|
||||
report = {
|
||||
"id": report_id,
|
||||
"title": title.strip(),
|
||||
"content": content.strip(),
|
||||
"severity": severity.lower().strip(),
|
||||
"timestamp": datetime.now(UTC).strftime("%Y-%m-%d %H:%M:%S UTC"),
|
||||
}
|
||||
|
||||
self.vulnerability_reports.append(report)
|
||||
logger.info(f"Added vulnerability report: {report_id} - {title}")
|
||||
return report_id
|
||||
|
||||
def set_final_scan_result(
|
||||
self,
|
||||
content: str,
|
||||
success: bool = True,
|
||||
) -> None:
|
||||
self.final_scan_result = content.strip()
|
||||
|
||||
self.scan_results = {
|
||||
"scan_completed": True,
|
||||
"content": content,
|
||||
"success": success,
|
||||
}
|
||||
|
||||
logger.info(f"Set final scan result: success={success}")
|
||||
|
||||
def log_agent_creation(
|
||||
self, agent_id: str, name: str, task: str, parent_id: str | None = None
|
||||
) -> None:
|
||||
agent_data: dict[str, Any] = {
|
||||
"id": agent_id,
|
||||
"name": name,
|
||||
"task": task,
|
||||
"status": "running",
|
||||
"parent_id": parent_id,
|
||||
"created_at": datetime.now(UTC).isoformat(),
|
||||
"updated_at": datetime.now(UTC).isoformat(),
|
||||
"tool_executions": [],
|
||||
}
|
||||
|
||||
self.agents[agent_id] = agent_data
|
||||
|
||||
def log_chat_message(
|
||||
self,
|
||||
content: str,
|
||||
role: str,
|
||||
agent_id: str | None = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
) -> int:
|
||||
message_id = self._next_message_id
|
||||
self._next_message_id += 1
|
||||
|
||||
message_data = {
|
||||
"message_id": message_id,
|
||||
"content": content,
|
||||
"role": role,
|
||||
"agent_id": agent_id,
|
||||
"timestamp": datetime.now(UTC).isoformat(),
|
||||
"metadata": metadata or {},
|
||||
}
|
||||
|
||||
self.chat_messages.append(message_data)
|
||||
return message_id
|
||||
|
||||
def log_tool_execution_start(self, agent_id: str, tool_name: str, args: dict[str, Any]) -> int:
|
||||
execution_id = self._next_execution_id
|
||||
self._next_execution_id += 1
|
||||
|
||||
now = datetime.now(UTC).isoformat()
|
||||
execution_data = {
|
||||
"execution_id": execution_id,
|
||||
"agent_id": agent_id,
|
||||
"tool_name": tool_name,
|
||||
"args": args,
|
||||
"status": "running",
|
||||
"result": None,
|
||||
"timestamp": now,
|
||||
"started_at": now,
|
||||
"completed_at": None,
|
||||
}
|
||||
|
||||
self.tool_executions[execution_id] = execution_data
|
||||
|
||||
if agent_id in self.agents:
|
||||
self.agents[agent_id]["tool_executions"].append(execution_id)
|
||||
|
||||
return execution_id
|
||||
|
||||
def update_tool_execution(
|
||||
self, execution_id: int, status: str, result: Any | None = None
|
||||
) -> None:
|
||||
if execution_id in self.tool_executions:
|
||||
self.tool_executions[execution_id]["status"] = status
|
||||
self.tool_executions[execution_id]["result"] = result
|
||||
self.tool_executions[execution_id]["completed_at"] = datetime.now(UTC).isoformat()
|
||||
|
||||
def update_agent_status(self, agent_id: str, status: str) -> None:
|
||||
if agent_id in self.agents:
|
||||
self.agents[agent_id]["status"] = status
|
||||
self.agents[agent_id]["updated_at"] = datetime.now(UTC).isoformat()
|
||||
|
||||
def set_scan_config(self, config: dict[str, Any]) -> None:
|
||||
self.scan_config = config
|
||||
self.run_metadata.update(
|
||||
{
|
||||
"target": config.get("target", {}),
|
||||
"scan_type": config.get("scan_type", "general"),
|
||||
"user_instructions": config.get("user_instructions", ""),
|
||||
"max_iterations": config.get("max_iterations", 200),
|
||||
}
|
||||
)
|
||||
|
||||
def save_run_data(self) -> None:
|
||||
try:
|
||||
run_dir = self.get_run_dir()
|
||||
self.end_time = datetime.now(UTC).isoformat()
|
||||
|
||||
if self.final_scan_result:
|
||||
scan_report_file = run_dir / "scan_report.md"
|
||||
with scan_report_file.open("w", encoding="utf-8") as f:
|
||||
f.write("# Security Scan Report\n\n")
|
||||
f.write(
|
||||
f"**Generated:** {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')}\n\n"
|
||||
)
|
||||
f.write(f"{self.final_scan_result}\n")
|
||||
logger.info(f"Saved final scan report to: {scan_report_file}")
|
||||
|
||||
if self.vulnerability_reports:
|
||||
vuln_dir = run_dir / "vulnerabilities"
|
||||
vuln_dir.mkdir(exist_ok=True)
|
||||
|
||||
severity_order = {"critical": 0, "high": 1, "medium": 2, "low": 3, "info": 4}
|
||||
sorted_reports = sorted(
|
||||
self.vulnerability_reports,
|
||||
key=lambda x: (severity_order.get(x["severity"], 5), x["timestamp"]),
|
||||
)
|
||||
|
||||
for report in sorted_reports:
|
||||
vuln_file = vuln_dir / f"{report['id']}.md"
|
||||
with vuln_file.open("w", encoding="utf-8") as f:
|
||||
f.write(f"# {report['title']}\n\n")
|
||||
f.write(f"**ID:** {report['id']}\n")
|
||||
f.write(f"**Severity:** {report['severity'].upper()}\n")
|
||||
f.write(f"**Found:** {report['timestamp']}\n\n")
|
||||
f.write("## Description\n\n")
|
||||
f.write(f"{report['content']}\n")
|
||||
|
||||
vuln_csv_file = run_dir / "vulnerabilities.csv"
|
||||
with vuln_csv_file.open("w", encoding="utf-8", newline="") as f:
|
||||
import csv
|
||||
|
||||
fieldnames = ["id", "title", "severity", "timestamp", "file"]
|
||||
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
|
||||
for report in sorted_reports:
|
||||
writer.writerow(
|
||||
{
|
||||
"id": report["id"],
|
||||
"title": report["title"],
|
||||
"severity": report["severity"].upper(),
|
||||
"timestamp": report["timestamp"],
|
||||
"file": f"vulnerabilities/{report['id']}.md",
|
||||
}
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Saved {len(self.vulnerability_reports)} vulnerability reports to: {vuln_dir}"
|
||||
)
|
||||
logger.info(f"Saved vulnerability index to: {vuln_csv_file}")
|
||||
|
||||
logger.info(f"📊 Essential scan data saved to: {run_dir}")
|
||||
|
||||
except (OSError, RuntimeError):
|
||||
logger.exception("Failed to save scan data")
|
||||
|
||||
def _calculate_duration(self) -> float:
|
||||
try:
|
||||
start = datetime.fromisoformat(self.start_time.replace("Z", "+00:00"))
|
||||
if self.end_time:
|
||||
end = datetime.fromisoformat(self.end_time.replace("Z", "+00:00"))
|
||||
return (end - start).total_seconds()
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
return 0.0
|
||||
|
||||
def get_agent_tools(self, agent_id: str) -> list[dict[str, Any]]:
|
||||
return [
|
||||
exec_data
|
||||
for exec_data in self.tool_executions.values()
|
||||
if exec_data.get("agent_id") == agent_id
|
||||
]
|
||||
|
||||
def get_real_tool_count(self) -> int:
|
||||
return sum(
|
||||
1
|
||||
for exec_data in self.tool_executions.values()
|
||||
if exec_data.get("tool_name") not in ["scan_start_info", "subagent_start_info"]
|
||||
)
|
||||
|
||||
def get_total_llm_stats(self) -> dict[str, Any]:
|
||||
from strix.tools.agents_graph.agents_graph_actions import _agent_instances
|
||||
|
||||
total_stats = {
|
||||
"input_tokens": 0,
|
||||
"output_tokens": 0,
|
||||
"cached_tokens": 0,
|
||||
"cache_creation_tokens": 0,
|
||||
"cost": 0.0,
|
||||
"requests": 0,
|
||||
"failed_requests": 0,
|
||||
}
|
||||
|
||||
for agent_instance in _agent_instances.values():
|
||||
if hasattr(agent_instance, "llm") and hasattr(agent_instance.llm, "_total_stats"):
|
||||
agent_stats = agent_instance.llm._total_stats
|
||||
total_stats["input_tokens"] += agent_stats.input_tokens
|
||||
total_stats["output_tokens"] += agent_stats.output_tokens
|
||||
total_stats["cached_tokens"] += agent_stats.cached_tokens
|
||||
total_stats["cache_creation_tokens"] += agent_stats.cache_creation_tokens
|
||||
total_stats["cost"] += agent_stats.cost
|
||||
total_stats["requests"] += agent_stats.requests
|
||||
total_stats["failed_requests"] += agent_stats.failed_requests
|
||||
|
||||
total_stats["cost"] = round(total_stats["cost"], 4)
|
||||
|
||||
return {
|
||||
"total": total_stats,
|
||||
"total_tokens": total_stats["input_tokens"] + total_stats["output_tokens"],
|
||||
}
|
||||
|
||||
def cleanup(self) -> None:
|
||||
self.save_run_data()
|
||||
@@ -0,0 +1,12 @@
|
||||
from strix.config.config import (
|
||||
Config,
|
||||
apply_saved_config,
|
||||
save_current_config,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Config",
|
||||
"apply_saved_config",
|
||||
"save_current_config",
|
||||
]
|
||||
@@ -0,0 +1,209 @@
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
STRIX_API_BASE = "https://models.strix.ai/api/v1"
|
||||
|
||||
|
||||
class Config:
|
||||
"""Configuration Manager for Strix."""
|
||||
|
||||
# LLM Configuration
|
||||
strix_llm = None
|
||||
llm_api_key = None
|
||||
llm_api_base = None
|
||||
openai_api_base = None
|
||||
litellm_base_url = None
|
||||
ollama_api_base = None
|
||||
strix_reasoning_effort = "high"
|
||||
strix_llm_max_retries = "5"
|
||||
strix_memory_compressor_timeout = "30"
|
||||
llm_timeout = "300"
|
||||
_LLM_CANONICAL_NAMES = (
|
||||
"strix_llm",
|
||||
"llm_api_key",
|
||||
"llm_api_base",
|
||||
"openai_api_base",
|
||||
"litellm_base_url",
|
||||
"ollama_api_base",
|
||||
"strix_reasoning_effort",
|
||||
"strix_llm_max_retries",
|
||||
"strix_memory_compressor_timeout",
|
||||
"llm_timeout",
|
||||
)
|
||||
|
||||
# Tool & Feature Configuration
|
||||
perplexity_api_key = None
|
||||
strix_disable_browser = "false"
|
||||
|
||||
# Runtime Configuration
|
||||
strix_image = "ghcr.io/usestrix/strix-sandbox:0.1.11"
|
||||
strix_runtime_backend = "docker"
|
||||
strix_sandbox_execution_timeout = "120"
|
||||
strix_sandbox_connect_timeout = "10"
|
||||
|
||||
# Telemetry
|
||||
strix_telemetry = "1"
|
||||
|
||||
# Config file override (set via --config CLI arg)
|
||||
_config_file_override: Path | None = None
|
||||
|
||||
@classmethod
|
||||
def _tracked_names(cls) -> list[str]:
|
||||
return [
|
||||
k
|
||||
for k, v in vars(cls).items()
|
||||
if not k.startswith("_") and k[0].islower() and (v is None or isinstance(v, str))
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def tracked_vars(cls) -> list[str]:
|
||||
return [name.upper() for name in cls._tracked_names()]
|
||||
|
||||
@classmethod
|
||||
def _llm_env_vars(cls) -> set[str]:
|
||||
return {name.upper() for name in cls._LLM_CANONICAL_NAMES}
|
||||
|
||||
@classmethod
|
||||
def _llm_env_changed(cls, saved_env: dict[str, Any]) -> bool:
|
||||
for var_name in cls._llm_env_vars():
|
||||
current = os.getenv(var_name)
|
||||
if current is None:
|
||||
continue
|
||||
if saved_env.get(var_name) != current:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def get(cls, name: str) -> str | None:
|
||||
env_name = name.upper()
|
||||
default = getattr(cls, name, None)
|
||||
return os.getenv(env_name, default)
|
||||
|
||||
@classmethod
|
||||
def config_dir(cls) -> Path:
|
||||
return Path.home() / ".strix"
|
||||
|
||||
@classmethod
|
||||
def config_file(cls) -> Path:
|
||||
if cls._config_file_override is not None:
|
||||
return cls._config_file_override
|
||||
return cls.config_dir() / "cli-config.json"
|
||||
|
||||
@classmethod
|
||||
def load(cls) -> dict[str, Any]:
|
||||
path = cls.config_file()
|
||||
if not path.exists():
|
||||
return {}
|
||||
try:
|
||||
with path.open("r", encoding="utf-8") as f:
|
||||
data: dict[str, Any] = json.load(f)
|
||||
return data
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def save(cls, config: dict[str, Any]) -> bool:
|
||||
try:
|
||||
cls.config_dir().mkdir(parents=True, exist_ok=True)
|
||||
config_path = cls.config_dir() / "cli-config.json"
|
||||
with config_path.open("w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2)
|
||||
except OSError:
|
||||
return False
|
||||
with contextlib.suppress(OSError):
|
||||
config_path.chmod(0o600) # may fail on Windows
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def apply_saved(cls, force: bool = False) -> dict[str, str]:
|
||||
saved = cls.load()
|
||||
env_vars = saved.get("env", {})
|
||||
if not isinstance(env_vars, dict):
|
||||
env_vars = {}
|
||||
cleared_vars = {
|
||||
var_name
|
||||
for var_name in cls.tracked_vars()
|
||||
if var_name in os.environ and os.environ.get(var_name) == ""
|
||||
}
|
||||
if cleared_vars:
|
||||
for var_name in cleared_vars:
|
||||
env_vars.pop(var_name, None)
|
||||
if cls._config_file_override is None:
|
||||
cls.save({"env": env_vars})
|
||||
if cls._llm_env_changed(env_vars):
|
||||
for var_name in cls._llm_env_vars():
|
||||
env_vars.pop(var_name, None)
|
||||
if cls._config_file_override is None:
|
||||
cls.save({"env": env_vars})
|
||||
applied = {}
|
||||
|
||||
for var_name, var_value in env_vars.items():
|
||||
if var_name in cls.tracked_vars() and (force or var_name not in os.environ):
|
||||
os.environ[var_name] = var_value
|
||||
applied[var_name] = var_value
|
||||
|
||||
return applied
|
||||
|
||||
@classmethod
|
||||
def capture_current(cls) -> dict[str, Any]:
|
||||
env_vars = {}
|
||||
for var_name in cls.tracked_vars():
|
||||
value = os.getenv(var_name)
|
||||
if value:
|
||||
env_vars[var_name] = value
|
||||
return {"env": env_vars}
|
||||
|
||||
@classmethod
|
||||
def save_current(cls) -> bool:
|
||||
existing = cls.load().get("env", {})
|
||||
merged = dict(existing)
|
||||
|
||||
for var_name in cls.tracked_vars():
|
||||
value = os.getenv(var_name)
|
||||
if value is None:
|
||||
pass
|
||||
elif value == "":
|
||||
merged.pop(var_name, None)
|
||||
else:
|
||||
merged[var_name] = value
|
||||
|
||||
return cls.save({"env": merged})
|
||||
|
||||
|
||||
def apply_saved_config(force: bool = False) -> dict[str, str]:
|
||||
return Config.apply_saved(force=force)
|
||||
|
||||
|
||||
def save_current_config() -> bool:
|
||||
return Config.save_current()
|
||||
|
||||
|
||||
def resolve_llm_config() -> tuple[str | None, str | None, str | None]:
|
||||
"""Resolve LLM model, api_key, and api_base based on STRIX_LLM prefix.
|
||||
|
||||
Returns:
|
||||
tuple: (model_name, api_key, api_base)
|
||||
"""
|
||||
model = Config.get("strix_llm")
|
||||
if not model:
|
||||
return None, None, None
|
||||
|
||||
api_key = Config.get("llm_api_key")
|
||||
|
||||
if model.startswith("strix/"):
|
||||
model_name = "openai/" + model[6:]
|
||||
api_base: str | None = STRIX_API_BASE
|
||||
else:
|
||||
model_name = model
|
||||
api_base = (
|
||||
Config.get("llm_api_base")
|
||||
or Config.get("openai_api_base")
|
||||
or Config.get("litellm_base_url")
|
||||
or Config.get("ollama_api_base")
|
||||
)
|
||||
|
||||
return model_name, api_key, api_base
|
||||
@@ -1,13 +1,36 @@
|
||||
Screen {
|
||||
background: #1a1a1a;
|
||||
background: #000000;
|
||||
color: #d4d4d4;
|
||||
}
|
||||
|
||||
.screen--selection {
|
||||
background: #2d3d2f;
|
||||
color: #e5e5e5;
|
||||
}
|
||||
|
||||
ToastRack {
|
||||
dock: top;
|
||||
align: right top;
|
||||
margin-bottom: 0;
|
||||
margin-top: 1;
|
||||
}
|
||||
|
||||
Toast {
|
||||
width: 25;
|
||||
background: #000000;
|
||||
border-left: outer #22c55e;
|
||||
}
|
||||
|
||||
Toast.-information .toast--title {
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
#splash_screen {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background: #1a1a1a;
|
||||
background: #000000;
|
||||
color: #22c55e;
|
||||
align: center middle;
|
||||
content-align: center middle;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -17,6 +40,7 @@ Screen {
|
||||
height: auto;
|
||||
background: transparent;
|
||||
text-align: center;
|
||||
content-align: center middle;
|
||||
padding: 2;
|
||||
}
|
||||
|
||||
@@ -24,7 +48,7 @@ Screen {
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
background: #1a1a1a;
|
||||
background: #000000;
|
||||
}
|
||||
|
||||
#content_container {
|
||||
@@ -33,14 +57,142 @@ Screen {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#agents_tree {
|
||||
#sidebar {
|
||||
width: 20%;
|
||||
background: transparent;
|
||||
border: round #262626;
|
||||
margin-left: 1;
|
||||
}
|
||||
|
||||
#sidebar.-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#agents_tree {
|
||||
height: 1fr;
|
||||
background: transparent;
|
||||
border: round #333333;
|
||||
border-title-color: #a8a29e;
|
||||
border-title-style: bold;
|
||||
margin-left: 1;
|
||||
padding: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
#stats_display {
|
||||
height: auto;
|
||||
max-height: 15;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#vulnerabilities_panel {
|
||||
height: auto;
|
||||
max-height: 12;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: round #333333;
|
||||
overflow-y: auto;
|
||||
scrollbar-background: #000000;
|
||||
scrollbar-color: #333333;
|
||||
scrollbar-corner-color: #000000;
|
||||
scrollbar-size-vertical: 1;
|
||||
}
|
||||
|
||||
#vulnerabilities_panel.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.vuln-item {
|
||||
height: auto;
|
||||
width: 100%;
|
||||
padding: 0 1;
|
||||
background: transparent;
|
||||
color: #d4d4d4;
|
||||
}
|
||||
|
||||
.vuln-item:hover {
|
||||
background: #1a1a1a;
|
||||
color: #fafaf9;
|
||||
}
|
||||
|
||||
VulnerabilityDetailScreen {
|
||||
align: center middle;
|
||||
background: #000000 80%;
|
||||
}
|
||||
|
||||
#vuln_detail_dialog {
|
||||
grid-size: 1;
|
||||
grid-gutter: 1;
|
||||
grid-rows: 1fr auto;
|
||||
padding: 2 3;
|
||||
width: 85%;
|
||||
max-width: 110;
|
||||
height: 85%;
|
||||
max-height: 45;
|
||||
border: solid #262626;
|
||||
background: #0a0a0a;
|
||||
}
|
||||
|
||||
#vuln_detail_scroll {
|
||||
height: 1fr;
|
||||
background: transparent;
|
||||
scrollbar-background: #0a0a0a;
|
||||
scrollbar-color: #404040;
|
||||
scrollbar-corner-color: #0a0a0a;
|
||||
scrollbar-size: 1 1;
|
||||
padding-right: 1;
|
||||
}
|
||||
|
||||
#vuln_detail_content {
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#vuln_detail_buttons {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
align: right middle;
|
||||
padding-top: 1;
|
||||
margin: 0;
|
||||
border-top: solid #1a1a1a;
|
||||
}
|
||||
|
||||
#copy_vuln_detail {
|
||||
width: auto;
|
||||
min-width: 12;
|
||||
height: auto;
|
||||
background: transparent;
|
||||
color: #525252;
|
||||
border: none;
|
||||
text-style: none;
|
||||
margin: 0 1;
|
||||
padding: 0 2;
|
||||
}
|
||||
|
||||
#close_vuln_detail {
|
||||
width: auto;
|
||||
min-width: 10;
|
||||
height: auto;
|
||||
background: transparent;
|
||||
color: #a3a3a3;
|
||||
border: none;
|
||||
text-style: none;
|
||||
margin: 0;
|
||||
padding: 0 2;
|
||||
}
|
||||
|
||||
#copy_vuln_detail:hover, #copy_vuln_detail:focus {
|
||||
background: transparent;
|
||||
color: #22c55e;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#close_vuln_detail:hover, #close_vuln_detail:focus {
|
||||
background: transparent;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#chat_area_container {
|
||||
@@ -48,16 +200,20 @@ Screen {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#chat_area_container.-full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#chat_history {
|
||||
height: 1fr;
|
||||
background: transparent;
|
||||
border: round #1a1a1a;
|
||||
border: round #0a0a0a;
|
||||
padding: 0;
|
||||
margin-bottom: 0;
|
||||
margin-right: 0;
|
||||
scrollbar-background: #0f0f0f;
|
||||
scrollbar-color: #262626;
|
||||
scrollbar-corner-color: #0f0f0f;
|
||||
scrollbar-background: #000000;
|
||||
scrollbar-color: #1a1a1a;
|
||||
scrollbar-corner-color: #000000;
|
||||
scrollbar-size: 1 1;
|
||||
}
|
||||
|
||||
@@ -79,7 +235,7 @@ Screen {
|
||||
color: #a3a3a3;
|
||||
text-align: left;
|
||||
content-align: left middle;
|
||||
text-style: italic;
|
||||
text-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@@ -99,11 +255,11 @@ Screen {
|
||||
#chat_input_container {
|
||||
height: 3;
|
||||
background: transparent;
|
||||
border: round #525252;
|
||||
border: round #333333;
|
||||
margin-right: 0;
|
||||
padding: 0;
|
||||
layout: horizontal;
|
||||
align-vertical: middle;
|
||||
align-vertical: top;
|
||||
}
|
||||
|
||||
#chat_input_container:focus-within {
|
||||
@@ -120,7 +276,7 @@ Screen {
|
||||
height: 100%;
|
||||
padding: 0 0 0 1;
|
||||
color: #737373;
|
||||
content-align-vertical: middle;
|
||||
content-align-vertical: top;
|
||||
}
|
||||
|
||||
#chat_history:focus {
|
||||
@@ -130,7 +286,7 @@ Screen {
|
||||
#chat_input {
|
||||
width: 1fr;
|
||||
height: 100%;
|
||||
background: #121212;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #d4d4d4;
|
||||
padding: 0;
|
||||
@@ -141,6 +297,14 @@ Screen {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#chat_input .text-area--cursor-line {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#chat_input:focus .text-area--cursor-line {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#chat_input > .text-area--placeholder {
|
||||
color: #525252;
|
||||
text-style: italic;
|
||||
@@ -184,39 +348,31 @@ Screen {
|
||||
}
|
||||
|
||||
.tool-call {
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
padding: 0 1;
|
||||
background: #0a0a0a;
|
||||
border: round #1a1a1a;
|
||||
border-left: thick #f59e0b;
|
||||
background: transparent;
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tool-call.status-completed {
|
||||
border-left: thick #22c55e;
|
||||
background: #0d1f12;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
background: transparent;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.tool-call.status-running {
|
||||
border-left: thick #f59e0b;
|
||||
background: #1f1611;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
background: transparent;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.tool-call.status-failed,
|
||||
.tool-call.status-error {
|
||||
border-left: thick #ef4444;
|
||||
background: #1f0d0d;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
background: transparent;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.browser-tool,
|
||||
@@ -228,209 +384,54 @@ Screen {
|
||||
.notes-tool,
|
||||
.thinking-tool,
|
||||
.web-search-tool,
|
||||
.finish-tool,
|
||||
.reporting-tool,
|
||||
.scan-info-tool,
|
||||
.subagent-info-tool {
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.browser-tool {
|
||||
border-left: thick #06b6d4;
|
||||
}
|
||||
|
||||
.browser-tool.status-completed {
|
||||
border-left: thick #06b6d4;
|
||||
background: transparent;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.browser-tool.status-running {
|
||||
border-left: thick #0891b2;
|
||||
background: transparent;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.terminal-tool {
|
||||
border-left: thick #22c55e;
|
||||
}
|
||||
|
||||
.terminal-tool.status-completed {
|
||||
border-left: thick #22c55e;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.terminal-tool.status-running {
|
||||
border-left: thick #16a34a;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.python-tool {
|
||||
border-left: thick #3b82f6;
|
||||
}
|
||||
|
||||
.python-tool.status-completed {
|
||||
border-left: thick #3b82f6;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.python-tool.status-running {
|
||||
border-left: thick #2563eb;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.agents-graph-tool {
|
||||
border-left: thick #fbbf24;
|
||||
}
|
||||
|
||||
.agents-graph-tool.status-completed {
|
||||
border-left: thick #fbbf24;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.agents-graph-tool.status-running {
|
||||
border-left: thick #f59e0b;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.file-edit-tool {
|
||||
border-left: thick #10b981;
|
||||
}
|
||||
|
||||
.file-edit-tool.status-completed {
|
||||
border-left: thick #10b981;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.file-edit-tool.status-running {
|
||||
border-left: thick #059669;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.proxy-tool {
|
||||
border-left: thick #06b6d4;
|
||||
}
|
||||
|
||||
.proxy-tool.status-completed {
|
||||
border-left: thick #06b6d4;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.proxy-tool.status-running {
|
||||
border-left: thick #0891b2;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.notes-tool {
|
||||
border-left: thick #fbbf24;
|
||||
}
|
||||
|
||||
.notes-tool.status-completed {
|
||||
border-left: thick #fbbf24;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.notes-tool.status-running {
|
||||
border-left: thick #f59e0b;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.thinking-tool {
|
||||
border-left: thick #a855f7;
|
||||
}
|
||||
|
||||
.thinking-tool.status-completed {
|
||||
border-left: thick #a855f7;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.thinking-tool.status-running {
|
||||
border-left: thick #9333ea;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.web-search-tool {
|
||||
border-left: thick #22c55e;
|
||||
}
|
||||
|
||||
.web-search-tool.status-completed {
|
||||
border-left: thick #22c55e;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.web-search-tool.status-running {
|
||||
border-left: thick #16a34a;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.finish-tool {
|
||||
border-left: thick #dc2626;
|
||||
}
|
||||
|
||||
.finish-tool.status-completed {
|
||||
border-left: thick #dc2626;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.finish-tool.status-running {
|
||||
border-left: thick #b91c1c;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.finish-tool,
|
||||
.reporting-tool {
|
||||
border-left: thick #ea580c;
|
||||
}
|
||||
|
||||
.reporting-tool.status-completed {
|
||||
border-left: thick #ea580c;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.reporting-tool.status-running {
|
||||
border-left: thick #c2410c;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.scan-info-tool {
|
||||
border-left: thick #22c55e;
|
||||
background: transparent;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.scan-info-tool.status-completed {
|
||||
border-left: thick #22c55e;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.scan-info-tool.status-running {
|
||||
border-left: thick #16a34a;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.subagent-info-tool {
|
||||
border-left: thick #22c55e;
|
||||
background: transparent;
|
||||
margin: 0 !important;
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.subagent-info-tool.status-completed {
|
||||
border-left: thick #22c55e;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.browser-tool.status-completed,
|
||||
.browser-tool.status-running,
|
||||
.terminal-tool.status-completed,
|
||||
.terminal-tool.status-running,
|
||||
.python-tool.status-completed,
|
||||
.python-tool.status-running,
|
||||
.agents-graph-tool.status-completed,
|
||||
.agents-graph-tool.status-running,
|
||||
.file-edit-tool.status-completed,
|
||||
.file-edit-tool.status-running,
|
||||
.proxy-tool.status-completed,
|
||||
.proxy-tool.status-running,
|
||||
.notes-tool.status-completed,
|
||||
.notes-tool.status-running,
|
||||
.thinking-tool.status-completed,
|
||||
.thinking-tool.status-running,
|
||||
.web-search-tool.status-completed,
|
||||
.web-search-tool.status-running,
|
||||
.scan-info-tool.status-completed,
|
||||
.scan-info-tool.status-running,
|
||||
.subagent-info-tool.status-completed,
|
||||
.subagent-info-tool.status-running {
|
||||
border-left: thick #16a34a;
|
||||
background: transparent;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.finish-tool.status-completed,
|
||||
.finish-tool.status-running,
|
||||
.reporting-tool.status-completed,
|
||||
.reporting-tool.status-running {
|
||||
background: transparent;
|
||||
margin-top: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
Tree {
|
||||
@@ -448,7 +449,7 @@ Tree > .tree--label {
|
||||
background: transparent;
|
||||
padding: 0 1;
|
||||
margin-bottom: 1;
|
||||
border-bottom: solid #262626;
|
||||
border-bottom: solid #1a1a1a;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -488,7 +489,7 @@ Tree > .tree--label {
|
||||
}
|
||||
|
||||
Tree:focus {
|
||||
border: round #262626;
|
||||
border: round #1a1a1a;
|
||||
}
|
||||
|
||||
Tree:focus > .tree--label {
|
||||
@@ -532,7 +533,7 @@ StopAgentScreen {
|
||||
width: 30;
|
||||
height: auto;
|
||||
border: round #a3a3a3;
|
||||
background: #1a1a1a 98%;
|
||||
background: #000000 98%;
|
||||
}
|
||||
|
||||
#stop_agent_title {
|
||||
@@ -594,8 +595,8 @@ QuitScreen {
|
||||
padding: 1;
|
||||
width: 24;
|
||||
height: auto;
|
||||
border: round #525252;
|
||||
background: #1a1a1a 98%;
|
||||
border: round #333333;
|
||||
background: #000000 98%;
|
||||
}
|
||||
|
||||
#quit_title {
|
||||
@@ -658,7 +659,7 @@ HelpScreen {
|
||||
width: 40;
|
||||
height: auto;
|
||||
border: round #22c55e;
|
||||
background: #1a1a1a 98%;
|
||||
background: #000000 98%;
|
||||
}
|
||||
|
||||
#help_title {
|
||||
@@ -0,0 +1,202 @@
|
||||
import atexit
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from rich.console import Console
|
||||
from rich.live import Live
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
|
||||
from strix.agents.StrixAgent import StrixAgent
|
||||
from strix.llm.config import LLMConfig
|
||||
from strix.telemetry.tracer import Tracer, set_global_tracer
|
||||
|
||||
from .utils import (
|
||||
build_live_stats_text,
|
||||
format_vulnerability_report,
|
||||
)
|
||||
|
||||
|
||||
async def run_cli(args: Any) -> None: # noqa: PLR0915
|
||||
console = Console()
|
||||
|
||||
start_text = Text()
|
||||
start_text.append("Penetration test initiated", style="bold #22c55e")
|
||||
|
||||
target_text = Text()
|
||||
target_text.append("Target", style="dim")
|
||||
target_text.append(" ")
|
||||
if len(args.targets_info) == 1:
|
||||
target_text.append(args.targets_info[0]["original"], style="bold white")
|
||||
else:
|
||||
target_text.append(f"{len(args.targets_info)} targets", style="bold white")
|
||||
for target_info in args.targets_info:
|
||||
target_text.append("\n ")
|
||||
target_text.append(target_info["original"], style="white")
|
||||
|
||||
results_text = Text()
|
||||
results_text.append("Output", style="dim")
|
||||
results_text.append(" ")
|
||||
results_text.append(f"strix_runs/{args.run_name}", style="#60a5fa")
|
||||
|
||||
note_text = Text()
|
||||
note_text.append("\n\n", style="dim")
|
||||
note_text.append("Vulnerabilities will be displayed in real-time.", style="dim")
|
||||
|
||||
startup_panel = Panel(
|
||||
Text.assemble(
|
||||
start_text,
|
||||
"\n\n",
|
||||
target_text,
|
||||
"\n",
|
||||
results_text,
|
||||
note_text,
|
||||
),
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="#22c55e",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(startup_panel)
|
||||
console.print()
|
||||
|
||||
scan_mode = getattr(args, "scan_mode", "deep")
|
||||
|
||||
scan_config = {
|
||||
"scan_id": args.run_name,
|
||||
"targets": args.targets_info,
|
||||
"user_instructions": args.instruction or "",
|
||||
"run_name": args.run_name,
|
||||
}
|
||||
|
||||
llm_config = LLMConfig(scan_mode=scan_mode)
|
||||
agent_config = {
|
||||
"llm_config": llm_config,
|
||||
"max_iterations": 300,
|
||||
"non_interactive": True,
|
||||
}
|
||||
|
||||
if getattr(args, "local_sources", None):
|
||||
agent_config["local_sources"] = args.local_sources
|
||||
|
||||
tracer = Tracer(args.run_name)
|
||||
tracer.set_scan_config(scan_config)
|
||||
|
||||
def display_vulnerability(report: dict[str, Any]) -> None:
|
||||
report_id = report.get("id", "unknown")
|
||||
|
||||
vuln_text = format_vulnerability_report(report)
|
||||
|
||||
vuln_panel = Panel(
|
||||
vuln_text,
|
||||
title=f"[bold red]{report_id.upper()}",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print(vuln_panel)
|
||||
console.print()
|
||||
|
||||
tracer.vulnerability_found_callback = display_vulnerability
|
||||
|
||||
def cleanup_on_exit() -> None:
|
||||
from strix.runtime import cleanup_runtime
|
||||
|
||||
tracer.cleanup()
|
||||
cleanup_runtime()
|
||||
|
||||
def signal_handler(_signum: int, _frame: Any) -> None:
|
||||
tracer.cleanup()
|
||||
sys.exit(1)
|
||||
|
||||
atexit.register(cleanup_on_exit)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
if hasattr(signal, "SIGHUP"):
|
||||
signal.signal(signal.SIGHUP, signal_handler)
|
||||
|
||||
set_global_tracer(tracer)
|
||||
|
||||
def create_live_status() -> Panel:
|
||||
status_text = Text()
|
||||
status_text.append("Penetration test in progress", style="bold #22c55e")
|
||||
status_text.append("\n\n")
|
||||
|
||||
stats_text = build_live_stats_text(tracer, agent_config)
|
||||
if stats_text:
|
||||
status_text.append(stats_text)
|
||||
|
||||
return Panel(
|
||||
status_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="#22c55e",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
try:
|
||||
console.print()
|
||||
|
||||
with Live(
|
||||
create_live_status(), console=console, refresh_per_second=2, transient=False
|
||||
) as live:
|
||||
stop_updates = threading.Event()
|
||||
|
||||
def update_status() -> None:
|
||||
while not stop_updates.is_set():
|
||||
try:
|
||||
live.update(create_live_status())
|
||||
time.sleep(2)
|
||||
except Exception: # noqa: BLE001
|
||||
break
|
||||
|
||||
update_thread = threading.Thread(target=update_status, daemon=True)
|
||||
update_thread.start()
|
||||
|
||||
try:
|
||||
agent = StrixAgent(agent_config)
|
||||
result = await agent.execute_scan(scan_config)
|
||||
|
||||
if isinstance(result, dict) and not result.get("success", True):
|
||||
error_msg = result.get("error", "Unknown error")
|
||||
error_details = result.get("details")
|
||||
console.print()
|
||||
console.print(f"[bold red]Penetration test failed:[/] {error_msg}")
|
||||
if error_details:
|
||||
console.print(f"[dim]{error_details}[/]")
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
finally:
|
||||
stop_updates.set()
|
||||
update_thread.join(timeout=1)
|
||||
|
||||
except Exception as e:
|
||||
console.print(f"[bold red]Error during penetration test:[/] {e}")
|
||||
raise
|
||||
|
||||
if tracer.final_scan_result:
|
||||
console.print()
|
||||
|
||||
final_report_text = Text()
|
||||
final_report_text.append("Penetration test summary", style="bold #60a5fa")
|
||||
|
||||
final_report_panel = Panel(
|
||||
Text.assemble(
|
||||
final_report_text,
|
||||
"\n\n",
|
||||
tracer.final_scan_result,
|
||||
),
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="#60a5fa",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print(final_report_panel)
|
||||
console.print()
|
||||
@@ -0,0 +1,586 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Strix Agent Interface
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import litellm
|
||||
from docker.errors import DockerException
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
|
||||
from strix.config import Config, apply_saved_config, save_current_config
|
||||
|
||||
|
||||
apply_saved_config()
|
||||
|
||||
from strix.interface.cli import run_cli # noqa: E402
|
||||
from strix.interface.tui import run_tui # noqa: E402
|
||||
from strix.interface.utils import ( # noqa: E402
|
||||
assign_workspace_subdirs,
|
||||
build_final_stats_text,
|
||||
check_docker_connection,
|
||||
clone_repository,
|
||||
collect_local_sources,
|
||||
generate_run_name,
|
||||
image_exists,
|
||||
infer_target_type,
|
||||
process_pull_line,
|
||||
rewrite_localhost_targets,
|
||||
validate_config_file,
|
||||
validate_llm_response,
|
||||
)
|
||||
from strix.runtime.docker_runtime import HOST_GATEWAY_HOSTNAME # noqa: E402
|
||||
from strix.telemetry import posthog # noqa: E402
|
||||
from strix.telemetry.tracer import get_global_tracer # noqa: E402
|
||||
|
||||
|
||||
logging.getLogger().setLevel(logging.ERROR)
|
||||
|
||||
|
||||
def validate_environment() -> None: # noqa: PLR0912, PLR0915
|
||||
console = Console()
|
||||
missing_required_vars = []
|
||||
missing_optional_vars = []
|
||||
|
||||
strix_llm = Config.get("strix_llm")
|
||||
uses_strix_models = strix_llm and strix_llm.startswith("strix/")
|
||||
|
||||
if not strix_llm:
|
||||
missing_required_vars.append("STRIX_LLM")
|
||||
|
||||
has_base_url = uses_strix_models or any(
|
||||
[
|
||||
Config.get("llm_api_base"),
|
||||
Config.get("openai_api_base"),
|
||||
Config.get("litellm_base_url"),
|
||||
Config.get("ollama_api_base"),
|
||||
]
|
||||
)
|
||||
|
||||
if not Config.get("llm_api_key"):
|
||||
missing_optional_vars.append("LLM_API_KEY")
|
||||
|
||||
if not has_base_url:
|
||||
missing_optional_vars.append("LLM_API_BASE")
|
||||
|
||||
if not Config.get("perplexity_api_key"):
|
||||
missing_optional_vars.append("PERPLEXITY_API_KEY")
|
||||
|
||||
if not Config.get("strix_reasoning_effort"):
|
||||
missing_optional_vars.append("STRIX_REASONING_EFFORT")
|
||||
|
||||
if missing_required_vars:
|
||||
error_text = Text()
|
||||
error_text.append("MISSING REQUIRED ENVIRONMENT VARIABLES", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
|
||||
for var in missing_required_vars:
|
||||
error_text.append(f"• {var}", style="bold yellow")
|
||||
error_text.append(" is not set\n", style="white")
|
||||
|
||||
if missing_optional_vars:
|
||||
error_text.append("\nOptional environment variables:\n", style="dim white")
|
||||
for var in missing_optional_vars:
|
||||
error_text.append(f"• {var}", style="dim yellow")
|
||||
error_text.append(" is not set\n", style="dim white")
|
||||
|
||||
error_text.append("\nRequired environment variables:\n", style="white")
|
||||
for var in missing_required_vars:
|
||||
if var == "STRIX_LLM":
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("STRIX_LLM", style="bold cyan")
|
||||
error_text.append(
|
||||
" - Model name to use with litellm (e.g., 'anthropic/claude-sonnet-4-6')\n",
|
||||
style="white",
|
||||
)
|
||||
|
||||
if missing_optional_vars:
|
||||
error_text.append("\nOptional environment variables:\n", style="white")
|
||||
for var in missing_optional_vars:
|
||||
if var == "LLM_API_KEY":
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("LLM_API_KEY", style="bold cyan")
|
||||
error_text.append(
|
||||
" - API key for the LLM provider "
|
||||
"(not needed for local models, Vertex AI, AWS, etc.)\n",
|
||||
style="white",
|
||||
)
|
||||
elif var == "LLM_API_BASE":
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("LLM_API_BASE", style="bold cyan")
|
||||
error_text.append(
|
||||
" - Custom API base URL if using local models (e.g., Ollama, LMStudio)\n",
|
||||
style="white",
|
||||
)
|
||||
elif var == "PERPLEXITY_API_KEY":
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("PERPLEXITY_API_KEY", style="bold cyan")
|
||||
error_text.append(
|
||||
" - API key for Perplexity AI web search (enables real-time research)\n",
|
||||
style="white",
|
||||
)
|
||||
elif var == "STRIX_REASONING_EFFORT":
|
||||
error_text.append("• ", style="white")
|
||||
error_text.append("STRIX_REASONING_EFFORT", style="bold cyan")
|
||||
error_text.append(
|
||||
" - Reasoning effort level: none, minimal, low, medium, high, xhigh "
|
||||
"(default: high)\n",
|
||||
style="white",
|
||||
)
|
||||
|
||||
error_text.append("\nExample setup:\n", style="white")
|
||||
if uses_strix_models:
|
||||
error_text.append("export STRIX_LLM='strix/claude-sonnet-4.6'\n", style="dim white")
|
||||
else:
|
||||
error_text.append("export STRIX_LLM='anthropic/claude-sonnet-4-6'\n", style="dim white")
|
||||
|
||||
if missing_optional_vars:
|
||||
for var in missing_optional_vars:
|
||||
if var == "LLM_API_KEY":
|
||||
error_text.append(
|
||||
"export LLM_API_KEY='your-api-key-here' "
|
||||
"# not needed for local models, Vertex AI, AWS, etc.\n",
|
||||
style="dim white",
|
||||
)
|
||||
elif var == "LLM_API_BASE":
|
||||
error_text.append(
|
||||
"export LLM_API_BASE='http://localhost:11434' "
|
||||
"# needed for local models only\n",
|
||||
style="dim white",
|
||||
)
|
||||
elif var == "PERPLEXITY_API_KEY":
|
||||
error_text.append(
|
||||
"export PERPLEXITY_API_KEY='your-perplexity-key-here'\n", style="dim white"
|
||||
)
|
||||
elif var == "STRIX_REASONING_EFFORT":
|
||||
error_text.append(
|
||||
"export STRIX_REASONING_EFFORT='high'\n",
|
||||
style="dim white",
|
||||
)
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_docker_installed() -> None:
|
||||
if shutil.which("docker") is None:
|
||||
console = Console()
|
||||
error_text = Text()
|
||||
error_text.append("DOCKER NOT INSTALLED", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("The 'docker' CLI was not found in your PATH.\n", style="white")
|
||||
error_text.append(
|
||||
"Please install Docker and ensure the 'docker' command is available.\n\n", style="white"
|
||||
)
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n", panel, "\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
async def warm_up_llm() -> None:
|
||||
from strix.config.config import resolve_llm_config
|
||||
|
||||
console = Console()
|
||||
|
||||
try:
|
||||
model_name, api_key, api_base = resolve_llm_config()
|
||||
|
||||
test_messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Reply with just 'OK'."},
|
||||
]
|
||||
|
||||
llm_timeout = int(Config.get("llm_timeout") or "300")
|
||||
|
||||
completion_kwargs: dict[str, Any] = {
|
||||
"model": model_name,
|
||||
"messages": test_messages,
|
||||
"timeout": llm_timeout,
|
||||
}
|
||||
if api_key:
|
||||
completion_kwargs["api_key"] = api_key
|
||||
if api_base:
|
||||
completion_kwargs["api_base"] = api_base
|
||||
|
||||
response = litellm.completion(**completion_kwargs)
|
||||
|
||||
validate_llm_response(response)
|
||||
|
||||
except Exception as e: # noqa: BLE001
|
||||
error_text = Text()
|
||||
error_text.append("LLM CONNECTION FAILED", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("Could not establish connection to the language model.\n", style="white")
|
||||
error_text.append("Please check your configuration and try again.\n", style="white")
|
||||
error_text.append(f"\nError: {e}", style="dim white")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_version() -> str:
|
||||
try:
|
||||
from importlib.metadata import version
|
||||
|
||||
return version("strix-agent")
|
||||
except Exception: # noqa: BLE001
|
||||
return "unknown"
|
||||
|
||||
|
||||
def parse_arguments() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Strix Multi-Agent Cybersecurity Penetration Testing Tool",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Web application penetration test
|
||||
strix --target https://example.com
|
||||
|
||||
# GitHub repository analysis
|
||||
strix --target https://github.com/user/repo
|
||||
strix --target git@github.com:user/repo.git
|
||||
|
||||
# Local code analysis
|
||||
strix --target ./my-project
|
||||
|
||||
# Domain penetration test
|
||||
strix --target example.com
|
||||
|
||||
# IP address penetration test
|
||||
strix --target 192.168.1.42
|
||||
|
||||
# Multiple targets (e.g., white-box testing with source and deployed app)
|
||||
strix --target https://github.com/user/repo --target https://example.com
|
||||
strix --target ./my-project --target https://staging.example.com --target https://prod.example.com
|
||||
|
||||
# Custom instructions (inline)
|
||||
strix --target example.com --instruction "Focus on authentication vulnerabilities"
|
||||
|
||||
# Custom instructions (from file)
|
||||
strix --target example.com --instruction-file ./instructions.txt
|
||||
strix --target https://app.com --instruction-file /path/to/detailed_instructions.md
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--version",
|
||||
action="version",
|
||||
version=f"strix {get_version()}",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--target",
|
||||
type=str,
|
||||
required=True,
|
||||
action="append",
|
||||
help="Target to test (URL, repository, local directory path, domain name, or IP address). "
|
||||
"Can be specified multiple times for multi-target scans.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--instruction",
|
||||
type=str,
|
||||
help="Custom instructions for the penetration test. This can be "
|
||||
"specific vulnerability types to focus on (e.g., 'Focus on IDOR and XSS'), "
|
||||
"testing approaches (e.g., 'Perform thorough authentication testing'), "
|
||||
"test credentials (e.g., 'Use the following credentials to access the app: "
|
||||
"admin:password123'), "
|
||||
"or areas of interest (e.g., 'Check login API endpoint for security issues').",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--instruction-file",
|
||||
type=str,
|
||||
help="Path to a file containing detailed custom instructions for the penetration test. "
|
||||
"Use this option when you have lengthy or complex instructions saved in a file "
|
||||
"(e.g., '--instruction-file ./detailed_instructions.txt').",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--non-interactive",
|
||||
action="store_true",
|
||||
help=(
|
||||
"Run in non-interactive mode (no TUI, exits on completion). "
|
||||
"Default is interactive mode with TUI."
|
||||
),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-m",
|
||||
"--scan-mode",
|
||||
type=str,
|
||||
choices=["quick", "standard", "deep"],
|
||||
default="deep",
|
||||
help=(
|
||||
"Scan mode: "
|
||||
"'quick' for fast CI/CD checks, "
|
||||
"'standard' for routine testing, "
|
||||
"'deep' for thorough security reviews (default). "
|
||||
"Default: deep."
|
||||
),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
type=str,
|
||||
help="Path to a custom config file (JSON) to use instead of ~/.strix/cli-config.json",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.instruction and args.instruction_file:
|
||||
parser.error(
|
||||
"Cannot specify both --instruction and --instruction-file. Use one or the other."
|
||||
)
|
||||
|
||||
if args.instruction_file:
|
||||
instruction_path = Path(args.instruction_file)
|
||||
try:
|
||||
with instruction_path.open(encoding="utf-8") as f:
|
||||
args.instruction = f.read().strip()
|
||||
if not args.instruction:
|
||||
parser.error(f"Instruction file '{instruction_path}' is empty")
|
||||
except Exception as e: # noqa: BLE001
|
||||
parser.error(f"Failed to read instruction file '{instruction_path}': {e}")
|
||||
|
||||
args.targets_info = []
|
||||
for target in args.target:
|
||||
try:
|
||||
target_type, target_dict = infer_target_type(target)
|
||||
|
||||
if target_type == "local_code":
|
||||
display_target = target_dict.get("target_path", target)
|
||||
else:
|
||||
display_target = target
|
||||
|
||||
args.targets_info.append(
|
||||
{"type": target_type, "details": target_dict, "original": display_target}
|
||||
)
|
||||
except ValueError:
|
||||
parser.error(f"Invalid target '{target}'")
|
||||
|
||||
assign_workspace_subdirs(args.targets_info)
|
||||
rewrite_localhost_targets(args.targets_info, HOST_GATEWAY_HOSTNAME)
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def display_completion_message(args: argparse.Namespace, results_path: Path) -> None:
|
||||
console = Console()
|
||||
tracer = get_global_tracer()
|
||||
|
||||
scan_completed = False
|
||||
if tracer and tracer.scan_results:
|
||||
scan_completed = tracer.scan_results.get("scan_completed", False)
|
||||
|
||||
has_vulnerabilities = tracer and len(tracer.vulnerability_reports) > 0
|
||||
|
||||
completion_text = Text()
|
||||
if scan_completed:
|
||||
completion_text.append("Penetration test completed", style="bold #22c55e")
|
||||
else:
|
||||
completion_text.append("SESSION ENDED", style="bold #eab308")
|
||||
|
||||
target_text = Text()
|
||||
target_text.append("Target", style="dim")
|
||||
target_text.append(" ")
|
||||
if len(args.targets_info) == 1:
|
||||
target_text.append(args.targets_info[0]["original"], style="bold white")
|
||||
else:
|
||||
target_text.append(f"{len(args.targets_info)} targets", style="bold white")
|
||||
for target_info in args.targets_info:
|
||||
target_text.append("\n ")
|
||||
target_text.append(target_info["original"], style="white")
|
||||
|
||||
stats_text = build_final_stats_text(tracer)
|
||||
|
||||
panel_parts = [completion_text, "\n\n", target_text]
|
||||
|
||||
if stats_text.plain:
|
||||
panel_parts.extend(["\n", stats_text])
|
||||
|
||||
if scan_completed or has_vulnerabilities:
|
||||
results_text = Text()
|
||||
results_text.append("\n")
|
||||
results_text.append("Output", style="dim")
|
||||
results_text.append(" ")
|
||||
results_text.append(str(results_path), style="#60a5fa")
|
||||
panel_parts.extend(["\n", results_text])
|
||||
|
||||
panel_content = Text.assemble(*panel_parts)
|
||||
|
||||
border_style = "#22c55e" if scan_completed else "#eab308"
|
||||
|
||||
panel = Panel(
|
||||
panel_content,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style=border_style,
|
||||
padding=(1, 2),
|
||||
)
|
||||
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
console.print("[#60a5fa]strix.ai[/] [dim]·[/] [#60a5fa]discord.gg/strix-ai[/]")
|
||||
console.print()
|
||||
|
||||
|
||||
def pull_docker_image() -> None:
|
||||
console = Console()
|
||||
client = check_docker_connection()
|
||||
|
||||
if image_exists(client, Config.get("strix_image")): # type: ignore[arg-type]
|
||||
return
|
||||
|
||||
console.print()
|
||||
console.print(f"[dim]Pulling image[/] {Config.get('strix_image')}")
|
||||
console.print("[dim yellow]This only happens on first run and may take a few minutes...[/]")
|
||||
console.print()
|
||||
|
||||
with console.status("[bold cyan]Downloading image layers...", spinner="dots") as status:
|
||||
try:
|
||||
layers_info: dict[str, str] = {}
|
||||
last_update = ""
|
||||
|
||||
for line in client.api.pull(Config.get("strix_image"), stream=True, decode=True):
|
||||
last_update = process_pull_line(line, layers_info, status, last_update)
|
||||
|
||||
except DockerException as e:
|
||||
console.print()
|
||||
error_text = Text()
|
||||
error_text.append("FAILED TO PULL IMAGE", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append(f"Could not download: {Config.get('strix_image')}\n", style="white")
|
||||
error_text.append(str(e), style="dim red")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print(panel, "\n")
|
||||
sys.exit(1)
|
||||
|
||||
success_text = Text()
|
||||
success_text.append("Docker image ready", style="#22c55e")
|
||||
console.print(success_text)
|
||||
console.print()
|
||||
|
||||
|
||||
def apply_config_override(config_path: str) -> None:
|
||||
Config._config_file_override = validate_config_file(config_path)
|
||||
apply_saved_config(force=True)
|
||||
|
||||
|
||||
def persist_config() -> None:
|
||||
if Config._config_file_override is None:
|
||||
save_current_config()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if sys.platform == "win32":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
args = parse_arguments()
|
||||
|
||||
if args.config:
|
||||
apply_config_override(args.config)
|
||||
|
||||
check_docker_installed()
|
||||
pull_docker_image()
|
||||
|
||||
validate_environment()
|
||||
asyncio.run(warm_up_llm())
|
||||
|
||||
persist_config()
|
||||
|
||||
args.run_name = generate_run_name(args.targets_info)
|
||||
|
||||
for target_info in args.targets_info:
|
||||
if target_info["type"] == "repository":
|
||||
repo_url = target_info["details"]["target_repo"]
|
||||
dest_name = target_info["details"].get("workspace_subdir")
|
||||
cloned_path = clone_repository(repo_url, args.run_name, dest_name)
|
||||
target_info["details"]["cloned_repo_path"] = cloned_path
|
||||
|
||||
args.local_sources = collect_local_sources(args.targets_info)
|
||||
|
||||
is_whitebox = bool(args.local_sources)
|
||||
|
||||
posthog.start(
|
||||
model=Config.get("strix_llm"),
|
||||
scan_mode=args.scan_mode,
|
||||
is_whitebox=is_whitebox,
|
||||
interactive=not args.non_interactive,
|
||||
has_instructions=bool(args.instruction),
|
||||
)
|
||||
|
||||
exit_reason = "user_exit"
|
||||
try:
|
||||
if args.non_interactive:
|
||||
asyncio.run(run_cli(args))
|
||||
else:
|
||||
asyncio.run(run_tui(args))
|
||||
except KeyboardInterrupt:
|
||||
exit_reason = "interrupted"
|
||||
except Exception as e:
|
||||
exit_reason = "error"
|
||||
posthog.error("unhandled_exception", str(e))
|
||||
raise
|
||||
finally:
|
||||
tracer = get_global_tracer()
|
||||
if tracer:
|
||||
posthog.end(tracer, exit_reason=exit_reason)
|
||||
|
||||
results_path = Path("strix_runs") / args.run_name
|
||||
display_completion_message(args, results_path)
|
||||
|
||||
if args.non_interactive:
|
||||
tracer = get_global_tracer()
|
||||
if tracer and tracer.vulnerability_reports:
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,121 @@
|
||||
import html
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
|
||||
_FUNCTION_TAG_PREFIX = "<function="
|
||||
|
||||
_FUNC_PATTERN = re.compile(r"<function=([^>]+)>")
|
||||
_FUNC_END_PATTERN = re.compile(r"</function>")
|
||||
_COMPLETE_PARAM_PATTERN = re.compile(r"<parameter=([^>]+)>(.*?)</parameter>", re.DOTALL)
|
||||
_INCOMPLETE_PARAM_PATTERN = re.compile(r"<parameter=([^>]+)>(.*)$", re.DOTALL)
|
||||
|
||||
|
||||
def _get_safe_content(content: str) -> tuple[str, str]:
|
||||
if not content:
|
||||
return "", ""
|
||||
|
||||
last_lt = content.rfind("<")
|
||||
if last_lt == -1:
|
||||
return content, ""
|
||||
|
||||
suffix = content[last_lt:]
|
||||
target = _FUNCTION_TAG_PREFIX # "<function="
|
||||
|
||||
if target.startswith(suffix):
|
||||
return content[:last_lt], suffix
|
||||
|
||||
return content, ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class StreamSegment:
|
||||
type: Literal["text", "tool"]
|
||||
content: str
|
||||
tool_name: str | None = None
|
||||
args: dict[str, str] | None = None
|
||||
is_complete: bool = False
|
||||
|
||||
|
||||
def parse_streaming_content(content: str) -> list[StreamSegment]:
|
||||
if not content:
|
||||
return []
|
||||
|
||||
segments: list[StreamSegment] = []
|
||||
|
||||
func_matches = list(_FUNC_PATTERN.finditer(content))
|
||||
|
||||
if not func_matches:
|
||||
safe_content, _ = _get_safe_content(content)
|
||||
text = safe_content.strip()
|
||||
if text:
|
||||
segments.append(StreamSegment(type="text", content=text))
|
||||
return segments
|
||||
|
||||
first_func_start = func_matches[0].start()
|
||||
if first_func_start > 0:
|
||||
text_before = content[:first_func_start].strip()
|
||||
if text_before:
|
||||
segments.append(StreamSegment(type="text", content=text_before))
|
||||
|
||||
for i, match in enumerate(func_matches):
|
||||
tool_name = match.group(1)
|
||||
func_start = match.end()
|
||||
|
||||
func_end_match = _FUNC_END_PATTERN.search(content, func_start)
|
||||
|
||||
if func_end_match:
|
||||
func_body = content[func_start : func_end_match.start()]
|
||||
is_complete = True
|
||||
end_pos = func_end_match.end()
|
||||
else:
|
||||
if i + 1 < len(func_matches):
|
||||
next_func_start = func_matches[i + 1].start()
|
||||
func_body = content[func_start:next_func_start]
|
||||
else:
|
||||
func_body = content[func_start:]
|
||||
is_complete = False
|
||||
end_pos = len(content)
|
||||
|
||||
args = _parse_streaming_params(func_body)
|
||||
|
||||
segments.append(
|
||||
StreamSegment(
|
||||
type="tool",
|
||||
content=func_body,
|
||||
tool_name=tool_name,
|
||||
args=args,
|
||||
is_complete=is_complete,
|
||||
)
|
||||
)
|
||||
|
||||
if is_complete and i + 1 < len(func_matches):
|
||||
next_start = func_matches[i + 1].start()
|
||||
text_between = content[end_pos:next_start].strip()
|
||||
if text_between:
|
||||
segments.append(StreamSegment(type="text", content=text_between))
|
||||
|
||||
return segments
|
||||
|
||||
|
||||
def _parse_streaming_params(func_body: str) -> dict[str, str]:
|
||||
args: dict[str, str] = {}
|
||||
|
||||
complete_matches = list(_COMPLETE_PARAM_PATTERN.finditer(func_body))
|
||||
complete_end_pos = 0
|
||||
|
||||
for match in complete_matches:
|
||||
param_name = match.group(1)
|
||||
param_value = html.unescape(match.group(2).strip())
|
||||
args[param_name] = param_value
|
||||
complete_end_pos = max(complete_end_pos, match.end())
|
||||
|
||||
remaining = func_body[complete_end_pos:]
|
||||
incomplete_match = _INCOMPLETE_PARAM_PATTERN.search(remaining)
|
||||
if incomplete_match:
|
||||
param_name = incomplete_match.group(1)
|
||||
param_value = html.unescape(incomplete_match.group(2).strip())
|
||||
args[param_name] = param_value
|
||||
|
||||
return args
|
||||
@@ -1,4 +1,5 @@
|
||||
from . import (
|
||||
agent_message_renderer,
|
||||
agents_graph_renderer,
|
||||
browser_renderer,
|
||||
file_edit_renderer,
|
||||
@@ -10,6 +11,7 @@ from . import (
|
||||
scan_info_renderer,
|
||||
terminal_renderer,
|
||||
thinking_renderer,
|
||||
todo_renderer,
|
||||
user_message_renderer,
|
||||
web_search_renderer,
|
||||
)
|
||||
@@ -20,6 +22,7 @@ from .registry import ToolTUIRegistry, get_tool_renderer, register_tool_renderer
|
||||
__all__ = [
|
||||
"BaseToolRenderer",
|
||||
"ToolTUIRegistry",
|
||||
"agent_message_renderer",
|
||||
"agents_graph_renderer",
|
||||
"browser_renderer",
|
||||
"file_edit_renderer",
|
||||
@@ -34,6 +37,7 @@ __all__ = [
|
||||
"scan_info_renderer",
|
||||
"terminal_renderer",
|
||||
"thinking_renderer",
|
||||
"todo_renderer",
|
||||
"user_message_renderer",
|
||||
"web_search_renderer",
|
||||
]
|
||||
@@ -0,0 +1,190 @@
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import get_lexer_by_name, guess_lexer
|
||||
from pygments.styles import get_style_by_name
|
||||
from pygments.util import ClassNotFound
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
_HEADER_STYLES = [
|
||||
("###### ", 7, "bold #4ade80"),
|
||||
("##### ", 6, "bold #22c55e"),
|
||||
("#### ", 5, "bold #16a34a"),
|
||||
("### ", 4, "bold #15803d"),
|
||||
("## ", 3, "bold #22c55e"),
|
||||
("# ", 2, "bold #4ade80"),
|
||||
]
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
def _get_token_color(token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
|
||||
def _highlight_code(code: str, language: str | None = None) -> Text:
|
||||
text = Text()
|
||||
|
||||
try:
|
||||
lexer = get_lexer_by_name(language) if language else guess_lexer(code)
|
||||
except ClassNotFound:
|
||||
text.append(code, style="#d4d4d4")
|
||||
return text
|
||||
|
||||
for token_type, token_value in lexer.get_tokens(code):
|
||||
if not token_value:
|
||||
continue
|
||||
color = _get_token_color(token_type)
|
||||
text.append(token_value, style=color)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def _try_parse_header(line: str) -> tuple[str, str] | None:
|
||||
for prefix, strip_len, style in _HEADER_STYLES:
|
||||
if line.startswith(prefix):
|
||||
return (line[strip_len:], style)
|
||||
return None
|
||||
|
||||
|
||||
def _apply_markdown_styles(text: str) -> Text: # noqa: PLR0912
|
||||
result = Text()
|
||||
lines = text.split("\n")
|
||||
|
||||
in_code_block = False
|
||||
code_block_lang: str | None = None
|
||||
code_block_lines: list[str] = []
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
if i > 0 and not in_code_block:
|
||||
result.append("\n")
|
||||
|
||||
if line.startswith("```"):
|
||||
if not in_code_block:
|
||||
in_code_block = True
|
||||
code_block_lang = line[3:].strip() or None
|
||||
code_block_lines = []
|
||||
if i > 0:
|
||||
result.append("\n")
|
||||
else:
|
||||
in_code_block = False
|
||||
code_content = "\n".join(code_block_lines)
|
||||
if code_content:
|
||||
result.append_text(_highlight_code(code_content, code_block_lang))
|
||||
code_block_lines = []
|
||||
code_block_lang = None
|
||||
continue
|
||||
|
||||
if in_code_block:
|
||||
code_block_lines.append(line)
|
||||
continue
|
||||
|
||||
header = _try_parse_header(line)
|
||||
if header:
|
||||
result.append(header[0], style=header[1])
|
||||
elif line.startswith("> "):
|
||||
result.append("┃ ", style="#22c55e")
|
||||
result.append_text(_process_inline_formatting(line[2:]))
|
||||
elif line.startswith(("- ", "* ")):
|
||||
result.append("• ", style="#22c55e")
|
||||
result.append_text(_process_inline_formatting(line[2:]))
|
||||
elif len(line) > 2 and line[0].isdigit() and line[1:3] in (". ", ") "):
|
||||
result.append(line[0] + ". ", style="#22c55e")
|
||||
result.append_text(_process_inline_formatting(line[2:]))
|
||||
elif line.strip() in ("---", "***", "___"):
|
||||
result.append("─" * 40, style="#22c55e")
|
||||
else:
|
||||
result.append_text(_process_inline_formatting(line))
|
||||
|
||||
if in_code_block and code_block_lines:
|
||||
code_content = "\n".join(code_block_lines)
|
||||
result.append_text(_highlight_code(code_content, code_block_lang))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def _process_inline_formatting(line: str) -> Text:
|
||||
result = Text()
|
||||
i = 0
|
||||
n = len(line)
|
||||
|
||||
while i < n:
|
||||
if i + 1 < n and line[i : i + 2] in ("**", "__"):
|
||||
marker = line[i : i + 2]
|
||||
end = line.find(marker, i + 2)
|
||||
if end != -1:
|
||||
result.append(line[i + 2 : end], style="bold #4ade80")
|
||||
i = end + 2
|
||||
continue
|
||||
|
||||
if i + 1 < n and line[i : i + 2] == "~~":
|
||||
end = line.find("~~", i + 2)
|
||||
if end != -1:
|
||||
result.append(line[i + 2 : end], style="strike #525252")
|
||||
i = end + 2
|
||||
continue
|
||||
|
||||
if line[i] == "`":
|
||||
end = line.find("`", i + 1)
|
||||
if end != -1:
|
||||
result.append(line[i + 1 : end], style="bold #22c55e on #0a0a0a")
|
||||
i = end + 1
|
||||
continue
|
||||
|
||||
if line[i] in ("*", "_"):
|
||||
marker = line[i]
|
||||
if i + 1 < n and line[i + 1] != marker:
|
||||
end = line.find(marker, i + 1)
|
||||
if end != -1 and (end + 1 >= n or line[end + 1] != marker):
|
||||
result.append(line[i + 1 : end], style="italic #86efac")
|
||||
i = end + 1
|
||||
continue
|
||||
|
||||
result.append(line[i])
|
||||
i += 1
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class AgentMessageRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "agent_message"
|
||||
css_classes: ClassVar[list[str]] = ["chat-message", "agent-message"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
content = tool_data.get("content", "")
|
||||
|
||||
if not content:
|
||||
return Static(Text(), classes=" ".join(cls.css_classes))
|
||||
|
||||
styled_text = _apply_markdown_styles(content)
|
||||
|
||||
return Static(styled_text, classes=" ".join(cls.css_classes))
|
||||
|
||||
@classmethod
|
||||
def render_simple(cls, content: str) -> Text:
|
||||
if not content:
|
||||
return Text()
|
||||
|
||||
from strix.llm.utils import clean_content
|
||||
|
||||
cleaned = clean_content(content)
|
||||
if not cleaned:
|
||||
return Text()
|
||||
|
||||
return _apply_markdown_styles(cleaned)
|
||||
@@ -0,0 +1,140 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewAgentGraphRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_agent_graph"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#a78bfa")
|
||||
text.append("viewing agents graph", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateAgentRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_agent"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
task = args.get("task", "")
|
||||
name = args.get("name", "Agent")
|
||||
|
||||
text = Text()
|
||||
text.append("◈ ", style="#a78bfa")
|
||||
text.append("spawning ", style="dim")
|
||||
text.append(name, style="bold #a78bfa")
|
||||
|
||||
if task:
|
||||
text.append("\n ")
|
||||
text.append(task, style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SendMessageToAgentRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "send_message_to_agent"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
message = args.get("message", "")
|
||||
agent_id = args.get("agent_id", "")
|
||||
|
||||
text = Text()
|
||||
text.append("→ ", style="#60a5fa")
|
||||
if agent_id:
|
||||
text.append(f"to {agent_id}", style="dim")
|
||||
else:
|
||||
text.append("sending message", style="dim")
|
||||
|
||||
if message:
|
||||
text.append("\n ")
|
||||
text.append(message, style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class AgentFinishRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "agent_finish"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
result_summary = args.get("result_summary", "")
|
||||
findings = args.get("findings", [])
|
||||
success = args.get("success", True)
|
||||
|
||||
text = Text()
|
||||
|
||||
if success:
|
||||
text.append("◆ ", style="#22c55e")
|
||||
text.append("Agent completed", style="bold #22c55e")
|
||||
else:
|
||||
text.append("◆ ", style="#ef4444")
|
||||
text.append("Agent failed", style="bold #ef4444")
|
||||
|
||||
if result_summary:
|
||||
text.append("\n ")
|
||||
text.append(result_summary, style="bold")
|
||||
|
||||
if findings and isinstance(findings, list):
|
||||
for finding in findings:
|
||||
text.append("\n • ")
|
||||
text.append(str(finding), style="dim")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Completing task...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class WaitForMessageRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "wait_for_message"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "agents-graph-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
reason = args.get("reason", "")
|
||||
|
||||
text = Text()
|
||||
text.append("○ ", style="#6b7280")
|
||||
text.append("waiting", style="dim")
|
||||
|
||||
if reason:
|
||||
text.append("\n ")
|
||||
text.append(reason, style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,94 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class BaseToolRenderer(ABC):
|
||||
tool_name: ClassVar[str] = ""
|
||||
css_classes: ClassVar[list[str]] = ["tool-call"]
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def build_text(cls, tool_data: dict[str, Any]) -> Text: # noqa: ARG003
|
||||
return Text()
|
||||
|
||||
@classmethod
|
||||
def create_static(cls, content: Text, status: str) -> Static:
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def status_icon(cls, status: str) -> tuple[str, str]:
|
||||
icons = {
|
||||
"running": ("● In progress...", "#f59e0b"),
|
||||
"completed": ("✓ Done", "#22c55e"),
|
||||
"failed": ("✗ Failed", "#dc2626"),
|
||||
"error": ("✗ Error", "#dc2626"),
|
||||
}
|
||||
return icons.get(status, ("○ Unknown", "dim"))
|
||||
|
||||
@classmethod
|
||||
def get_css_classes(cls, status: str) -> str:
|
||||
base_classes = cls.css_classes.copy()
|
||||
base_classes.append(f"status-{status}")
|
||||
return " ".join(base_classes)
|
||||
|
||||
@classmethod
|
||||
def text_with_style(cls, content: str, style: str | None = None) -> Text:
|
||||
text = Text()
|
||||
text.append(content, style=style)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def text_icon_label(
|
||||
cls,
|
||||
icon: str,
|
||||
label: str,
|
||||
icon_style: str | None = None,
|
||||
label_style: str | None = None,
|
||||
) -> Text:
|
||||
text = Text()
|
||||
text.append(icon, style=icon_style)
|
||||
text.append(" ")
|
||||
text.append(label, style=label_style)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def text_header(
|
||||
cls,
|
||||
icon: str,
|
||||
title: str,
|
||||
subtitle: str = "",
|
||||
title_style: str = "bold",
|
||||
subtitle_style: str = "dim",
|
||||
) -> Text:
|
||||
text = Text()
|
||||
text.append(icon)
|
||||
text.append(" ")
|
||||
text.append(title, style=title_style)
|
||||
if subtitle:
|
||||
text.append(" ")
|
||||
text.append(subtitle, style=subtitle_style)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def text_key_value(
|
||||
cls,
|
||||
key: str,
|
||||
value: str,
|
||||
key_style: str = "dim",
|
||||
value_style: str | None = None,
|
||||
indent: int = 2,
|
||||
) -> Text:
|
||||
text = Text()
|
||||
text.append(" " * indent)
|
||||
text.append(key, style=key_style)
|
||||
text.append(": ")
|
||||
text.append(value, style=value_style)
|
||||
return text
|
||||
@@ -0,0 +1,136 @@
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.styles import get_style_by_name
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class BrowserRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "browser_action"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "browser-tool"]
|
||||
|
||||
SIMPLE_ACTIONS: ClassVar[dict[str, str]] = {
|
||||
"back": "going back in browser history",
|
||||
"forward": "going forward in browser history",
|
||||
"scroll_down": "scrolling down",
|
||||
"scroll_up": "scrolling up",
|
||||
"refresh": "refreshing browser tab",
|
||||
"close_tab": "closing browser tab",
|
||||
"switch_tab": "switching browser tab",
|
||||
"list_tabs": "listing browser tabs",
|
||||
"view_source": "viewing page source",
|
||||
"get_console_logs": "getting console logs",
|
||||
"screenshot": "taking screenshot of browser tab",
|
||||
"wait": "waiting...",
|
||||
"close": "closing browser",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def _get_token_color(cls, token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _highlight_js(cls, code: str) -> Text:
|
||||
lexer = get_lexer_by_name("javascript")
|
||||
text = Text()
|
||||
|
||||
for token_type, token_value in lexer.get_tokens(code):
|
||||
if not token_value:
|
||||
continue
|
||||
color = cls._get_token_color(token_type)
|
||||
text.append(token_value, style=color)
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
action = args.get("action", "")
|
||||
content = cls._build_content(action, args)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _build_url_action(cls, text: Text, label: str, url: str | None, suffix: str = "") -> None:
|
||||
text.append(label, style="#06b6d4")
|
||||
if url:
|
||||
text.append(url, style="#06b6d4")
|
||||
if suffix:
|
||||
text.append(suffix, style="#06b6d4")
|
||||
|
||||
@classmethod
|
||||
def _build_content(cls, action: str, args: dict[str, Any]) -> Text:
|
||||
text = Text()
|
||||
text.append("🌐 ")
|
||||
|
||||
if action in cls.SIMPLE_ACTIONS:
|
||||
text.append(cls.SIMPLE_ACTIONS[action], style="#06b6d4")
|
||||
return text
|
||||
|
||||
url = args.get("url")
|
||||
|
||||
url_actions = {
|
||||
"launch": ("launching ", " on browser" if url else "browser"),
|
||||
"goto": ("navigating to ", ""),
|
||||
"new_tab": ("opening tab ", ""),
|
||||
}
|
||||
if action in url_actions:
|
||||
label, suffix = url_actions[action]
|
||||
if action == "launch" and not url:
|
||||
text.append("launching browser", style="#06b6d4")
|
||||
else:
|
||||
cls._build_url_action(text, label, url, suffix)
|
||||
return text
|
||||
|
||||
click_actions = {
|
||||
"click": "clicking",
|
||||
"double_click": "double clicking",
|
||||
"hover": "hovering",
|
||||
}
|
||||
if action in click_actions:
|
||||
text.append(click_actions[action], style="#06b6d4")
|
||||
return text
|
||||
|
||||
handlers: dict[str, tuple[str, str | None]] = {
|
||||
"type": ("typing ", args.get("text")),
|
||||
"press_key": ("pressing key ", args.get("key")),
|
||||
"save_pdf": ("saving PDF to ", args.get("file_path")),
|
||||
}
|
||||
if action in handlers:
|
||||
label, value = handlers[action]
|
||||
text.append(label, style="#06b6d4")
|
||||
if value:
|
||||
text.append(str(value), style="#06b6d4")
|
||||
return text
|
||||
|
||||
if action == "execute_js":
|
||||
text.append("executing javascript", style="#06b6d4")
|
||||
js_code = args.get("js_code")
|
||||
if js_code:
|
||||
text.append("\n")
|
||||
text.append_text(cls._highlight_js(js_code))
|
||||
return text
|
||||
|
||||
if action:
|
||||
text.append(action, style="#06b6d4")
|
||||
return text
|
||||
@@ -0,0 +1,177 @@
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import get_lexer_by_name, get_lexer_for_filename
|
||||
from pygments.styles import get_style_by_name
|
||||
from pygments.util import ClassNotFound
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
def _get_lexer_for_file(path: str) -> Any:
|
||||
try:
|
||||
return get_lexer_for_filename(path)
|
||||
except ClassNotFound:
|
||||
return get_lexer_by_name("text")
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class StrReplaceEditorRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "str_replace_editor"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def _get_token_color(cls, token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _highlight_code(cls, code: str, path: str) -> Text:
|
||||
lexer = _get_lexer_for_file(path)
|
||||
text = Text()
|
||||
|
||||
for token_type, token_value in lexer.get_tokens(code):
|
||||
if not token_value:
|
||||
continue
|
||||
color = cls._get_token_color(token_type)
|
||||
text.append(token_value, style=color)
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
|
||||
command = args.get("command", "")
|
||||
path = args.get("path", "")
|
||||
old_str = args.get("old_str", "")
|
||||
new_str = args.get("new_str", "")
|
||||
file_text = args.get("file_text", "")
|
||||
|
||||
text = Text()
|
||||
|
||||
icons_and_labels = {
|
||||
"view": ("◇ ", "read", "#10b981"),
|
||||
"str_replace": ("◇ ", "edit", "#10b981"),
|
||||
"create": ("◇ ", "create", "#10b981"),
|
||||
"insert": ("◇ ", "insert", "#10b981"),
|
||||
"undo_edit": ("◇ ", "undo", "#10b981"),
|
||||
}
|
||||
|
||||
icon, label, color = icons_and_labels.get(command, ("◇ ", "file", "#10b981"))
|
||||
text.append(icon, style=color)
|
||||
text.append(label, style="dim")
|
||||
|
||||
if path:
|
||||
path_display = path[-60:] if len(path) > 60 else path
|
||||
text.append(" ")
|
||||
text.append(path_display, style="dim")
|
||||
|
||||
if command == "str_replace" and (old_str or new_str):
|
||||
if old_str:
|
||||
highlighted_old = cls._highlight_code(old_str, path)
|
||||
for line in highlighted_old.plain.split("\n"):
|
||||
text.append("\n")
|
||||
text.append("-", style="#ef4444")
|
||||
text.append(" ")
|
||||
text.append(line)
|
||||
|
||||
if new_str:
|
||||
highlighted_new = cls._highlight_code(new_str, path)
|
||||
for line in highlighted_new.plain.split("\n"):
|
||||
text.append("\n")
|
||||
text.append("+", style="#22c55e")
|
||||
text.append(" ")
|
||||
text.append(line)
|
||||
|
||||
elif command == "create" and file_text:
|
||||
text.append("\n")
|
||||
text.append_text(cls._highlight_code(file_text, path))
|
||||
|
||||
elif command == "insert" and new_str:
|
||||
highlighted_new = cls._highlight_code(new_str, path)
|
||||
for line in highlighted_new.plain.split("\n"):
|
||||
text.append("\n")
|
||||
text.append("+", style="#22c55e")
|
||||
text.append(" ")
|
||||
text.append(line)
|
||||
|
||||
elif isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif not (result and isinstance(result, dict) and "content" in result) and not path:
|
||||
text.append(" ")
|
||||
text.append("Processing...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListFilesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_files"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
path = args.get("path", "")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#10b981")
|
||||
text.append("list", style="dim")
|
||||
text.append(" ")
|
||||
|
||||
if path:
|
||||
path_display = path[-60:] if len(path) > 60 else path
|
||||
text.append(path_display, style="dim")
|
||||
else:
|
||||
text.append("Current directory", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SearchFilesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "search_files"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "file-edit-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
path = args.get("path", "")
|
||||
regex = args.get("regex", "")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#a855f7")
|
||||
text.append("search", style="dim")
|
||||
text.append(" ")
|
||||
|
||||
if path and regex:
|
||||
text.append(path, style="dim")
|
||||
text.append(" ", style="dim")
|
||||
text.append(regex, style="#a855f7")
|
||||
elif path:
|
||||
text.append(path, style="dim")
|
||||
elif regex:
|
||||
text.append(regex, style="#a855f7")
|
||||
else:
|
||||
text.append("...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,65 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
FIELD_STYLE = "bold #4ade80"
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class FinishScanRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "finish_scan"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "finish-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
executive_summary = args.get("executive_summary", "")
|
||||
methodology = args.get("methodology", "")
|
||||
technical_analysis = args.get("technical_analysis", "")
|
||||
recommendations = args.get("recommendations", "")
|
||||
|
||||
text = Text()
|
||||
text.append("◆ ", style="#22c55e")
|
||||
text.append("Penetration test completed", style="bold #22c55e")
|
||||
|
||||
if executive_summary:
|
||||
text.append("\n\n")
|
||||
text.append("Executive Summary", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(executive_summary)
|
||||
|
||||
if methodology:
|
||||
text.append("\n\n")
|
||||
text.append("Methodology", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(methodology)
|
||||
|
||||
if technical_analysis:
|
||||
text.append("\n\n")
|
||||
text.append("Technical Analysis", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(technical_analysis)
|
||||
|
||||
if recommendations:
|
||||
text.append("\n\n")
|
||||
text.append("Recommendations", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(recommendations)
|
||||
|
||||
if not (executive_summary or methodology or technical_analysis or recommendations):
|
||||
text.append("\n ")
|
||||
text.append("Generating final report...", style="dim")
|
||||
|
||||
padded = Text()
|
||||
padded.append("\n\n")
|
||||
padded.append_text(text)
|
||||
padded.append("\n\n")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(padded, classes=css_classes)
|
||||
@@ -0,0 +1,133 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
title = args.get("title", "")
|
||||
content = args.get("content", "")
|
||||
category = args.get("category", "general")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#fbbf24")
|
||||
text.append("note", style="dim")
|
||||
text.append(" ")
|
||||
text.append(f"({category})", style="dim")
|
||||
|
||||
if title:
|
||||
text.append("\n ")
|
||||
text.append(title.strip())
|
||||
|
||||
if content:
|
||||
text.append("\n ")
|
||||
text.append(content.strip(), style="dim")
|
||||
|
||||
if not title and not content:
|
||||
text.append("\n ")
|
||||
text.append("Capturing...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class DeleteNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "delete_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: ARG003
|
||||
text = Text()
|
||||
text.append("◇ ", style="#fbbf24")
|
||||
text.append("note removed", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class UpdateNoteRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "update_note"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
title = args.get("title")
|
||||
content = args.get("content")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#fbbf24")
|
||||
text.append("note updated", style="dim")
|
||||
|
||||
if title:
|
||||
text.append("\n ")
|
||||
text.append(title)
|
||||
|
||||
if content:
|
||||
text.append("\n ")
|
||||
text.append(content.strip(), style="dim")
|
||||
|
||||
if not title and not content:
|
||||
text.append("\n ")
|
||||
text.append("Updating...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListNotesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_notes"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "notes-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("◇ ", style="#fbbf24")
|
||||
text.append("notes", style="dim")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict) and result.get("success"):
|
||||
count = result.get("total_count", 0)
|
||||
notes = result.get("notes", []) or []
|
||||
|
||||
if count == 0:
|
||||
text.append("\n ")
|
||||
text.append("No notes", style="dim")
|
||||
else:
|
||||
for note in notes:
|
||||
title = note.get("title", "").strip() or "(untitled)"
|
||||
category = note.get("category", "general")
|
||||
note_content = note.get("content", "").strip()
|
||||
|
||||
text.append("\n - ")
|
||||
text.append(title)
|
||||
text.append(f" ({category})", style="dim")
|
||||
|
||||
if note_content:
|
||||
text.append("\n ")
|
||||
text.append(note_content, style="dim")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Loading...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,610 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
PROXY_ICON = "<~>"
|
||||
MAX_REQUESTS_DISPLAY = 20
|
||||
MAX_LINE_LENGTH = 200
|
||||
|
||||
|
||||
def _truncate(text: str, max_len: int = 80) -> str:
|
||||
return text[: max_len - 3] + "..." if len(text) > max_len else text
|
||||
|
||||
|
||||
def _sanitize(text: str, max_len: int = 150) -> str:
|
||||
"""Remove newlines and truncate text."""
|
||||
clean = text.replace("\n", " ").replace("\r", "").replace("\t", " ")
|
||||
return _truncate(clean, max_len)
|
||||
|
||||
|
||||
def _status_style(code: int | None) -> str:
|
||||
if code is None:
|
||||
return "dim"
|
||||
if 200 <= code < 300:
|
||||
return "#22c55e" # green
|
||||
if 300 <= code < 400:
|
||||
return "#eab308" # yellow
|
||||
if 400 <= code < 500:
|
||||
return "#f97316" # orange
|
||||
if code >= 500:
|
||||
return "#ef4444" # red
|
||||
return "dim"
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListRequestsRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_requests"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912 # noqa: PLR0912
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
httpql_filter = args.get("httpql_filter")
|
||||
sort_by = args.get("sort_by")
|
||||
sort_order = args.get("sort_order")
|
||||
scope_id = args.get("scope_id")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
text.append(" listing requests", style="#06b6d4")
|
||||
|
||||
if httpql_filter:
|
||||
text.append(f" where {_truncate(httpql_filter, 150)}", style="dim italic")
|
||||
|
||||
meta_parts = []
|
||||
if sort_by and sort_by != "timestamp":
|
||||
meta_parts.append(f"by:{sort_by}")
|
||||
if sort_order and sort_order != "desc":
|
||||
meta_parts.append(sort_order)
|
||||
if scope_id and isinstance(scope_id, str):
|
||||
meta_parts.append(f"scope:{scope_id[:8]}")
|
||||
if meta_parts:
|
||||
text.append(f" ({', '.join(meta_parts)})", style="dim")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f" error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
else:
|
||||
total = result.get("total_count", 0)
|
||||
requests = result.get("requests", [])
|
||||
|
||||
text.append(f" [{total} found]", style="dim")
|
||||
|
||||
if requests and isinstance(requests, list):
|
||||
text.append("\n")
|
||||
for i, req in enumerate(requests[:MAX_REQUESTS_DISPLAY]):
|
||||
if not isinstance(req, dict):
|
||||
continue
|
||||
method = req.get("method", "?")
|
||||
host = req.get("host", "")
|
||||
path = req.get("path", "/")
|
||||
resp = req.get("response") or {}
|
||||
code = resp.get("statusCode") if isinstance(resp, dict) else None
|
||||
|
||||
text.append(" ")
|
||||
text.append(f"{method:6}", style="#a78bfa")
|
||||
text.append(f" {_truncate(host + path, 180)}", style="dim")
|
||||
if code:
|
||||
text.append(f" {code}", style=_status_style(code))
|
||||
|
||||
if i < min(len(requests), MAX_REQUESTS_DISPLAY) - 1:
|
||||
text.append("\n")
|
||||
|
||||
if len(requests) > MAX_REQUESTS_DISPLAY:
|
||||
text.append("\n")
|
||||
text.append(
|
||||
f" ... +{len(requests) - MAX_REQUESTS_DISPLAY} more",
|
||||
style="dim italic",
|
||||
)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
request_id = args.get("request_id", "")
|
||||
part = args.get("part", "request")
|
||||
search_pattern = args.get("search_pattern")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
|
||||
action = "searching" if search_pattern else "viewing"
|
||||
text.append(f" {action} {part}", style="#06b6d4")
|
||||
|
||||
if request_id:
|
||||
text.append(f" #{request_id}", style="dim")
|
||||
|
||||
if search_pattern:
|
||||
text.append(f" /{_truncate(search_pattern, 100)}/", style="dim italic")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f" error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
elif "matches" in result:
|
||||
matches = result.get("matches", [])
|
||||
total = result.get("total_matches", len(matches))
|
||||
text.append(f" [{total} matches]", style="dim")
|
||||
|
||||
if matches and isinstance(matches, list):
|
||||
text.append("\n")
|
||||
for i, m in enumerate(matches[:5]):
|
||||
if not isinstance(m, dict):
|
||||
continue
|
||||
before = m.get("before", "") or ""
|
||||
match_text = m.get("match", "") or ""
|
||||
after = m.get("after", "") or ""
|
||||
|
||||
before = before.replace("\n", " ").replace("\r", "")[-100:]
|
||||
after = after.replace("\n", " ").replace("\r", "")[:100]
|
||||
|
||||
text.append(" ")
|
||||
|
||||
if before:
|
||||
text.append(f"...{before}", style="dim")
|
||||
text.append(match_text, style="#22c55e bold")
|
||||
if after:
|
||||
text.append(f"{after}...", style="dim")
|
||||
|
||||
if i < min(len(matches), 5) - 1:
|
||||
text.append("\n")
|
||||
|
||||
if len(matches) > 5:
|
||||
text.append("\n")
|
||||
text.append(f" ... +{len(matches) - 5} more matches", style="dim italic")
|
||||
|
||||
elif "content" in result:
|
||||
showing = result.get("showing_lines", "")
|
||||
has_more = result.get("has_more", False)
|
||||
content = result.get("content", "")
|
||||
|
||||
text.append(f" [{showing}]", style="dim")
|
||||
|
||||
if content and isinstance(content, str):
|
||||
lines = content.split("\n")[:15]
|
||||
text.append("\n")
|
||||
for i, line in enumerate(lines):
|
||||
text.append(" ")
|
||||
text.append(_truncate(line, MAX_LINE_LENGTH), style="dim")
|
||||
if i < len(lines) - 1:
|
||||
text.append("\n")
|
||||
|
||||
if has_more or len(lines) > 15:
|
||||
text.append("\n")
|
||||
text.append(" ... more content available", style="dim italic")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SendRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "send_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
method = args.get("method", "GET")
|
||||
url = args.get("url", "")
|
||||
req_headers = args.get("headers")
|
||||
req_body = args.get("body", "")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
text.append(" sending request", style="#06b6d4")
|
||||
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(method, style="#a78bfa")
|
||||
text.append(f" {_truncate(url, 180)}", style="dim")
|
||||
|
||||
if req_headers and isinstance(req_headers, dict):
|
||||
for k, v in list(req_headers.items())[:5]:
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(f"{k}: ", style="dim")
|
||||
text.append(_sanitize(str(v), 150), style="dim")
|
||||
|
||||
if req_body and isinstance(req_body, str):
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
body_lines = req_body.split("\n")[:4]
|
||||
for i, line in enumerate(body_lines):
|
||||
if i > 0:
|
||||
text.append("\n")
|
||||
text.append(" ", style="dim")
|
||||
text.append(_truncate(line, MAX_LINE_LENGTH), style="dim")
|
||||
if len(req_body.split("\n")) > 4:
|
||||
text.append(" ...", style="dim italic")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f"\n error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
else:
|
||||
code = result.get("status_code")
|
||||
time_ms = result.get("response_time_ms")
|
||||
|
||||
text.append("\n")
|
||||
text.append(" << ", style="#22c55e")
|
||||
if code:
|
||||
text.append(f"{code}", style=_status_style(code))
|
||||
if time_ms:
|
||||
text.append(f" ({time_ms}ms)", style="dim")
|
||||
|
||||
body = result.get("body", "")
|
||||
if body and isinstance(body, str):
|
||||
lines = body.split("\n")[:6]
|
||||
for line in lines:
|
||||
text.append("\n")
|
||||
text.append(" << ", style="#22c55e")
|
||||
text.append(_truncate(line, MAX_LINE_LENGTH - 5), style="dim")
|
||||
|
||||
if len(body.split("\n")) > 6:
|
||||
text.append("\n")
|
||||
text.append(" ...", style="dim italic")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class RepeatRequestRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "repeat_request"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
request_id = args.get("request_id", "")
|
||||
modifications = args.get("modifications")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
text.append(" repeating request", style="#06b6d4")
|
||||
|
||||
if request_id:
|
||||
text.append(f" #{request_id}", style="dim")
|
||||
|
||||
if modifications and isinstance(modifications, dict):
|
||||
text.append("\n modifications:", style="dim italic")
|
||||
|
||||
if "url" in modifications:
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(f"url: {_truncate(str(modifications['url']), 180)}", style="dim")
|
||||
|
||||
if "headers" in modifications and isinstance(modifications["headers"], dict):
|
||||
for k, v in list(modifications["headers"].items())[:5]:
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(f"{k}: {_sanitize(str(v), 150)}", style="dim")
|
||||
|
||||
if "cookies" in modifications and isinstance(modifications["cookies"], dict):
|
||||
for k, v in list(modifications["cookies"].items())[:5]:
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(f"cookie {k}={_sanitize(str(v), 100)}", style="dim")
|
||||
|
||||
if "params" in modifications and isinstance(modifications["params"], dict):
|
||||
for k, v in list(modifications["params"].items())[:5]:
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
text.append(f"param {k}={_sanitize(str(v), 100)}", style="dim")
|
||||
|
||||
if "body" in modifications and isinstance(modifications["body"], str):
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
body_lines = modifications["body"].split("\n")[:4]
|
||||
for i, line in enumerate(body_lines):
|
||||
if i > 0:
|
||||
text.append("\n")
|
||||
text.append(" ", style="dim")
|
||||
text.append(_truncate(line, MAX_LINE_LENGTH), style="dim")
|
||||
if len(modifications["body"].split("\n")) > 4:
|
||||
text.append(" ...", style="dim italic")
|
||||
|
||||
elif modifications and isinstance(modifications, str):
|
||||
text.append(f"\n {_truncate(modifications, 200)}", style="dim italic")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f"\n error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
else:
|
||||
req = result.get("request", {})
|
||||
method = req.get("method", "")
|
||||
url = req.get("url", "")
|
||||
code = result.get("status_code")
|
||||
time_ms = result.get("response_time_ms")
|
||||
|
||||
text.append("\n")
|
||||
text.append(" >> ", style="#3b82f6")
|
||||
if method:
|
||||
text.append(f"{method} ", style="#a78bfa")
|
||||
if url:
|
||||
text.append(_truncate(url, 180), style="dim")
|
||||
|
||||
text.append("\n")
|
||||
text.append(" << ", style="#22c55e")
|
||||
if code:
|
||||
text.append(f"{code}", style=_status_style(code))
|
||||
if time_ms:
|
||||
text.append(f" ({time_ms}ms)", style="dim")
|
||||
|
||||
body = result.get("body", "")
|
||||
if body and isinstance(body, str):
|
||||
lines = body.split("\n")[:5]
|
||||
for line in lines:
|
||||
text.append("\n")
|
||||
text.append(" << ", style="#22c55e")
|
||||
text.append(_truncate(line, MAX_LINE_LENGTH - 5), style="dim")
|
||||
|
||||
if len(body.split("\n")) > 5:
|
||||
text.append("\n")
|
||||
text.append(" ...", style="dim italic")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ScopeRulesRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "scope_rules"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
action = args.get("action", "")
|
||||
scope_name = args.get("scope_name", "")
|
||||
scope_id = args.get("scope_id", "")
|
||||
allowlist = args.get("allowlist")
|
||||
denylist = args.get("denylist")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
|
||||
action_map = {
|
||||
"get": "getting",
|
||||
"list": "listing",
|
||||
"create": "creating",
|
||||
"update": "updating",
|
||||
"delete": "deleting",
|
||||
}
|
||||
action_text = action_map.get(action, action + "ing" if action else "managing")
|
||||
text.append(f" {action_text} proxy scope", style="#06b6d4")
|
||||
|
||||
if scope_name:
|
||||
text.append(f" '{_truncate(scope_name, 50)}'", style="dim italic")
|
||||
if scope_id and isinstance(scope_id, str):
|
||||
text.append(f" #{scope_id[:8]}", style="dim")
|
||||
|
||||
if allowlist and isinstance(allowlist, list):
|
||||
allow_str = ", ".join(_truncate(str(a), 40) for a in allowlist[:4])
|
||||
text.append(f"\n allow: {allow_str}", style="dim")
|
||||
if len(allowlist) > 4:
|
||||
text.append(f" +{len(allowlist) - 4}", style="dim italic")
|
||||
if denylist and isinstance(denylist, list):
|
||||
deny_str = ", ".join(_truncate(str(d), 40) for d in denylist[:4])
|
||||
text.append(f"\n deny: {deny_str}", style="dim")
|
||||
if len(denylist) > 4:
|
||||
text.append(f" +{len(denylist) - 4}", style="dim italic")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f" error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
elif "scopes" in result:
|
||||
scopes = result.get("scopes", [])
|
||||
text.append(f" [{len(scopes)} scopes]", style="dim")
|
||||
|
||||
if scopes and isinstance(scopes, list):
|
||||
text.append("\n")
|
||||
for i, scope in enumerate(scopes[:5]):
|
||||
if not isinstance(scope, dict):
|
||||
continue
|
||||
name = scope.get("name", "?")
|
||||
allow = scope.get("allowlist") or []
|
||||
text.append(" ")
|
||||
text.append(_truncate(str(name), 40), style="#22c55e")
|
||||
if allow and isinstance(allow, list):
|
||||
allow_str = ", ".join(_truncate(str(a), 30) for a in allow[:3])
|
||||
text.append(f" {allow_str}", style="dim")
|
||||
if len(allow) > 3:
|
||||
text.append(f" +{len(allow) - 3}", style="dim italic")
|
||||
if i < min(len(scopes), 5) - 1:
|
||||
text.append("\n")
|
||||
|
||||
elif "scope" in result:
|
||||
scope = result.get("scope") or {}
|
||||
if isinstance(scope, dict):
|
||||
allow = scope.get("allowlist") or []
|
||||
deny = scope.get("denylist") or []
|
||||
|
||||
if allow and isinstance(allow, list):
|
||||
allow_str = ", ".join(_truncate(str(a), 40) for a in allow[:5])
|
||||
text.append(f"\n allow: {allow_str}", style="dim")
|
||||
if deny and isinstance(deny, list):
|
||||
deny_str = ", ".join(_truncate(str(d), 40) for d in deny[:5])
|
||||
text.append(f"\n deny: {deny_str}", style="dim")
|
||||
|
||||
elif "message" in result:
|
||||
text.append(f" {result['message']}", style="#22c55e")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListSitemapRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_sitemap"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
parent_id = args.get("parent_id")
|
||||
scope_id = args.get("scope_id")
|
||||
depth = args.get("depth")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
text.append(" listing sitemap", style="#06b6d4")
|
||||
|
||||
if parent_id:
|
||||
text.append(f" under #{_truncate(str(parent_id), 20)}", style="dim")
|
||||
|
||||
meta_parts = []
|
||||
if scope_id and isinstance(scope_id, str):
|
||||
meta_parts.append(f"scope:{scope_id[:8]}")
|
||||
if depth and depth != "DIRECT":
|
||||
meta_parts.append(depth.lower())
|
||||
if meta_parts:
|
||||
text.append(f" ({', '.join(meta_parts)})", style="dim")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f" error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
else:
|
||||
total = result.get("total_count", 0)
|
||||
entries = result.get("entries", [])
|
||||
|
||||
text.append(f" [{total} entries]", style="dim")
|
||||
|
||||
if entries and isinstance(entries, list):
|
||||
text.append("\n")
|
||||
for i, entry in enumerate(entries[:MAX_REQUESTS_DISPLAY]):
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
kind = entry.get("kind") or "?"
|
||||
label = entry.get("label") or "?"
|
||||
has_children = entry.get("hasDescendants", False)
|
||||
req = entry.get("request") or {}
|
||||
|
||||
kind_style = {
|
||||
"DOMAIN": "#f59e0b",
|
||||
"DIRECTORY": "#3b82f6",
|
||||
"REQUEST": "#22c55e",
|
||||
}.get(kind, "dim")
|
||||
|
||||
text.append(" ")
|
||||
kind_abbr = kind[:3] if isinstance(kind, str) else "?"
|
||||
text.append(f"{kind_abbr:3}", style=kind_style)
|
||||
text.append(f" {_truncate(label, 150)}", style="dim")
|
||||
|
||||
if req:
|
||||
method = req.get("method", "")
|
||||
code = req.get("status")
|
||||
if method:
|
||||
text.append(f" {method}", style="#a78bfa")
|
||||
if code:
|
||||
text.append(f" {code}", style=_status_style(code))
|
||||
|
||||
if has_children:
|
||||
text.append(" +", style="dim italic")
|
||||
|
||||
if i < min(len(entries), MAX_REQUESTS_DISPLAY) - 1:
|
||||
text.append("\n")
|
||||
|
||||
if len(entries) > MAX_REQUESTS_DISPLAY:
|
||||
text.append("\n")
|
||||
text.append(
|
||||
f" ... +{len(entries) - MAX_REQUESTS_DISPLAY} more", style="dim italic"
|
||||
)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ViewSitemapEntryRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "view_sitemap_entry"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "proxy-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result")
|
||||
status = tool_data.get("status", "running")
|
||||
|
||||
entry_id = args.get("entry_id", "")
|
||||
|
||||
text = Text()
|
||||
text.append(PROXY_ICON, style="dim")
|
||||
text.append(" viewing sitemap", style="#06b6d4")
|
||||
|
||||
if entry_id:
|
||||
text.append(f" #{_truncate(str(entry_id), 20)}", style="dim")
|
||||
|
||||
if status == "completed" and isinstance(result, dict):
|
||||
if "error" in result:
|
||||
text.append(f" error: {_sanitize(str(result['error']), 150)}", style="#ef4444")
|
||||
elif "entry" in result:
|
||||
entry = result.get("entry") or {}
|
||||
if not isinstance(entry, dict):
|
||||
entry = {}
|
||||
kind = entry.get("kind", "")
|
||||
label = entry.get("label", "")
|
||||
related = entry.get("related_requests") or {}
|
||||
related_reqs = related.get("requests", []) if isinstance(related, dict) else []
|
||||
total_related = related.get("total_count", 0) if isinstance(related, dict) else 0
|
||||
|
||||
if kind and label:
|
||||
text.append(f" {kind}: {_truncate(label, 120)}", style="dim")
|
||||
|
||||
if total_related:
|
||||
text.append(f" [{total_related} requests]", style="dim")
|
||||
|
||||
if related_reqs and isinstance(related_reqs, list):
|
||||
text.append("\n")
|
||||
for i, req in enumerate(related_reqs[:10]):
|
||||
if not isinstance(req, dict):
|
||||
continue
|
||||
method = req.get("method", "?")
|
||||
path = req.get("path", "/")
|
||||
code = req.get("status")
|
||||
|
||||
text.append(" ")
|
||||
text.append(f"{method:6}", style="#a78bfa")
|
||||
text.append(f" {_truncate(path, 180)}", style="dim")
|
||||
if code:
|
||||
text.append(f" {code}", style=_status_style(code))
|
||||
|
||||
if i < min(len(related_reqs), 10) - 1:
|
||||
text.append("\n")
|
||||
|
||||
if len(related_reqs) > 10:
|
||||
text.append("\n")
|
||||
text.append(f" ... +{len(related_reqs) - 10} more", style="dim italic")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,155 @@
|
||||
import re
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import PythonLexer
|
||||
from pygments.styles import get_style_by_name
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
MAX_OUTPUT_LINES = 50
|
||||
MAX_LINE_LENGTH = 200
|
||||
|
||||
ANSI_PATTERN = re.compile(r"\x1b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*\x07)")
|
||||
|
||||
STRIP_PATTERNS = [
|
||||
r"\.\.\. \[(stdout|stderr|result|output|error) truncated at \d+k? chars\]",
|
||||
]
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
@cache
|
||||
def _get_lexer() -> PythonLexer:
|
||||
return PythonLexer()
|
||||
|
||||
|
||||
@cache
|
||||
def _get_token_color(token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class PythonRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "python_action"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "python-tool"]
|
||||
|
||||
@classmethod
|
||||
def _highlight_python(cls, code: str) -> Text:
|
||||
text = Text()
|
||||
for token_type, token_value in _get_lexer().get_tokens(code):
|
||||
if token_value:
|
||||
text.append(token_value, style=_get_token_color(token_type))
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def _clean_output(cls, output: str) -> str:
|
||||
cleaned = output
|
||||
for pattern in STRIP_PATTERNS:
|
||||
cleaned = re.sub(pattern, "", cleaned)
|
||||
return cleaned.strip()
|
||||
|
||||
@classmethod
|
||||
def _strip_ansi(cls, text: str) -> str:
|
||||
return ANSI_PATTERN.sub("", text)
|
||||
|
||||
@classmethod
|
||||
def _truncate_line(cls, line: str) -> str:
|
||||
clean_line = cls._strip_ansi(line)
|
||||
if len(clean_line) > MAX_LINE_LENGTH:
|
||||
return clean_line[: MAX_LINE_LENGTH - 3] + "..."
|
||||
return clean_line
|
||||
|
||||
@classmethod
|
||||
def _format_output(cls, output: str) -> Text:
|
||||
text = Text()
|
||||
lines = output.splitlines()
|
||||
total_lines = len(lines)
|
||||
|
||||
head_count = MAX_OUTPUT_LINES // 2
|
||||
tail_count = MAX_OUTPUT_LINES - head_count - 1
|
||||
|
||||
if total_lines <= MAX_OUTPUT_LINES:
|
||||
display_lines = lines
|
||||
truncated = False
|
||||
hidden_count = 0
|
||||
else:
|
||||
display_lines = lines[:head_count]
|
||||
truncated = True
|
||||
hidden_count = total_lines - head_count - tail_count
|
||||
|
||||
for i, line in enumerate(display_lines):
|
||||
truncated_line = cls._truncate_line(line)
|
||||
text.append(" ")
|
||||
text.append(truncated_line, style="dim")
|
||||
if i < len(display_lines) - 1 or truncated:
|
||||
text.append("\n")
|
||||
|
||||
if truncated:
|
||||
text.append(f" ... {hidden_count} lines truncated ...", style="dim italic")
|
||||
text.append("\n")
|
||||
tail_lines = lines[-tail_count:]
|
||||
for i, line in enumerate(tail_lines):
|
||||
truncated_line = cls._truncate_line(line)
|
||||
text.append(" ")
|
||||
text.append(truncated_line, style="dim")
|
||||
if i < len(tail_lines) - 1:
|
||||
text.append("\n")
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def _append_output(cls, text: Text, result: dict[str, Any] | str) -> None:
|
||||
if isinstance(result, str):
|
||||
if result.strip():
|
||||
text.append("\n")
|
||||
text.append_text(cls._format_output(result))
|
||||
return
|
||||
|
||||
stdout = result.get("stdout", "")
|
||||
stdout = cls._clean_output(stdout) if stdout else ""
|
||||
|
||||
if stdout:
|
||||
text.append("\n")
|
||||
formatted_output = cls._format_output(stdout)
|
||||
text.append_text(formatted_output)
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
result = tool_data.get("result")
|
||||
|
||||
action = args.get("action", "")
|
||||
code = args.get("code", "")
|
||||
|
||||
text = Text()
|
||||
text.append("</> ", style="dim")
|
||||
|
||||
if code and action in ["new_session", "execute"]:
|
||||
text.append_text(cls._highlight_python(code))
|
||||
elif action == "close":
|
||||
text.append("Closing session...", style="dim")
|
||||
elif action == "list_sessions":
|
||||
text.append("Listing sessions...", style="dim")
|
||||
else:
|
||||
text.append("Running...", style="dim")
|
||||
|
||||
if result and isinstance(result, dict | str):
|
||||
cls._append_output(text, result)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
@@ -47,26 +48,32 @@ def render_tool_widget(tool_data: dict[str, Any]) -> Static:
|
||||
|
||||
|
||||
def _render_default_tool_widget(tool_data: dict[str, Any]) -> Static:
|
||||
tool_name = BaseToolRenderer.escape_markup(tool_data.get("tool_name", "Unknown Tool"))
|
||||
tool_name = tool_data.get("tool_name", "Unknown Tool")
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
result = tool_data.get("result")
|
||||
|
||||
status_text = BaseToolRenderer.get_status_icon(status)
|
||||
text = Text()
|
||||
|
||||
header = f"→ Using tool [bold blue]{tool_name}[/]"
|
||||
content_parts = [header]
|
||||
text.append("→ Using tool ", style="dim")
|
||||
text.append(tool_name, style="bold blue")
|
||||
text.append("\n")
|
||||
|
||||
args_str = BaseToolRenderer.format_args(args)
|
||||
if args_str:
|
||||
content_parts.append(args_str)
|
||||
for k, v in list(args.items()):
|
||||
str_v = str(v)
|
||||
text.append(" ")
|
||||
text.append(k, style="dim")
|
||||
text.append(": ")
|
||||
text.append(str_v)
|
||||
text.append("\n")
|
||||
|
||||
if status in ["completed", "failed", "error"] and result is not None:
|
||||
result_str = BaseToolRenderer.format_result(result)
|
||||
if result_str:
|
||||
content_parts.append(f"[bold]Result:[/] {result_str}")
|
||||
result_str = str(result)
|
||||
text.append("Result: ", style="bold")
|
||||
text.append(result_str)
|
||||
else:
|
||||
content_parts.append(status_text)
|
||||
icon, color = BaseToolRenderer.status_icon(status)
|
||||
text.append(icon, style=color)
|
||||
|
||||
css_classes = BaseToolRenderer.get_css_classes(status)
|
||||
return Static("\n".join(content_parts), classes=css_classes)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,255 @@
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import PythonLexer
|
||||
from pygments.styles import get_style_by_name
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from strix.tools.reporting.reporting_actions import (
|
||||
parse_code_locations_xml,
|
||||
parse_cvss_xml,
|
||||
)
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
FIELD_STYLE = "bold #4ade80"
|
||||
DIM_STYLE = "dim"
|
||||
FILE_STYLE = "bold #60a5fa"
|
||||
LINE_STYLE = "#facc15"
|
||||
LABEL_STYLE = "italic #a1a1aa"
|
||||
CODE_STYLE = "#e2e8f0"
|
||||
BEFORE_STYLE = "#ef4444"
|
||||
AFTER_STYLE = "#22c55e"
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateVulnerabilityReportRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_vulnerability_report"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "reporting-tool"]
|
||||
|
||||
SEVERITY_COLORS: ClassVar[dict[str, str]] = {
|
||||
"critical": "#dc2626",
|
||||
"high": "#ea580c",
|
||||
"medium": "#d97706",
|
||||
"low": "#65a30d",
|
||||
"info": "#0284c7",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def _get_token_color(cls, token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _highlight_python(cls, code: str) -> Text:
|
||||
lexer = PythonLexer()
|
||||
text = Text()
|
||||
|
||||
for token_type, token_value in lexer.get_tokens(code):
|
||||
if not token_value:
|
||||
continue
|
||||
color = cls._get_token_color(token_type)
|
||||
text.append(token_value, style=color)
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def _get_cvss_color(cls, cvss_score: float) -> str:
|
||||
if cvss_score >= 9.0:
|
||||
return "#dc2626"
|
||||
if cvss_score >= 7.0:
|
||||
return "#ea580c"
|
||||
if cvss_score >= 4.0:
|
||||
return "#d97706"
|
||||
if cvss_score >= 0.1:
|
||||
return "#65a30d"
|
||||
return "#6b7280"
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static: # noqa: PLR0912, PLR0915
|
||||
args = tool_data.get("args", {})
|
||||
result = tool_data.get("result", {})
|
||||
|
||||
title = args.get("title", "")
|
||||
description = args.get("description", "")
|
||||
impact = args.get("impact", "")
|
||||
target = args.get("target", "")
|
||||
technical_analysis = args.get("technical_analysis", "")
|
||||
poc_description = args.get("poc_description", "")
|
||||
poc_script_code = args.get("poc_script_code", "")
|
||||
remediation_steps = args.get("remediation_steps", "")
|
||||
|
||||
cvss_breakdown_xml = args.get("cvss_breakdown", "")
|
||||
code_locations_xml = args.get("code_locations", "")
|
||||
|
||||
endpoint = args.get("endpoint", "")
|
||||
method = args.get("method", "")
|
||||
cve = args.get("cve", "")
|
||||
cwe = args.get("cwe", "")
|
||||
|
||||
severity = ""
|
||||
cvss_score = None
|
||||
if isinstance(result, dict):
|
||||
severity = result.get("severity", "")
|
||||
cvss_score = result.get("cvss_score")
|
||||
|
||||
text = Text()
|
||||
text.append("🐞 ")
|
||||
text.append("Vulnerability Report", style="bold #ea580c")
|
||||
|
||||
if title:
|
||||
text.append("\n\n")
|
||||
text.append("Title: ", style=FIELD_STYLE)
|
||||
text.append(title)
|
||||
|
||||
if severity:
|
||||
text.append("\n\n")
|
||||
text.append("Severity: ", style=FIELD_STYLE)
|
||||
severity_color = cls.SEVERITY_COLORS.get(severity.lower(), "#6b7280")
|
||||
text.append(severity.upper(), style=f"bold {severity_color}")
|
||||
|
||||
if cvss_score is not None:
|
||||
text.append("\n\n")
|
||||
text.append("CVSS Score: ", style=FIELD_STYLE)
|
||||
cvss_color = cls._get_cvss_color(cvss_score)
|
||||
text.append(str(cvss_score), style=f"bold {cvss_color}")
|
||||
|
||||
if target:
|
||||
text.append("\n\n")
|
||||
text.append("Target: ", style=FIELD_STYLE)
|
||||
text.append(target)
|
||||
|
||||
if endpoint:
|
||||
text.append("\n\n")
|
||||
text.append("Endpoint: ", style=FIELD_STYLE)
|
||||
text.append(endpoint)
|
||||
|
||||
if method:
|
||||
text.append("\n\n")
|
||||
text.append("Method: ", style=FIELD_STYLE)
|
||||
text.append(method)
|
||||
|
||||
if cve:
|
||||
text.append("\n\n")
|
||||
text.append("CVE: ", style=FIELD_STYLE)
|
||||
text.append(cve)
|
||||
|
||||
if cwe:
|
||||
text.append("\n\n")
|
||||
text.append("CWE: ", style=FIELD_STYLE)
|
||||
text.append(cwe)
|
||||
|
||||
parsed_cvss = parse_cvss_xml(cvss_breakdown_xml) if cvss_breakdown_xml else None
|
||||
if parsed_cvss:
|
||||
text.append("\n\n")
|
||||
cvss_parts = []
|
||||
for key, prefix in [
|
||||
("attack_vector", "AV"),
|
||||
("attack_complexity", "AC"),
|
||||
("privileges_required", "PR"),
|
||||
("user_interaction", "UI"),
|
||||
("scope", "S"),
|
||||
("confidentiality", "C"),
|
||||
("integrity", "I"),
|
||||
("availability", "A"),
|
||||
]:
|
||||
val = parsed_cvss.get(key)
|
||||
if val:
|
||||
cvss_parts.append(f"{prefix}:{val}")
|
||||
text.append("CVSS Vector: ", style=FIELD_STYLE)
|
||||
text.append("/".join(cvss_parts), style=DIM_STYLE)
|
||||
|
||||
if description:
|
||||
text.append("\n\n")
|
||||
text.append("Description", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(description)
|
||||
|
||||
if impact:
|
||||
text.append("\n\n")
|
||||
text.append("Impact", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(impact)
|
||||
|
||||
if technical_analysis:
|
||||
text.append("\n\n")
|
||||
text.append("Technical Analysis", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(technical_analysis)
|
||||
|
||||
parsed_locations = (
|
||||
parse_code_locations_xml(code_locations_xml) if code_locations_xml else None
|
||||
)
|
||||
if parsed_locations:
|
||||
text.append("\n\n")
|
||||
text.append("Code Locations", style=FIELD_STYLE)
|
||||
for i, loc in enumerate(parsed_locations):
|
||||
text.append("\n\n")
|
||||
text.append(f" Location {i + 1}: ", style=DIM_STYLE)
|
||||
text.append(loc.get("file", "unknown"), style=FILE_STYLE)
|
||||
start = loc.get("start_line")
|
||||
end = loc.get("end_line")
|
||||
if start is not None:
|
||||
if end and end != start:
|
||||
text.append(f":{start}-{end}", style=LINE_STYLE)
|
||||
else:
|
||||
text.append(f":{start}", style=LINE_STYLE)
|
||||
if loc.get("label"):
|
||||
text.append(f"\n {loc['label']}", style=LABEL_STYLE)
|
||||
if loc.get("snippet"):
|
||||
text.append("\n ")
|
||||
text.append(loc["snippet"], style=CODE_STYLE)
|
||||
if loc.get("fix_before") or loc.get("fix_after"):
|
||||
text.append("\n ")
|
||||
text.append("Fix:", style=DIM_STYLE)
|
||||
if loc.get("fix_before"):
|
||||
text.append("\n ")
|
||||
text.append("- ", style=BEFORE_STYLE)
|
||||
text.append(loc["fix_before"], style=BEFORE_STYLE)
|
||||
if loc.get("fix_after"):
|
||||
text.append("\n ")
|
||||
text.append("+ ", style=AFTER_STYLE)
|
||||
text.append(loc["fix_after"], style=AFTER_STYLE)
|
||||
|
||||
if poc_description:
|
||||
text.append("\n\n")
|
||||
text.append("PoC Description", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(poc_description)
|
||||
|
||||
if poc_script_code:
|
||||
text.append("\n\n")
|
||||
text.append("PoC Code", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append_text(cls._highlight_python(poc_script_code))
|
||||
|
||||
if remediation_steps:
|
||||
text.append("\n\n")
|
||||
text.append("Remediation", style=FIELD_STYLE)
|
||||
text.append("\n")
|
||||
text.append(remediation_steps)
|
||||
|
||||
if not title:
|
||||
text.append("\n ")
|
||||
text.append("Creating report...", style="dim")
|
||||
|
||||
padded = Text()
|
||||
padded.append("\n\n")
|
||||
padded.append_text(text)
|
||||
padded.append("\n\n")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(padded, classes=css_classes)
|
||||
@@ -0,0 +1,68 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ScanStartInfoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "scan_start_info"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "scan-info-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
targets = args.get("targets", [])
|
||||
|
||||
text = Text()
|
||||
text.append("◈ ", style="#22c55e")
|
||||
text.append("Starting penetration test")
|
||||
|
||||
if len(targets) == 1:
|
||||
text.append(" on ")
|
||||
text.append(cls._get_target_display(targets[0]))
|
||||
elif len(targets) > 1:
|
||||
text.append(f" on {len(targets)} targets")
|
||||
for target_info in targets:
|
||||
text.append("\n • ")
|
||||
text.append(cls._get_target_display(target_info))
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _get_target_display(cls, target_info: dict[str, Any]) -> str:
|
||||
original = target_info.get("original")
|
||||
if original:
|
||||
return str(original)
|
||||
return "unknown target"
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class SubagentStartInfoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "subagent_start_info"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "subagent-info-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
|
||||
name = str(args.get("name", "Unknown Agent"))
|
||||
task = str(args.get("task", ""))
|
||||
|
||||
text = Text()
|
||||
text.append("◈ ", style="#a78bfa")
|
||||
text.append("subagent ", style="dim")
|
||||
text.append(name, style="bold #a78bfa")
|
||||
|
||||
if task:
|
||||
text.append("\n ")
|
||||
text.append(task, style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,311 @@
|
||||
import re
|
||||
from functools import cache
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.styles import get_style_by_name
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
MAX_OUTPUT_LINES = 50
|
||||
MAX_LINE_LENGTH = 200
|
||||
|
||||
STRIP_PATTERNS = [
|
||||
(
|
||||
r"\n?\[Command still running after [\d.]+s - showing output so far\.?"
|
||||
r"\s*(?:Use C-c to interrupt if needed\.)?\]"
|
||||
),
|
||||
r"^\[Below is the output of the previous command\.\]\n?",
|
||||
r"^No command is currently running\. Cannot send input\.$",
|
||||
(
|
||||
r"^A command is already running\. Use is_input=true to send input to it, "
|
||||
r"or interrupt it first \(e\.g\., with C-c\)\.$"
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@cache
|
||||
def _get_style_colors() -> dict[Any, str]:
|
||||
style = get_style_by_name("native")
|
||||
return {token: f"#{style_def['color']}" for token, style_def in style if style_def["color"]}
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class TerminalRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "terminal_execute"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "terminal-tool"]
|
||||
|
||||
CONTROL_SEQUENCES: ClassVar[set[str]] = {
|
||||
"C-c",
|
||||
"C-d",
|
||||
"C-z",
|
||||
"C-a",
|
||||
"C-e",
|
||||
"C-k",
|
||||
"C-l",
|
||||
"C-u",
|
||||
"C-w",
|
||||
"C-r",
|
||||
"C-s",
|
||||
"C-t",
|
||||
"C-y",
|
||||
"^c",
|
||||
"^d",
|
||||
"^z",
|
||||
"^a",
|
||||
"^e",
|
||||
"^k",
|
||||
"^l",
|
||||
"^u",
|
||||
"^w",
|
||||
"^r",
|
||||
"^s",
|
||||
"^t",
|
||||
"^y",
|
||||
}
|
||||
SPECIAL_KEYS: ClassVar[set[str]] = {
|
||||
"Enter",
|
||||
"Escape",
|
||||
"Space",
|
||||
"Tab",
|
||||
"BTab",
|
||||
"BSpace",
|
||||
"DC",
|
||||
"IC",
|
||||
"Up",
|
||||
"Down",
|
||||
"Left",
|
||||
"Right",
|
||||
"Home",
|
||||
"End",
|
||||
"PageUp",
|
||||
"PageDown",
|
||||
"PgUp",
|
||||
"PgDn",
|
||||
"PPage",
|
||||
"NPage",
|
||||
"F1",
|
||||
"F2",
|
||||
"F3",
|
||||
"F4",
|
||||
"F5",
|
||||
"F6",
|
||||
"F7",
|
||||
"F8",
|
||||
"F9",
|
||||
"F10",
|
||||
"F11",
|
||||
"F12",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def _get_token_color(cls, token_type: Any) -> str | None:
|
||||
colors = _get_style_colors()
|
||||
while token_type:
|
||||
if token_type in colors:
|
||||
return colors[token_type]
|
||||
token_type = token_type.parent
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _highlight_bash(cls, code: str) -> Text:
|
||||
lexer = get_lexer_by_name("bash")
|
||||
text = Text()
|
||||
|
||||
for token_type, token_value in lexer.get_tokens(code):
|
||||
if not token_value:
|
||||
continue
|
||||
color = cls._get_token_color(token_type)
|
||||
text.append(token_value, style=color)
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
status = tool_data.get("status", "unknown")
|
||||
result = tool_data.get("result")
|
||||
|
||||
command = args.get("command", "")
|
||||
is_input = args.get("is_input", False)
|
||||
|
||||
content = cls._build_content(command, is_input, status, result)
|
||||
|
||||
css_classes = cls.get_css_classes(status)
|
||||
return Static(content, classes=css_classes)
|
||||
|
||||
@classmethod
|
||||
def _build_content(
|
||||
cls, command: str, is_input: bool, status: str, result: dict[str, Any] | str | None
|
||||
) -> Text:
|
||||
text = Text()
|
||||
terminal_icon = ">_"
|
||||
|
||||
if not command.strip():
|
||||
text.append(terminal_icon, style="dim")
|
||||
text.append(" ")
|
||||
text.append("getting logs...", style="dim")
|
||||
if result:
|
||||
cls._append_output(text, result, status, command)
|
||||
return text
|
||||
|
||||
is_special = (
|
||||
command in cls.CONTROL_SEQUENCES
|
||||
or command in cls.SPECIAL_KEYS
|
||||
or command.startswith(("M-", "S-", "C-S-", "C-M-", "S-M-"))
|
||||
)
|
||||
|
||||
text.append(terminal_icon, style="dim")
|
||||
text.append(" ")
|
||||
|
||||
if is_special:
|
||||
text.append(command, style="#ef4444")
|
||||
elif is_input:
|
||||
text.append(">>>", style="#3b82f6")
|
||||
text.append(" ")
|
||||
text.append_text(cls._format_command(command))
|
||||
else:
|
||||
text.append("$", style="#22c55e")
|
||||
text.append(" ")
|
||||
text.append_text(cls._format_command(command))
|
||||
|
||||
if result:
|
||||
cls._append_output(text, result, status, command)
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def _clean_output(cls, output: str, command: str = "") -> str:
|
||||
cleaned = output
|
||||
|
||||
for pattern in STRIP_PATTERNS:
|
||||
cleaned = re.sub(pattern, "", cleaned, flags=re.MULTILINE)
|
||||
|
||||
if cleaned.strip():
|
||||
lines = cleaned.splitlines()
|
||||
filtered_lines: list[str] = []
|
||||
for line in lines:
|
||||
if not filtered_lines and not line.strip():
|
||||
continue
|
||||
if re.match(r"^\[STRIX_\d+\]\$\s*", line):
|
||||
continue
|
||||
if command and line.strip() == command.strip():
|
||||
continue
|
||||
if command and re.match(r"^[\$#>]\s*" + re.escape(command.strip()) + r"\s*$", line):
|
||||
continue
|
||||
filtered_lines.append(line)
|
||||
|
||||
while filtered_lines and re.match(r"^\[STRIX_\d+\]\$\s*", filtered_lines[-1]):
|
||||
filtered_lines.pop()
|
||||
|
||||
cleaned = "\n".join(filtered_lines)
|
||||
|
||||
return cleaned.strip()
|
||||
|
||||
@classmethod
|
||||
def _append_output(
|
||||
cls, text: Text, result: dict[str, Any] | str, tool_status: str, command: str = ""
|
||||
) -> None:
|
||||
if isinstance(result, str):
|
||||
if result.strip():
|
||||
text.append("\n")
|
||||
text.append_text(cls._format_output(result))
|
||||
return
|
||||
|
||||
raw_output = result.get("content", "")
|
||||
output = cls._clean_output(raw_output, command)
|
||||
error = result.get("error")
|
||||
exit_code = result.get("exit_code")
|
||||
result_status = result.get("status", "")
|
||||
|
||||
if error and not cls._is_status_message(error):
|
||||
text.append("\n")
|
||||
text.append(" error: ", style="bold #ef4444")
|
||||
text.append(cls._truncate_line(error), style="#ef4444")
|
||||
return
|
||||
|
||||
if result_status == "running" or tool_status == "running":
|
||||
if output and output.strip():
|
||||
text.append("\n")
|
||||
formatted_output = cls._format_output(output)
|
||||
text.append_text(formatted_output)
|
||||
return
|
||||
|
||||
if not output or not output.strip():
|
||||
if exit_code is not None and exit_code != 0:
|
||||
text.append("\n")
|
||||
text.append(f" exit {exit_code}", style="dim #ef4444")
|
||||
return
|
||||
|
||||
text.append("\n")
|
||||
formatted_output = cls._format_output(output)
|
||||
text.append_text(formatted_output)
|
||||
|
||||
if exit_code is not None and exit_code != 0:
|
||||
text.append("\n")
|
||||
text.append(f" exit {exit_code}", style="dim #ef4444")
|
||||
|
||||
@classmethod
|
||||
def _is_status_message(cls, message: str) -> bool:
|
||||
status_patterns = [
|
||||
r"No command is currently running",
|
||||
r"A command is already running",
|
||||
r"Cannot send input",
|
||||
r"Use is_input=true",
|
||||
r"Use C-c to interrupt",
|
||||
r"showing output so far",
|
||||
]
|
||||
return any(re.search(pattern, message) for pattern in status_patterns)
|
||||
|
||||
@classmethod
|
||||
def _format_output(cls, output: str) -> Text:
|
||||
text = Text()
|
||||
lines = output.splitlines()
|
||||
total_lines = len(lines)
|
||||
|
||||
head_count = MAX_OUTPUT_LINES // 2
|
||||
tail_count = MAX_OUTPUT_LINES - head_count - 1
|
||||
|
||||
if total_lines <= MAX_OUTPUT_LINES:
|
||||
display_lines = lines
|
||||
truncated = False
|
||||
hidden_count = 0
|
||||
else:
|
||||
display_lines = lines[:head_count]
|
||||
truncated = True
|
||||
hidden_count = total_lines - head_count - tail_count
|
||||
|
||||
for i, line in enumerate(display_lines):
|
||||
truncated_line = cls._truncate_line(line)
|
||||
text.append(" ")
|
||||
text.append(truncated_line, style="dim")
|
||||
if i < len(display_lines) - 1 or truncated:
|
||||
text.append("\n")
|
||||
|
||||
if truncated:
|
||||
text.append(f" ... {hidden_count} lines truncated ...", style="dim italic")
|
||||
text.append("\n")
|
||||
tail_lines = lines[-tail_count:]
|
||||
for i, line in enumerate(tail_lines):
|
||||
truncated_line = cls._truncate_line(line)
|
||||
text.append(" ")
|
||||
text.append(truncated_line, style="dim")
|
||||
if i < len(tail_lines) - 1:
|
||||
text.append("\n")
|
||||
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def _truncate_line(cls, line: str) -> str:
|
||||
clean_line = re.sub(r"\x1b\[[0-9;]*m", "", line)
|
||||
if len(clean_line) > MAX_LINE_LENGTH:
|
||||
return line[: MAX_LINE_LENGTH - 3] + "..."
|
||||
return line
|
||||
|
||||
@classmethod
|
||||
def _format_command(cls, command: str) -> Text:
|
||||
return cls._highlight_bash(command)
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
@@ -14,16 +15,17 @@ class ThinkRenderer(BaseToolRenderer):
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
args = tool_data.get("args", {})
|
||||
|
||||
thought = args.get("thought", "")
|
||||
|
||||
header = "🧠 [bold #a855f7]Thinking[/]"
|
||||
text = Text()
|
||||
text.append("🧠 ")
|
||||
text.append("Thinking", style="bold #a855f7")
|
||||
text.append("\n ")
|
||||
|
||||
if thought:
|
||||
thought_display = thought[:200] + "..." if len(thought) > 200 else thought
|
||||
content = f"{header}\n [italic dim]{cls.escape_markup(thought_display)}[/]"
|
||||
text.append(thought, style="italic dim")
|
||||
else:
|
||||
content = f"{header}\n [italic dim]Thinking...[/]"
|
||||
text.append("Thinking...", style="italic dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content, classes=css_classes)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,225 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
STATUS_MARKERS: dict[str, str] = {
|
||||
"pending": "[ ]",
|
||||
"in_progress": "[~]",
|
||||
"done": "[•]",
|
||||
}
|
||||
|
||||
|
||||
def _format_todo_lines(text: Text, result: dict[str, Any]) -> None:
|
||||
todos = result.get("todos")
|
||||
if not isinstance(todos, list) or not todos:
|
||||
text.append("\n ")
|
||||
text.append("No todos", style="dim")
|
||||
return
|
||||
|
||||
for todo in todos:
|
||||
status = todo.get("status", "pending")
|
||||
marker = STATUS_MARKERS.get(status, STATUS_MARKERS["pending"])
|
||||
|
||||
title = todo.get("title", "").strip() or "(untitled)"
|
||||
|
||||
text.append("\n ")
|
||||
text.append(marker)
|
||||
text.append(" ")
|
||||
|
||||
if status == "done":
|
||||
text.append(title, style="dim strike")
|
||||
elif status == "in_progress":
|
||||
text.append(title, style="italic")
|
||||
else:
|
||||
text.append(title)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class CreateTodoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "create_todo"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todo", style="bold #a78bfa")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Failed to create todo")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Creating...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class ListTodosRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "list_todos"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todos", style="bold #a78bfa")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Unable to list todos")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Loading...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class UpdateTodoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "update_todo"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todo Updated", style="bold #a78bfa")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Failed to update todo")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Updating...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class MarkTodoDoneRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "mark_todo_done"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todo Completed", style="bold #a78bfa")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Failed to mark todo done")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Marking done...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class MarkTodoPendingRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "mark_todo_pending"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todo Reopened", style="bold #f59e0b")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Failed to reopen todo")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Reopening...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class DeleteTodoRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "delete_todo"
|
||||
css_classes: ClassVar[list[str]] = ["tool-call", "todo-tool"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
result = tool_data.get("result")
|
||||
|
||||
text = Text()
|
||||
text.append("📋 ")
|
||||
text.append("Todo Removed", style="bold #94a3b8")
|
||||
|
||||
if isinstance(result, str) and result.strip():
|
||||
text.append("\n ")
|
||||
text.append(result.strip(), style="dim")
|
||||
elif result and isinstance(result, dict):
|
||||
if result.get("success"):
|
||||
_format_todo_lines(text, result)
|
||||
else:
|
||||
error = result.get("error", "Failed to remove todo")
|
||||
text.append("\n ")
|
||||
text.append(error, style="#ef4444")
|
||||
else:
|
||||
text.append("\n ")
|
||||
text.append("Removing...", style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,50 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
from .registry import register_tool_renderer
|
||||
|
||||
|
||||
@register_tool_renderer
|
||||
class UserMessageRenderer(BaseToolRenderer):
|
||||
tool_name: ClassVar[str] = "user_message"
|
||||
css_classes: ClassVar[list[str]] = ["chat-message", "user-message"]
|
||||
|
||||
@classmethod
|
||||
def render(cls, tool_data: dict[str, Any]) -> Static:
|
||||
content = tool_data.get("content", "")
|
||||
|
||||
if not content:
|
||||
return Static(Text(), classes=" ".join(cls.css_classes))
|
||||
|
||||
styled_text = cls._format_user_message(content)
|
||||
|
||||
return Static(styled_text, classes=" ".join(cls.css_classes))
|
||||
|
||||
@classmethod
|
||||
def render_simple(cls, content: str) -> Text:
|
||||
if not content:
|
||||
return Text()
|
||||
|
||||
return cls._format_user_message(content)
|
||||
|
||||
@classmethod
|
||||
def _format_user_message(cls, content: str) -> Text:
|
||||
text = Text()
|
||||
|
||||
text.append("▍", style="#3b82f6")
|
||||
text.append(" ")
|
||||
text.append("You:", style="bold")
|
||||
text.append("\n")
|
||||
|
||||
lines = content.split("\n")
|
||||
for i, line in enumerate(lines):
|
||||
if i > 0:
|
||||
text.append("\n")
|
||||
text.append("▍", style="#3b82f6")
|
||||
text.append(" ")
|
||||
text.append(line)
|
||||
|
||||
return text
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from rich.text import Text
|
||||
from textual.widgets import Static
|
||||
|
||||
from .base_renderer import BaseToolRenderer
|
||||
@@ -16,13 +17,13 @@ class WebSearchRenderer(BaseToolRenderer):
|
||||
args = tool_data.get("args", {})
|
||||
query = args.get("query", "")
|
||||
|
||||
header = "🌐 [bold #60a5fa]Searching the web...[/]"
|
||||
text = Text()
|
||||
text.append("🌐 ")
|
||||
text.append("Searching the web...", style="bold #60a5fa")
|
||||
|
||||
if query:
|
||||
query_display = query[:100] + "..." if len(query) > 100 else query
|
||||
content_text = f"{header}\n [dim]{cls.escape_markup(query_display)}[/]"
|
||||
else:
|
||||
content_text = f"{header}"
|
||||
text.append("\n ")
|
||||
text.append(query, style="dim")
|
||||
|
||||
css_classes = cls.get_css_classes("completed")
|
||||
return Static(content_text, classes=css_classes)
|
||||
return Static(text, classes=css_classes)
|
||||
@@ -0,0 +1,845 @@
|
||||
import ipaddress
|
||||
import json
|
||||
import re
|
||||
import secrets
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
import docker
|
||||
from docker.errors import DockerException, ImageNotFound
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
|
||||
|
||||
# Token formatting utilities
|
||||
def format_token_count(count: float) -> str:
|
||||
count = int(count)
|
||||
if count >= 1_000_000:
|
||||
return f"{count / 1_000_000:.1f}M"
|
||||
if count >= 1_000:
|
||||
return f"{count / 1_000:.1f}K"
|
||||
return str(count)
|
||||
|
||||
|
||||
# Display utilities
|
||||
def get_severity_color(severity: str) -> str:
|
||||
severity_colors = {
|
||||
"critical": "#dc2626",
|
||||
"high": "#ea580c",
|
||||
"medium": "#d97706",
|
||||
"low": "#65a30d",
|
||||
"info": "#0284c7",
|
||||
}
|
||||
return severity_colors.get(severity, "#6b7280")
|
||||
|
||||
|
||||
def get_cvss_color(cvss_score: float) -> str:
|
||||
if cvss_score >= 9.0:
|
||||
return "#dc2626"
|
||||
if cvss_score >= 7.0:
|
||||
return "#ea580c"
|
||||
if cvss_score >= 4.0:
|
||||
return "#d97706"
|
||||
if cvss_score >= 0.1:
|
||||
return "#65a30d"
|
||||
return "#6b7280"
|
||||
|
||||
|
||||
def format_vulnerability_report(report: dict[str, Any]) -> Text: # noqa: PLR0912, PLR0915
|
||||
"""Format a vulnerability report for CLI display with all rich fields."""
|
||||
field_style = "bold #4ade80"
|
||||
|
||||
text = Text()
|
||||
|
||||
title = report.get("title", "")
|
||||
if title:
|
||||
text.append("Vulnerability Report", style="bold #ea580c")
|
||||
text.append("\n\n")
|
||||
text.append("Title: ", style=field_style)
|
||||
text.append(title)
|
||||
|
||||
severity = report.get("severity", "")
|
||||
if severity:
|
||||
text.append("\n\n")
|
||||
text.append("Severity: ", style=field_style)
|
||||
severity_color = get_severity_color(severity.lower())
|
||||
text.append(severity.upper(), style=f"bold {severity_color}")
|
||||
|
||||
cvss = report.get("cvss")
|
||||
if cvss is not None:
|
||||
text.append("\n\n")
|
||||
text.append("CVSS Score: ", style=field_style)
|
||||
cvss_color = get_cvss_color(cvss)
|
||||
text.append(f"{cvss:.1f}", style=f"bold {cvss_color}")
|
||||
|
||||
target = report.get("target")
|
||||
if target:
|
||||
text.append("\n\n")
|
||||
text.append("Target: ", style=field_style)
|
||||
text.append(target)
|
||||
|
||||
endpoint = report.get("endpoint")
|
||||
if endpoint:
|
||||
text.append("\n\n")
|
||||
text.append("Endpoint: ", style=field_style)
|
||||
text.append(endpoint)
|
||||
|
||||
method = report.get("method")
|
||||
if method:
|
||||
text.append("\n\n")
|
||||
text.append("Method: ", style=field_style)
|
||||
text.append(method)
|
||||
|
||||
cve = report.get("cve")
|
||||
if cve:
|
||||
text.append("\n\n")
|
||||
text.append("CVE: ", style=field_style)
|
||||
text.append(cve)
|
||||
|
||||
cvss_breakdown = report.get("cvss_breakdown", {})
|
||||
if cvss_breakdown:
|
||||
text.append("\n\n")
|
||||
cvss_parts = []
|
||||
if cvss_breakdown.get("attack_vector"):
|
||||
cvss_parts.append(f"AV:{cvss_breakdown['attack_vector']}")
|
||||
if cvss_breakdown.get("attack_complexity"):
|
||||
cvss_parts.append(f"AC:{cvss_breakdown['attack_complexity']}")
|
||||
if cvss_breakdown.get("privileges_required"):
|
||||
cvss_parts.append(f"PR:{cvss_breakdown['privileges_required']}")
|
||||
if cvss_breakdown.get("user_interaction"):
|
||||
cvss_parts.append(f"UI:{cvss_breakdown['user_interaction']}")
|
||||
if cvss_breakdown.get("scope"):
|
||||
cvss_parts.append(f"S:{cvss_breakdown['scope']}")
|
||||
if cvss_breakdown.get("confidentiality"):
|
||||
cvss_parts.append(f"C:{cvss_breakdown['confidentiality']}")
|
||||
if cvss_breakdown.get("integrity"):
|
||||
cvss_parts.append(f"I:{cvss_breakdown['integrity']}")
|
||||
if cvss_breakdown.get("availability"):
|
||||
cvss_parts.append(f"A:{cvss_breakdown['availability']}")
|
||||
if cvss_parts:
|
||||
text.append("CVSS Vector: ", style=field_style)
|
||||
text.append("/".join(cvss_parts), style="dim")
|
||||
|
||||
description = report.get("description")
|
||||
if description:
|
||||
text.append("\n\n")
|
||||
text.append("Description", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(description)
|
||||
|
||||
impact = report.get("impact")
|
||||
if impact:
|
||||
text.append("\n\n")
|
||||
text.append("Impact", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(impact)
|
||||
|
||||
technical_analysis = report.get("technical_analysis")
|
||||
if technical_analysis:
|
||||
text.append("\n\n")
|
||||
text.append("Technical Analysis", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(technical_analysis)
|
||||
|
||||
poc_description = report.get("poc_description")
|
||||
if poc_description:
|
||||
text.append("\n\n")
|
||||
text.append("PoC Description", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(poc_description)
|
||||
|
||||
poc_script_code = report.get("poc_script_code")
|
||||
if poc_script_code:
|
||||
text.append("\n\n")
|
||||
text.append("PoC Code", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(poc_script_code, style="dim")
|
||||
|
||||
code_locations = report.get("code_locations")
|
||||
if code_locations:
|
||||
text.append("\n\n")
|
||||
text.append("Code Locations", style=field_style)
|
||||
for i, loc in enumerate(code_locations):
|
||||
text.append("\n\n")
|
||||
text.append(f" Location {i + 1}: ", style="dim")
|
||||
text.append(loc.get("file", "unknown"), style="bold")
|
||||
start = loc.get("start_line")
|
||||
end = loc.get("end_line")
|
||||
if start is not None:
|
||||
if end and end != start:
|
||||
text.append(f":{start}-{end}")
|
||||
else:
|
||||
text.append(f":{start}")
|
||||
if loc.get("label"):
|
||||
text.append(f"\n {loc['label']}", style="italic dim")
|
||||
if loc.get("snippet"):
|
||||
text.append("\n ")
|
||||
text.append(loc["snippet"], style="dim")
|
||||
if loc.get("fix_before") or loc.get("fix_after"):
|
||||
text.append("\n Fix:")
|
||||
if loc.get("fix_before"):
|
||||
text.append("\n - ", style="dim")
|
||||
text.append(loc["fix_before"], style="dim")
|
||||
if loc.get("fix_after"):
|
||||
text.append("\n + ", style="dim")
|
||||
text.append(loc["fix_after"], style="dim")
|
||||
|
||||
remediation_steps = report.get("remediation_steps")
|
||||
if remediation_steps:
|
||||
text.append("\n\n")
|
||||
text.append("Remediation", style=field_style)
|
||||
text.append("\n")
|
||||
text.append(remediation_steps)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def _build_vulnerability_stats(stats_text: Text, tracer: Any) -> None:
|
||||
"""Build vulnerability section of stats text."""
|
||||
vuln_count = len(tracer.vulnerability_reports)
|
||||
|
||||
if vuln_count > 0:
|
||||
severity_counts = {"critical": 0, "high": 0, "medium": 0, "low": 0, "info": 0}
|
||||
for report in tracer.vulnerability_reports:
|
||||
severity = report.get("severity", "").lower()
|
||||
if severity in severity_counts:
|
||||
severity_counts[severity] += 1
|
||||
|
||||
stats_text.append("Vulnerabilities ", style="bold red")
|
||||
|
||||
severity_parts = []
|
||||
for severity in ["critical", "high", "medium", "low", "info"]:
|
||||
count = severity_counts[severity]
|
||||
if count > 0:
|
||||
severity_color = get_severity_color(severity)
|
||||
severity_text = Text()
|
||||
severity_text.append(f"{severity.upper()}: ", style=severity_color)
|
||||
severity_text.append(str(count), style=f"bold {severity_color}")
|
||||
severity_parts.append(severity_text)
|
||||
|
||||
for i, part in enumerate(severity_parts):
|
||||
stats_text.append(part)
|
||||
if i < len(severity_parts) - 1:
|
||||
stats_text.append(" | ", style="dim white")
|
||||
|
||||
stats_text.append(" (Total: ", style="dim white")
|
||||
stats_text.append(str(vuln_count), style="bold yellow")
|
||||
stats_text.append(")", style="dim white")
|
||||
stats_text.append("\n")
|
||||
else:
|
||||
stats_text.append("Vulnerabilities ", style="bold #22c55e")
|
||||
stats_text.append("0", style="bold white")
|
||||
stats_text.append(" (No exploitable vulnerabilities detected)", style="dim green")
|
||||
stats_text.append("\n")
|
||||
|
||||
|
||||
def _build_llm_stats(stats_text: Text, total_stats: dict[str, Any]) -> None:
|
||||
"""Build LLM usage section of stats text."""
|
||||
if total_stats["requests"] > 0:
|
||||
stats_text.append("\n")
|
||||
stats_text.append("Input Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["input_tokens"]), style="white")
|
||||
|
||||
if total_stats["cached_tokens"] > 0:
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Cached Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["cached_tokens"]), style="white")
|
||||
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Output Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["output_tokens"]), style="white")
|
||||
|
||||
if total_stats["cost"] > 0:
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Cost ", style="dim")
|
||||
stats_text.append(f"${total_stats['cost']:.4f}", style="bold #fbbf24")
|
||||
else:
|
||||
stats_text.append("\n")
|
||||
stats_text.append("Cost ", style="dim")
|
||||
stats_text.append("$0.0000 ", style="#fbbf24")
|
||||
stats_text.append("· ", style="dim white")
|
||||
stats_text.append("Tokens ", style="dim")
|
||||
stats_text.append("0", style="white")
|
||||
|
||||
|
||||
def build_final_stats_text(tracer: Any) -> Text:
|
||||
"""Build stats text for final output with detailed messages and LLM usage."""
|
||||
stats_text = Text()
|
||||
if not tracer:
|
||||
return stats_text
|
||||
|
||||
_build_vulnerability_stats(stats_text, tracer)
|
||||
|
||||
tool_count = tracer.get_real_tool_count()
|
||||
agent_count = len(tracer.agents)
|
||||
|
||||
stats_text.append("Agents", style="dim")
|
||||
stats_text.append(" ")
|
||||
stats_text.append(str(agent_count), style="bold white")
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Tools", style="dim")
|
||||
stats_text.append(" ")
|
||||
stats_text.append(str(tool_count), style="bold white")
|
||||
|
||||
llm_stats = tracer.get_total_llm_stats()
|
||||
_build_llm_stats(stats_text, llm_stats["total"])
|
||||
|
||||
return stats_text
|
||||
|
||||
|
||||
def build_live_stats_text(tracer: Any, agent_config: dict[str, Any] | None = None) -> Text:
|
||||
stats_text = Text()
|
||||
if not tracer:
|
||||
return stats_text
|
||||
|
||||
if agent_config:
|
||||
llm_config = agent_config["llm_config"]
|
||||
model = getattr(llm_config, "model_name", "Unknown")
|
||||
stats_text.append("Model ", style="dim")
|
||||
stats_text.append(model, style="white")
|
||||
stats_text.append("\n")
|
||||
|
||||
vuln_count = len(tracer.vulnerability_reports)
|
||||
tool_count = tracer.get_real_tool_count()
|
||||
agent_count = len(tracer.agents)
|
||||
|
||||
stats_text.append("Vulnerabilities ", style="dim")
|
||||
stats_text.append(f"{vuln_count}", style="white")
|
||||
stats_text.append("\n")
|
||||
if vuln_count > 0:
|
||||
severity_counts = {"critical": 0, "high": 0, "medium": 0, "low": 0, "info": 0}
|
||||
for report in tracer.vulnerability_reports:
|
||||
severity = report.get("severity", "").lower()
|
||||
if severity in severity_counts:
|
||||
severity_counts[severity] += 1
|
||||
|
||||
severity_parts = []
|
||||
for severity in ["critical", "high", "medium", "low", "info"]:
|
||||
count = severity_counts[severity]
|
||||
if count > 0:
|
||||
severity_color = get_severity_color(severity)
|
||||
severity_text = Text()
|
||||
severity_text.append(f"{severity.upper()}: ", style=severity_color)
|
||||
severity_text.append(str(count), style=f"bold {severity_color}")
|
||||
severity_parts.append(severity_text)
|
||||
|
||||
for i, part in enumerate(severity_parts):
|
||||
stats_text.append(part)
|
||||
if i < len(severity_parts) - 1:
|
||||
stats_text.append(" | ", style="dim white")
|
||||
|
||||
stats_text.append("\n")
|
||||
|
||||
stats_text.append("Agents ", style="dim")
|
||||
stats_text.append(str(agent_count), style="white")
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Tools ", style="dim")
|
||||
stats_text.append(str(tool_count), style="white")
|
||||
|
||||
llm_stats = tracer.get_total_llm_stats()
|
||||
total_stats = llm_stats["total"]
|
||||
|
||||
stats_text.append("\n")
|
||||
|
||||
stats_text.append("Input Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["input_tokens"]), style="white")
|
||||
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Cached Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["cached_tokens"]), style="white")
|
||||
|
||||
stats_text.append("\n")
|
||||
|
||||
stats_text.append("Output Tokens ", style="dim")
|
||||
stats_text.append(format_token_count(total_stats["output_tokens"]), style="white")
|
||||
|
||||
stats_text.append(" · ", style="dim white")
|
||||
stats_text.append("Cost ", style="dim")
|
||||
stats_text.append(f"${total_stats['cost']:.4f}", style="#fbbf24")
|
||||
|
||||
return stats_text
|
||||
|
||||
|
||||
def build_tui_stats_text(tracer: Any, agent_config: dict[str, Any] | None = None) -> Text:
|
||||
stats_text = Text()
|
||||
if not tracer:
|
||||
return stats_text
|
||||
|
||||
if agent_config:
|
||||
llm_config = agent_config["llm_config"]
|
||||
model = getattr(llm_config, "model_name", "Unknown")
|
||||
stats_text.append(model, style="white")
|
||||
|
||||
llm_stats = tracer.get_total_llm_stats()
|
||||
total_stats = llm_stats["total"]
|
||||
|
||||
total_tokens = total_stats["input_tokens"] + total_stats["output_tokens"]
|
||||
if total_tokens > 0:
|
||||
stats_text.append("\n")
|
||||
stats_text.append(f"{format_token_count(total_tokens)} tokens", style="white")
|
||||
|
||||
if total_stats["cost"] > 0:
|
||||
stats_text.append(" · ", style="white")
|
||||
stats_text.append(f"${total_stats['cost']:.2f}", style="white")
|
||||
|
||||
return stats_text
|
||||
|
||||
|
||||
# Name generation utilities
|
||||
|
||||
|
||||
def _slugify_for_run_name(text: str, max_length: int = 32) -> str:
|
||||
text = text.lower().strip()
|
||||
text = re.sub(r"[^a-z0-9]+", "-", text)
|
||||
text = text.strip("-")
|
||||
if len(text) > max_length:
|
||||
text = text[:max_length].rstrip("-")
|
||||
return text or "pentest"
|
||||
|
||||
|
||||
def _derive_target_label_for_run_name(targets_info: list[dict[str, Any]] | None) -> str: # noqa: PLR0911
|
||||
if not targets_info:
|
||||
return "pentest"
|
||||
|
||||
first = targets_info[0]
|
||||
target_type = first.get("type")
|
||||
details = first.get("details", {}) or {}
|
||||
original = first.get("original", "") or ""
|
||||
|
||||
if target_type == "web_application":
|
||||
url = details.get("target_url", original)
|
||||
try:
|
||||
parsed = urlparse(url)
|
||||
return str(parsed.netloc or parsed.path or url)
|
||||
except Exception: # noqa: BLE001
|
||||
return str(url)
|
||||
|
||||
if target_type == "repository":
|
||||
repo = details.get("target_repo", original)
|
||||
parsed = urlparse(repo)
|
||||
path = parsed.path or repo
|
||||
name = path.rstrip("/").split("/")[-1] or path
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
return str(name)
|
||||
|
||||
if target_type == "local_code":
|
||||
path_str = details.get("target_path", original)
|
||||
try:
|
||||
return str(Path(path_str).name or path_str)
|
||||
except Exception: # noqa: BLE001
|
||||
return str(path_str)
|
||||
|
||||
if target_type == "ip_address":
|
||||
return str(details.get("target_ip", original) or original)
|
||||
|
||||
return str(original or "pentest")
|
||||
|
||||
|
||||
def generate_run_name(targets_info: list[dict[str, Any]] | None = None) -> str:
|
||||
base_label = _derive_target_label_for_run_name(targets_info)
|
||||
slug = _slugify_for_run_name(base_label)
|
||||
|
||||
random_suffix = secrets.token_hex(2)
|
||||
|
||||
return f"{slug}_{random_suffix}"
|
||||
|
||||
|
||||
# Target processing utilities
|
||||
|
||||
|
||||
def _is_http_git_repo(url: str) -> bool:
|
||||
check_url = f"{url.rstrip('/')}/info/refs?service=git-upload-pack"
|
||||
try:
|
||||
req = Request(check_url, headers={"User-Agent": "git/strix"}) # noqa: S310
|
||||
with urlopen(req, timeout=10) as resp: # noqa: S310 # nosec B310
|
||||
return "x-git-upload-pack-advertisement" in resp.headers.get("Content-Type", "")
|
||||
except HTTPError as e:
|
||||
return e.code == 401
|
||||
except (URLError, OSError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def infer_target_type(target: str) -> tuple[str, dict[str, str]]: # noqa: PLR0911, PLR0912
|
||||
if not target or not isinstance(target, str):
|
||||
raise ValueError("Target must be a non-empty string")
|
||||
|
||||
target = target.strip()
|
||||
|
||||
if target.startswith("git@"):
|
||||
return "repository", {"target_repo": target}
|
||||
|
||||
if target.startswith("git://"):
|
||||
return "repository", {"target_repo": target}
|
||||
|
||||
parsed = urlparse(target)
|
||||
if parsed.scheme in ("http", "https"):
|
||||
if parsed.username or parsed.password:
|
||||
return "repository", {"target_repo": target}
|
||||
if parsed.path.rstrip("/").endswith(".git"):
|
||||
return "repository", {"target_repo": target}
|
||||
if parsed.query or parsed.fragment:
|
||||
return "web_application", {"target_url": target}
|
||||
path_segments = [s for s in parsed.path.split("/") if s]
|
||||
if len(path_segments) >= 2 and _is_http_git_repo(target):
|
||||
return "repository", {"target_repo": target}
|
||||
return "web_application", {"target_url": target}
|
||||
|
||||
try:
|
||||
ip_obj = ipaddress.ip_address(target)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
return "ip_address", {"target_ip": str(ip_obj)}
|
||||
|
||||
path = Path(target).expanduser()
|
||||
try:
|
||||
if path.exists():
|
||||
if path.is_dir():
|
||||
return "local_code", {"target_path": str(path.resolve())}
|
||||
raise ValueError(f"Path exists but is not a directory: {target}")
|
||||
except (OSError, RuntimeError) as e:
|
||||
raise ValueError(f"Invalid path: {target} - {e!s}") from e
|
||||
|
||||
if target.endswith(".git"):
|
||||
return "repository", {"target_repo": target}
|
||||
|
||||
if "/" in target:
|
||||
host_part, _, path_part = target.partition("/")
|
||||
if "." in host_part and not host_part.startswith(".") and path_part:
|
||||
full_url = f"https://{target}"
|
||||
if _is_http_git_repo(full_url):
|
||||
return "repository", {"target_repo": full_url}
|
||||
return "web_application", {"target_url": full_url}
|
||||
|
||||
if "." in target and "/" not in target and not target.startswith("."):
|
||||
parts = target.split(".")
|
||||
if len(parts) >= 2 and all(p and p.strip() for p in parts):
|
||||
return "web_application", {"target_url": f"https://{target}"}
|
||||
|
||||
raise ValueError(
|
||||
f"Invalid target: {target}\n"
|
||||
"Target must be one of:\n"
|
||||
"- A valid URL (http:// or https://)\n"
|
||||
"- A Git repository URL (https://host/org/repo or git@host:org/repo.git)\n"
|
||||
"- A local directory path\n"
|
||||
"- A domain name (e.g., example.com)\n"
|
||||
"- An IP address (e.g., 192.168.1.10)"
|
||||
)
|
||||
|
||||
|
||||
def sanitize_name(name: str) -> str:
|
||||
sanitized = re.sub(r"[^A-Za-z0-9._-]", "-", name.strip())
|
||||
return sanitized or "target"
|
||||
|
||||
|
||||
def derive_repo_base_name(repo_url: str) -> str:
|
||||
if repo_url.endswith("/"):
|
||||
repo_url = repo_url[:-1]
|
||||
|
||||
if ":" in repo_url and repo_url.startswith("git@"):
|
||||
path_part = repo_url.split(":", 1)[1]
|
||||
else:
|
||||
path_part = urlparse(repo_url).path or repo_url
|
||||
|
||||
candidate = path_part.split("/")[-1]
|
||||
if candidate.endswith(".git"):
|
||||
candidate = candidate[:-4]
|
||||
|
||||
return sanitize_name(candidate or "repository")
|
||||
|
||||
|
||||
def derive_local_base_name(path_str: str) -> str:
|
||||
try:
|
||||
base = Path(path_str).resolve().name
|
||||
except (OSError, RuntimeError):
|
||||
base = Path(path_str).name
|
||||
return sanitize_name(base or "workspace")
|
||||
|
||||
|
||||
def assign_workspace_subdirs(targets_info: list[dict[str, Any]]) -> None:
|
||||
name_counts: dict[str, int] = {}
|
||||
|
||||
for target in targets_info:
|
||||
target_type = target["type"]
|
||||
details = target["details"]
|
||||
|
||||
base_name: str | None = None
|
||||
if target_type == "repository":
|
||||
base_name = derive_repo_base_name(details["target_repo"])
|
||||
elif target_type == "local_code":
|
||||
base_name = derive_local_base_name(details.get("target_path", "local"))
|
||||
|
||||
if base_name is None:
|
||||
continue
|
||||
|
||||
count = name_counts.get(base_name, 0) + 1
|
||||
name_counts[base_name] = count
|
||||
|
||||
workspace_subdir = base_name if count == 1 else f"{base_name}-{count}"
|
||||
|
||||
details["workspace_subdir"] = workspace_subdir
|
||||
|
||||
|
||||
def collect_local_sources(targets_info: list[dict[str, Any]]) -> list[dict[str, str]]:
|
||||
local_sources: list[dict[str, str]] = []
|
||||
|
||||
for target_info in targets_info:
|
||||
details = target_info["details"]
|
||||
workspace_subdir = details.get("workspace_subdir")
|
||||
|
||||
if target_info["type"] == "local_code" and "target_path" in details:
|
||||
local_sources.append(
|
||||
{
|
||||
"source_path": details["target_path"],
|
||||
"workspace_subdir": workspace_subdir,
|
||||
}
|
||||
)
|
||||
|
||||
elif target_info["type"] == "repository" and "cloned_repo_path" in details:
|
||||
local_sources.append(
|
||||
{
|
||||
"source_path": details["cloned_repo_path"],
|
||||
"workspace_subdir": workspace_subdir,
|
||||
}
|
||||
)
|
||||
|
||||
return local_sources
|
||||
|
||||
|
||||
def _is_localhost_host(host: str) -> bool:
|
||||
host_lower = host.lower().strip("[]")
|
||||
|
||||
if host_lower in ("localhost", "0.0.0.0", "::1"): # nosec B104
|
||||
return True
|
||||
|
||||
try:
|
||||
ip = ipaddress.ip_address(host_lower)
|
||||
if isinstance(ip, ipaddress.IPv4Address):
|
||||
return ip.is_loopback # 127.0.0.0/8
|
||||
if isinstance(ip, ipaddress.IPv6Address):
|
||||
return ip.is_loopback # ::1
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def rewrite_localhost_targets(targets_info: list[dict[str, Any]], host_gateway: str) -> None:
|
||||
from yarl import URL # type: ignore[import-not-found]
|
||||
|
||||
for target_info in targets_info:
|
||||
target_type = target_info.get("type")
|
||||
details = target_info.get("details", {})
|
||||
|
||||
if target_type == "web_application":
|
||||
target_url = details.get("target_url", "")
|
||||
try:
|
||||
url = URL(target_url)
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
if url.host and _is_localhost_host(url.host):
|
||||
details["target_url"] = str(url.with_host(host_gateway))
|
||||
|
||||
elif target_type == "ip_address":
|
||||
target_ip = details.get("target_ip", "")
|
||||
if target_ip and _is_localhost_host(target_ip):
|
||||
details["target_ip"] = host_gateway
|
||||
|
||||
|
||||
# Repository utilities
|
||||
def clone_repository(repo_url: str, run_name: str, dest_name: str | None = None) -> str:
|
||||
console = Console()
|
||||
|
||||
git_executable = shutil.which("git")
|
||||
if git_executable is None:
|
||||
raise FileNotFoundError("Git executable not found in PATH")
|
||||
|
||||
temp_dir = Path(tempfile.gettempdir()) / "strix_repos" / run_name
|
||||
temp_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if dest_name:
|
||||
repo_name = dest_name
|
||||
else:
|
||||
repo_name = Path(repo_url).stem if repo_url.endswith(".git") else Path(repo_url).name
|
||||
|
||||
clone_path = temp_dir / repo_name
|
||||
|
||||
if clone_path.exists():
|
||||
shutil.rmtree(clone_path)
|
||||
|
||||
try:
|
||||
with console.status(f"[bold cyan]Cloning repository {repo_url}...", spinner="dots"):
|
||||
subprocess.run( # noqa: S603
|
||||
[
|
||||
git_executable,
|
||||
"clone",
|
||||
repo_url,
|
||||
str(clone_path),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
|
||||
return str(clone_path.absolute())
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
error_text = Text()
|
||||
error_text.append("REPOSITORY CLONE FAILED", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append(f"Could not clone repository: {repo_url}\n", style="white")
|
||||
error_text.append(
|
||||
f"Error: {e.stderr if hasattr(e, 'stderr') and e.stderr else str(e)}", style="dim red"
|
||||
)
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
except FileNotFoundError:
|
||||
error_text = Text()
|
||||
error_text.append("GIT NOT FOUND", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("Git is not installed or not available in PATH.\n", style="white")
|
||||
error_text.append("Please install Git to clone repositories.\n", style="white")
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n")
|
||||
console.print(panel)
|
||||
console.print()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Docker utilities
|
||||
def check_docker_connection() -> Any:
|
||||
try:
|
||||
return docker.from_env()
|
||||
except DockerException:
|
||||
console = Console()
|
||||
error_text = Text()
|
||||
error_text.append("DOCKER NOT AVAILABLE", style="bold red")
|
||||
error_text.append("\n\n", style="white")
|
||||
error_text.append("Cannot connect to Docker daemon.\n", style="white")
|
||||
error_text.append(
|
||||
"Please ensure Docker Desktop is installed and running, and try running strix again.\n",
|
||||
style="white",
|
||||
)
|
||||
|
||||
panel = Panel(
|
||||
error_text,
|
||||
title="[bold white]STRIX",
|
||||
title_align="left",
|
||||
border_style="red",
|
||||
padding=(1, 2),
|
||||
)
|
||||
console.print("\n", panel, "\n")
|
||||
raise RuntimeError("Docker not available") from None
|
||||
|
||||
|
||||
def image_exists(client: Any, image_name: str) -> bool:
|
||||
try:
|
||||
client.images.get(image_name)
|
||||
except ImageNotFound:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def update_layer_status(layers_info: dict[str, str], layer_id: str, layer_status: str) -> None:
|
||||
if "Pull complete" in layer_status or "Already exists" in layer_status:
|
||||
layers_info[layer_id] = "✓"
|
||||
elif "Downloading" in layer_status:
|
||||
layers_info[layer_id] = "↓"
|
||||
elif "Extracting" in layer_status:
|
||||
layers_info[layer_id] = "📦"
|
||||
elif "Waiting" in layer_status:
|
||||
layers_info[layer_id] = "⏳"
|
||||
else:
|
||||
layers_info[layer_id] = "•"
|
||||
|
||||
|
||||
def process_pull_line(
|
||||
line: dict[str, Any], layers_info: dict[str, str], status: Any, last_update: str
|
||||
) -> str:
|
||||
if "id" in line and "status" in line:
|
||||
layer_id = line["id"]
|
||||
update_layer_status(layers_info, layer_id, line["status"])
|
||||
|
||||
completed = sum(1 for v in layers_info.values() if v == "✓")
|
||||
total = len(layers_info)
|
||||
|
||||
if total > 0:
|
||||
update_msg = f"[bold cyan]Progress: {completed}/{total} layers complete"
|
||||
if update_msg != last_update:
|
||||
status.update(update_msg)
|
||||
return update_msg
|
||||
|
||||
elif "status" in line and "id" not in line:
|
||||
global_status = line["status"]
|
||||
if "Pulling from" in global_status:
|
||||
status.update("[bold cyan]Fetching image manifest...")
|
||||
elif "Digest:" in global_status:
|
||||
status.update("[bold cyan]Verifying image...")
|
||||
elif "Status:" in global_status:
|
||||
status.update("[bold cyan]Finalizing...")
|
||||
|
||||
return last_update
|
||||
|
||||
|
||||
# LLM utilities
|
||||
def validate_llm_response(response: Any) -> None:
|
||||
if not response or not response.choices or not response.choices[0].message.content:
|
||||
raise RuntimeError("Invalid response from LLM")
|
||||
|
||||
|
||||
def validate_config_file(config_path: str) -> Path:
|
||||
console = Console()
|
||||
path = Path(config_path)
|
||||
|
||||
if not path.exists():
|
||||
console.print(f"[bold red]Error:[/] Config file not found: {config_path}")
|
||||
sys.exit(1)
|
||||
|
||||
if path.suffix != ".json":
|
||||
console.print("[bold red]Error:[/] Config file must be a .json file")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with path.open("r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
console.print(f"[bold red]Error:[/] Invalid JSON in config file: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if not isinstance(data, dict):
|
||||
console.print("[bold red]Error:[/] Config file must contain a JSON object")
|
||||
sys.exit(1)
|
||||
|
||||
if "env" not in data or not isinstance(data.get("env"), dict):
|
||||
console.print("[bold red]Error:[/] Config file must have an 'env' object")
|
||||
sys.exit(1)
|
||||
|
||||
return path
|
||||
@@ -1,12 +1,19 @@
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
import litellm
|
||||
|
||||
from .config import LLMConfig
|
||||
from .llm import LLM
|
||||
from .llm import LLM, LLMRequestFailedError
|
||||
|
||||
|
||||
__all__ = [
|
||||
"LLM",
|
||||
"LLMConfig",
|
||||
"LLMRequestFailedError",
|
||||
]
|
||||
|
||||
litellm.drop_params = True
|
||||
litellm._logging._disable_debugging()
|
||||
logging.getLogger("asyncio").setLevel(logging.CRITICAL)
|
||||
logging.getLogger("asyncio").propagate = False
|
||||
warnings.filterwarnings("ignore", category=RuntimeWarning, module="asyncio")
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
import os
|
||||
from strix.config import Config
|
||||
from strix.config.config import resolve_llm_config
|
||||
|
||||
|
||||
class LLMConfig:
|
||||
def __init__(
|
||||
self,
|
||||
model_name: str | None = None,
|
||||
temperature: float = 0,
|
||||
enable_prompt_caching: bool = True,
|
||||
prompt_modules: list[str] | None = None,
|
||||
skills: list[str] | None = None,
|
||||
timeout: int | None = None,
|
||||
scan_mode: str = "deep",
|
||||
):
|
||||
self.model_name = model_name or os.getenv("STRIX_LLM", "anthropic/claude-opus-4-1-20250805")
|
||||
resolved_model, self.api_key, self.api_base = resolve_llm_config()
|
||||
self.model_name = model_name or resolved_model
|
||||
|
||||
if not self.model_name:
|
||||
raise ValueError("STRIX_LLM environment variable must be set and not empty")
|
||||
|
||||
self.temperature = max(0.0, min(1.0, temperature))
|
||||
self.enable_prompt_caching = enable_prompt_caching
|
||||
self.prompt_modules = prompt_modules or []
|
||||
self.skills = skills or []
|
||||
|
||||
self.timeout = timeout or int(Config.get("llm_timeout") or "300")
|
||||
|
||||
self.scan_mode = scan_mode if scan_mode in ["quick", "standard", "deep"] else "deep"
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import litellm
|
||||
|
||||
from strix.config.config import resolve_llm_config
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEDUPE_SYSTEM_PROMPT = """You are an expert vulnerability report deduplication judge.
|
||||
Your task is to determine if a candidate vulnerability report describes the SAME vulnerability
|
||||
as any existing report.
|
||||
|
||||
CRITICAL DEDUPLICATION RULES:
|
||||
|
||||
1. SAME VULNERABILITY means:
|
||||
- Same root cause (e.g., "missing input validation" not just "SQL injection")
|
||||
- Same affected component/endpoint/file (exact match or clear overlap)
|
||||
- Same exploitation method or attack vector
|
||||
- Would be fixed by the same code change/patch
|
||||
|
||||
2. NOT DUPLICATES if:
|
||||
- Different endpoints even with same vulnerability type (e.g., SQLi in /login vs /search)
|
||||
- Different parameters in same endpoint (e.g., XSS in 'name' vs 'comment' field)
|
||||
- Different root causes (e.g., stored XSS vs reflected XSS in same field)
|
||||
- Different severity levels due to different impact
|
||||
- One is authenticated, other is unauthenticated
|
||||
|
||||
3. ARE DUPLICATES even if:
|
||||
- Titles are worded differently
|
||||
- Descriptions have different level of detail
|
||||
- PoC uses different payloads but exploits same issue
|
||||
- One report is more thorough than another
|
||||
- Minor variations in technical analysis
|
||||
|
||||
COMPARISON GUIDELINES:
|
||||
- Focus on the technical root cause, not surface-level similarities
|
||||
- Same vulnerability type (SQLi, XSS) doesn't mean duplicate - location matters
|
||||
- Consider the fix: would fixing one also fix the other?
|
||||
- When uncertain, lean towards NOT duplicate
|
||||
|
||||
FIELDS TO ANALYZE:
|
||||
- title, description: General vulnerability info
|
||||
- target, endpoint, method: Exact location of vulnerability
|
||||
- technical_analysis: Root cause details
|
||||
- poc_description: How it's exploited
|
||||
- impact: What damage it can cause
|
||||
|
||||
YOU MUST RESPOND WITH EXACTLY THIS XML FORMAT AND NOTHING ELSE:
|
||||
|
||||
<dedupe_result>
|
||||
<is_duplicate>true</is_duplicate>
|
||||
<duplicate_id>vuln-0001</duplicate_id>
|
||||
<confidence>0.95</confidence>
|
||||
<reason>Both reports describe SQL injection in /api/login via the username parameter</reason>
|
||||
</dedupe_result>
|
||||
|
||||
OR if not a duplicate:
|
||||
|
||||
<dedupe_result>
|
||||
<is_duplicate>false</is_duplicate>
|
||||
<duplicate_id></duplicate_id>
|
||||
<confidence>0.90</confidence>
|
||||
<reason>Different endpoints: candidate is /api/search, existing is /api/login</reason>
|
||||
</dedupe_result>
|
||||
|
||||
RULES:
|
||||
- is_duplicate MUST be exactly "true" or "false" (lowercase)
|
||||
- duplicate_id MUST be the exact ID from existing reports or empty if not duplicate
|
||||
- confidence MUST be a decimal (your confidence level in the decision)
|
||||
- reason MUST be a specific explanation mentioning endpoint/parameter/root cause
|
||||
- DO NOT include any text outside the <dedupe_result> tags"""
|
||||
|
||||
|
||||
def _prepare_report_for_comparison(report: dict[str, Any]) -> dict[str, Any]:
|
||||
relevant_fields = [
|
||||
"id",
|
||||
"title",
|
||||
"description",
|
||||
"impact",
|
||||
"target",
|
||||
"technical_analysis",
|
||||
"poc_description",
|
||||
"endpoint",
|
||||
"method",
|
||||
]
|
||||
|
||||
cleaned = {}
|
||||
for field in relevant_fields:
|
||||
if report.get(field):
|
||||
value = report[field]
|
||||
if isinstance(value, str) and len(value) > 8000:
|
||||
value = value[:8000] + "...[truncated]"
|
||||
cleaned[field] = value
|
||||
|
||||
return cleaned
|
||||
|
||||
|
||||
def _extract_xml_field(content: str, field: str) -> str:
|
||||
pattern = rf"<{field}>(.*?)</{field}>"
|
||||
match = re.search(pattern, content, re.DOTALL | re.IGNORECASE)
|
||||
if match:
|
||||
return match.group(1).strip()
|
||||
return ""
|
||||
|
||||
|
||||
def _parse_dedupe_response(content: str) -> dict[str, Any]:
|
||||
result_match = re.search(
|
||||
r"<dedupe_result>(.*?)</dedupe_result>", content, re.DOTALL | re.IGNORECASE
|
||||
)
|
||||
|
||||
if not result_match:
|
||||
logger.warning(f"No <dedupe_result> block found in response: {content[:500]}")
|
||||
raise ValueError("No <dedupe_result> block found in response")
|
||||
|
||||
result_content = result_match.group(1)
|
||||
|
||||
is_duplicate_str = _extract_xml_field(result_content, "is_duplicate")
|
||||
duplicate_id = _extract_xml_field(result_content, "duplicate_id")
|
||||
confidence_str = _extract_xml_field(result_content, "confidence")
|
||||
reason = _extract_xml_field(result_content, "reason")
|
||||
|
||||
is_duplicate = is_duplicate_str.lower() == "true"
|
||||
|
||||
try:
|
||||
confidence = float(confidence_str) if confidence_str else 0.0
|
||||
except ValueError:
|
||||
confidence = 0.0
|
||||
|
||||
return {
|
||||
"is_duplicate": is_duplicate,
|
||||
"duplicate_id": duplicate_id[:64] if duplicate_id else "",
|
||||
"confidence": confidence,
|
||||
"reason": reason[:500] if reason else "",
|
||||
}
|
||||
|
||||
|
||||
def check_duplicate(
|
||||
candidate: dict[str, Any], existing_reports: list[dict[str, Any]]
|
||||
) -> dict[str, Any]:
|
||||
if not existing_reports:
|
||||
return {
|
||||
"is_duplicate": False,
|
||||
"duplicate_id": "",
|
||||
"confidence": 1.0,
|
||||
"reason": "No existing reports to compare against",
|
||||
}
|
||||
|
||||
try:
|
||||
candidate_cleaned = _prepare_report_for_comparison(candidate)
|
||||
existing_cleaned = [_prepare_report_for_comparison(r) for r in existing_reports]
|
||||
|
||||
comparison_data = {"candidate": candidate_cleaned, "existing_reports": existing_cleaned}
|
||||
|
||||
model_name, api_key, api_base = resolve_llm_config()
|
||||
|
||||
messages = [
|
||||
{"role": "system", "content": DEDUPE_SYSTEM_PROMPT},
|
||||
{
|
||||
"role": "user",
|
||||
"content": (
|
||||
f"Compare this candidate vulnerability against existing reports:\n\n"
|
||||
f"{json.dumps(comparison_data, indent=2)}\n\n"
|
||||
f"Respond with ONLY the <dedupe_result> XML block."
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
completion_kwargs: dict[str, Any] = {
|
||||
"model": model_name,
|
||||
"messages": messages,
|
||||
"timeout": 120,
|
||||
}
|
||||
if api_key:
|
||||
completion_kwargs["api_key"] = api_key
|
||||
if api_base:
|
||||
completion_kwargs["api_base"] = api_base
|
||||
|
||||
response = litellm.completion(**completion_kwargs)
|
||||
|
||||
content = response.choices[0].message.content
|
||||
if not content:
|
||||
return {
|
||||
"is_duplicate": False,
|
||||
"duplicate_id": "",
|
||||
"confidence": 0.0,
|
||||
"reason": "Empty response from LLM",
|
||||
}
|
||||
|
||||
result = _parse_dedupe_response(content)
|
||||
|
||||
logger.info(
|
||||
f"Deduplication check: is_duplicate={result['is_duplicate']}, "
|
||||
f"confidence={result['confidence']}, reason={result['reason'][:100]}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Error during vulnerability deduplication check")
|
||||
return {
|
||||
"is_duplicate": False,
|
||||
"duplicate_id": "",
|
||||
"confidence": 0.0,
|
||||
"reason": f"Deduplication check failed: {e}",
|
||||
"error": str(e),
|
||||
}
|
||||
else:
|
||||
return result
|
||||
@@ -1,47 +1,42 @@
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
from collections.abc import AsyncIterator
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import litellm
|
||||
from jinja2 import (
|
||||
Environment,
|
||||
FileSystemLoader,
|
||||
select_autoescape,
|
||||
)
|
||||
from litellm import ModelResponse, completion_cost
|
||||
from litellm.utils import supports_prompt_caching
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from litellm import acompletion, completion_cost, stream_chunk_builder, supports_reasoning
|
||||
from litellm.utils import supports_prompt_caching, supports_vision
|
||||
|
||||
from strix.config import Config
|
||||
from strix.llm.config import LLMConfig
|
||||
from strix.llm.memory_compressor import MemoryCompressor
|
||||
from strix.llm.request_queue import get_global_queue
|
||||
from strix.llm.utils import _truncate_to_first_function, parse_tool_invocations
|
||||
from strix.prompts import load_prompt_modules
|
||||
from strix.llm.utils import (
|
||||
_truncate_to_first_function,
|
||||
fix_incomplete_tool_call,
|
||||
parse_tool_invocations,
|
||||
)
|
||||
from strix.skills import load_skills
|
||||
from strix.tools import get_tools_prompt
|
||||
from strix.utils.resource_paths import get_strix_resource_path
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
api_key = os.getenv("LLM_API_KEY")
|
||||
if api_key:
|
||||
litellm.api_key = api_key
|
||||
litellm.drop_params = True
|
||||
litellm.modify_params = True
|
||||
|
||||
|
||||
class StepRole(str, Enum):
|
||||
AGENT = "agent"
|
||||
USER = "user"
|
||||
SYSTEM = "system"
|
||||
class LLMRequestFailedError(Exception):
|
||||
def __init__(self, message: str, details: str | None = None):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
self.details = details
|
||||
|
||||
|
||||
@dataclass
|
||||
class LLMResponse:
|
||||
content: str
|
||||
tool_invocations: list[dict[str, Any]] | None = None
|
||||
scan_id: str | None = None
|
||||
step_number: int = 1
|
||||
role: StepRole = StepRole.AGENT
|
||||
thinking_blocks: list[dict[str, Any]] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -49,20 +44,16 @@ class RequestStats:
|
||||
input_tokens: int = 0
|
||||
output_tokens: int = 0
|
||||
cached_tokens: int = 0
|
||||
cache_creation_tokens: int = 0
|
||||
cost: float = 0.0
|
||||
requests: int = 0
|
||||
failed_requests: int = 0
|
||||
|
||||
def to_dict(self) -> dict[str, int | float]:
|
||||
return {
|
||||
"input_tokens": self.input_tokens,
|
||||
"output_tokens": self.output_tokens,
|
||||
"cached_tokens": self.cached_tokens,
|
||||
"cache_creation_tokens": self.cache_creation_tokens,
|
||||
"cost": round(self.cost, 4),
|
||||
"requests": self.requests,
|
||||
"failed_requests": self.failed_requests,
|
||||
}
|
||||
|
||||
|
||||
@@ -70,241 +61,260 @@ class LLM:
|
||||
def __init__(self, config: LLMConfig, agent_name: str | None = None):
|
||||
self.config = config
|
||||
self.agent_name = agent_name
|
||||
self.agent_id: str | None = None
|
||||
self._total_stats = RequestStats()
|
||||
self._last_request_stats = RequestStats()
|
||||
self.memory_compressor = MemoryCompressor(model_name=config.model_name)
|
||||
self.system_prompt = self._load_system_prompt(agent_name)
|
||||
|
||||
self.memory_compressor = MemoryCompressor()
|
||||
reasoning = Config.get("strix_reasoning_effort")
|
||||
if reasoning:
|
||||
self._reasoning_effort = reasoning
|
||||
elif config.scan_mode == "quick":
|
||||
self._reasoning_effort = "medium"
|
||||
else:
|
||||
self._reasoning_effort = "high"
|
||||
|
||||
if agent_name:
|
||||
prompt_dir = Path(__file__).parent.parent / "agents" / agent_name
|
||||
prompts_dir = Path(__file__).parent.parent / "prompts"
|
||||
def _load_system_prompt(self, agent_name: str | None) -> str:
|
||||
if not agent_name:
|
||||
return ""
|
||||
|
||||
loader = FileSystemLoader([prompt_dir, prompts_dir])
|
||||
self.jinja_env = Environment(
|
||||
loader=loader,
|
||||
try:
|
||||
prompt_dir = get_strix_resource_path("agents", agent_name)
|
||||
skills_dir = get_strix_resource_path("skills")
|
||||
env = Environment(
|
||||
loader=FileSystemLoader([prompt_dir, skills_dir]),
|
||||
autoescape=select_autoescape(enabled_extensions=(), default_for_string=False),
|
||||
)
|
||||
|
||||
try:
|
||||
prompt_module_content = load_prompt_modules(
|
||||
self.config.prompt_modules or [], self.jinja_env
|
||||
)
|
||||
skills_to_load = [
|
||||
*list(self.config.skills or []),
|
||||
f"scan_modes/{self.config.scan_mode}",
|
||||
]
|
||||
skill_content = load_skills(skills_to_load)
|
||||
env.globals["get_skill"] = lambda name: skill_content.get(name, "")
|
||||
|
||||
def get_module(name: str) -> str:
|
||||
return prompt_module_content.get(name, "")
|
||||
|
||||
self.jinja_env.globals["get_module"] = get_module
|
||||
|
||||
self.system_prompt = self.jinja_env.get_template("system_prompt.jinja").render(
|
||||
get_tools_prompt=get_tools_prompt,
|
||||
loaded_module_names=list(prompt_module_content.keys()),
|
||||
**prompt_module_content,
|
||||
)
|
||||
except (FileNotFoundError, OSError, ValueError) as e:
|
||||
logger.warning(f"Failed to load system prompt for {agent_name}: {e}")
|
||||
self.system_prompt = "You are a helpful AI assistant."
|
||||
else:
|
||||
self.system_prompt = "You are a helpful AI assistant."
|
||||
|
||||
def _add_cache_control_to_content(
|
||||
self, content: str | list[dict[str, Any]]
|
||||
) -> str | list[dict[str, Any]]:
|
||||
if isinstance(content, str):
|
||||
return [{"type": "text", "text": content, "cache_control": {"type": "ephemeral"}}]
|
||||
if isinstance(content, list) and content:
|
||||
last_item = content[-1]
|
||||
if isinstance(last_item, dict) and last_item.get("type") == "text":
|
||||
return content[:-1] + [{**last_item, "cache_control": {"type": "ephemeral"}}]
|
||||
return content
|
||||
|
||||
def _is_anthropic_model(self) -> bool:
|
||||
if not self.config.model_name:
|
||||
return False
|
||||
model_lower = self.config.model_name.lower()
|
||||
return any(provider in model_lower for provider in ["anthropic/", "claude"])
|
||||
|
||||
def _calculate_cache_interval(self, total_messages: int) -> int:
|
||||
if total_messages <= 1:
|
||||
return 10
|
||||
|
||||
max_cached_messages = 3
|
||||
non_system_messages = total_messages - 1
|
||||
|
||||
interval = 10
|
||||
while non_system_messages // interval > max_cached_messages:
|
||||
interval += 10
|
||||
|
||||
return interval
|
||||
|
||||
def _prepare_cached_messages(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
if (
|
||||
not self.config.enable_prompt_caching
|
||||
or not supports_prompt_caching(self.config.model_name)
|
||||
or not messages
|
||||
):
|
||||
return messages
|
||||
|
||||
if not self._is_anthropic_model():
|
||||
return messages
|
||||
|
||||
cached_messages = list(messages)
|
||||
|
||||
if cached_messages and cached_messages[0].get("role") == "system":
|
||||
system_message = cached_messages[0].copy()
|
||||
system_message["content"] = self._add_cache_control_to_content(
|
||||
system_message["content"]
|
||||
result = env.get_template("system_prompt.jinja").render(
|
||||
get_tools_prompt=get_tools_prompt,
|
||||
loaded_skill_names=list(skill_content.keys()),
|
||||
**skill_content,
|
||||
)
|
||||
cached_messages[0] = system_message
|
||||
return str(result)
|
||||
except Exception: # noqa: BLE001
|
||||
return ""
|
||||
|
||||
total_messages = len(cached_messages)
|
||||
if total_messages > 1:
|
||||
interval = self._calculate_cache_interval(total_messages)
|
||||
|
||||
cached_count = 0
|
||||
for i in range(interval, total_messages, interval):
|
||||
if cached_count >= 3:
|
||||
break
|
||||
|
||||
if i < len(cached_messages):
|
||||
message = cached_messages[i].copy()
|
||||
message["content"] = self._add_cache_control_to_content(message["content"])
|
||||
cached_messages[i] = message
|
||||
cached_count += 1
|
||||
|
||||
return cached_messages
|
||||
def set_agent_identity(self, agent_name: str | None, agent_id: str | None) -> None:
|
||||
if agent_name:
|
||||
self.agent_name = agent_name
|
||||
if agent_id:
|
||||
self.agent_id = agent_id
|
||||
|
||||
async def generate(
|
||||
self,
|
||||
conversation_history: list[dict[str, Any]],
|
||||
scan_id: str | None = None,
|
||||
step_number: int = 1,
|
||||
) -> LLMResponse:
|
||||
messages = [{"role": "system", "content": self.system_prompt}]
|
||||
self, conversation_history: list[dict[str, Any]]
|
||||
) -> AsyncIterator[LLMResponse]:
|
||||
messages = self._prepare_messages(conversation_history)
|
||||
max_retries = int(Config.get("strix_llm_max_retries") or "5")
|
||||
|
||||
compressed_history = list(self.memory_compressor.compress_history(conversation_history))
|
||||
for attempt in range(max_retries + 1):
|
||||
try:
|
||||
async for response in self._stream(messages):
|
||||
yield response
|
||||
return # noqa: TRY300
|
||||
except Exception as e: # noqa: BLE001
|
||||
if attempt >= max_retries or not self._should_retry(e):
|
||||
self._raise_error(e)
|
||||
wait = min(10, 2 * (2**attempt))
|
||||
await asyncio.sleep(wait)
|
||||
|
||||
conversation_history.clear()
|
||||
conversation_history.extend(compressed_history)
|
||||
messages.extend(compressed_history)
|
||||
|
||||
cached_messages = self._prepare_cached_messages(messages)
|
||||
|
||||
try:
|
||||
response = await self._make_request(cached_messages)
|
||||
self._update_usage_stats(response)
|
||||
|
||||
content = ""
|
||||
if (
|
||||
response.choices
|
||||
and hasattr(response.choices[0], "message")
|
||||
and response.choices[0].message
|
||||
):
|
||||
content = getattr(response.choices[0].message, "content", "") or ""
|
||||
|
||||
content = _truncate_to_first_function(content)
|
||||
|
||||
if "</function>" in content:
|
||||
function_end_index = content.find("</function>") + len("</function>")
|
||||
content = content[:function_end_index]
|
||||
|
||||
tool_invocations = parse_tool_invocations(content)
|
||||
|
||||
return LLMResponse(
|
||||
scan_id=scan_id,
|
||||
step_number=step_number,
|
||||
role=StepRole.AGENT,
|
||||
content=content,
|
||||
tool_invocations=tool_invocations if tool_invocations else None,
|
||||
)
|
||||
|
||||
except (ValueError, TypeError, RuntimeError):
|
||||
logger.exception("Error in LLM generation")
|
||||
return LLMResponse(
|
||||
scan_id=scan_id,
|
||||
step_number=step_number,
|
||||
role=StepRole.AGENT,
|
||||
content="An error occurred while generating the response",
|
||||
tool_invocations=None,
|
||||
)
|
||||
|
||||
@property
|
||||
def usage_stats(self) -> dict[str, dict[str, int | float]]:
|
||||
return {
|
||||
"total": self._total_stats.to_dict(),
|
||||
"last_request": self._last_request_stats.to_dict(),
|
||||
}
|
||||
|
||||
def get_cache_config(self) -> dict[str, bool]:
|
||||
return {
|
||||
"enabled": self.config.enable_prompt_caching,
|
||||
"supported": supports_prompt_caching(self.config.model_name),
|
||||
}
|
||||
|
||||
async def _make_request(
|
||||
self,
|
||||
messages: list[dict[str, Any]],
|
||||
) -> ModelResponse:
|
||||
completion_args = {
|
||||
"model": self.config.model_name,
|
||||
"messages": messages,
|
||||
"temperature": self.config.temperature,
|
||||
"stop": ["</function>"],
|
||||
}
|
||||
|
||||
queue = get_global_queue()
|
||||
response = await queue.make_request(completion_args)
|
||||
async def _stream(self, messages: list[dict[str, Any]]) -> AsyncIterator[LLMResponse]:
|
||||
accumulated = ""
|
||||
chunks: list[Any] = []
|
||||
done_streaming = 0
|
||||
|
||||
self._total_stats.requests += 1
|
||||
self._last_request_stats = RequestStats(requests=1)
|
||||
response = await acompletion(**self._build_completion_args(messages), stream=True)
|
||||
|
||||
return response
|
||||
async for chunk in response:
|
||||
chunks.append(chunk)
|
||||
if done_streaming:
|
||||
done_streaming += 1
|
||||
if getattr(chunk, "usage", None) or done_streaming > 5:
|
||||
break
|
||||
continue
|
||||
delta = self._get_chunk_content(chunk)
|
||||
if delta:
|
||||
accumulated += delta
|
||||
if "</function>" in accumulated:
|
||||
accumulated = accumulated[
|
||||
: accumulated.find("</function>") + len("</function>")
|
||||
]
|
||||
yield LLMResponse(content=accumulated)
|
||||
done_streaming = 1
|
||||
continue
|
||||
yield LLMResponse(content=accumulated)
|
||||
|
||||
def _update_usage_stats(self, response: ModelResponse) -> None:
|
||||
if chunks:
|
||||
self._update_usage_stats(stream_chunk_builder(chunks))
|
||||
|
||||
accumulated = fix_incomplete_tool_call(_truncate_to_first_function(accumulated))
|
||||
yield LLMResponse(
|
||||
content=accumulated,
|
||||
tool_invocations=parse_tool_invocations(accumulated),
|
||||
thinking_blocks=self._extract_thinking(chunks),
|
||||
)
|
||||
|
||||
def _prepare_messages(self, conversation_history: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
messages = [{"role": "system", "content": self.system_prompt}]
|
||||
|
||||
if self.agent_name:
|
||||
messages.append(
|
||||
{
|
||||
"role": "user",
|
||||
"content": (
|
||||
f"\n\n<agent_identity>\n"
|
||||
f"<meta>Internal metadata: do not echo or reference.</meta>\n"
|
||||
f"<agent_name>{self.agent_name}</agent_name>\n"
|
||||
f"<agent_id>{self.agent_id}</agent_id>\n"
|
||||
f"</agent_identity>\n\n"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
compressed = list(self.memory_compressor.compress_history(conversation_history))
|
||||
conversation_history.clear()
|
||||
conversation_history.extend(compressed)
|
||||
messages.extend(compressed)
|
||||
|
||||
if self._is_anthropic() and self.config.enable_prompt_caching:
|
||||
messages = self._add_cache_control(messages)
|
||||
|
||||
return messages
|
||||
|
||||
def _build_completion_args(self, messages: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
if not self._supports_vision():
|
||||
messages = self._strip_images(messages)
|
||||
|
||||
args: dict[str, Any] = {
|
||||
"model": self.config.model_name,
|
||||
"messages": messages,
|
||||
"timeout": self.config.timeout,
|
||||
"stream_options": {"include_usage": True},
|
||||
}
|
||||
|
||||
if self.config.api_key:
|
||||
args["api_key"] = self.config.api_key
|
||||
if self.config.api_base:
|
||||
args["api_base"] = self.config.api_base
|
||||
if self._supports_reasoning():
|
||||
args["reasoning_effort"] = self._reasoning_effort
|
||||
|
||||
return args
|
||||
|
||||
def _get_chunk_content(self, chunk: Any) -> str:
|
||||
if chunk.choices and hasattr(chunk.choices[0], "delta"):
|
||||
return getattr(chunk.choices[0].delta, "content", "") or ""
|
||||
return ""
|
||||
|
||||
def _extract_thinking(self, chunks: list[Any]) -> list[dict[str, Any]] | None:
|
||||
if not chunks or not self._supports_reasoning():
|
||||
return None
|
||||
try:
|
||||
resp = stream_chunk_builder(chunks)
|
||||
if resp.choices and hasattr(resp.choices[0].message, "thinking_blocks"):
|
||||
blocks: list[dict[str, Any]] = resp.choices[0].message.thinking_blocks
|
||||
return blocks
|
||||
except Exception: # noqa: BLE001, S110 # nosec B110
|
||||
pass
|
||||
return None
|
||||
|
||||
def _update_usage_stats(self, response: Any) -> None:
|
||||
try:
|
||||
if hasattr(response, "usage") and response.usage:
|
||||
input_tokens = getattr(response.usage, "prompt_tokens", 0)
|
||||
output_tokens = getattr(response.usage, "completion_tokens", 0)
|
||||
|
||||
cached_tokens = 0
|
||||
cache_creation_tokens = 0
|
||||
|
||||
if hasattr(response.usage, "prompt_tokens_details"):
|
||||
prompt_details = response.usage.prompt_tokens_details
|
||||
if hasattr(prompt_details, "cached_tokens"):
|
||||
cached_tokens = prompt_details.cached_tokens or 0
|
||||
|
||||
if hasattr(response.usage, "cache_creation_input_tokens"):
|
||||
cache_creation_tokens = response.usage.cache_creation_input_tokens or 0
|
||||
|
||||
else:
|
||||
input_tokens = 0
|
||||
output_tokens = 0
|
||||
cached_tokens = 0
|
||||
cache_creation_tokens = 0
|
||||
|
||||
try:
|
||||
cost = completion_cost(response) or 0.0
|
||||
except (ValueError, TypeError, RuntimeError) as e:
|
||||
logger.warning(f"Failed to calculate cost: {e}")
|
||||
except Exception: # noqa: BLE001
|
||||
cost = 0.0
|
||||
|
||||
self._total_stats.input_tokens += input_tokens
|
||||
self._total_stats.output_tokens += output_tokens
|
||||
self._total_stats.cached_tokens += cached_tokens
|
||||
self._total_stats.cache_creation_tokens += cache_creation_tokens
|
||||
self._total_stats.cost += cost
|
||||
|
||||
self._last_request_stats.input_tokens = input_tokens
|
||||
self._last_request_stats.output_tokens = output_tokens
|
||||
self._last_request_stats.cached_tokens = cached_tokens
|
||||
self._last_request_stats.cache_creation_tokens = cache_creation_tokens
|
||||
self._last_request_stats.cost = cost
|
||||
except Exception: # noqa: BLE001, S110 # nosec B110
|
||||
pass
|
||||
|
||||
if cached_tokens > 0:
|
||||
logger.info(f"Cache hit: {cached_tokens} cached tokens, {input_tokens} new tokens")
|
||||
if cache_creation_tokens > 0:
|
||||
logger.info(f"Cache creation: {cache_creation_tokens} tokens written to cache")
|
||||
def _should_retry(self, e: Exception) -> bool:
|
||||
code = getattr(e, "status_code", None) or getattr(
|
||||
getattr(e, "response", None), "status_code", None
|
||||
)
|
||||
return code is None or litellm._should_retry(code)
|
||||
|
||||
logger.info(f"Usage stats: {self.usage_stats}")
|
||||
except (AttributeError, TypeError, ValueError) as e:
|
||||
logger.warning(f"Failed to update usage stats: {e}")
|
||||
def _raise_error(self, e: Exception) -> None:
|
||||
from strix.telemetry import posthog
|
||||
|
||||
posthog.error("llm_error", type(e).__name__)
|
||||
raise LLMRequestFailedError(f"LLM request failed: {type(e).__name__}", str(e)) from e
|
||||
|
||||
def _is_anthropic(self) -> bool:
|
||||
if not self.config.model_name:
|
||||
return False
|
||||
return any(p in self.config.model_name.lower() for p in ["anthropic/", "claude"])
|
||||
|
||||
def _supports_vision(self) -> bool:
|
||||
try:
|
||||
return bool(supports_vision(model=self.config.model_name))
|
||||
except Exception: # noqa: BLE001
|
||||
return False
|
||||
|
||||
def _supports_reasoning(self) -> bool:
|
||||
try:
|
||||
return bool(supports_reasoning(model=self.config.model_name))
|
||||
except Exception: # noqa: BLE001
|
||||
return False
|
||||
|
||||
def _strip_images(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
result = []
|
||||
for msg in messages:
|
||||
content = msg.get("content")
|
||||
if isinstance(content, list):
|
||||
text_parts = []
|
||||
for item in content:
|
||||
if isinstance(item, dict) and item.get("type") == "text":
|
||||
text_parts.append(item.get("text", ""))
|
||||
elif isinstance(item, dict) and item.get("type") == "image_url":
|
||||
text_parts.append("[Image removed - model doesn't support vision]")
|
||||
result.append({**msg, "content": "\n".join(text_parts)})
|
||||
else:
|
||||
result.append(msg)
|
||||
return result
|
||||
|
||||
def _add_cache_control(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
if not messages or not supports_prompt_caching(self.config.model_name):
|
||||
return messages
|
||||
|
||||
result = list(messages)
|
||||
|
||||
if result[0].get("role") == "system":
|
||||
content = result[0]["content"]
|
||||
result[0] = {
|
||||
**result[0],
|
||||
"content": [
|
||||
{"type": "text", "text": content, "cache_control": {"type": "ephemeral"}}
|
||||
]
|
||||
if isinstance(content, str)
|
||||
else content,
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import logging
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
import litellm
|
||||
|
||||
from strix.config.config import Config, resolve_llm_config
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -85,6 +86,7 @@ def _extract_message_text(msg: dict[str, Any]) -> str:
|
||||
def _summarize_messages(
|
||||
messages: list[dict[str, Any]],
|
||||
model: str,
|
||||
timeout: int = 30,
|
||||
) -> dict[str, Any]:
|
||||
if not messages:
|
||||
empty_summary = "<context_summary message_count='0'>{text}</context_summary>"
|
||||
@@ -102,14 +104,23 @@ def _summarize_messages(
|
||||
conversation = "\n".join(formatted)
|
||||
prompt = SUMMARY_PROMPT_TEMPLATE.format(conversation=conversation)
|
||||
|
||||
_, api_key, api_base = resolve_llm_config()
|
||||
|
||||
try:
|
||||
completion_args = {
|
||||
completion_args: dict[str, Any] = {
|
||||
"model": model,
|
||||
"messages": [{"role": "user", "content": prompt}],
|
||||
"timeout": timeout,
|
||||
}
|
||||
if api_key:
|
||||
completion_args["api_key"] = api_key
|
||||
if api_base:
|
||||
completion_args["api_base"] = api_base
|
||||
|
||||
response = litellm.completion(**completion_args)
|
||||
summary = response.choices[0].message.content
|
||||
summary = response.choices[0].message.content or ""
|
||||
if not summary.strip():
|
||||
return messages[0]
|
||||
summary_msg = "<context_summary message_count='{count}'>{text}</context_summary>"
|
||||
return {
|
||||
"role": "assistant",
|
||||
@@ -143,9 +154,11 @@ class MemoryCompressor:
|
||||
self,
|
||||
max_images: int = 3,
|
||||
model_name: str | None = None,
|
||||
timeout: int | None = None,
|
||||
):
|
||||
self.max_images = max_images
|
||||
self.model_name = model_name or os.getenv("STRIX_LLM", "anthropic/claude-opus-4-1-20250805")
|
||||
self.model_name = model_name or Config.get("strix_llm")
|
||||
self.timeout = timeout or int(Config.get("strix_memory_compressor_timeout") or "30")
|
||||
|
||||
if not self.model_name:
|
||||
raise ValueError("STRIX_LLM environment variable must be set and not empty")
|
||||
@@ -199,7 +212,7 @@ class MemoryCompressor:
|
||||
chunk_size = 10
|
||||
for i in range(0, len(old_msgs), chunk_size):
|
||||
chunk = old_msgs[i : i + chunk_size]
|
||||
summary = _summarize_messages(chunk, model_name)
|
||||
summary = _summarize_messages(chunk, model_name, self.timeout)
|
||||
if summary:
|
||||
compressed.append(summary)
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from litellm import ModelResponse, completion
|
||||
from tenacity import retry, stop_after_attempt, wait_exponential
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LLMRequestQueue:
|
||||
def __init__(self, max_concurrent: int = 6, delay_between_requests: float = 1.0):
|
||||
self.max_concurrent = max_concurrent
|
||||
self.delay_between_requests = delay_between_requests
|
||||
self._semaphore = threading.BoundedSemaphore(max_concurrent)
|
||||
self._last_request_time = 0.0
|
||||
self._lock = threading.Lock()
|
||||
|
||||
async def make_request(self, completion_args: dict[str, Any]) -> ModelResponse:
|
||||
try:
|
||||
while not self._semaphore.acquire(timeout=0.2):
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
with self._lock:
|
||||
now = time.time()
|
||||
time_since_last = now - self._last_request_time
|
||||
sleep_needed = max(0, self.delay_between_requests - time_since_last)
|
||||
self._last_request_time = now + sleep_needed
|
||||
|
||||
if sleep_needed > 0:
|
||||
await asyncio.sleep(sleep_needed)
|
||||
|
||||
return await self._reliable_request(completion_args)
|
||||
finally:
|
||||
self._semaphore.release()
|
||||
|
||||
@retry( # type: ignore[misc]
|
||||
stop=stop_after_attempt(15),
|
||||
wait=wait_exponential(multiplier=1.2, min=1, max=300),
|
||||
reraise=True,
|
||||
)
|
||||
async def _reliable_request(self, completion_args: dict[str, Any]) -> ModelResponse:
|
||||
response = completion(**completion_args, stream=False)
|
||||
if isinstance(response, ModelResponse):
|
||||
return response
|
||||
self._raise_unexpected_response()
|
||||
raise RuntimeError("Unreachable code")
|
||||
|
||||
def _raise_unexpected_response(self) -> None:
|
||||
raise RuntimeError("Unexpected response type")
|
||||
|
||||
|
||||
_global_queue: LLMRequestQueue | None = None
|
||||
|
||||
|
||||
def get_global_queue() -> LLMRequestQueue:
|
||||
global _global_queue # noqa: PLW0603
|
||||
if _global_queue is None:
|
||||
_global_queue = LLMRequestQueue()
|
||||
return _global_queue
|
||||