Skip to main content

Phi-Complexity

Pour M'offrir un café sur Buy Me a Coffee

Code quality metrics based on Golden Ratio (φ) mathematical invariants

Python 3.9+ License: MIT Tests

phi-complexity is the first code quality library that measures the health of your Python code using universal mathematical invariants derived from the Golden Ratio (φ = 1.618...).

Unlike pylint (cultural rules) or radon (McCabe metrics), phi-complexity answers:

"Is this code in resonance with the natural laws of order, or is it collapsing under its own entropy?"


⚡ Quick Start

pip install git+https://github.com/spockoo/Phi-Complexity.git

Note : le paquet est aussi sur PyPI (pip install phi-complexity, 0.12.0) — identique à cet arbre depuis le 2026-10-01.

# Audit a file
phi check my_script.py

# Audit a folder
phi check ./src/

# Generate a Markdown report
phi report my_script.py --output report.md

# CI/CD strict mode (exit 1 if radiance < 75)
phi check ./src/ --min-radiance 75

# Freeze the structural state (reference)
phi snapshot ./src/ --out ref.json

# Watch for silent degradations
phi veille ./src/ --ref ref.json

Python API

from phi_complexity import auditer, rapport_console, rapport_markdown

# Get metrics as a dict
metrics = auditer("my_script.py")
print(metrics["radiance"])          # → 82.4
print(metrics["statut_gnostique"])  # → "EN ÉVEIL ◈"
print(metrics["oudjat"])            # → {"nom": "process_data", "ligne": 42, ...}

# Print console report
print(rapport_console("my_script.py"))

# Save Markdown report
rapport_markdown("my_script.py", sortie="report.md")

📊 Metrics

