sigmagate 0.1.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.
- sigmagate-0.1.0/PKG-INFO +124 -0
- sigmagate-0.1.0/README.md +97 -0
- sigmagate-0.1.0/pyproject.toml +43 -0
- sigmagate-0.1.0/setup.cfg +4 -0
- sigmagate-0.1.0/sigmagate/__init__.py +69 -0
- sigmagate-0.1.0/sigmagate/cli.py +199 -0
- sigmagate-0.1.0/sigmagate/client.py +162 -0
- sigmagate-0.1.0/sigmagate/exceptions.py +45 -0
- sigmagate-0.1.0/sigmagate/gate.py +76 -0
- sigmagate-0.1.0/sigmagate/qr.py +95 -0
- sigmagate-0.1.0/sigmagate/seal.py +131 -0
- sigmagate-0.1.0/sigmagate/verax.py +156 -0
- sigmagate-0.1.0/sigmagate.egg-info/PKG-INFO +124 -0
- sigmagate-0.1.0/sigmagate.egg-info/SOURCES.txt +21 -0
- sigmagate-0.1.0/sigmagate.egg-info/dependency_links.txt +1 -0
- sigmagate-0.1.0/sigmagate.egg-info/entry_points.txt +2 -0
- sigmagate-0.1.0/sigmagate.egg-info/requires.txt +7 -0
- sigmagate-0.1.0/sigmagate.egg-info/top_level.txt +1 -0
- sigmagate-0.1.0/tests/test_client.py +51 -0
- sigmagate-0.1.0/tests/test_gate.py +71 -0
- sigmagate-0.1.0/tests/test_qr.py +62 -0
- sigmagate-0.1.0/tests/test_seal.py +70 -0
- sigmagate-0.1.0/tests/test_verax.py +94 -0
sigmagate-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sigmagate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sigmagate SDK — Physics-gated AI, VERAX truth auditing, and document sealing in one package.
|
|
5
|
+
Author-email: José Casado Martínez <hello@sigmagate.io>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://sigmagate.io
|
|
8
|
+
Project-URL: Documentation, https://sigmagate.io/docs/sdk
|
|
9
|
+
Project-URL: Repository, https://github.com/hisocer-lab/sigmagate-sdk
|
|
10
|
+
Keywords: ai,verification,verax,physics,coherence,seal,llm,gate
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Requires-Dist: requests>=2.28
|
|
22
|
+
Requires-Dist: click>=8.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
26
|
+
Requires-Dist: responses>=0.25; extra == "dev"
|
|
27
|
+
|
|
28
|
+
# Sigmagate SDK
|
|
29
|
+
|
|
30
|
+
**Physics-gated AI, VERAX truth auditing, and HCQ document sealing — in one Python package.**
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/sigmagate/)
|
|
33
|
+
[](https://www.python.org/)
|
|
34
|
+
[](https://github.com/hisocer-lab/sigmagate-sdk)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install sigmagate
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from sigmagate import Sigmagate
|
|
44
|
+
|
|
45
|
+
sg = Sigmagate(api_key="your-key")
|
|
46
|
+
|
|
47
|
+
# Measure quantum coherence (qR)
|
|
48
|
+
state = sg.qr.measure()
|
|
49
|
+
print(state.level) # DEEP_CRYSTAL | CASI_EP | DEEP_NOISE
|
|
50
|
+
|
|
51
|
+
# Gate a function — only executes when coherence is high enough
|
|
52
|
+
@sg.gate(threshold=1.0)
|
|
53
|
+
def sign_contract(doc):
|
|
54
|
+
return process(doc)
|
|
55
|
+
|
|
56
|
+
result = sign_contract(doc)
|
|
57
|
+
print(result.value, result.qr) # function output + qR at execution time
|
|
58
|
+
|
|
59
|
+
# Audit AI-generated text with VERAX
|
|
60
|
+
audit = sg.verax.check("The brain uses only 10% of its capacity.")
|
|
61
|
+
print(audit.global_score) # 0–100
|
|
62
|
+
for claim in audit.issues:
|
|
63
|
+
print(claim.emoji, claim.text) # 🔴 problematic claims
|
|
64
|
+
|
|
65
|
+
# Audit with fix prompts (VERAX Margin)
|
|
66
|
+
margin = sg.verax.audit_margin("The brain uses only 10% of its capacity.")
|
|
67
|
+
for prompt in margin.fix_prompts:
|
|
68
|
+
print(prompt) # auto-generated correction instructions
|
|
69
|
+
|
|
70
|
+
# Seal a document with HCQ (Hash Convergencia Cuántica)
|
|
71
|
+
receipt = sg.seal.document("This is the official text.")
|
|
72
|
+
print(receipt.hcq) # HCQ-a1b2c3d4...
|
|
73
|
+
print(receipt.verify_url) # https://sigmagate.io/verify/...
|
|
74
|
+
|
|
75
|
+
# Verify a seal
|
|
76
|
+
result = sg.seal.verify("HCQ-a1b2c3d4")
|
|
77
|
+
print(result.valid) # True / False
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## CLI
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
sgm qr # current coherence level
|
|
84
|
+
sgm windows --days 7 # crystal windows in last 7 days
|
|
85
|
+
sgm audit "text to check" # VERAX audit
|
|
86
|
+
sgm audit "text" --margin # VERAX Margin with fix prompts
|
|
87
|
+
sgm audit report.txt # audit from file
|
|
88
|
+
sgm seal document.pdf # seal a file
|
|
89
|
+
sgm verify HCQ-a1b2c3d4 # verify a seal
|
|
90
|
+
sgm health # API status
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Modules
|
|
94
|
+
|
|
95
|
+
| Module | Description |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `sg.qr` | Quantum coherence measurement — `measure()`, `windows()`, `entropy()` |
|
|
98
|
+
| `sg.gate` | Physics-gated execution decorator — `@sg.gate(threshold)` |
|
|
99
|
+
| `sg.verax` | Truth auditing — `check()`, `audit_margin()` |
|
|
100
|
+
| `sg.seal` | HCQ document sealing — `document()`, `verify()` |
|
|
101
|
+
|
|
102
|
+
## VERAX levels
|
|
103
|
+
|
|
104
|
+
| Level | Label | Meaning |
|
|
105
|
+
|---|---|---|
|
|
106
|
+
| V1 | CONFIRMED 🟢 | Solid evidence |
|
|
107
|
+
| V2 | VIABLE 🔵 | Partial / plausible |
|
|
108
|
+
| V3 | THEORETICAL 🟡 | Speculative, needs source |
|
|
109
|
+
| V4 | SPECULATIVE 🔴 | No support / hallucination |
|
|
110
|
+
|
|
111
|
+
## Installation
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install sigmagate
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Get an API key at [sigmagate.io](https://sigmagate.io).
|
|
118
|
+
|
|
119
|
+
## Links
|
|
120
|
+
|
|
121
|
+
- [Documentation](https://sigmagate.io/docs/sdk)
|
|
122
|
+
- [API Reference](https://sigmagate.io/docs/api)
|
|
123
|
+
- [GitHub](https://github.com/hisocer-lab/sigmagate-sdk)
|
|
124
|
+
- [sigmagate.io](https://sigmagate.io)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Sigmagate SDK
|
|
2
|
+
|
|
3
|
+
**Physics-gated AI, VERAX truth auditing, and HCQ document sealing — in one Python package.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/sigmagate/)
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://github.com/hisocer-lab/sigmagate-sdk)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install sigmagate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from sigmagate import Sigmagate
|
|
17
|
+
|
|
18
|
+
sg = Sigmagate(api_key="your-key")
|
|
19
|
+
|
|
20
|
+
# Measure quantum coherence (qR)
|
|
21
|
+
state = sg.qr.measure()
|
|
22
|
+
print(state.level) # DEEP_CRYSTAL | CASI_EP | DEEP_NOISE
|
|
23
|
+
|
|
24
|
+
# Gate a function — only executes when coherence is high enough
|
|
25
|
+
@sg.gate(threshold=1.0)
|
|
26
|
+
def sign_contract(doc):
|
|
27
|
+
return process(doc)
|
|
28
|
+
|
|
29
|
+
result = sign_contract(doc)
|
|
30
|
+
print(result.value, result.qr) # function output + qR at execution time
|
|
31
|
+
|
|
32
|
+
# Audit AI-generated text with VERAX
|
|
33
|
+
audit = sg.verax.check("The brain uses only 10% of its capacity.")
|
|
34
|
+
print(audit.global_score) # 0–100
|
|
35
|
+
for claim in audit.issues:
|
|
36
|
+
print(claim.emoji, claim.text) # 🔴 problematic claims
|
|
37
|
+
|
|
38
|
+
# Audit with fix prompts (VERAX Margin)
|
|
39
|
+
margin = sg.verax.audit_margin("The brain uses only 10% of its capacity.")
|
|
40
|
+
for prompt in margin.fix_prompts:
|
|
41
|
+
print(prompt) # auto-generated correction instructions
|
|
42
|
+
|
|
43
|
+
# Seal a document with HCQ (Hash Convergencia Cuántica)
|
|
44
|
+
receipt = sg.seal.document("This is the official text.")
|
|
45
|
+
print(receipt.hcq) # HCQ-a1b2c3d4...
|
|
46
|
+
print(receipt.verify_url) # https://sigmagate.io/verify/...
|
|
47
|
+
|
|
48
|
+
# Verify a seal
|
|
49
|
+
result = sg.seal.verify("HCQ-a1b2c3d4")
|
|
50
|
+
print(result.valid) # True / False
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## CLI
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
sgm qr # current coherence level
|
|
57
|
+
sgm windows --days 7 # crystal windows in last 7 days
|
|
58
|
+
sgm audit "text to check" # VERAX audit
|
|
59
|
+
sgm audit "text" --margin # VERAX Margin with fix prompts
|
|
60
|
+
sgm audit report.txt # audit from file
|
|
61
|
+
sgm seal document.pdf # seal a file
|
|
62
|
+
sgm verify HCQ-a1b2c3d4 # verify a seal
|
|
63
|
+
sgm health # API status
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Modules
|
|
67
|
+
|
|
68
|
+
| Module | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `sg.qr` | Quantum coherence measurement — `measure()`, `windows()`, `entropy()` |
|
|
71
|
+
| `sg.gate` | Physics-gated execution decorator — `@sg.gate(threshold)` |
|
|
72
|
+
| `sg.verax` | Truth auditing — `check()`, `audit_margin()` |
|
|
73
|
+
| `sg.seal` | HCQ document sealing — `document()`, `verify()` |
|
|
74
|
+
|
|
75
|
+
## VERAX levels
|
|
76
|
+
|
|
77
|
+
| Level | Label | Meaning |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| V1 | CONFIRMED 🟢 | Solid evidence |
|
|
80
|
+
| V2 | VIABLE 🔵 | Partial / plausible |
|
|
81
|
+
| V3 | THEORETICAL 🟡 | Speculative, needs source |
|
|
82
|
+
| V4 | SPECULATIVE 🔴 | No support / hallucination |
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install sigmagate
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Get an API key at [sigmagate.io](https://sigmagate.io).
|
|
91
|
+
|
|
92
|
+
## Links
|
|
93
|
+
|
|
94
|
+
- [Documentation](https://sigmagate.io/docs/sdk)
|
|
95
|
+
- [API Reference](https://sigmagate.io/docs/api)
|
|
96
|
+
- [GitHub](https://github.com/hisocer-lab/sigmagate-sdk)
|
|
97
|
+
- [sigmagate.io](https://sigmagate.io)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sigmagate"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Sigmagate SDK — Physics-gated AI, VERAX truth auditing, and document sealing in one package."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "José Casado Martínez", email = "hello@sigmagate.io" }]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
keywords = ["ai", "verification", "verax", "physics", "coherence", "seal", "llm", "gate"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["requests>=2.28", "click>=8.0"]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = ["pytest>=8.0", "pytest-cov", "responses>=0.25"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://sigmagate.io"
|
|
31
|
+
Documentation = "https://sigmagate.io/docs/sdk"
|
|
32
|
+
Repository = "https://github.com/hisocer-lab/sigmagate-sdk"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
sgm = "sigmagate.cli:cli"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["."]
|
|
39
|
+
include = ["sigmagate*"]
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
addopts = "-v --tb=short"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Sigmagate SDK
|
|
3
|
+
=============
|
|
4
|
+
Physics-gated AI, VERAX truth auditing, and document sealing.
|
|
5
|
+
|
|
6
|
+
Quick start::
|
|
7
|
+
|
|
8
|
+
from sigmagate import Sigmagate
|
|
9
|
+
|
|
10
|
+
sg = Sigmagate(api_key="HL-VX1-...") # or set SIGMAGATE_API_KEY env var
|
|
11
|
+
|
|
12
|
+
# Current qR coherence
|
|
13
|
+
state = sg.qr.measure()
|
|
14
|
+
print(state) # qR=1.247 [DEEP_CRYSTAL] — CRYSTAL ✓
|
|
15
|
+
|
|
16
|
+
# Seal a document
|
|
17
|
+
receipt = sg.seal("report.pdf")
|
|
18
|
+
print(receipt.hcq) # HCQ-a1b2c3d4
|
|
19
|
+
print(receipt.verify_url) # https://sigmagate.io/verify/HCQ-a1b2c3d4
|
|
20
|
+
|
|
21
|
+
# VERAX truth audit
|
|
22
|
+
result = sg.verax.check("The human brain uses only 10% of its capacity.")
|
|
23
|
+
print(result.summary())
|
|
24
|
+
|
|
25
|
+
# VERAX Margin — with fix prompts
|
|
26
|
+
result = sg.verax.audit_margin(ai_response_text)
|
|
27
|
+
for fp in result.fix_prompts:
|
|
28
|
+
print(fp)
|
|
29
|
+
|
|
30
|
+
# Physics-gated execution
|
|
31
|
+
@sg.gate(threshold=1.0, seal=True)
|
|
32
|
+
def sign_contract(doc_hash: str) -> dict:
|
|
33
|
+
return {"signed": True, "hash": doc_hash}
|
|
34
|
+
|
|
35
|
+
CLI::
|
|
36
|
+
|
|
37
|
+
sgm qr
|
|
38
|
+
sgm seal report.pdf
|
|
39
|
+
sgm verify HCQ-a1b2c3d4
|
|
40
|
+
sgm audit "The Earth is flat." --margin
|
|
41
|
+
sgm health
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
__version__ = "0.1.0"
|
|
45
|
+
__author__ = "José Casado Martínez"
|
|
46
|
+
__email__ = "hello@sigmagate.io"
|
|
47
|
+
|
|
48
|
+
from .client import Sigmagate
|
|
49
|
+
from .exceptions import (
|
|
50
|
+
SigmagateError,
|
|
51
|
+
AuthError,
|
|
52
|
+
GateClosedError,
|
|
53
|
+
APIError,
|
|
54
|
+
SealError,
|
|
55
|
+
VeraxError,
|
|
56
|
+
)
|
|
57
|
+
from .qr import QRState, CrystalWindow
|
|
58
|
+
from .seal import SealReceipt, VerifyResult
|
|
59
|
+
from .gate import GateResult
|
|
60
|
+
from .verax import VeraxResult, Claim, V1, V2, V3, V4
|
|
61
|
+
|
|
62
|
+
__all__ = [
|
|
63
|
+
"Sigmagate",
|
|
64
|
+
"SigmagateError", "AuthError", "GateClosedError", "APIError", "SealError", "VeraxError",
|
|
65
|
+
"QRState", "CrystalWindow",
|
|
66
|
+
"SealReceipt", "VerifyResult",
|
|
67
|
+
"GateResult",
|
|
68
|
+
"VeraxResult", "Claim", "V1", "V2", "V3", "V4",
|
|
69
|
+
]
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Sigmagate SDK — CLI (sgm <command>)."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import json
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
from .client import Sigmagate
|
|
9
|
+
from .exceptions import SigmagateError, GateClosedError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _client() -> Sigmagate:
|
|
13
|
+
key = os.environ.get("SIGMAGATE_API_KEY") or os.environ.get("VERAX_API_KEY", "")
|
|
14
|
+
if not key:
|
|
15
|
+
click.echo("Error: set SIGMAGATE_API_KEY environment variable.", err=True)
|
|
16
|
+
sys.exit(1)
|
|
17
|
+
return Sigmagate(api_key=key)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.group()
|
|
21
|
+
@click.version_option("0.1.0", prog_name="sgm")
|
|
22
|
+
def cli():
|
|
23
|
+
"""Sigmagate SDK — physics-gated AI, VERAX truth auditing, document sealing."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# ── qr ────────────────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
@cli.command("qr")
|
|
29
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON")
|
|
30
|
+
def cmd_qr(as_json):
|
|
31
|
+
"""Measure current qR coherence from the Sigmagate network."""
|
|
32
|
+
try:
|
|
33
|
+
sg = _client()
|
|
34
|
+
state = sg.qr.measure()
|
|
35
|
+
if as_json:
|
|
36
|
+
click.echo(json.dumps({
|
|
37
|
+
"qr_score": state.qr_score,
|
|
38
|
+
"level": state.level,
|
|
39
|
+
"phi_pt": state.phi_pt,
|
|
40
|
+
"sigma_e": state.sigma_e,
|
|
41
|
+
"ts": state.ts,
|
|
42
|
+
}))
|
|
43
|
+
else:
|
|
44
|
+
crystal = "✓ GATE OPEN" if state.is_crystal else "✗ gate closed"
|
|
45
|
+
click.echo(f"qR = {state.qr_score:.4f} [{state.level}] {crystal}")
|
|
46
|
+
except SigmagateError as e:
|
|
47
|
+
click.echo(f"Error: {e}", err=True)
|
|
48
|
+
sys.exit(1)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@cli.command("windows")
|
|
52
|
+
def cmd_windows():
|
|
53
|
+
"""Show upcoming predicted DEEP_CRYSTAL windows."""
|
|
54
|
+
try:
|
|
55
|
+
sg = _client()
|
|
56
|
+
windows = sg.qr.windows()
|
|
57
|
+
if not windows:
|
|
58
|
+
click.echo("No predicted windows available.")
|
|
59
|
+
return
|
|
60
|
+
click.echo(f"{'Start':<25} {'End':<25} {'Peak qR':>8} Conf")
|
|
61
|
+
click.echo("-" * 70)
|
|
62
|
+
for w in windows:
|
|
63
|
+
peak = f"{w.peak_qr:.3f}" if w.peak_qr else " — "
|
|
64
|
+
click.echo(f"{w.start:<25} {w.end:<25} {peak:>8} {w.confidence:.0%}")
|
|
65
|
+
except SigmagateError as e:
|
|
66
|
+
click.echo(f"Error: {e}", err=True)
|
|
67
|
+
sys.exit(1)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ── seal ──────────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
@cli.command("seal")
|
|
73
|
+
@click.argument("source")
|
|
74
|
+
@click.option("--label", default="", help="Human-readable label for the seal")
|
|
75
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON")
|
|
76
|
+
def cmd_seal(source, label, as_json):
|
|
77
|
+
"""Seal a file, text snippet, or stdin with HCQ (Hash Convergencia Cuántica).
|
|
78
|
+
|
|
79
|
+
SOURCE can be a file path or a quoted text string.
|
|
80
|
+
Use '-' to read from stdin.
|
|
81
|
+
|
|
82
|
+
Examples:\n
|
|
83
|
+
sgm seal thesis.pdf\n
|
|
84
|
+
sgm seal "The speed of light is 299,792,458 m/s"\n
|
|
85
|
+
cat document.txt | sgm seal -
|
|
86
|
+
"""
|
|
87
|
+
try:
|
|
88
|
+
if source == "-":
|
|
89
|
+
content = sys.stdin.read()
|
|
90
|
+
else:
|
|
91
|
+
content = source
|
|
92
|
+
|
|
93
|
+
sg = _client()
|
|
94
|
+
receipt = sg.seal.document(content, label=label)
|
|
95
|
+
|
|
96
|
+
if as_json:
|
|
97
|
+
click.echo(json.dumps({
|
|
98
|
+
"hcq": receipt.hcq,
|
|
99
|
+
"sha256": receipt.sha256,
|
|
100
|
+
"ts_utc": receipt.ts_utc,
|
|
101
|
+
"qr_at_seal": receipt.qr_at_seal,
|
|
102
|
+
"level": receipt.level,
|
|
103
|
+
"verify_url": receipt.verify_url,
|
|
104
|
+
}))
|
|
105
|
+
else:
|
|
106
|
+
click.echo(str(receipt))
|
|
107
|
+
except SigmagateError as e:
|
|
108
|
+
click.echo(f"Error: {e}", err=True)
|
|
109
|
+
sys.exit(1)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@cli.command("verify")
|
|
113
|
+
@click.argument("hcq")
|
|
114
|
+
def cmd_verify(hcq):
|
|
115
|
+
"""Verify an HCQ seal by its identifier.
|
|
116
|
+
|
|
117
|
+
Example: sgm verify HCQ-a1b2c3d4
|
|
118
|
+
"""
|
|
119
|
+
try:
|
|
120
|
+
sg = _client()
|
|
121
|
+
result = sg.seal.verify(hcq)
|
|
122
|
+
status = "✓ VALID" if result.valid else "✗ INVALID"
|
|
123
|
+
click.echo(f"{status} {result.hcq}")
|
|
124
|
+
if result.valid:
|
|
125
|
+
click.echo(f" Sealed: {result.ts_utc}")
|
|
126
|
+
click.echo(f" qR: {result.qr_at_seal:.3f}")
|
|
127
|
+
click.echo(f" SHA-256: {result.sha256}")
|
|
128
|
+
else:
|
|
129
|
+
click.echo(f" {result.message}", err=True)
|
|
130
|
+
except SigmagateError as e:
|
|
131
|
+
click.echo(f"Error: {e}", err=True)
|
|
132
|
+
sys.exit(1)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# ── verax ─────────────────────────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
@cli.command("audit")
|
|
138
|
+
@click.argument("text_or_file")
|
|
139
|
+
@click.option("--lang", default="en", show_default=True, help="Language (en|es)")
|
|
140
|
+
@click.option("--margin", is_flag=True, help="Include fix prompts (VERAX Margin)")
|
|
141
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON")
|
|
142
|
+
def cmd_audit(text_or_file, lang, margin, as_json):
|
|
143
|
+
"""Audit text with VERAX — returns evidence level and claims.
|
|
144
|
+
|
|
145
|
+
TEXT_OR_FILE can be a text string or a path to a .txt / .md file.
|
|
146
|
+
|
|
147
|
+
Examples:\n
|
|
148
|
+
sgm audit "The Moon is made of cheese."\n
|
|
149
|
+
sgm audit paper.md --lang es --margin
|
|
150
|
+
"""
|
|
151
|
+
import os
|
|
152
|
+
try:
|
|
153
|
+
if os.path.isfile(text_or_file):
|
|
154
|
+
with open(text_or_file, "r") as f:
|
|
155
|
+
text = f.read()
|
|
156
|
+
else:
|
|
157
|
+
text = text_or_file
|
|
158
|
+
|
|
159
|
+
sg = _client()
|
|
160
|
+
result = sg.verax.audit_margin(text, language=lang) if margin else sg.verax.check(text, language=lang)
|
|
161
|
+
|
|
162
|
+
if as_json:
|
|
163
|
+
click.echo(json.dumps({
|
|
164
|
+
"global_score": result.global_score,
|
|
165
|
+
"global_level": result.global_level,
|
|
166
|
+
"engine": result.engine,
|
|
167
|
+
"claims": [
|
|
168
|
+
{"text": c.text, "level": c.level,
|
|
169
|
+
"issue_code": c.issue_code, "fix_prompt": c.fix_prompt}
|
|
170
|
+
for c in result.claims
|
|
171
|
+
],
|
|
172
|
+
}, indent=2))
|
|
173
|
+
else:
|
|
174
|
+
click.echo(result.summary())
|
|
175
|
+
if margin and result.fix_prompts:
|
|
176
|
+
click.echo(f"\n── Fix prompts ({len(result.fix_prompts)}) ──")
|
|
177
|
+
for i, fp in enumerate(result.fix_prompts, 1):
|
|
178
|
+
click.echo(f"[{i}] {fp}")
|
|
179
|
+
except SigmagateError as e:
|
|
180
|
+
click.echo(f"Error: {e}", err=True)
|
|
181
|
+
sys.exit(1)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# ── health ────────────────────────────────────────────────────────────────────
|
|
185
|
+
|
|
186
|
+
@cli.command("health")
|
|
187
|
+
def cmd_health():
|
|
188
|
+
"""Check Sigmagate API health."""
|
|
189
|
+
try:
|
|
190
|
+
sg = _client()
|
|
191
|
+
data = sg.health()
|
|
192
|
+
click.echo(f"Status: {data.get('status', '?')} | Engine: {data.get('verax_engine', '?')} | {data.get('ts', '')}")
|
|
193
|
+
except SigmagateError as e:
|
|
194
|
+
click.echo(f"Offline: {e}", err=True)
|
|
195
|
+
sys.exit(1)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if __name__ == "__main__":
|
|
199
|
+
cli()
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Sigmagate SDK — base HTTP client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
import hashlib
|
|
8
|
+
from typing import Any, Dict, Optional
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
from .exceptions import AuthError, APIError
|
|
13
|
+
|
|
14
|
+
_DEFAULT_BASE_URL = "https://api.hisocer.com"
|
|
15
|
+
_DEFAULT_TIMEOUT = 15
|
|
16
|
+
_DEFAULT_RETRIES = 2
|
|
17
|
+
_RETRY_STATUSES = {429, 500, 502, 503, 504}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _HTTPClient:
|
|
21
|
+
"""Thin requests wrapper with retry logic and VERAX-key auth."""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
api_key: str,
|
|
26
|
+
base_url: str = _DEFAULT_BASE_URL,
|
|
27
|
+
timeout: int = _DEFAULT_TIMEOUT,
|
|
28
|
+
retries: int = _DEFAULT_RETRIES,
|
|
29
|
+
):
|
|
30
|
+
if not api_key:
|
|
31
|
+
raise AuthError("api_key is required. Get yours at sigmagate.io")
|
|
32
|
+
self._api_key = api_key
|
|
33
|
+
self._base_url = base_url.rstrip("/")
|
|
34
|
+
self._timeout = timeout
|
|
35
|
+
self._retries = retries
|
|
36
|
+
self._session = requests.Session()
|
|
37
|
+
self._session.headers.update({
|
|
38
|
+
"Authorization": f"Bearer {api_key}",
|
|
39
|
+
"x-verax-key": api_key,
|
|
40
|
+
"User-Agent": "sigmagate-python/0.1.0",
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
def _url(self, path: str) -> str:
|
|
44
|
+
return f"{self._base_url}/{path.lstrip('/')}"
|
|
45
|
+
|
|
46
|
+
def _request(self, method: str, path: str, **kwargs) -> Dict[str, Any]:
|
|
47
|
+
url = self._url(path)
|
|
48
|
+
attempt = 0
|
|
49
|
+
while True:
|
|
50
|
+
try:
|
|
51
|
+
resp = self._session.request(
|
|
52
|
+
method, url, timeout=self._timeout, **kwargs
|
|
53
|
+
)
|
|
54
|
+
except requests.exceptions.ConnectionError as e:
|
|
55
|
+
raise APIError(0, f"Connection error: {e}") from e
|
|
56
|
+
except requests.exceptions.Timeout as e:
|
|
57
|
+
raise APIError(0, f"Timeout after {self._timeout}s") from e
|
|
58
|
+
|
|
59
|
+
if resp.status_code == 401:
|
|
60
|
+
raise AuthError("Invalid API key — check sigmagate.io/dashboard")
|
|
61
|
+
if resp.status_code in _RETRY_STATUSES and attempt < self._retries:
|
|
62
|
+
attempt += 1
|
|
63
|
+
time.sleep(attempt * 1.5)
|
|
64
|
+
continue
|
|
65
|
+
if not resp.ok:
|
|
66
|
+
detail = ""
|
|
67
|
+
try:
|
|
68
|
+
detail = resp.json().get("detail", resp.text[:200])
|
|
69
|
+
except Exception:
|
|
70
|
+
detail = resp.text[:200]
|
|
71
|
+
raise APIError(resp.status_code, detail)
|
|
72
|
+
|
|
73
|
+
return resp.json()
|
|
74
|
+
|
|
75
|
+
def get(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
76
|
+
return self._request("GET", path, **kwargs)
|
|
77
|
+
|
|
78
|
+
def post(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
79
|
+
return self._request("POST", path, **kwargs)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Sigmagate:
|
|
83
|
+
"""Entry point for the Sigmagate SDK.
|
|
84
|
+
|
|
85
|
+
Usage::
|
|
86
|
+
|
|
87
|
+
from sigmagate import Sigmagate
|
|
88
|
+
|
|
89
|
+
sg = Sigmagate(api_key="HL-VX1-...")
|
|
90
|
+
|
|
91
|
+
# qR coherence
|
|
92
|
+
state = sg.qr.measure()
|
|
93
|
+
print(state.qr_score, state.level)
|
|
94
|
+
|
|
95
|
+
# Document sealing
|
|
96
|
+
receipt = sg.seal("thesis.pdf")
|
|
97
|
+
print(receipt.hcq, receipt.verify_url)
|
|
98
|
+
|
|
99
|
+
# VERAX truth audit
|
|
100
|
+
result = sg.verax.check("The Earth is flat.")
|
|
101
|
+
print(result.level, result.claims)
|
|
102
|
+
|
|
103
|
+
# Physics-gated execution
|
|
104
|
+
@sg.gate(threshold=1.0)
|
|
105
|
+
def sign_contract(doc):
|
|
106
|
+
...
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
def __init__(
|
|
110
|
+
self,
|
|
111
|
+
api_key: Optional[str] = None,
|
|
112
|
+
base_url: str = _DEFAULT_BASE_URL,
|
|
113
|
+
timeout: int = _DEFAULT_TIMEOUT,
|
|
114
|
+
):
|
|
115
|
+
key = api_key or os.environ.get("SIGMAGATE_API_KEY") or os.environ.get("VERAX_API_KEY", "")
|
|
116
|
+
self._http = _HTTPClient(key, base_url=base_url, timeout=timeout)
|
|
117
|
+
|
|
118
|
+
# lazy-init sub-clients
|
|
119
|
+
self._qr = None
|
|
120
|
+
self._seal = None
|
|
121
|
+
self._verax = None
|
|
122
|
+
self._gate_c = None
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def qr(self):
|
|
126
|
+
if self._qr is None:
|
|
127
|
+
from .qr import QRClient
|
|
128
|
+
self._qr = QRClient(self._http)
|
|
129
|
+
return self._qr
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def seal(self):
|
|
133
|
+
if self._seal is None:
|
|
134
|
+
from .seal import SealClient
|
|
135
|
+
self._seal = SealClient(self._http)
|
|
136
|
+
return self._seal
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def verax(self):
|
|
140
|
+
if self._verax is None:
|
|
141
|
+
from .verax import VeraxClient
|
|
142
|
+
self._verax = VeraxClient(self._http)
|
|
143
|
+
return self._verax
|
|
144
|
+
|
|
145
|
+
def gate(self, threshold: float = 1.0, seal: bool = False):
|
|
146
|
+
"""Decorator — executes the function only when qR ≥ threshold.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
threshold: minimum qR required (default 1.0 = DEEP_CRYSTAL)
|
|
150
|
+
seal: if True, seals the return value with HCQ on success
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
GateClosedError: if current qR < threshold
|
|
154
|
+
"""
|
|
155
|
+
if self._gate_c is None:
|
|
156
|
+
from .gate import GateClient
|
|
157
|
+
self._gate_c = GateClient(self._http)
|
|
158
|
+
return self._gate_c.decorator(threshold=threshold, seal=seal)
|
|
159
|
+
|
|
160
|
+
def health(self) -> Dict[str, Any]:
|
|
161
|
+
"""Check API health and current engine status."""
|
|
162
|
+
return self._http.get("/v1/health")
|