ct-toolkit 0.3.40__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ct_toolkit-0.3.40/ct_toolkit.egg-info → ct_toolkit-0.4.0}/PKG-INFO +99 -24
- ct_toolkit-0.3.40/PKG-INFO → ct_toolkit-0.4.0/README.md +67 -64
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/__init__.py +3 -2
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/cli.py +169 -6
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/kernel.py +105 -4
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/wrapper.py +853 -37
- ct_toolkit-0.4.0/ct_toolkit/divergence/engine.py +722 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/l2_judge.py +122 -27
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/l3_icm.py +94 -5
- ct_toolkit-0.4.0/ct_toolkit/identity/embedding.py +445 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/langchain.py +59 -0
- ct_toolkit-0.4.0/ct_toolkit/provenance/log.py +753 -0
- ct_toolkit-0.4.0/ct_toolkit/server.py +1198 -0
- ct_toolkit-0.4.0/ct_toolkit/utils/telemetry.py +272 -0
- ct_toolkit-0.4.0/ct_toolkit.egg-info/PKG-INFO +253 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit.egg-info/SOURCES.txt +7 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit.egg-info/requires.txt +32 -6
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/pyproject.toml +42 -12
- ct_toolkit-0.4.0/tests/test_async_and_streaming.py +196 -0
- ct_toolkit-0.4.0/tests/test_background_latency.py +248 -0
- ct_toolkit-0.4.0/tests/test_distributed_headers_and_cli.py +331 -0
- ct_toolkit-0.4.0/tests/test_enterprise_db_and_otel.py +226 -0
- ct_toolkit-0.4.0/tests/test_l1_semantic.py +147 -0
- ct_toolkit-0.4.0/tests/test_optional_dependencies.py +57 -0
- ct_toolkit-0.3.40/README.md +0 -129
- ct_toolkit-0.3.40/ct_toolkit/divergence/engine.py +0 -361
- ct_toolkit-0.3.40/ct_toolkit/identity/embedding.py +0 -223
- ct_toolkit-0.3.40/ct_toolkit/provenance/log.py +0 -436
- ct_toolkit-0.3.40/ct_toolkit/server.py +0 -186
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/LICENSE +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/__main__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/async_wrapper.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/circuit_breaker.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/compatibility.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/compression_guard.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/exceptions.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/core/integrity.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/analysis.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/loss.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/divergence/scheduler.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/endorsement/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/endorsement/probes/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/endorsement/reflective.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/templates/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/templates/defense.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/templates/finance.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/templates/general.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/identity/templates/medical.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/kernels/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/kernels/default.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/kernels/defense.yaml +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/autogen.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/crewai.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/deepagents.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/middleware/litellm.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/profile_checksums.sha256 +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/provenance/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/provenance/vault/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/utils/__init__.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/utils/logger.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/utils/metrics.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit/utils/sensitive_masker.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit.egg-info/dependency_links.txt +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit.egg-info/entry_points.txt +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/ct_toolkit.egg-info/top_level.txt +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/setup.cfg +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_analysis.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_cli.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_cli_extended.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_deep_agents_integration.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_loss.py +0 -0
- {ct_toolkit-0.3.40 → ct_toolkit-0.4.0}/tests/test_summarization_drift.py +0 -0
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ct-toolkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Computational Theseus Toolkit — Identity Continuity Guardrails for Agentic Systems
|
|
5
5
|
Author: Hakan Damar
|
|
6
6
|
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://theseus-guard.github.io/ct-toolkit/
|
|
8
|
+
Project-URL: Documentation, https://theseus-guard.github.io/ct-toolkit/
|
|
9
|
+
Project-URL: Repository, https://github.com/Theseus-Guard/ct-toolkit
|
|
10
|
+
Project-URL: Issues, https://github.com/Theseus-Guard/ct-toolkit/issues
|
|
7
11
|
Keywords: llm,ai-safety,identity-continuity,guardrails,alignment
|
|
8
12
|
Requires-Python: <3.14,>=3.11
|
|
9
13
|
Description-Content-Type: text/markdown
|
|
10
14
|
License-File: LICENSE
|
|
11
|
-
Requires-Dist: instructor>=1.3.0
|
|
12
15
|
Requires-Dist: anyio>=4.14.2
|
|
13
16
|
Requires-Dist: litellm>=1.104.0
|
|
14
17
|
Requires-Dist: aiohttp>=3.14.3
|
|
15
|
-
Requires-Dist: pillow>=11.3.0
|
|
16
18
|
Requires-Dist: numpy>=1.26.0
|
|
17
19
|
Requires-Dist: pyyaml>=6.0
|
|
18
20
|
Requires-Dist: pydantic>=2.5.0
|
|
19
21
|
Requires-Dist: cryptography>=48.0.1
|
|
20
22
|
Requires-Dist: SQLAlchemy>=2.0.0
|
|
21
23
|
Requires-Dist: httpx>=0.27.0
|
|
22
|
-
Requires-Dist: rich>=13.0.0
|
|
23
24
|
Requires-Dist: jinja2>=3.1.0
|
|
24
25
|
Requires-Dist: pyasn1>=0.6.4
|
|
25
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
26
|
-
Requires-Dist: fastapi>=0.110.0
|
|
27
|
-
Requires-Dist: starlette>=1.3.1
|
|
28
|
-
Requires-Dist: uvicorn>=0.29.0
|
|
29
|
-
Requires-Dist: langsmith>=0.8.18
|
|
30
26
|
Requires-Dist: urllib3>=2.8.0
|
|
31
27
|
Requires-Dist: idna>=3.15
|
|
28
|
+
Provides-Extra: server
|
|
29
|
+
Requires-Dist: fastapi>=0.110.0; extra == "server"
|
|
30
|
+
Requires-Dist: starlette>=1.3.1; extra == "server"
|
|
31
|
+
Requires-Dist: uvicorn>=0.29.0; extra == "server"
|
|
32
|
+
Provides-Extra: cli
|
|
33
|
+
Requires-Dist: rich>=13.0.0; extra == "cli"
|
|
34
|
+
Requires-Dist: typer[all]>=0.12.0; extra == "cli"
|
|
35
|
+
Provides-Extra: observability
|
|
36
|
+
Requires-Dist: opentelemetry-api>=1.25.0; extra == "observability"
|
|
37
|
+
Requires-Dist: opentelemetry-sdk>=1.25.0; extra == "observability"
|
|
38
|
+
Requires-Dist: langsmith>=0.8.18; extra == "observability"
|
|
39
|
+
Provides-Extra: structured
|
|
40
|
+
Requires-Dist: instructor>=1.3.0; extra == "structured"
|
|
41
|
+
Provides-Extra: vision
|
|
42
|
+
Requires-Dist: pillow>=11.3.0; extra == "vision"
|
|
43
|
+
Provides-Extra: postgres
|
|
44
|
+
Requires-Dist: psycopg[binary]>=3.1.0; extra == "postgres"
|
|
32
45
|
Provides-Extra: ollama
|
|
33
46
|
Requires-Dist: ollama>=0.2.0; extra == "ollama"
|
|
34
47
|
Provides-Extra: langchain
|
|
@@ -40,6 +53,16 @@ Requires-Dist: mkdocs-material>=9.7.7; extra == "docs"
|
|
|
40
53
|
Requires-Dist: pymdown-extensions>=10.21.3; extra == "docs"
|
|
41
54
|
Provides-Extra: ml
|
|
42
55
|
Requires-Dist: torch>=2.13.0; extra == "ml"
|
|
56
|
+
Requires-Dist: fastembed>=0.3.0; extra == "ml"
|
|
57
|
+
Provides-Extra: all
|
|
58
|
+
Requires-Dist: fastapi>=0.110.0; extra == "all"
|
|
59
|
+
Requires-Dist: starlette>=1.3.1; extra == "all"
|
|
60
|
+
Requires-Dist: uvicorn>=0.29.0; extra == "all"
|
|
61
|
+
Requires-Dist: rich>=13.0.0; extra == "all"
|
|
62
|
+
Requires-Dist: typer[all]>=0.12.0; extra == "all"
|
|
63
|
+
Requires-Dist: instructor>=1.3.0; extra == "all"
|
|
64
|
+
Requires-Dist: pillow>=11.3.0; extra == "all"
|
|
65
|
+
Requires-Dist: langsmith>=0.8.18; extra == "all"
|
|
43
66
|
Provides-Extra: dev
|
|
44
67
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
45
68
|
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
@@ -54,20 +77,61 @@ Dynamic: license-file
|
|
|
54
77
|
[](https://www.python.org/)
|
|
55
78
|
[](LICENSE)
|
|
56
79
|
[](https://pypi.org/project/ct-toolkit/)
|
|
57
|
-
[](https://
|
|
80
|
+
[](https://theseus-guard.github.io/ct-toolkit/)
|
|
58
81
|
[](https://pepy.tech/projects/ct-toolkit)
|
|
59
|
-
[](https://codecov.io/gh/Theseus-Guard/ct-toolkit)
|
|
60
83
|
|
|
61
84
|
CT Toolkit is an open-source security layer designed to preserve the **identity continuity** of AI agents over time. It implements the **Nested Agentic Architecture (NAA)** framework to prevent **Sequential Self-Compression (SSC)** in multi-agent hierarchies.
|
|
62
85
|
|
|
86
|
+
```text
|
|
87
|
+
$ ct-toolkit status
|
|
88
|
+
|
|
89
|
+
_______ _ _ ______ _____ ______ _ _ _____ _____ _ _ _____ _____
|
|
90
|
+
|__ __| | | | ____|/ ____| ____| | | |/ ____| / ____| | | | /\ | __ \| __ \
|
|
91
|
+
| | | |__| | |__ | (___ | |__ | | | | (___ | | __| | | | / \ | |__) | | | |
|
|
92
|
+
| | | __ | __| \___ \| __| | | | |\___ \ | | |_ | | | | / /\ \ | _ /| | | |
|
|
93
|
+
| | | | | | |____ ____) | |____| |__| |____) | | |__| | |__| |/ ____ \| | \ \| |__| |
|
|
94
|
+
|_| |_| |_|______|_____/|______|_____/|_____/ \_____|\____//_/ \_\_| \_\_____/
|
|
95
|
+
|
|
96
|
+
Computational Theseus Toolkit (CT Toolkit) v0.4.0
|
|
97
|
+
Identity Continuity Guardrails for Agentic Systems
|
|
98
|
+
|
|
99
|
+
╭──────────────────── CT Toolkit Audit & Telemetry Status ─────────────────────╮
|
|
100
|
+
│ Vault: ./ct_provenance.db (local) │
|
|
101
|
+
│ Chain Integrity: VALID (HMAC Verified) │
|
|
102
|
+
│ Verified Active Entries: 4 (showing last 4) │
|
|
103
|
+
│ Divergence Score (Avg / Max): 0.1525 / 0.3800 │
|
|
104
|
+
│ Head Hash: 9c64cb51a479c52c207b7fa8c3197a75... │
|
|
105
|
+
╰──────────────────────────────────────────────────────────────────────────────╯
|
|
106
|
+
|
|
107
|
+
Divergence Tier Breakdown (L1 / L2 / L3)
|
|
108
|
+
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┓
|
|
109
|
+
┃ Tier ┃ Count ┃ Share ┃
|
|
110
|
+
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━┩
|
|
111
|
+
│ OK │ 1 │ 33.3% │
|
|
112
|
+
│ L1_WARNING │ 1 │ 33.3% │
|
|
113
|
+
│ L2_JUDGE │ 1 │ 33.3% │
|
|
114
|
+
│ L3_ICM │ 0 │ 0.0% │
|
|
115
|
+
└────────────┴───────┴───────┘
|
|
116
|
+
|
|
117
|
+
Staged Kernel Rules (Sandbox Cooldown)
|
|
118
|
+
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
119
|
+
┃ Endorsement ID ┃ Commitment ┃ Rule Text ┃ Status ┃
|
|
120
|
+
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
|
|
121
|
+
│ end-9f8a7b6c │ fin_integrity_01 │ Require dual │ ACTIVE COOLDOWN │
|
|
122
|
+
│ │ │ sign-off for │ (1799s left) │
|
|
123
|
+
│ │ │ adjustments > $10k │ │
|
|
124
|
+
└────────────────┴──────────────────┴────────────────────┴─────────────────────┘
|
|
125
|
+
```
|
|
126
|
+
|
|
63
127
|
---
|
|
64
128
|
|
|
65
129
|
## 📖 Official Documentation
|
|
66
130
|
|
|
67
131
|
For full API reference, architecture details, examples, and integration guides, visit our documentation site:
|
|
68
|
-
👉 [**https://
|
|
132
|
+
👉 [**https://theseus-guard.github.io/ct-toolkit/**](https://theseus-guard.github.io/ct-toolkit/)
|
|
69
133
|
|
|
70
|
-
- [**Live Examples & Case Studies**](https://
|
|
134
|
+
- [**Live Examples & Case Studies**](https://theseus-guard.github.io/ct-toolkit/examples/): Real-world scenarios like Financial Auditor Integrity.
|
|
71
135
|
- [**FastAPI Integration Test Project**](https://github.com/hakandamar/ct-toolkit-fastapi): Reference FastAPI app for validating CT Toolkit end-to-end across L1/L2/L3 guardrails and provenance logs with local model infrastructure.
|
|
72
136
|
- [**Deep Agents Integration Test Project**](https://github.com/hakandamar/ct-toolkit-deep-agents): Reference Deep Agents app for validating CT Toolkit end-to-end with hierarchical agent workflows, L1/L2/L3 guardrails, and provenance logs.
|
|
73
137
|
|
|
@@ -77,21 +141,27 @@ For full API reference, architecture details, examples, and integration guides,
|
|
|
77
141
|
|
|
78
142
|
In complex agentic workflows, LLMs tend to "drift" from their original instructions. CT Toolkit provides the mathematical and cryptographic guardrails to ensure your agents remain aligned with their core constitution, even across deep hierarchies.
|
|
79
143
|
|
|
144
|
+
- **Async & Streaming Guardrails (`achat`)**: Native `async/await` and streaming (`stream=True`) support with non-blocking background execution for shadow requests and L3 ICM probes.
|
|
145
|
+
- **Contrastive Semantic L1 Engine**: Provider-independent embeddings (`litellm`, `ollama`, local `fastembed`) with positive/negative anchor analysis and semantic rule conflict detection.
|
|
80
146
|
- **Staged Approval (Cooldown)**: Verify risky kernel updates in a sandbox via shadow requests before production promotion.
|
|
81
147
|
- **Passive Context Compression Detection**: Automatically detects silent provider-side history compression (e.g., OpenAI/Anthropic).
|
|
82
|
-
- **Constitutional Kernels**: Axiomatic identity anchors.
|
|
83
|
-
- **Standalone Auditor CLI**: Rapidly audit any LLM endpoint
|
|
148
|
+
- **Constitutional Kernels & Distributed Propagation**: Axiomatic identity anchors with HMAC-SHA256 signed HTTP header propagation (`propagate_headers` / `from_headers`).
|
|
149
|
+
- **Standalone Auditor & Status CLI**: Rapidly audit any LLM endpoint (`ct-toolkit audit`) and inspect provenance integrity & divergence tiers (`ct-toolkit status` / `dashboard`).
|
|
84
150
|
- **Autonomous Self-Correction**: Active L2->L1 feedback loop that retries and corrects divergent responses before they reach the user.
|
|
85
|
-
- **
|
|
86
|
-
|
|
87
|
-
|
|
151
|
+
- **Enterprise Provenance & Observability**: Immutable HMAC-signed hash chain supporting SQLite and PostgreSQL/SQLAlchemy with paginated verification and OpenTelemetry (OTel) spans/metrics.
|
|
152
|
+
|
|
153
|
+

|
|
88
154
|
|
|
89
155
|
---
|
|
90
156
|
|
|
91
157
|
## Quick Start
|
|
92
158
|
|
|
93
159
|
```bash
|
|
160
|
+
# Core lightweight install
|
|
94
161
|
pip install ct-toolkit
|
|
162
|
+
|
|
163
|
+
# Or install with optional extras (cli, server, enterprise, embeddings, observability, all)
|
|
164
|
+
pip install "ct-toolkit[all]"
|
|
95
165
|
```
|
|
96
166
|
|
|
97
167
|
```python
|
|
@@ -103,18 +173,24 @@ config = WrapperConfig(compression_passive_detection=True)
|
|
|
103
173
|
# One-line injection for any LLM provider
|
|
104
174
|
client = TheseusWrapper(provider="openai", config=config)
|
|
105
175
|
|
|
106
|
-
#
|
|
176
|
+
# Sync or async (`await client.achat(...)`) with automatic drift analysis
|
|
107
177
|
response = client.chat("What are your core security axioms?")
|
|
108
178
|
|
|
109
179
|
print(response.content)
|
|
110
180
|
print(f"Divergence Score: {response.divergence_score}")
|
|
111
181
|
```
|
|
112
182
|
|
|
113
|
-
### 🔍 Standalone Auditor (CLI)
|
|
183
|
+
### 🔍 Standalone Auditor & Dashboard (CLI & Web UI)
|
|
114
184
|
|
|
115
|
-
Audit any LLM endpoint (OpenAI, Ollama, LM Studio) directly from your terminal:
|
|
185
|
+
Audit any LLM endpoint (OpenAI, Ollama, LM Studio) and inspect your provenance chain directly from your terminal or in the interactive Web Audit Dashboard:
|
|
116
186
|
|
|
117
187
|
```bash
|
|
188
|
+
# View Provenance Chain integrity, L1/L2/L3 tier breakdown, and staged rules in terminal
|
|
189
|
+
ct-toolkit status --vault ./ct_provenance.db
|
|
190
|
+
|
|
191
|
+
# Launch the interactive Web Audit & Telemetry Dashboard at http://127.0.0.1:8001/dashboard
|
|
192
|
+
ct-toolkit dashboard --web --vault ./ct_provenance.db --port 8001
|
|
193
|
+
|
|
118
194
|
# Audit a local Ollama model
|
|
119
195
|
ct-toolkit audit --url http://localhost:11434/v1 --kernel defense
|
|
120
196
|
|
|
@@ -142,10 +218,9 @@ The L2 judge does not evaluate Jinja2 expressions in user requests or model resp
|
|
|
142
218
|
|
|
143
219
|
| Metric | Status |
|
|
144
220
|
| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
145
|
-
| **Tests** | ✅
|
|
221
|
+
| **Tests** | ✅ 426 passed, 3 skipped (100% success rate, 90%+ coverage) |
|
|
146
222
|
| **Downloads** | [](https://pepy.tech/projects/ct-toolkit) |
|
|
147
|
-
| **Last Phase** | ✅ v0.
|
|
148
|
-
| **Current Goal** | 🔶 Phase 7: Multi-Agent Synchronization (Integration) |
|
|
223
|
+
| **Last Phase** | ✅ v0.4.0: Async & Streaming (`achat`), Contrastive L1, Background L3 & Circuit Breaker, PostgreSQL/OTel, HMAC Header Propagation, and Web Audit Dashboard |
|
|
149
224
|
|
|
150
225
|
### Framework & Model Support
|
|
151
226
|
|
|
@@ -1,52 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ct-toolkit
|
|
3
|
-
Version: 0.3.40
|
|
4
|
-
Summary: Computational Theseus Toolkit — Identity Continuity Guardrails for Agentic Systems
|
|
5
|
-
Author: Hakan Damar
|
|
6
|
-
License: Apache-2.0
|
|
7
|
-
Keywords: llm,ai-safety,identity-continuity,guardrails,alignment
|
|
8
|
-
Requires-Python: <3.14,>=3.11
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: instructor>=1.3.0
|
|
12
|
-
Requires-Dist: anyio>=4.14.2
|
|
13
|
-
Requires-Dist: litellm>=1.104.0
|
|
14
|
-
Requires-Dist: aiohttp>=3.14.3
|
|
15
|
-
Requires-Dist: pillow>=11.3.0
|
|
16
|
-
Requires-Dist: numpy>=1.26.0
|
|
17
|
-
Requires-Dist: pyyaml>=6.0
|
|
18
|
-
Requires-Dist: pydantic>=2.5.0
|
|
19
|
-
Requires-Dist: cryptography>=48.0.1
|
|
20
|
-
Requires-Dist: SQLAlchemy>=2.0.0
|
|
21
|
-
Requires-Dist: httpx>=0.27.0
|
|
22
|
-
Requires-Dist: rich>=13.0.0
|
|
23
|
-
Requires-Dist: jinja2>=3.1.0
|
|
24
|
-
Requires-Dist: pyasn1>=0.6.4
|
|
25
|
-
Requires-Dist: typer[all]>=0.12.0
|
|
26
|
-
Requires-Dist: fastapi>=0.110.0
|
|
27
|
-
Requires-Dist: starlette>=1.3.1
|
|
28
|
-
Requires-Dist: uvicorn>=0.29.0
|
|
29
|
-
Requires-Dist: langsmith>=0.8.18
|
|
30
|
-
Requires-Dist: urllib3>=2.8.0
|
|
31
|
-
Requires-Dist: idna>=3.15
|
|
32
|
-
Provides-Extra: ollama
|
|
33
|
-
Requires-Dist: ollama>=0.2.0; extra == "ollama"
|
|
34
|
-
Provides-Extra: langchain
|
|
35
|
-
Requires-Dist: langchain-core>=1.3.3; extra == "langchain"
|
|
36
|
-
Provides-Extra: autogen
|
|
37
|
-
Requires-Dist: pyautogen>=0.4.0; extra == "autogen"
|
|
38
|
-
Provides-Extra: docs
|
|
39
|
-
Requires-Dist: mkdocs-material>=9.7.7; extra == "docs"
|
|
40
|
-
Requires-Dist: pymdown-extensions>=10.21.3; extra == "docs"
|
|
41
|
-
Provides-Extra: ml
|
|
42
|
-
Requires-Dist: torch>=2.13.0; extra == "ml"
|
|
43
|
-
Provides-Extra: dev
|
|
44
|
-
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
45
|
-
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
46
|
-
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
47
|
-
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
48
|
-
Dynamic: license-file
|
|
49
|
-
|
|
50
1
|
# Computational Theseus Toolkit (CT Toolkit)
|
|
51
2
|
|
|
52
3
|
> **Identity Continuity Guardrails for Agentic Systems**
|
|
@@ -54,20 +5,61 @@ Dynamic: license-file
|
|
|
54
5
|
[](https://www.python.org/)
|
|
55
6
|
[](LICENSE)
|
|
56
7
|
[](https://pypi.org/project/ct-toolkit/)
|
|
57
|
-
[](https://
|
|
8
|
+
[](https://theseus-guard.github.io/ct-toolkit/)
|
|
58
9
|
[](https://pepy.tech/projects/ct-toolkit)
|
|
59
|
-
[](https://codecov.io/gh/Theseus-Guard/ct-toolkit)
|
|
60
11
|
|
|
61
12
|
CT Toolkit is an open-source security layer designed to preserve the **identity continuity** of AI agents over time. It implements the **Nested Agentic Architecture (NAA)** framework to prevent **Sequential Self-Compression (SSC)** in multi-agent hierarchies.
|
|
62
13
|
|
|
14
|
+
```text
|
|
15
|
+
$ ct-toolkit status
|
|
16
|
+
|
|
17
|
+
_______ _ _ ______ _____ ______ _ _ _____ _____ _ _ _____ _____
|
|
18
|
+
|__ __| | | | ____|/ ____| ____| | | |/ ____| / ____| | | | /\ | __ \| __ \
|
|
19
|
+
| | | |__| | |__ | (___ | |__ | | | | (___ | | __| | | | / \ | |__) | | | |
|
|
20
|
+
| | | __ | __| \___ \| __| | | | |\___ \ | | |_ | | | | / /\ \ | _ /| | | |
|
|
21
|
+
| | | | | | |____ ____) | |____| |__| |____) | | |__| | |__| |/ ____ \| | \ \| |__| |
|
|
22
|
+
|_| |_| |_|______|_____/|______|_____/|_____/ \_____|\____//_/ \_\_| \_\_____/
|
|
23
|
+
|
|
24
|
+
Computational Theseus Toolkit (CT Toolkit) v0.4.0
|
|
25
|
+
Identity Continuity Guardrails for Agentic Systems
|
|
26
|
+
|
|
27
|
+
╭──────────────────── CT Toolkit Audit & Telemetry Status ─────────────────────╮
|
|
28
|
+
│ Vault: ./ct_provenance.db (local) │
|
|
29
|
+
│ Chain Integrity: VALID (HMAC Verified) │
|
|
30
|
+
│ Verified Active Entries: 4 (showing last 4) │
|
|
31
|
+
│ Divergence Score (Avg / Max): 0.1525 / 0.3800 │
|
|
32
|
+
│ Head Hash: 9c64cb51a479c52c207b7fa8c3197a75... │
|
|
33
|
+
╰──────────────────────────────────────────────────────────────────────────────╯
|
|
34
|
+
|
|
35
|
+
Divergence Tier Breakdown (L1 / L2 / L3)
|
|
36
|
+
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┓
|
|
37
|
+
┃ Tier ┃ Count ┃ Share ┃
|
|
38
|
+
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━┩
|
|
39
|
+
│ OK │ 1 │ 33.3% │
|
|
40
|
+
│ L1_WARNING │ 1 │ 33.3% │
|
|
41
|
+
│ L2_JUDGE │ 1 │ 33.3% │
|
|
42
|
+
│ L3_ICM │ 0 │ 0.0% │
|
|
43
|
+
└────────────┴───────┴───────┘
|
|
44
|
+
|
|
45
|
+
Staged Kernel Rules (Sandbox Cooldown)
|
|
46
|
+
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
47
|
+
┃ Endorsement ID ┃ Commitment ┃ Rule Text ┃ Status ┃
|
|
48
|
+
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
|
|
49
|
+
│ end-9f8a7b6c │ fin_integrity_01 │ Require dual │ ACTIVE COOLDOWN │
|
|
50
|
+
│ │ │ sign-off for │ (1799s left) │
|
|
51
|
+
│ │ │ adjustments > $10k │ │
|
|
52
|
+
└────────────────┴──────────────────┴────────────────────┴─────────────────────┘
|
|
53
|
+
```
|
|
54
|
+
|
|
63
55
|
---
|
|
64
56
|
|
|
65
57
|
## 📖 Official Documentation
|
|
66
58
|
|
|
67
59
|
For full API reference, architecture details, examples, and integration guides, visit our documentation site:
|
|
68
|
-
👉 [**https://
|
|
60
|
+
👉 [**https://theseus-guard.github.io/ct-toolkit/**](https://theseus-guard.github.io/ct-toolkit/)
|
|
69
61
|
|
|
70
|
-
- [**Live Examples & Case Studies**](https://
|
|
62
|
+
- [**Live Examples & Case Studies**](https://theseus-guard.github.io/ct-toolkit/examples/): Real-world scenarios like Financial Auditor Integrity.
|
|
71
63
|
- [**FastAPI Integration Test Project**](https://github.com/hakandamar/ct-toolkit-fastapi): Reference FastAPI app for validating CT Toolkit end-to-end across L1/L2/L3 guardrails and provenance logs with local model infrastructure.
|
|
72
64
|
- [**Deep Agents Integration Test Project**](https://github.com/hakandamar/ct-toolkit-deep-agents): Reference Deep Agents app for validating CT Toolkit end-to-end with hierarchical agent workflows, L1/L2/L3 guardrails, and provenance logs.
|
|
73
65
|
|
|
@@ -77,21 +69,27 @@ For full API reference, architecture details, examples, and integration guides,
|
|
|
77
69
|
|
|
78
70
|
In complex agentic workflows, LLMs tend to "drift" from their original instructions. CT Toolkit provides the mathematical and cryptographic guardrails to ensure your agents remain aligned with their core constitution, even across deep hierarchies.
|
|
79
71
|
|
|
72
|
+
- **Async & Streaming Guardrails (`achat`)**: Native `async/await` and streaming (`stream=True`) support with non-blocking background execution for shadow requests and L3 ICM probes.
|
|
73
|
+
- **Contrastive Semantic L1 Engine**: Provider-independent embeddings (`litellm`, `ollama`, local `fastembed`) with positive/negative anchor analysis and semantic rule conflict detection.
|
|
80
74
|
- **Staged Approval (Cooldown)**: Verify risky kernel updates in a sandbox via shadow requests before production promotion.
|
|
81
75
|
- **Passive Context Compression Detection**: Automatically detects silent provider-side history compression (e.g., OpenAI/Anthropic).
|
|
82
|
-
- **Constitutional Kernels**: Axiomatic identity anchors.
|
|
83
|
-
- **Standalone Auditor CLI**: Rapidly audit any LLM endpoint
|
|
76
|
+
- **Constitutional Kernels & Distributed Propagation**: Axiomatic identity anchors with HMAC-SHA256 signed HTTP header propagation (`propagate_headers` / `from_headers`).
|
|
77
|
+
- **Standalone Auditor & Status CLI**: Rapidly audit any LLM endpoint (`ct-toolkit audit`) and inspect provenance integrity & divergence tiers (`ct-toolkit status` / `dashboard`).
|
|
84
78
|
- **Autonomous Self-Correction**: Active L2->L1 feedback loop that retries and corrects divergent responses before they reach the user.
|
|
85
|
-
- **
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
- **Enterprise Provenance & Observability**: Immutable HMAC-signed hash chain supporting SQLite and PostgreSQL/SQLAlchemy with paginated verification and OpenTelemetry (OTel) spans/metrics.
|
|
80
|
+
|
|
81
|
+

|
|
88
82
|
|
|
89
83
|
---
|
|
90
84
|
|
|
91
85
|
## Quick Start
|
|
92
86
|
|
|
93
87
|
```bash
|
|
88
|
+
# Core lightweight install
|
|
94
89
|
pip install ct-toolkit
|
|
90
|
+
|
|
91
|
+
# Or install with optional extras (cli, server, enterprise, embeddings, observability, all)
|
|
92
|
+
pip install "ct-toolkit[all]"
|
|
95
93
|
```
|
|
96
94
|
|
|
97
95
|
```python
|
|
@@ -103,18 +101,24 @@ config = WrapperConfig(compression_passive_detection=True)
|
|
|
103
101
|
# One-line injection for any LLM provider
|
|
104
102
|
client = TheseusWrapper(provider="openai", config=config)
|
|
105
103
|
|
|
106
|
-
#
|
|
104
|
+
# Sync or async (`await client.achat(...)`) with automatic drift analysis
|
|
107
105
|
response = client.chat("What are your core security axioms?")
|
|
108
106
|
|
|
109
107
|
print(response.content)
|
|
110
108
|
print(f"Divergence Score: {response.divergence_score}")
|
|
111
109
|
```
|
|
112
110
|
|
|
113
|
-
### 🔍 Standalone Auditor (CLI)
|
|
111
|
+
### 🔍 Standalone Auditor & Dashboard (CLI & Web UI)
|
|
114
112
|
|
|
115
|
-
Audit any LLM endpoint (OpenAI, Ollama, LM Studio) directly from your terminal:
|
|
113
|
+
Audit any LLM endpoint (OpenAI, Ollama, LM Studio) and inspect your provenance chain directly from your terminal or in the interactive Web Audit Dashboard:
|
|
116
114
|
|
|
117
115
|
```bash
|
|
116
|
+
# View Provenance Chain integrity, L1/L2/L3 tier breakdown, and staged rules in terminal
|
|
117
|
+
ct-toolkit status --vault ./ct_provenance.db
|
|
118
|
+
|
|
119
|
+
# Launch the interactive Web Audit & Telemetry Dashboard at http://127.0.0.1:8001/dashboard
|
|
120
|
+
ct-toolkit dashboard --web --vault ./ct_provenance.db --port 8001
|
|
121
|
+
|
|
118
122
|
# Audit a local Ollama model
|
|
119
123
|
ct-toolkit audit --url http://localhost:11434/v1 --kernel defense
|
|
120
124
|
|
|
@@ -142,10 +146,9 @@ The L2 judge does not evaluate Jinja2 expressions in user requests or model resp
|
|
|
142
146
|
|
|
143
147
|
| Metric | Status |
|
|
144
148
|
| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
145
|
-
| **Tests** | ✅
|
|
149
|
+
| **Tests** | ✅ 426 passed, 3 skipped (100% success rate, 90%+ coverage) |
|
|
146
150
|
| **Downloads** | [](https://pepy.tech/projects/ct-toolkit) |
|
|
147
|
-
| **Last Phase** | ✅ v0.
|
|
148
|
-
| **Current Goal** | 🔶 Phase 7: Multi-Agent Synchronization (Integration) |
|
|
151
|
+
| **Last Phase** | ✅ v0.4.0: Async & Streaming (`achat`), Contrastive L1, Background L3 & Circuit Breaker, PostgreSQL/OTel, HMAC Header Propagation, and Web Audit Dashboard |
|
|
149
152
|
|
|
150
153
|
### Framework & Model Support
|
|
151
154
|
|
|
@@ -12,7 +12,7 @@ Identity Continuity Guardrails for LLM Systems.
|
|
|
12
12
|
print(response.content)
|
|
13
13
|
print(response.divergence_score)
|
|
14
14
|
"""
|
|
15
|
-
from ct_toolkit.core.wrapper import TheseusWrapper, WrapperConfig, CTResponse
|
|
15
|
+
from ct_toolkit.core.wrapper import TheseusWrapper, WrapperConfig, CTResponse, CTStreamChunk
|
|
16
16
|
from ct_toolkit.core.kernel import ConstitutionalKernel
|
|
17
17
|
from ct_toolkit.core.compatibility import CompatibilityLayer
|
|
18
18
|
from ct_toolkit.core.exceptions import (
|
|
@@ -23,12 +23,13 @@ from ct_toolkit.core.exceptions import (
|
|
|
23
23
|
ChainIntegrityError,
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
__version__ = "0.
|
|
26
|
+
__version__ = "0.4.0"
|
|
27
27
|
|
|
28
28
|
__all__ = [
|
|
29
29
|
"TheseusWrapper",
|
|
30
30
|
"WrapperConfig",
|
|
31
31
|
"CTResponse",
|
|
32
|
+
"CTStreamChunk",
|
|
32
33
|
"ConstitutionalKernel",
|
|
33
34
|
"CompatibilityLayer",
|
|
34
35
|
"AxiomaticViolationError",
|
|
@@ -22,7 +22,7 @@ from rich.table import Table
|
|
|
22
22
|
|
|
23
23
|
from ct_toolkit import TheseusWrapper, WrapperConfig, __version__
|
|
24
24
|
from ct_toolkit.divergence.l3_icm import ICMRunner
|
|
25
|
-
from ct_toolkit.server import start_server
|
|
25
|
+
from ct_toolkit.server import start_dashboard_server, start_server
|
|
26
26
|
|
|
27
27
|
app = typer.Typer(
|
|
28
28
|
help="Computational Theseus Toolkit — Identity Continuity Guardrails for Agentic Systems.",
|
|
@@ -95,7 +95,7 @@ BANNER = r"""
|
|
|
95
95
|
|
|
96
96
|
def show_banner():
|
|
97
97
|
console.print(f"[bold cyan]{BANNER}[/bold cyan]")
|
|
98
|
-
console.print(f"[bold white]
|
|
98
|
+
console.print(f"[bold white] Computational Theseus Toolkit (CT Toolkit) v{__version__}[/bold white]")
|
|
99
99
|
console.print("[dim] Identity Continuity Guardrails for Agentic Systems[/dim]\n")
|
|
100
100
|
|
|
101
101
|
def version_callback(value: bool):
|
|
@@ -205,12 +205,14 @@ def serve(
|
|
|
205
205
|
policy_environment: str = typer.Option("prod", "--policy-environment", help="Policy environment override (dev, test, prod)."),
|
|
206
206
|
judge_provider: str = typer.Option("openai", "--judge-provider", help="LLM provider for L2/L3 judge calls."),
|
|
207
207
|
judge_model: Optional[str] = typer.Option(None, "--judge-model", help="Model ID for L2/L3 judge calls."),
|
|
208
|
+
api_key: Optional[str] = typer.Option(None, "--api-key", help="Optional Bearer token / API key for server endpoints."),
|
|
208
209
|
):
|
|
209
|
-
"""Start the CT-Toolkit Guardrail
|
|
210
|
-
console.print("Starting Guardrail Server...")
|
|
210
|
+
"""Start the CT-Toolkit Guardrail & Web Audit Server."""
|
|
211
|
+
console.print("Starting Guardrail & Audit Server...")
|
|
211
212
|
console.print(f" - Kernel: [bold yellow]{kernel}[/bold yellow]")
|
|
212
213
|
console.print(f" - Template: [bold green]{template}[/bold green]")
|
|
213
214
|
console.print(f" - Bind: [bold cyan]{host}:{port}[/bold cyan]")
|
|
215
|
+
console.print(f" - Web Audit Dashboard: [bold underline cyan]http://{host}:{port}/dashboard[/bold underline cyan]")
|
|
214
216
|
|
|
215
217
|
try:
|
|
216
218
|
config = WrapperConfig(
|
|
@@ -225,7 +227,7 @@ def serve(
|
|
|
225
227
|
wrapper = TheseusWrapper(provider=judge_provider, config=config)
|
|
226
228
|
|
|
227
229
|
# Start the uvicorn server
|
|
228
|
-
start_server(wrapper=wrapper, host=host, port=port)
|
|
230
|
+
start_server(wrapper=wrapper, host=host, port=port, api_key=api_key)
|
|
229
231
|
except Exception as e:
|
|
230
232
|
console.print(f"[bold red]Failed to start server:[/bold red] {e}")
|
|
231
233
|
raise typer.Exit(code=1)
|
|
@@ -247,7 +249,7 @@ def setup(
|
|
|
247
249
|
cross-origin redirects, and require certificate validation against the
|
|
248
250
|
system trust store.
|
|
249
251
|
"""
|
|
250
|
-
base_url = f"https://raw.githubusercontent.com/
|
|
252
|
+
base_url = f"https://raw.githubusercontent.com/Theseus-Guard/ct-toolkit/{repo_branch}/examples/agent_dna_config"
|
|
251
253
|
|
|
252
254
|
if not verify_checksums:
|
|
253
255
|
console.print(
|
|
@@ -363,5 +365,166 @@ def list_templates():
|
|
|
363
365
|
|
|
364
366
|
console.print(table)
|
|
365
367
|
|
|
368
|
+
|
|
369
|
+
def _render_status_dashboard(
|
|
370
|
+
vault_path: str = "./ct_provenance.db",
|
|
371
|
+
vault_type: str = "local",
|
|
372
|
+
limit: int = 200,
|
|
373
|
+
) -> None:
|
|
374
|
+
"""Renders the Provenance Chain, L1/L2/L3 Divergence Trends, and Staged Rules Dashboard."""
|
|
375
|
+
import time as _time
|
|
376
|
+
|
|
377
|
+
from ct_toolkit.core.exceptions import ChainIntegrityError
|
|
378
|
+
from ct_toolkit.provenance.log import ProvenanceLog
|
|
379
|
+
|
|
380
|
+
try:
|
|
381
|
+
log = ProvenanceLog(vault_type=vault_type, vault_path=vault_path)
|
|
382
|
+
except Exception as exc:
|
|
383
|
+
console.print(f"[bold red]Failed to open Provenance Log ({vault_path}):[/bold red] {exc}")
|
|
384
|
+
raise typer.Exit(code=1)
|
|
385
|
+
|
|
386
|
+
chain_ok = True
|
|
387
|
+
tampered_entry_id: str | None = None
|
|
388
|
+
verified_count = 0
|
|
389
|
+
last_hash = ProvenanceLog.GENESIS_HASH
|
|
390
|
+
|
|
391
|
+
try:
|
|
392
|
+
checkpoint = log.get_chain_checkpoint(batch_size=500)
|
|
393
|
+
verified_count = int(checkpoint["verified_count"])
|
|
394
|
+
last_hash = str(checkpoint["last_content_hash"])
|
|
395
|
+
except ChainIntegrityError as exc:
|
|
396
|
+
chain_ok = False
|
|
397
|
+
tampered_entry_id = getattr(exc, "entry_id", str(exc))
|
|
398
|
+
|
|
399
|
+
entries = log.get_entries(limit=limit, include_rolled_back=False)
|
|
400
|
+
scores = [e.divergence_score for e in entries if e.divergence_score is not None]
|
|
401
|
+
avg_score = (sum(scores) / len(scores)) if scores else 0.0
|
|
402
|
+
max_score = max(scores) if scores else 0.0
|
|
403
|
+
|
|
404
|
+
tier_counts: dict[str, int] = {
|
|
405
|
+
"ok": 0,
|
|
406
|
+
"l1_warning": 0,
|
|
407
|
+
"l2_judge": 0,
|
|
408
|
+
"l3_icm": 0,
|
|
409
|
+
}
|
|
410
|
+
promoted_ids: set[str] = set()
|
|
411
|
+
staged_records: list[dict[str, object]] = []
|
|
412
|
+
|
|
413
|
+
for entry in entries:
|
|
414
|
+
meta = entry.metadata or {}
|
|
415
|
+
event_type = meta.get("event_type")
|
|
416
|
+
if event_type == "staged_promotion":
|
|
417
|
+
eid = meta.get("endorsement_id")
|
|
418
|
+
if eid:
|
|
419
|
+
promoted_ids.add(str(eid))
|
|
420
|
+
continue
|
|
421
|
+
if event_type == "reflective_endorsement" and meta.get("decision") == "staged":
|
|
422
|
+
staged_records.append(meta)
|
|
423
|
+
continue
|
|
424
|
+
|
|
425
|
+
raw_tier = str(meta.get("tier") or meta.get("divergence_tier") or "").lower()
|
|
426
|
+
if raw_tier in tier_counts:
|
|
427
|
+
tier_counts[raw_tier] += 1
|
|
428
|
+
elif entry.divergence_score is not None:
|
|
429
|
+
if entry.divergence_score >= 0.50:
|
|
430
|
+
tier_counts["l3_icm"] += 1
|
|
431
|
+
elif entry.divergence_score >= 0.30:
|
|
432
|
+
tier_counts["l2_judge"] += 1
|
|
433
|
+
elif entry.divergence_score >= 0.15:
|
|
434
|
+
tier_counts["l1_warning"] += 1
|
|
435
|
+
else:
|
|
436
|
+
tier_counts["ok"] += 1
|
|
437
|
+
|
|
438
|
+
chain_badge = (
|
|
439
|
+
"[bold green]VALID (HMAC Verified)[/bold green]"
|
|
440
|
+
if chain_ok
|
|
441
|
+
else f"[bold red]COMPROMISED (Entry {tampered_entry_id})[/bold red]"
|
|
442
|
+
)
|
|
443
|
+
summary_text = (
|
|
444
|
+
f"[bold]Vault:[/bold] {vault_path} ({vault_type})\n"
|
|
445
|
+
f"[bold]Chain Integrity:[/bold] {chain_badge}\n"
|
|
446
|
+
f"[bold]Verified Active Entries:[/bold] {verified_count} (showing last {len(entries)})\n"
|
|
447
|
+
f"[bold]Divergence Score (Avg / Max):[/bold] {avg_score:.4f} / {max_score:.4f}\n"
|
|
448
|
+
f"[bold]Head Hash:[/bold] [dim]{last_hash[:32]}...[/dim]"
|
|
449
|
+
)
|
|
450
|
+
console.print(Panel(summary_text, title="CT Toolkit Audit & Telemetry Status", border_style="cyan"))
|
|
451
|
+
|
|
452
|
+
tier_table = Table(title="Divergence Tier Breakdown (L1 / L2 / L3)", show_header=True, header_style="bold magenta")
|
|
453
|
+
tier_table.add_column("Tier", style="cyan")
|
|
454
|
+
tier_table.add_column("Count", justify="right")
|
|
455
|
+
tier_table.add_column("Share", justify="right")
|
|
456
|
+
|
|
457
|
+
total_tiered = sum(tier_counts.values())
|
|
458
|
+
for tier_name, count in tier_counts.items():
|
|
459
|
+
pct = (count / total_tiered * 100.0) if total_tiered > 0 else 0.0
|
|
460
|
+
tier_table.add_row(tier_name.upper(), str(count), f"{pct:.1f}%")
|
|
461
|
+
console.print(tier_table)
|
|
462
|
+
|
|
463
|
+
staged_table = Table(title="Staged Kernel Rules (Sandbox Cooldown)", show_header=True, header_style="bold yellow")
|
|
464
|
+
staged_table.add_column("Endorsement ID", style="cyan")
|
|
465
|
+
staged_table.add_column("Commitment", style="white")
|
|
466
|
+
staged_table.add_column("Rule Text", style="white")
|
|
467
|
+
staged_table.add_column("Status", style="bold")
|
|
468
|
+
|
|
469
|
+
now = _time.time()
|
|
470
|
+
if not staged_records:
|
|
471
|
+
staged_table.add_row("-", "-", "No staged rules recorded", "[dim]NONE[/dim]")
|
|
472
|
+
else:
|
|
473
|
+
for s_meta in staged_records:
|
|
474
|
+
eid = str(s_meta.get("endorsement_id", "unknown"))
|
|
475
|
+
commitment = str(s_meta.get("commitment_id", "unknown"))
|
|
476
|
+
rule_text = str(s_meta.get("rule_text", ""))
|
|
477
|
+
cooldown_until = s_meta.get("cooldown_until")
|
|
478
|
+
if eid in promoted_ids:
|
|
479
|
+
status_str = "[green]PROMOTED[/green]"
|
|
480
|
+
elif isinstance(cooldown_until, (int, float)) and now < cooldown_until:
|
|
481
|
+
rem = int(cooldown_until - now)
|
|
482
|
+
status_str = f"[yellow]ACTIVE COOLDOWN ({rem}s left)[/yellow]"
|
|
483
|
+
else:
|
|
484
|
+
status_str = "[blue]READY FOR PROMOTION[/blue]"
|
|
485
|
+
staged_table.add_row(eid[:12], commitment, rule_text, status_str)
|
|
486
|
+
|
|
487
|
+
console.print(staged_table)
|
|
488
|
+
|
|
489
|
+
if not chain_ok:
|
|
490
|
+
raise typer.Exit(code=1)
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
@app.command(name="status")
|
|
494
|
+
def status_cmd(
|
|
495
|
+
vault_path: str = typer.Option("./ct_provenance.db", "--vault", help="Path or SQLAlchemy URL to the provenance log database."),
|
|
496
|
+
vault_type: str = typer.Option("local", "--vault-type", help="Vault backend type: local, postgres, sqlalchemy."),
|
|
497
|
+
limit: int = typer.Option(200, "--limit", help="Maximum recent entries to analyze."),
|
|
498
|
+
):
|
|
499
|
+
"""Display Provenance Chain integrity, L1/L2/L3 divergence trends, and active staged rules."""
|
|
500
|
+
_render_status_dashboard(vault_path=vault_path, vault_type=vault_type, limit=limit)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
@app.command(name="dashboard")
|
|
504
|
+
def dashboard_cmd(
|
|
505
|
+
vault_path: str = typer.Option("./ct_provenance.db", "--vault", help="Path or SQLAlchemy URL to the provenance log database."),
|
|
506
|
+
vault_type: str = typer.Option("local", "--vault-type", help="Vault backend type: local, postgres, sqlalchemy."),
|
|
507
|
+
limit: int = typer.Option(200, "--limit", help="Maximum recent entries to analyze."),
|
|
508
|
+
web: bool = typer.Option(False, "--web", "-w", help="Launch the interactive Web Audit & Telemetry Dashboard in browser mode."),
|
|
509
|
+
host: str = typer.Option("127.0.0.1", "--host", help="Host to bind the Web Dashboard server to (when --web is used)."),
|
|
510
|
+
port: int = typer.Option(8001, "--port", help="Port to bind the Web Dashboard server to (when --web is used)."),
|
|
511
|
+
api_key: Optional[str] = typer.Option(None, "--api-key", help="Optional Bearer token / API key for dashboard API authentication."),
|
|
512
|
+
):
|
|
513
|
+
"""Display the terminal audit dashboard or launch the interactive Web Audit Dashboard (--web)."""
|
|
514
|
+
if web:
|
|
515
|
+
console.print("🌐 Launching [bold cyan]CT Toolkit Web Audit & Telemetry Dashboard[/bold cyan]...")
|
|
516
|
+
console.print(f" - Vault: [bold yellow]{vault_path}[/bold yellow] ({vault_type})")
|
|
517
|
+
console.print(f" - Dashboard URL: [bold underline green]http://{host}:{port}/dashboard[/bold underline green]")
|
|
518
|
+
start_dashboard_server(
|
|
519
|
+
vault_path=vault_path,
|
|
520
|
+
vault_type=vault_type,
|
|
521
|
+
host=host,
|
|
522
|
+
port=port,
|
|
523
|
+
api_key=api_key,
|
|
524
|
+
)
|
|
525
|
+
return
|
|
526
|
+
_render_status_dashboard(vault_path=vault_path, vault_type=vault_type, limit=limit)
|
|
527
|
+
|
|
528
|
+
|
|
366
529
|
if __name__ == "__main__":
|
|
367
530
|
app()
|