datapi-selfheal 0.3.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.
Files changed (71) hide show
  1. datapi_selfheal-0.3.0/LICENSE +21 -0
  2. datapi_selfheal-0.3.0/PKG-INFO +313 -0
  3. datapi_selfheal-0.3.0/README.md +284 -0
  4. datapi_selfheal-0.3.0/pyproject.toml +72 -0
  5. datapi_selfheal-0.3.0/setup.cfg +4 -0
  6. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/PKG-INFO +313 -0
  7. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/SOURCES.txt +69 -0
  8. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/dependency_links.txt +1 -0
  9. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/entry_points.txt +3 -0
  10. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/requires.txt +7 -0
  11. datapi_selfheal-0.3.0/src/datapi_selfheal.egg-info/top_level.txt +3 -0
  12. datapi_selfheal-0.3.0/src/selfheal_api/__init__.py +106 -0
  13. datapi_selfheal-0.3.0/src/selfheal_api/_sandbox_exec.py +124 -0
  14. datapi_selfheal-0.3.0/src/selfheal_api/autoheal.py +658 -0
  15. datapi_selfheal-0.3.0/src/selfheal_api/billing.py +738 -0
  16. datapi_selfheal-0.3.0/src/selfheal_api/cli.py +958 -0
  17. datapi_selfheal-0.3.0/src/selfheal_api/dashboard.py +1094 -0
  18. datapi_selfheal-0.3.0/src/selfheal_api/eval_fixtures.py +39 -0
  19. datapi_selfheal-0.3.0/src/selfheal_api/github_app.py +1050 -0
  20. datapi_selfheal-0.3.0/src/selfheal_api/github_jwt.py +145 -0
  21. datapi_selfheal-0.3.0/src/selfheal_api/ledger.py +305 -0
  22. datapi_selfheal-0.3.0/src/selfheal_api/metrics.py +259 -0
  23. datapi_selfheal-0.3.0/src/selfheal_api/middleware.py +297 -0
  24. datapi_selfheal-0.3.0/src/selfheal_api/modelgen.py +333 -0
  25. datapi_selfheal-0.3.0/src/selfheal_api/notifier.py +426 -0
  26. datapi_selfheal-0.3.0/src/selfheal_api/remediation.py +277 -0
  27. datapi_selfheal-0.3.0/src/selfheal_api/replay.py +126 -0
  28. datapi_selfheal-0.3.0/src/selfheal_api/sandbox.py +157 -0
  29. datapi_selfheal-0.3.0/src/selfheal_api/server.py +1480 -0
  30. datapi_selfheal-0.3.0/src/selfheal_api/server_hosted.py +1656 -0
  31. datapi_selfheal-0.3.0/src/selfheal_api/specwatch.py +203 -0
  32. datapi_selfheal-0.3.0/src/selfheal_api/worker.py +212 -0
  33. datapi_selfheal-0.3.0/src/sentinel/__init__.py +33 -0
  34. datapi_selfheal-0.3.0/src/sentinel/detector.py +626 -0
  35. datapi_selfheal-0.3.0/src/sentinel/guard.py +345 -0
  36. datapi_selfheal-0.3.0/src/sentinel/llm_fallback.py +256 -0
  37. datapi_selfheal-0.3.0/src/synthesizer/__init__.py +31 -0
  38. datapi_selfheal-0.3.0/src/synthesizer/openapi_emitter.py +181 -0
  39. datapi_selfheal-0.3.0/src/synthesizer/patcher.py +944 -0
  40. datapi_selfheal-0.3.0/src/synthesizer/zod_emitter.py +336 -0
  41. datapi_selfheal-0.3.0/tests/test_auto_heal.py +720 -0
  42. datapi_selfheal-0.3.0/tests/test_billing.py +413 -0
  43. datapi_selfheal-0.3.0/tests/test_billing_flows.py +168 -0
  44. datapi_selfheal-0.3.0/tests/test_cli.py +835 -0
  45. datapi_selfheal-0.3.0/tests/test_connect.py +265 -0
  46. datapi_selfheal-0.3.0/tests/test_console.py +139 -0
  47. datapi_selfheal-0.3.0/tests/test_dashboard.py +203 -0
  48. datapi_selfheal-0.3.0/tests/test_detector_mutations.py +86 -0
  49. datapi_selfheal-0.3.0/tests/test_doctor_deploy.py +105 -0
  50. datapi_selfheal-0.3.0/tests/test_drift_and_patch.py +581 -0
  51. datapi_selfheal-0.3.0/tests/test_github_app.py +343 -0
  52. datapi_selfheal-0.3.0/tests/test_github_app_auth.py +324 -0
  53. datapi_selfheal-0.3.0/tests/test_guard.py +248 -0
  54. datapi_selfheal-0.3.0/tests/test_guard_and_dedup.py +209 -0
  55. datapi_selfheal-0.3.0/tests/test_hosted_install.py +223 -0
  56. datapi_selfheal-0.3.0/tests/test_ledger.py +321 -0
  57. datapi_selfheal-0.3.0/tests/test_llm_fallback.py +268 -0
  58. datapi_selfheal-0.3.0/tests/test_metrics.py +83 -0
  59. datapi_selfheal-0.3.0/tests/test_middleware.py +509 -0
  60. datapi_selfheal-0.3.0/tests/test_modelgen.py +131 -0
  61. datapi_selfheal-0.3.0/tests/test_nested_and_zod.py +585 -0
  62. datapi_selfheal-0.3.0/tests/test_notifier.py +268 -0
  63. datapi_selfheal-0.3.0/tests/test_notifiers.py +293 -0
  64. datapi_selfheal-0.3.0/tests/test_openapi_emitter.py +183 -0
  65. datapi_selfheal-0.3.0/tests/test_perf_benchmarks.py +135 -0
  66. datapi_selfheal-0.3.0/tests/test_remediation.py +362 -0
  67. datapi_selfheal-0.3.0/tests/test_replay.py +162 -0
  68. datapi_selfheal-0.3.0/tests/test_server.py +1405 -0
  69. datapi_selfheal-0.3.0/tests/test_smoke.py +12 -0
  70. datapi_selfheal-0.3.0/tests/test_specwatch.py +235 -0
  71. datapi_selfheal-0.3.0/tests/test_worker.py +326 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SelfHealAPI Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,313 @@