Metric Description Mathematical basis
Radiance Score Global quality score (0–100) 100 - f(Lilith) - g(H) - h(Anomalies) - i(Fib)
Variance de Lilith Structural instability Population variance of function complexities
Shannon Entropy Information density H = -Σ p·log₂(p)
φ-Ratio Dominant function ratio max_complexity / mean → should tend toward φ
Fibonacci Distance Natural size alignment `Σ
Zeta-Score Global resonance ζ_meta(functions, φ) converging series

Gnostic Status Levels

Score Status Meaning
≥ 85 HERMÉTIQUE ✦ Stable, harmonious, production-ready
60–84 EN ÉVEIL ◈ Potential exists, some entropy zones
< 60 DORMANT ░ Deep restructuring recommended

🧭 Command Stability Matrix

Command Stability Purpose
phi check Stable Audit radiance for files/folders (console, JSON, SARIF) + quality gates
phi report Stable Markdown report
phi index Stable Project map: symbols, collisions, φ-health
phi snapshot Stable Freeze structural state (dated, MD5-signed reference)
phi veille Stable Detect silent degradations vs reference (STABLE / DÉGRADATION DÉTECTÉE / INSTRUMENT DÉGRADÉ)
phi chemins Stable Belief map: symbols ranked by posterior — which hole to attack first
phi oracle Stable Exhibited reasoning chain (prior → evidence → posterior → action)
phi sonde Stable A/B probes: tracing the unconditional from the conditional (closure pole / obstruction pole)
phi piste-sorry Nouveau Track a Lean 4 sorry: rigorous inventory, import graph, registry work-items — the path from any complexity
phi chemins-verifiables Nouveau Guided wiring candidates, each formally identified as a proof — Lean decides (PROUVÉ / RÉFUTÉ / INDÉCIDÉ)
phi infer Experimental Bayesian inference and self-suture prediction
phi explorer Experimental Interactive explorer (self-contained HTML, zero network)
phi entropie Experimental Entropy lens: the ciphered ledger of narrowing (H and ΔH in bits, EFT bounds)
phi ou-aller Experimental Where to go next: attention list (not a decision)
phi edit Experimental Edit a file in the phi TUI editor

Tip: keep phi check/phi report/phi oracle in CI. Use phi snapshot + phi veille to catch silent regressions between releases.


🔍 Sample Output

╔══════════════════════════════════════════════════╗
║      PHI-COMPLEXITY — AUDIT DE RADIANCE          ║
╚══════════════════════════════════════════════════╝

  📄 Fichier : my_script.py
  📅 Date    : 2026-04-08 17:11

  ☼  RADIANCE     : ██████████████░░░░░░  72.6 / 100
  ⚖  LILITH       : 11221.9  (Structural variance)
  🌊 ENTROPIE     : 2.48 bits  (Shannon)
  ◈  PHI-RATIO    : 3.43  (ideal: φ = 1.618, Δ=1.81)
  ζ  ZETA-SCORE   : 0.3656  (Global resonance)

  STATUT : EN ÉVEIL ◈

  🔎 OUDJAT : 'process_data' (Line 42, Complexity: 376)

  ⚠  SUTURES IDENTIFIED (2):
  🟡 Line 18 [LILITH] : Nested loop (depth 2). Consider a helper function.
     >> for j in range(b):
  🟢 Line 67 [LILITH] : 'load_data' receives 6 arguments. Encapsulate in an object.
     >> def load_data(path, sep, enc, cols, dtype, na):

🛡 La Veille — the instrument never lies silently

A bad instrument fails silently. phi-complexity fails loudly :

  • phi veille never reports ✅ on top of a degraded analyzer — it reports INSTRUMENT DÉGRADÉ (exit 3) instead of a fake degradation;
  • phi snapshot refuses a degraded baseline without --force;
  • every development of the instrument carries its mission justification (phi_complexity/mission.py) : which goal it serves. A module added without justification fails the test suite — mechanically, not by discipline.

Trust in the tool is verified trust, never faith : 386 tests, run on every change.


🧮 Mathematical Foundations

The Radiance Formula is derived from:

  • φ-Meta Framework (Tomy Verreault, 2026) — Axioms AX-A0 through AX-A58
  • Law of Antifragility (EQ-AFR-BMAD): φ_{t+1} = P_φ(φ_t + k·Var(E_t)·E_t)
  • Cybernetics — Feedback and variance as control metrics
  • Shannon Information Theory — Code as an information channel

The Sovereign Coding Rules are derived from:

  • The C Book (Banahan, Brady, Doran) — Scope hermeticity, resource lifecycle
  • JaCaMo / Multi-Agent Programming — Agent independence and encapsulation

🏗 Sovereign Architecture

Zero heavy dependencies.
Pure Python standard library (ast, math, json) + tree-sitter (optional, for non-Python languages).
phi_complexity/
├── core.py               ← Golden constants (PHI, TAXE_SUTURE, ETA_GOLDEN...) + VERSION
├── analyseur.py          ← AST fractal dissection
├── metriques.py          ← Radiance Index calculation
├── rapport.py            ← Console / Markdown / JSON rendering
├── cli.py                ← the 15 phi commands
├── veille.py             ← Silent-degradation detection (STABLE / DÉGRADATION DÉTECTÉE)
├── mission.py            ← Mission-justification registry (anti-divergence guard)
├── croyances.py          ← Bayesian belief layer over symbols
├── sondes.py             ← A/B probes (closure / obstruction poles)
├── piste_sorry.py        ← Rigorous sorry inventory + import graph (Lean 4)
├── chemins_verifiables.py← Guided wiring candidates Lean formally decides
├── parseur_lean.py       ← Robust Lean parser (regex-based, no size limit)
├── dependances.py        ← Lean dependency graph (exact deps, transitive closure)
├── entropie.py           ← Entropy lens (H, ΔH, EFT bounds)
├── oracle.py             ← Exhibited reasoning traces
├── explorateur.py        ← Interactive explorer
├── bayes.py / eft.py     ← Bayesian EFT machinery, error-free transformations
├── carte.py / ancrage.py ← Maps, anchoring
├── durcissement.py       ← Hardening battery
├── modeles.py            ← Models
├── editeur/              ← TUI editor (phi edit)
├── formules/             ← Formula language
└── langs/                ← Multi-language backends (Python native, tree-sitter generic)

🔗 Integration

GitHub Action

- name: Phi-Complexity Audit
  run: |
    pip install git+https://github.com/spockoo/Phi-Complexity.git
    phi check ./src/ --min-radiance 75

Watchdog (snapshot + veille)

phi snapshot ./src/ --out ref.json   # after each audited release
phi veille ./src/ --ref ref.json     # at the start of the next work session

📜 License

MIT — Tomy Verreault, 2026

Anchored in the Bibliothèque Céleste — Morphic Phi Framework (φ-Meta)

📜 Historique des Versions (Changelog)

  • v0.13.0 (Extraction robuste) :

    • Nouveau phi_complexity/dependances.py : graphe de dépendances Lean — extraction exacte (fermeture transitive, tri topologique). Élimine le danger d'oubli d'une dépendance.
    • Nouveau extraire_declarations_robuste() dans parseur_lean.py : extraction par regex, pas de limite de taille. Corrige l'échec silencieux de tree-sitter sur fichiers >5000 lignes (147 → 196 déclarations).
    • Corrigé : extraction du corps par délimitation exacte (entre deux déclarations) au lieu de l'heuristique 50 lignes.
  • v0.12.0 (Chemins vérifiables) :

    • Nouveau phi piste-sorry : piste d'un sorry Lean 4 — inventaire rigoureux (commentaires/chaînes exclus), graphe d'imports, chantiers du registre.
    • Nouveau phi chemins-verifiables : propose des candidats de câblage guidés, chacun identifié formellement comme une preuve ; Lean tranche mécaniquement (PROUVÉ / RÉFUTÉ / INDÉCIDÉ). Jamais le sorry lui-même, jamais un sorry déguisé.
    • Vocabulaire : « terminer » remplace les termes violents pour les hypothèses closes.
    • Exclusion des artefacts .lake des scans (vitesse, pas de bruit Mathlib).
  • v0.11.0 (La Veille) — release GitHub :

    • Garde anti-divergence : chaque module porte sa justification « but de mission » (mission.py) — un module sans justification fait échouer les tests.
    • Durcissement : l'instrument échoue bruyamment (INSTRUMENT DÉGRADÉ, exit 3) au lieu de mentir quand l'analyseur manque ; phi snapshot refuse une baseline dégradée sans --force.
    • 386 tests verts, multi-langages (Python natif + tree-sitter générique).

Note d'honnêteté : les numéros 0.1.1–0.2.2 publiés avant octobre 2026 couvraient du scaffolding généré par bots, supprimé lors du nettoyage du 2026-10-01 (seule la 0.1.0 a été conservée). PyPI sert désormais la 0.12.0, identique à cet arbre. L'historique fiable commence à v0.11.0.

Metadata

Release files for phi-complexity 0.13.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phi-complexity 0.13.1
File Size Uploaded
phi_complexity-0.13.1.tar.gz 282.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phi-complexity 0.13.1
File Interpreter ABI Platform
phi_complexity-0.13.1-py3-none-any.whl Python 3 none any Details

Total release size: 498.4 kB

Release files / phi_complexity-0.13.1.tar.gz

Download URL phi_complexity-0.13.1.tar.gz
Size 282.1 kB
Tags Source
SHA-256 checksum
How to use checksums
57a2b48d5965e28b1d5357b58d5e303b5737cf66ff1bae510568eba1ee66c7bd
BLAKE2b-256 checksum
How to use checksums
7f379e32172c9d0b069b20c1bfd62f3192e722c2a06c79a9f24580b1b3a7da06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / phi_complexity-0.13.1-py3-none-any.whl

Download URL phi_complexity-0.13.1-py3-none-any.whl
Size 216.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
678be951bd1f0bb7487454c3df7d06888ce9078b1fade2634bf2b3469918393d
BLAKE2b-256 checksum
How to use checksums
1787dfbd9df9b49bc23a8e5c842c101548b7d00383c1b42fe53df390e8de23ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.13.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page