Xuanji General Strategic Prototype
Author: Peng Hao
Affiliation: Python Historical Strategy Lab
License: MIT
PHSL: Xuanji Strategic Audit Terminal 🛡️
Python Historical Strategy Lab (PHSL) presents the Xuanji Strategic Audit Terminal, an advanced, AI-driven wargaming and strategic simulation system.
Xuanji acts as a digital wind tunnel for strategy, performing rigorous "Red Team" audits on strategic visions by mapping them to historical prototypes and stress-testing them in simulated environments. By integrating systems thinking,the system quantifies the physical viability of a strategy against real-world environmental noise, friction, and resistance.
📐 The Core Strategic Axiom
At the heart of the Xuanji engine is the structural conservation of historical and realistic isomorphism. Strategic effectiveness is calculated using the following core formula:
$$E = \frac{P \cdot (ssc_d \cdot L)}{(I \cdot (1 + vol)) + P}$$
Dimensional Variables:
$E$ (Strategic Effectiveness): The actualized impact of the strategy.
$P$ (Resource Pressure): The resources and effort applied.
$ssc_d$ (SSC Density / Logical Density): The binding strength between the strategic vision and physical assets, which is mathematically equivalent to the likelihood P(E|H) in Bayes' theorem.
$L$ (Leverage): The strategic multiplier (e.g., technological generation gaps).
$I$ (Inertia): The inherent resistance or friction of the target environment.
$vol$ (Volatility): Geopolitical or market fluctuations.
✨ Key Features
Strategic Oracle (AI Intelligence): Powered by Google's Gemini 2.5 Pro model, the Oracle module dynamically searches for historical prototypes, estimates Bayesian parameters, and outputs comprehensive JSON-formatted intelligence reports.
Bayesian Cognitive Engine: Refines the probability of success using Bayesian noise filtration (FRE Validation) and Monte Carlo simulations to find the "Truth Distribution."
Physics-Based Stress Testing:
- ERT (Environmental Resilience Test): Calculates system stability and identifies the critical Collapse Line (Break Point / BP).
- SIP (Strategic Ignition Point): Models efficiency against environmental resistance to find the exact Activation Pressure (AP) needed for a strategy to take effect across different leverage tiers (L1-L3 vs. L-0 Baseline).
Interactive UI & Visualizations: A sleek Streamlit dashboard (app.py) combined with matplotlib logic (visualizer.py) to render structural resilience audits and truth curves.
📂 Project StructurePlaintextphsl/
├── app.py # Main Streamlit web application and UI layout
├── controller.py # Central nervous system orchestrating Oracle and Engine
├── engine.py # Core mathematical and Bayesian calculation engine
├── arena.py # Acts as the Dynamic Digital Wind Tunnel for strategy testing.
├── oracle.py # Gemini API integration for historical & intelligence mapping
├── protocol.py # Isomorphism protocol for contextual switching
├── report_generator.py # CLI-based comprehensive strategy report generation
├── visualizer.py # Custom Matplotlib plotting library (Truth curves, SIP, ERT)
└── init.py # Package initialization
🚀 Installation & Setup
- Clone the repository and navigate to the project directory:(Ensure you have Python 3.8+ installed)
- Install required dependencies:Bashpip install streamlit google-genai matplotlib pandas numpy
- Configure Network/Proxy (If applicable):By default, oracle.py is configured with local proxies. If you are running this in an environment without proxy requirements, you may need to comment out lines 10-11 in oracle.py.
- 💻 Usage Run the Streamlit application from your terminal:Bash streamlit run app.py
Operating the Terminal:
Open the local web address provided by Streamlit.In the sidebar console, enter your Google Gemini API Key.Input your Strategic Vision Description (e.g., "The impact of the Belt and Road Initiative on restructuring global supply chains...").Click "⚡ 启动全领域审计" (Initiate All-Domain Audit).
Review the generated intelligence reports, historical isomorphism mappings, and physics-based stress test charts.
🛠️ System Components Breakdown
-
The Oracle (oracle.py): Acts as the Chief Auditing Officer. It enforces logical dimensionality reduction, applies real-time intelligence gathering, and matches inputs with evolutionary or military history.
-
The Engine (engine.py): Executes the mathematical heavy lifting. It applies noise filters to leverage factors, ensuring that technological or structural advantages decay appropriately in high-noise environments.
-
The Visualizer (visualizer.py): Generates high-fidelity, cyberpunk-styled (dark theme) charts to visualize the Monte Carlo truth curves and strategic hedge auditing.
-
The Arena (arena.py): Acts as the Dynamic Digital Wind Tunnel. It orchestrates multi-agent, double-blind red/blue adversarial simulations across multiple parallel universes. By pit-testing the red team's strategy against dynamic environmental blowbacks round-by-round, it tracks physical attrition, applies life/death isolation statistics, and calculates the true Emergent Break Point and absolute survival rates under extreme resistance.
Metadata
Release files for phsl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phsl-0.1.0.tar.gz | 41.6 kB | With provenance | Details for phsl-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phsl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for phsl-0.1.0-py3-none-any.whl |
Total release size: 83.5 kB
Release files / phsl-0.1.0.tar.gz
| Download URL | phsl-0.1.0.tar.gz |
|---|---|
| Size | 41.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e1cd00293bba2e9dbc6cfe9ef51fa9fa5df16440fbdd9657699a6290f6f0e4b
|
|
BLAKE2b-256 checksum How to use checksums |
1db0b639db971960f53f5646ad44051f4e85cd9c2ed0d599140c112e79ed9a0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logRelease files / phsl-0.1.0-py3-none-any.whl
| Download URL | phsl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 41.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b28755a19d07cf4604a7031df265761f2979d23f23f05336bd930bb4803d8a8f
|
|
BLAKE2b-256 checksum How to use checksums |
557000e99239395cd6dd97047c7e6860568ecc4fa6f093b98bc74fca5ac8f027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logSecurity for phsl 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for phsl-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.