1
+ Metadata-Version: 2.4
2
+ Name: datapi-selfheal
3
+ Version: 0.3.0
4
+ Summary: Datapi SelfHeal: schema-drift detection and verified remediation engine
5
+ Author-email: CREOVA <engineering@creova.ai>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/creova-gif/selfheal-api
8
+ Project-URL: Repository, https://github.com/creova-gif/selfheal-api
9
+ Project-URL: Documentation, https://github.com/creova-gif/selfheal-api/tree/main/docs
10
+ Project-URL: Issues, https://github.com/creova-gif/selfheal-api/issues
11
+ Keywords: api,schema-drift,contract-testing,pydantic,openapi,remediation,webhooks,integration-reliability
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Topic :: System :: Monitoring
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pydantic>=2.14.4
23
+ Requires-Dist: libcst>=1.9.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=9.2.0; extra == "dev"
26
+ Requires-Dist: mypy>=2.4.1; extra == "dev"
27
+ Requires-Dist: ruff>=0.6; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # Datapi SelfHeal: Schema-Drift Detection & Verified Remediation
31
+
32
+ > **Datapi SelfHeal** is the API reliability and verified-remediation capability
33
+ > within the [Datapi](https://github.com/creova-gif/datapi) ecosystem.
34
+ > *Build APIs. Keep them reliable.* — Detect drift. Verify the fix.
35
+ >
36
+ > (Formerly standalone as "SelfHealAPI"; the repository, license, and
37
+ > `selfheal` CLI/package identifiers are unchanged.)
38
+
39
+ [![CI](https://github.com/creova-gif/selfheal-api/actions/workflows/ci.yml/badge.svg)](https://github.com/creova-gif/selfheal-api/actions/workflows/ci.yml)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
41
+ [![Version: 0.3.0](https://img.shields.io/badge/version-0.3.0-informational.svg)](CHANGELOG.md)
42
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](pyproject.toml)
43
+
44
+ Datapi SelfHeal detects third-party API payload drift at the system boundary, redacts all scalar values into structural primitives before analysis, and synthesizes `libcst` adapter patches that pass strict sandbox verification (`verify_patch`, `mypy --strict`, and `pytest`) before a pull request is opened.
45
+
46
+ ```mermaid
47
+ flowchart LR
48
+ Payload["Incoming JSON Payload"] --> Sentinel["Sentinel (detect_drift / Zero-PII)"]
49
+ Sentinel --> Synthesizer["Synthesizer (libcst / Zod / OpenAPI 3.1)"]
50
+ Synthesizer --> Gate["Sandbox Gate (verify_patch, mypy --strict, pytest)"]
51
+ Gate --> Outputs["PR / Guard / Hosted Server"]
52
+ ```
53
+
54
+ ## Overview
55
+
56
+ Modern integrations break silently when upstream webhooks or REST APIs rename fields, coerce integers to strings, wrap scalars in lists, or nest properties. Datapi SelfHeal closes the loop between runtime detection and verified code remediation while enforcing a **Zero-PII boundary**:
57
+
58
+ 1. **Sentinel (`src/sentinel/detector.py`)**: Validates incoming JSON payloads against Pydantic v2 models (`strict=True`), classifies every scalar into a zero-PII `PrimitiveKind` (`<str>`, `<int>`, `<int_str>`, `<float_str>`, `<bool_str>`, `<iso_datetime>`, `<null>`), and emits an immutable `DriftReport` with matched candidate source paths.
59
+ 2. **Synthesizer (`src/synthesizer/patcher.py`)**: Transforms a `DriftReport` into a `PatchPlan` and applies a `libcst.CSTTransformer` to inject a typed `@model_validator(mode="before")` normalizer and safe union/literal widening without losing formatting.
60
+ 3. **Sandbox Gate (`verify_patch`)**: Parses the patched CST, executes the model in an isolated namespace, validates both the drifted payload and canonical legacy payload with `strict=True`, and enforces `mypy --strict` + `pytest` before any patch is written or PR is opened.
61
+
62
+ - **Architecture, Security & Threat Model:** See [`AGENTS.md`](AGENTS.md), [`SECURITY.md`](SECURITY.md), [`docs/adr/001-redacted-ast-synthesis-and-sandbox-gate.md`](docs/adr/001-redacted-ast-synthesis-and-sandbox-gate.md), and [`docs/THREAT_MODEL.md`](docs/THREAT_MODEL.md).
63
+
64
+ ## Features
65
+
66
+ - **Zero-PII Scalar Redaction:** Raw payload values never leave your boundary for LLM fallback (`AnthropicSchemaMappingProvider`) or persistent storage (`DriftEventLedger`).
67
+ - **Formatting-Preserving `libcst` Patching:** Generates typed Pydantic v2 `@model_validator(mode="before")` adapters, nested sub-model normalizers, and list/scalar coercions.
68
+ - **Fail-Closed Verification Gate:** Every patch must pass `verify_patch`, `mypy --strict --shadow-file`, and `pytest` before disk write or PR creation.
69
+ - **Multi-Target Emitters:** Emit TypeScript Zod preprocessors (`--zod`) and OpenAPI 3.1 `x-selfheal-aliases` / `x-selfheal-coercions` schemas (`--openapi`).
70
+ - **Runtime Guard & Middleware:** Drop-in `@selfheal_guard` decorator (sync/async) plus zero-dependency `SelfHealASGIMiddleware` and `SelfHealWSGIMiddleware`.
71
+ - **Hosted Multi-Tenant Server & Drift Console:** Cloud Run-ready HTTP server with HMAC webhook verification, SQLite WAL event ledger, Slack/webhook alerting, and an XSS-safe HTML5 Drift Console (`GET /dashboard`).
72
+ - **Replay Regression Harness:** Deterministic `run_replay_corpus` verification over recorded redacted samples.
73
+
74
+ ## Installation
75
+
76
+ Requires **Python 3.12+**. From PyPI:
77
+
78
+ ```bash
79
+ pip install datapi-selfheal
80
+ ```
81
+
82
+ Or from source:
83
+
84
+ ```bash
85
+ git clone https://github.com/creova-gif/selfheal-api.git
86
+ cd selfheal-api
87
+
88
+ python3.12 -m venv .venv
89
+ source .venv/bin/activate
90
+ pip install -e ".[dev]"
91
+ ```
92
+
93
+ One-command E2E demo (seeded upstream drift → detection → verified patch → reviewable draft-PR artifact):
94
+
95
+ ```bash
96
+ scripts/demo/run.sh # evidence lands in evaluations/demo/<timestamp>/
97
+ ```
98
+
99
+ Run the quality gates locally:
100
+
101
+ ```bash
102
+ .venv/bin/ruff check src tests
103
+ .venv/bin/mypy --strict src tests
104
+ .venv/bin/pytest -v
105
+ ```
106
+
107
+ ## Usage
108
+
109
+ ### `selfheal` CLI (`init`, `check`, `heal`, `schema`, `replay`, `doctor`)
110
+
111
+ ```bash
112
+ # Scaffold starter selfheal.config.json and GitHub Actions workflow
113
+ selfheal init
114
+
115
+ # Verify Python, SQLite, dependencies, and toolchain readiness (zero-secret output)
116
+ selfheal doctor --json
117
+
118
+ # Detect schema drift and emit zero-PII DriftReport JSON (exit 0=clean, 1=drift, 2=error)
119
+ selfheal check --model path/to/models.py:Invoice --payload drifted.json
120
+
121
+ # Emit standalone JSON Schema, OpenAPI 3.1.0, or TypeScript/Zod from any Pydantic model
122
+ selfheal schema --model path/to/models.py:Invoice --format openapi --out openapi.json
123
+
124
+ # Replay a JSONL corpus against a Pydantic model
125
+ selfheal replay --model path/to/models.py:Invoice --corpus samples.jsonl
126
+
127
+ # Hosted onboarding: exchange a GitHub App install token for an org API key
128
+ selfheal connect --install-token "$INSTALL_TOKEN" --repo owner/repo
129
+
130
+ # Generate Pydantic (or Zod) models from captured payload samples
131
+ selfheal models init --samples samples/*.json --format pydantic --out models.py
132
+
133
+ # Synthesize a libcst patch, run verify_patch + mypy --strict --shadow-file + pytest,
134
+ # preview the unified diff, emit TypeScript Zod & OpenAPI 3.1 outputs, write, and open a PR
135
+ selfheal heal \
136
+ --model path/to/models.py:Invoice \
137
+ --payload drifted.json \
138
+ --canonical canonical.json \
139
+ --diff \
140
+ --zod generated/invoice_adapter.ts \
141
+ --openapi generated/openapi.json \
142
+ --write \
143
+ --open-pr
144
+ ```
145
+
146
+ Useful `heal` flags:
147
+ - `--llm-fallback`: enable zero-PII `AnthropicSchemaMappingProvider` for opaque field renames.
148
+ - `--pytest-args "..."`: pass extra arguments to the `pytest` verification gate.
149
+ - `--branch <name>`: override the auto-generated `selfheal/<model>-<fingerprint>` branch name.
150
+
151
+ ### Runtime Guard (`@selfheal_guard`)
152
+
153
+ Decorate sync or async boundary handlers to detect drift in-process, deduplicate identical drift fingerprints, and optionally normalize incoming payloads (`normalize=True`):
154
+
155
+ ```python
156
+ from sentinel.guard import DriftDeduplicator, selfheal_guard
157
+ from sentinel.llm_fallback import AnthropicSchemaMappingProvider
158
+
159
+ dedup = DriftDeduplicator(max_fingerprints=1024)
160
+ provider = AnthropicSchemaMappingProvider(max_calls=50)
161
+
162
+ @selfheal_guard(
163
+ Invoice,
164
+ mapping_provider=provider,
165
+ deduplicator=dedup,
166
+ normalize=True,
167
+ on_drift=lambda report, fp: print(f"Drift detected ({fp[:8]}): {len(report.issues)} issues"),
168
+ )
169
+ async def handle_webhook(payload: dict[str, object]) -> Invoice:
170
+ return Invoice.model_validate(payload)
171
+ ```
172
+
173
+ ### ASGI & WSGI Middleware
174
+
175
+ Inspect JSON request bodies at runtime without framework lock-in using `SelfHealASGIMiddleware` or `SelfHealWSGIMiddleware` with `RouteBinding`:
176
+
177
+ ```python
178
+ from selfheal_api import RouteBinding, SelfHealASGIMiddleware
179
+
180
+ app = SelfHealASGIMiddleware(
181
+ fastapi_or_starlette_app,
182
+ routes=[RouteBinding(path="/webhooks/invoice", model_cls=Invoice, normalize=True)],
183
+ on_drift=lambda report, fp: print(f"Route drift {fp[:8]}: {len(report.issues)} issues"),
184
+ )
185
+ ```
186
+
187
+ ### Replay Regression Harness
188
+
189
+ Validate a `PatchPlan` against a corpus of recorded samples using `run_replay_corpus`:
190
+
191
+ ```python
192
+ from selfheal_api.replay import ReplaySample, run_replay_corpus
193
+
194
+ samples = [ReplaySample(sample_id="stripe-v2", payload=drifted_payload)]
195
+ report = run_replay_corpus(Invoice, samples, plan=patch_result.plan)
196
+ assert report.failed == 0
197
+ ```
198
+
199
+ ### TypeScript / Zod Adapter Emission
200
+
201
+ Generate a typed TypeScript preprocessor alongside Python CST patches via `selfheal heal --zod <out.ts>` or programmatically with `synthesize_zod_preprocessor(plan)`:
202
+
203
+ ```ts
204
+ import { z } from 'zod';
205
+ import { createSelfHealZodAdapter } from './invoice_adapter';
206
+
207
+ const InvoiceSchema = createSelfHealZodAdapter(
208
+ z.object({ id: z.string(), amount_cents: z.number().int() }),
209
+ );
210
+ ```
211
+
212
+ ### Hosted Multi-Tenant Server & Drift Console
213
+
214
+ Run the hosted webhook receiver locally or deploy to GCP Cloud Run using `Dockerfile` and [`deploy/cloudrun.yaml`](deploy/cloudrun.yaml):
215
+
216
+ ```bash
217
+ python -m selfheal_api.server
218
+ # or via the installed console script:
219
+ selfheal-server
220
+ ```
221
+
222
+ Endpoints:
223
+ - `GET /healthz` (`HEAD` supported): liveness probe.
224
+ - `GET /readyz` (`HEAD` supported): readiness probe verifying `DriftLedger`, `BillingStore`, and `InstallationRegistry` SQLite health.
225
+ - `GET /metrics` (`?format=prometheus`): JSON or Prometheus v0.0.4 telemetry metrics.
226
+ - `GET /openapi.json`: live OpenAPI 3.1.0 specification including registered `model_registry` schemas.
227
+ - `POST /webhooks/drift`: multi-tenant drift ingestion with HMAC verification, rate limiting, and Slack/webhook alerting.
228
+ - `POST /webhooks/stripe` & `POST /webhooks/github`: Stripe billing and GitHub App installation webhook handlers.
229
+ - `GET /dashboard`: WCAG 2.1 AA self-contained, CSP-strict HTML5 Drift Console with audit export links.
230
+ - `GET /console`: per-org integration health console (monitored dependencies, drift events, remediation proposals, verification evidence, PR status, spec-watch panels) scoped by `shk_*` API key.
231
+ - `GET /api/v1/events` (`?limit=...&offset=...&model=...`), `GET /api/v1/events/export` (`?format=csv|jsonl`), and `GET /api/v1/summary`: SQLite WAL zero-PII drift event ledger and audit export APIs.
232
+ - `POST /jobs/digest`, `POST /jobs/spec-watch`, `POST /jobs/revert`: jobs-token-guarded schedulers and the auto-heal revert path.
233
+ - `POST /orgs/<id>/install`, `POST /orgs/<id>/connect`, `POST /orgs/<id>/billing/*`: GitHub App install flow, repo binding + API keys, and Stripe checkout/portal.
234
+
235
+ ## Configuration
236
+
237
+ See [`.env.example`](.env.example) for a starter template. The hosted server (`src/selfheal_api/server.py`), Cloud Run manifest (`deploy/cloudrun.yaml`), and LLM fallback provider (`src/sentinel/llm_fallback.py`) read the following environment variables:
238
+
239
+ | Variable | Default | Description |
240
+ | --- | --- | --- |
241
+ | `PORT` | `8080` | HTTP listen port for `selfheal-server` / Cloud Run. |
242
+ | `SELFHEAL_HOST` | `0.0.0.0` | Bind host address for `selfheal-server`. |
243
+ | `SELFHEAL_DB_PATH` | `:memory:` | SQLite WAL persistence path (e.g. `/data/selfheal.db`) for ledger, billing, and installations. |
244
+ | `SELFHEAL_RETENTION_DAYS` | `0` | Startup retention window in days (`> 0` prunes expired drift events on boot). |
245
+ | `SELFHEAL_MODELS` | `""` | Comma-separated `module.path:ClassName` specs loaded at startup. |
246
+ | `SELFHEAL_WEBHOOK_SECRET` | `""` | HMAC-SHA256 shared secret for `POST /webhooks/drift`. |
247
+ | `STRIPE_WEBHOOK_SECRET` | `""` | Stripe webhook signing secret (falls back to `SELFHEAL_STRIPE_WEBHOOK_SECRET`). |
248
+ | `GITHUB_APP_WEBHOOK_SECRET` | `""` | GitHub App webhook signing secret (falls back to `SELFHEAL_GITHUB_WEBHOOK_SECRET`). |
249
+ | `SELFHEAL_MAX_RPM` | `60` | Per-tenant requests-per-minute rate limit. |
250
+ | `SELFHEAL_MAX_LLM_CALLS` | `20` | Per-tenant cap on zero-PII LLM fallback calls. |
251
+ | `SELFHEAL_SLACK_WEBHOOK_URL` | `""` | Optional `https://` Slack webhook URL for zero-PII drift alerts. |
252
+ | `SELFHEAL_ALERT_WEBHOOK_URL` | `""` | Optional `https://` generic webhook URL for signed `DriftAlert` notifications. |
253
+ | `SELFHEAL_ALERT_WEBHOOK_SECRET` | `""` | Optional HMAC-SHA256 secret (`X-SelfHeal-Signature`) for `SELFHEAL_ALERT_WEBHOOK_URL`. |
254
+ | `ANTHROPIC_API_KEY` | `""` | API key for `AnthropicSchemaMappingProvider` when `--llm-fallback` is enabled. |
255
+ | `SELFHEAL_STATE_SECRET` | `""` | HMAC secret for hosted install-state nonces. |
256
+ | `SELFHEAL_JOBS_TOKEN` | `""` | Bearer token guarding `POST /jobs/*` endpoints. |
257
+ | `SELFHEAL_GITHUB_APP_ID` / `SELFHEAL_GITHUB_APP_PRIVATE_KEY` / `SELFHEAL_GITHUB_APP_SLUG` | `""` | GitHub App credentials for installation tokens, repo reads, and draft-PR creation. |
258
+ | `STRIPE_SECRET_KEY` / `STRIPE_PRICE_PRO` / `STRIPE_PRICE_TEAM` | `""` | Stripe billing configuration for hosted plans. |
259
+ | `SELFHEAL_DIGEST_INTERVAL_SECONDS` / `SELFHEAL_SPECWATCH_INTERVAL_SECONDS` | `604800` / `3600` | In-process scheduler intervals (`SELFHEAL_*_SCHEDULER=inprocess` to enable). |
260
+
261
+ ## Documentation
262
+
263
+ - [`docs/product/PRD.md`](docs/product/PRD.md) — product requirements
264
+ - [`docs/architecture/overview.md`](docs/architecture/overview.md) — system architecture
265
+ - [`docs/design/`](docs/design/) — design system specification
266
+ - [`docs/security/`](docs/security/) — data handling + sandbox evaluation
267
+ - [`docs/operations/runbooks.md`](docs/operations/runbooks.md) — incident runbooks
268
+ - [`docs/deploy-cloud-run.md`](docs/deploy-cloud-run.md) — Cloud Run deployment
269
+ - [`docs/commercial/pricing.md`](docs/commercial/pricing.md) — pricing hypotheses
270
+ - [`research/`](research/) — market, competitor, and technical research
271
+
272
+ ## Benchmarks
273
+
274
+ Measured on Python 3.12.12 (`pydantic 2.14.4`, `libcst 1.9.0`) across the 40-mutation benchmark suite simulating Stripe, HubSpot, and Weather API drift (`tests/test_drift_and_patch.py`):
275
+
276
+ | Metric | Target threshold | Measured result | Evidence |
277
+ | --- | --- | --- | --- |
278
+ | Drift detection recall | 100% | **100.0%** (40 / 40) | `test_40_mutation_benchmark_thresholds` |
279
+ | Auto-patch verification pass rate | >= 85% | **100.0%** (40 / 40) | `test_40_mutation_benchmark_thresholds` |
280
+ | Sentinel runtime check latency (median) | < 2.0 ms | **0.017 ms** (range 0.016 to 0.020 ms across 7 runs) | Bound by `pydantic-core` validation + dict traversal on 1 core |
281
+ | Sentinel runtime check latency (p99) | < 2.0 ms | **0.040 ms** (range 0.033 to 0.059 ms across 7 runs) | Bound by `ValidationError` formatting and token scoring |
282
+
283
+ Regenerate the benchmark numbers with:
284
+
285
+ ```bash
286
+ PYTHONPATH=src .venv/bin/python -c "
287
+ import statistics
288
+ from tests.test_drift_and_patch import ALL_40_MUTATIONS
289
+ from sentinel import detect_drift
290
+ from synthesizer import synthesize_patch, verify_patch
291
+
292
+ for _, m, _, _, mut in ALL_40_MUTATIONS:
293
+ detect_drift(m, mut)
294
+
295
+ medians, p99s = [], []
296
+ for _ in range(7):
297
+ s = sorted(detect_drift(m, mut).elapsed_ms for _, m, _, _, mut in ALL_40_MUTATIONS)
298
+ medians.append(s[len(s) // 2])
299
+ p99s.append(s[int(len(s) * 0.99)])
300
+
301
+ detected = sum(1 for _, m, _, _, mut in ALL_40_MUTATIONS if detect_drift(m, mut).has_drift)
302
+ passed = sum(1 for _, m, src, can, mut in ALL_40_MUTATIONS if verify_patch(synthesize_patch(src, detect_drift(m, mut)), mut, can).passed)
303
+ print(f'Recall: {detected}/{len(ALL_40_MUTATIONS)} | Pass: {passed}/{len(ALL_40_MUTATIONS)} | Median: {statistics.median(medians):.3f}ms | p99: {statistics.median(p99s):.3f}ms')
304
+ "
305
+ ```
306
+
307
+ ## Contributing
308
+
309
+ Contributions are welcome! Please read [`CONTRIBUTING.md`](CONTRIBUTING.md) for local setup, quality gates (`ruff`, `mypy --strict`, `pytest`), ADR guidelines, and Zero-PII security requirements.
310
+
311
+ ## License
312
+
313
+ Licensed under the [MIT License](LICENSE).
@@ -0,0 +1,284 @@
1
+ # Datapi SelfHeal: Schema-Drift Detection & Verified Remediation
2
+
3
+ > **Datapi SelfHeal** is the API reliability and verified-remediation capability
4
+ > within the [Datapi](https://github.com/creova-gif/datapi) ecosystem.
5
+ > *Build APIs. Keep them reliable.* — Detect drift. Verify the fix.
6
+ >
7
+ > (Formerly standalone as "SelfHealAPI"; the repository, license, and
8
+ > `selfheal` CLI/package identifiers are unchanged.)
9
+
10
+ [![CI](https://github.com/creova-gif/selfheal-api/actions/workflows/ci.yml/badge.svg)](https://github.com/creova-gif/selfheal-api/actions/workflows/ci.yml)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
12
+ [![Version: 0.3.0](https://img.shields.io/badge/version-0.3.0-informational.svg)](CHANGELOG.md)
13
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](pyproject.toml)
14
+
15
+ Datapi SelfHeal detects third-party API payload drift at the system boundary, redacts all scalar values into structural primitives before analysis, and synthesizes `libcst` adapter patches that pass strict sandbox verification (`verify_patch`, `mypy --strict`, and `pytest`) before a pull request is opened.
16
+
17
+ ```mermaid
18
+ flowchart LR
19
+ Payload["Incoming JSON Payload"] --> Sentinel["Sentinel (detect_drift / Zero-PII)"]
20
+ Sentinel --> Synthesizer["Synthesizer (libcst / Zod / OpenAPI 3.1)"]
21
+ Synthesizer --> Gate["Sandbox Gate (verify_patch, mypy --strict, pytest)"]
22
+ Gate --> Outputs["PR / Guard / Hosted Server"]
23
+ ```
24
+
25
+ ## Overview
26
+
27
+ Modern integrations break silently when upstream webhooks or REST APIs rename fields, coerce integers to strings, wrap scalars in lists, or nest properties. Datapi SelfHeal closes the loop between runtime detection and verified code remediation while enforcing a **Zero-PII boundary**:
28
+
29
+ 1. **Sentinel (`src/sentinel/detector.py`)**: Validates incoming JSON payloads against Pydantic v2 models (`strict=True`), classifies every scalar into a zero-PII `PrimitiveKind` (`<str>`, `<int>`, `<int_str>`, `<float_str>`, `<bool_str>`, `<iso_datetime>`, `<null>`), and emits an immutable `DriftReport` with matched candidate source paths.
30
+ 2. **Synthesizer (`src/synthesizer/patcher.py`)**: Transforms a `DriftReport` into a `PatchPlan` and applies a `libcst.CSTTransformer` to inject a typed `@model_validator(mode="before")` normalizer and safe union/literal widening without losing formatting.
31
+ 3. **Sandbox Gate (`verify_patch`)**: Parses the patched CST, executes the model in an isolated namespace, validates both the drifted payload and canonical legacy payload with `strict=True`, and enforces `mypy --strict` + `pytest` before any patch is written or PR is opened.
32
+
33
+ - **Architecture, Security & Threat Model:** See [`AGENTS.md`](AGENTS.md), [`SECURITY.md`](SECURITY.md), [`docs/adr/001-redacted-ast-synthesis-and-sandbox-gate.md`](docs/adr/001-redacted-ast-synthesis-and-sandbox-gate.md), and [`docs/THREAT_MODEL.md`](docs/THREAT_MODEL.md).
34
+
35
+ ## Features
36
+
37
+ - **Zero-PII Scalar Redaction:** Raw payload values never leave your boundary for LLM fallback (`AnthropicSchemaMappingProvider`) or persistent storage (`DriftEventLedger`).
38
+ - **Formatting-Preserving `libcst` Patching:** Generates typed Pydantic v2 `@model_validator(mode="before")` adapters, nested sub-model normalizers, and list/scalar coercions.
39
+ - **Fail-Closed Verification Gate:** Every patch must pass `verify_patch`, `mypy --strict --shadow-file`, and `pytest` before disk write or PR creation.
40
+ - **Multi-Target Emitters:** Emit TypeScript Zod preprocessors (`--zod`) and OpenAPI 3.1 `x-selfheal-aliases` / `x-selfheal-coercions` schemas (`--openapi`).
41
+ - **Runtime Guard & Middleware:** Drop-in `@selfheal_guard` decorator (sync/async) plus zero-dependency `SelfHealASGIMiddleware` and `SelfHealWSGIMiddleware`.
42
+ - **Hosted Multi-Tenant Server & Drift Console:** Cloud Run-ready HTTP server with HMAC webhook verification, SQLite WAL event ledger, Slack/webhook alerting, and an XSS-safe HTML5 Drift Console (`GET /dashboard`).
43
+ - **Replay Regression Harness:** Deterministic `run_replay_corpus` verification over recorded redacted samples.
44
+
45
+ ## Installation
46
+
47
+ Requires **Python 3.12+**. From PyPI:
48
+
49
+ ```bash
50
+ pip install datapi-selfheal
51
+ ```
52
+
53
+ Or from source:
54
+
55
+ ```bash
56
+ git clone https://github.com/creova-gif/selfheal-api.git
57
+ cd selfheal-api
58
+
59
+ python3.12 -m venv .venv
60
+ source .venv/bin/activate
61
+ pip install -e ".[dev]"
62
+ ```
63
+
64
+ One-command E2E demo (seeded upstream drift → detection → verified patch → reviewable draft-PR artifact):
65
+
66
+ ```bash
67
+ scripts/demo/run.sh # evidence lands in evaluations/demo/<timestamp>/
68
+ ```
69
+
70
+ Run the quality gates locally:
71
+
72
+ ```bash
73
+ .venv/bin/ruff check src tests
74
+ .venv/bin/mypy --strict src tests
75
+ .venv/bin/pytest -v
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ### `selfheal` CLI (`init`, `check`, `heal`, `schema`, `replay`, `doctor`)
81
+
82
+ ```bash
83
+ # Scaffold starter selfheal.config.json and GitHub Actions workflow
84
+ selfheal init
85
+
86
+ # Verify Python, SQLite, dependencies, and toolchain readiness (zero-secret output)
87
+ selfheal doctor --json
88
+
89
+ # Detect schema drift and emit zero-PII DriftReport JSON (exit 0=clean, 1=drift, 2=error)
90
+ selfheal check --model path/to/models.py:Invoice --payload drifted.json
91
+
92
+ # Emit standalone JSON Schema, OpenAPI 3.1.0, or TypeScript/Zod from any Pydantic model
93
+ selfheal schema --model path/to/models.py:Invoice --format openapi --out openapi.json
94
+
95
+ # Replay a JSONL corpus against a Pydantic model
96
+ selfheal replay --model path/to/models.py:Invoice --corpus samples.jsonl
97
+
98
+ # Hosted onboarding: exchange a GitHub App install token for an org API key
99
+ selfheal connect --install-token "$INSTALL_TOKEN" --repo owner/repo
100
+
101
+ # Generate Pydantic (or Zod) models from captured payload samples
102
+ selfheal models init --samples samples/*.json --format pydantic --out models.py
103
+
104
+ # Synthesize a libcst patch, run verify_patch + mypy --strict --shadow-file + pytest,
105
+ # preview the unified diff, emit TypeScript Zod & OpenAPI 3.1 outputs, write, and open a PR
106
+ selfheal heal \
107
+ --model path/to/models.py:Invoice \
108
+ --payload drifted.json \
109
+ --canonical canonical.json \
110
+ --diff \
111
+ --zod generated/invoice_adapter.ts \
112
+ --openapi generated/openapi.json \
113
+ --write \
114
+ --open-pr
115
+ ```
116
+
117
+ Useful `heal` flags:
118
+ - `--llm-fallback`: enable zero-PII `AnthropicSchemaMappingProvider` for opaque field renames.
119
+ - `--pytest-args "..."`: pass extra arguments to the `pytest` verification gate.
120
+ - `--branch <name>`: override the auto-generated `selfheal/<model>-<fingerprint>` branch name.
121
+
122
+ ### Runtime Guard (`@selfheal_guard`)
123
+
124
+ Decorate sync or async boundary handlers to detect drift in-process, deduplicate identical drift fingerprints, and optionally normalize incoming payloads (`normalize=True`):
125
+
126
+ ```python
127
+ from sentinel.guard import DriftDeduplicator, selfheal_guard
128
+ from sentinel.llm_fallback import AnthropicSchemaMappingProvider
129
+
130
+ dedup = DriftDeduplicator(max_fingerprints=1024)
131
+ provider = AnthropicSchemaMappingProvider(max_calls=50)
132
+
133
+ @selfheal_guard(
134
+ Invoice,
135
+ mapping_provider=provider,
136
+ deduplicator=dedup,
137
+ normalize=True,
138
+ on_drift=lambda report, fp: print(f"Drift detected ({fp[:8]}): {len(report.issues)} issues"),
139
+ )
140
+ async def handle_webhook(payload: dict[str, object]) -> Invoice:
141
+ return Invoice.model_validate(payload)
142
+ ```
143
+
144
+ ### ASGI & WSGI Middleware
145
+
146
+ Inspect JSON request bodies at runtime without framework lock-in using `SelfHealASGIMiddleware` or `SelfHealWSGIMiddleware` with `RouteBinding`:
147
+
148
+ ```python
149
+ from selfheal_api import RouteBinding, SelfHealASGIMiddleware
150
+
151
+ app = SelfHealASGIMiddleware(
152
+ fastapi_or_starlette_app,
153
+ routes=[RouteBinding(path="/webhooks/invoice", model_cls=Invoice, normalize=True)],
154
+ on_drift=lambda report, fp: print(f"Route drift {fp[:8]}: {len(report.issues)} issues"),
155
+ )
156
+ ```
157
+
158
+ ### Replay Regression Harness
159
+
160
+ Validate a `PatchPlan` against a corpus of recorded samples using `run_replay_corpus`:
161
+
162
+ ```python
163
+ from selfheal_api.replay import ReplaySample, run_replay_corpus
164
+
165
+ samples = [ReplaySample(sample_id="stripe-v2", payload=drifted_payload)]
166
+ report = run_replay_corpus(Invoice, samples, plan=patch_result.plan)
167
+ assert report.failed == 0
168
+ ```
169
+
170
+ ### TypeScript / Zod Adapter Emission
171
+
172
+ Generate a typed TypeScript preprocessor alongside Python CST patches via `selfheal heal --zod <out.ts>` or programmatically with `synthesize_zod_preprocessor(plan)`:
173
+
174
+ ```ts
175
+ import { z } from 'zod';
176
+ import { createSelfHealZodAdapter } from './invoice_adapter';
177
+
178
+ const InvoiceSchema = createSelfHealZodAdapter(
179
+ z.object({ id: z.string(), amount_cents: z.number().int() }),
180
+ );
181
+ ```
182
+
183
+ ### Hosted Multi-Tenant Server & Drift Console
184
+
185
+ Run the hosted webhook receiver locally or deploy to GCP Cloud Run using `Dockerfile` and [`deploy/cloudrun.yaml`](deploy/cloudrun.yaml):
186
+
187
+ ```bash
188
+ python -m selfheal_api.server
189
+ # or via the installed console script:
190
+ selfheal-server
191
+ ```
192
+
193
+ Endpoints:
194
+ - `GET /healthz` (`HEAD` supported): liveness probe.
195
+ - `GET /readyz` (`HEAD` supported): readiness probe verifying `DriftLedger`, `BillingStore`, and `InstallationRegistry` SQLite health.
196
+ - `GET /metrics` (`?format=prometheus`): JSON or Prometheus v0.0.4 telemetry metrics.
197
+ - `GET /openapi.json`: live OpenAPI 3.1.0 specification including registered `model_registry` schemas.
198
+ - `POST /webhooks/drift`: multi-tenant drift ingestion with HMAC verification, rate limiting, and Slack/webhook alerting.
199
+ - `POST /webhooks/stripe` & `POST /webhooks/github`: Stripe billing and GitHub App installation webhook handlers.
200
+ - `GET /dashboard`: WCAG 2.1 AA self-contained, CSP-strict HTML5 Drift Console with audit export links.
201
+ - `GET /console`: per-org integration health console (monitored dependencies, drift events, remediation proposals, verification evidence, PR status, spec-watch panels) scoped by `shk_*` API key.
202
+ - `GET /api/v1/events` (`?limit=...&offset=...&model=...`), `GET /api/v1/events/export` (`?format=csv|jsonl`), and `GET /api/v1/summary`: SQLite WAL zero-PII drift event ledger and audit export APIs.
203
+ - `POST /jobs/digest`, `POST /jobs/spec-watch`, `POST /jobs/revert`: jobs-token-guarded schedulers and the auto-heal revert path.
204
+ - `POST /orgs/<id>/install`, `POST /orgs/<id>/connect`, `POST /orgs/<id>/billing/*`: GitHub App install flow, repo binding + API keys, and Stripe checkout/portal.
205
+
206
+ ## Configuration
207
+
208
+ See [`.env.example`](.env.example) for a starter template. The hosted server (`src/selfheal_api/server.py`), Cloud Run manifest (`deploy/cloudrun.yaml`), and LLM fallback provider (`src/sentinel/llm_fallback.py`) read the following environment variables:
209
+
210
+ | Variable | Default | Description |
211
+ | --- | --- | --- |
212
+ | `PORT` | `8080` | HTTP listen port for `selfheal-server` / Cloud Run. |
213
+ | `SELFHEAL_HOST` | `0.0.0.0` | Bind host address for `selfheal-server`. |
214
+ | `SELFHEAL_DB_PATH` | `:memory:` | SQLite WAL persistence path (e.g. `/data/selfheal.db`) for ledger, billing, and installations. |
215
+ | `SELFHEAL_RETENTION_DAYS` | `0` | Startup retention window in days (`> 0` prunes expired drift events on boot). |
216
+ | `SELFHEAL_MODELS` | `""` | Comma-separated `module.path:ClassName` specs loaded at startup. |
217
+ | `SELFHEAL_WEBHOOK_SECRET` | `""` | HMAC-SHA256 shared secret for `POST /webhooks/drift`. |
218
+ | `STRIPE_WEBHOOK_SECRET` | `""` | Stripe webhook signing secret (falls back to `SELFHEAL_STRIPE_WEBHOOK_SECRET`). |
219
+ | `GITHUB_APP_WEBHOOK_SECRET` | `""` | GitHub App webhook signing secret (falls back to `SELFHEAL_GITHUB_WEBHOOK_SECRET`). |
220
+ | `SELFHEAL_MAX_RPM` | `60` | Per-tenant requests-per-minute rate limit. |
221
+ | `SELFHEAL_MAX_LLM_CALLS` | `20` | Per-tenant cap on zero-PII LLM fallback calls. |
222
+ | `SELFHEAL_SLACK_WEBHOOK_URL` | `""` | Optional `https://` Slack webhook URL for zero-PII drift alerts. |
223
+ | `SELFHEAL_ALERT_WEBHOOK_URL` | `""` | Optional `https://` generic webhook URL for signed `DriftAlert` notifications. |
224
+ | `SELFHEAL_ALERT_WEBHOOK_SECRET` | `""` | Optional HMAC-SHA256 secret (`X-SelfHeal-Signature`) for `SELFHEAL_ALERT_WEBHOOK_URL`. |
225
+ | `ANTHROPIC_API_KEY` | `""` | API key for `AnthropicSchemaMappingProvider` when `--llm-fallback` is enabled. |
226
+ | `SELFHEAL_STATE_SECRET` | `""` | HMAC secret for hosted install-state nonces. |
227
+ | `SELFHEAL_JOBS_TOKEN` | `""` | Bearer token guarding `POST /jobs/*` endpoints. |
228
+ | `SELFHEAL_GITHUB_APP_ID` / `SELFHEAL_GITHUB_APP_PRIVATE_KEY` / `SELFHEAL_GITHUB_APP_SLUG` | `""` | GitHub App credentials for installation tokens, repo reads, and draft-PR creation. |
229
+ | `STRIPE_SECRET_KEY` / `STRIPE_PRICE_PRO` / `STRIPE_PRICE_TEAM` | `""` | Stripe billing configuration for hosted plans. |
230
+ | `SELFHEAL_DIGEST_INTERVAL_SECONDS` / `SELFHEAL_SPECWATCH_INTERVAL_SECONDS` | `604800` / `3600` | In-process scheduler intervals (`SELFHEAL_*_SCHEDULER=inprocess` to enable). |
231
+
232
+ ## Documentation
233
+
234
+ - [`docs/product/PRD.md`](docs/product/PRD.md) — product requirements
235
+ - [`docs/architecture/overview.md`](docs/architecture/overview.md) — system architecture
236
+ - [`docs/design/`](docs/design/) — design system specification
237
+ - [`docs/security/`](docs/security/) — data handling + sandbox evaluation
238
+ - [`docs/operations/runbooks.md`](docs/operations/runbooks.md) — incident runbooks
239
+ - [`docs/deploy-cloud-run.md`](docs/deploy-cloud-run.md) — Cloud Run deployment
240
+ - [`docs/commercial/pricing.md`](docs/commercial/pricing.md) — pricing hypotheses
241
+ - [`research/`](research/) — market, competitor, and technical research
242
+
243
+ ## Benchmarks
244
+
245
+ Measured on Python 3.12.12 (`pydantic 2.14.4`, `libcst 1.9.0`) across the 40-mutation benchmark suite simulating Stripe, HubSpot, and Weather API drift (`tests/test_drift_and_patch.py`):
246
+
247
+ | Metric | Target threshold | Measured result | Evidence |
248
+ | --- | --- | --- | --- |
249
+ | Drift detection recall | 100% | **100.0%** (40 / 40) | `test_40_mutation_benchmark_thresholds` |
250
+ | Auto-patch verification pass rate | >= 85% | **100.0%** (40 / 40) | `test_40_mutation_benchmark_thresholds` |
251
+ | Sentinel runtime check latency (median) | < 2.0 ms | **0.017 ms** (range 0.016 to 0.020 ms across 7 runs) | Bound by `pydantic-core` validation + dict traversal on 1 core |
252
+ | Sentinel runtime check latency (p99) | < 2.0 ms | **0.040 ms** (range 0.033 to 0.059 ms across 7 runs) | Bound by `ValidationError` formatting and token scoring |
253
+
254
+ Regenerate the benchmark numbers with:
255
+
256
+ ```bash
257
+ PYTHONPATH=src .venv/bin/python -c "
258
+ import statistics
259
+ from tests.test_drift_and_patch import ALL_40_MUTATIONS
260
+ from sentinel import detect_drift
261
+ from synthesizer import synthesize_patch, verify_patch
262
+
263
+ for _, m, _, _, mut in ALL_40_MUTATIONS:
264
+ detect_drift(m, mut)
265
+
266
+ medians, p99s = [], []
267
+ for _ in range(7):
268
+ s = sorted(detect_drift(m, mut).elapsed_ms for _, m, _, _, mut in ALL_40_MUTATIONS)
269
+ medians.append(s[len(s) // 2])
270
+ p99s.append(s[int(len(s) * 0.99)])
271
+
272
+ detected = sum(1 for _, m, _, _, mut in ALL_40_MUTATIONS if detect_drift(m, mut).has_drift)
273
+ passed = sum(1 for _, m, src, can, mut in ALL_40_MUTATIONS if verify_patch(synthesize_patch(src, detect_drift(m, mut)), mut, can).passed)
274
+ print(f'Recall: {detected}/{len(ALL_40_MUTATIONS)} | Pass: {passed}/{len(ALL_40_MUTATIONS)} | Median: {statistics.median(medians):.3f}ms | p99: {statistics.median(p99s):.3f}ms')
275
+ "
276
+ ```
277
+
278
+ ## Contributing
279
+
280
+ Contributions are welcome! Please read [`CONTRIBUTING.md`](CONTRIBUTING.md) for local setup, quality gates (`ruff`, `mypy --strict`, `pytest`), ADR guidelines, and Zero-PII security requirements.
281
+
282
+ ## License
283
+
284
+ Licensed under the [MIT License](LICENSE).