sektron-gate 0.1.3__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.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: sektron-gate
3
+ Version: 0.1.3
4
+ Summary: Zero-dependency, fail-closed 5-stage policy gate for AI agent tool calls.
5
+ Author: João Víctor Oliveira Santos (sektronium)
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/sektronium/sektron
8
+ Project-URL: Homepage, https://github.com/sektronium/sektron
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+
12
+ # `sektron-gate`
13
+
14
+ Zero-dependency (Python 3.10+ stdlib only), fail-closed policy gate for AI agent tool calls.
15
+
16
+ ## 5-Line Quickstart
17
+
18
+ ```python
19
+ from sektron_gate import ArgConstraint, GateEngine, Policy
20
+
21
+ policy = Policy(
22
+ allowlist=frozenset({"read_file"}),
23
+ arg_constraints={"read_file": {"path": ArgConstraint(allowed_prefixes=("/workspace/",))}},
24
+ )
25
+ decision = GateEngine(policy).evaluate("read_file", {"path": "/workspace/report.txt"})
26
+ assert decision.allowed and decision.reason_code.value == "ALLOWED"
27
+ ```
28
+
29
+ ## 5-Stage Evaluation Pipeline (Fail-Closed)
30
+ 1. `deny_all` kill-switch
31
+ 2. `denylist` exact match
32
+ 3. `allowlist` membership (missing/empty fails closed)
33
+ 4. Canonicalization, payload byte cap, and reserved `_sektron_approval` key stripping (anti-smuggling)
34
+ 5. `ArgConstraint` validation + optional human-gate token verification
35
+
36
+ ## Honest Limits
37
+ Evaluates structural contracts and parameter constraints only. Does not perform semantic prompt-injection detection or inspect what a downstream tool does once permitted.
@@ -0,0 +1,26 @@
1
+ # `sektron-gate`
2
+
3
+ Zero-dependency (Python 3.10+ stdlib only), fail-closed policy gate for AI agent tool calls.
4
+
5
+ ## 5-Line Quickstart
6
+
7
+ ```python
8
+ from sektron_gate import ArgConstraint, GateEngine, Policy
9
+
10
+ policy = Policy(
11
+ allowlist=frozenset({"read_file"}),
12
+ arg_constraints={"read_file": {"path": ArgConstraint(allowed_prefixes=("/workspace/",))}},
13
+ )
14
+ decision = GateEngine(policy).evaluate("read_file", {"path": "/workspace/report.txt"})
15
+ assert decision.allowed and decision.reason_code.value == "ALLOWED"
16
+ ```
17
+
18
+ ## 5-Stage Evaluation Pipeline (Fail-Closed)
19
+ 1. `deny_all` kill-switch
20
+ 2. `denylist` exact match
21
+ 3. `allowlist` membership (missing/empty fails closed)
22
+ 4. Canonicalization, payload byte cap, and reserved `_sektron_approval` key stripping (anti-smuggling)
23
+ 5. `ArgConstraint` validation + optional human-gate token verification
24
+
25
+ ## Honest Limits
26
+ Evaluates structural contracts and parameter constraints only. Does not perform semantic prompt-injection detection or inspect what a downstream tool does once permitted.
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sektron-gate"
7
+ version = "0.1.3"
8
+ description = "Zero-dependency, fail-closed 5-stage policy gate for AI agent tool calls."
9
+ readme = "README.md"
10
+ license = {text = "Apache-2.0"}
11
+ requires-python = ">=3.10"
12
+ authors = [{name = "João Víctor Oliveira Santos (sektronium)"}]
13
+ dependencies = []
14
+
15
+ [project.urls]
16
+ Repository = "https://github.com/sektronium/sektron"
17
+ Homepage = "https://github.com/sektronium/sektron"
18
+
19
+ [tool.setuptools.packages.find]
20
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ """sektron-gate: Zero-dependency, fail-closed tool policy engine."""
2
+
3
+ from .canonical import CanonicalizationError, canonical_json, sha256_canonical
4
+ from .policy import (
5
+ APPROVAL_SMUGGLE_KEY,
6
+ ArgConstraint,
7
+ Decision,
8
+ DefinitionChangedError,
9
+ GateEngine,
10
+ Policy,
11
+ ReasonCode,
12
+ ToolDriftResult,
13
+ ToolPinGuard,
14
+ definition_digest,
15
+ verify_tools_list,
16
+ )
17
+
18
+ __all__ = [
19
+ "APPROVAL_SMUGGLE_KEY",
20
+ "ArgConstraint",
21
+ "CanonicalizationError",
22
+ "Decision",
23
+ "DefinitionChangedError",
24
+ "GateEngine",
25
+ "Policy",
26
+ "ReasonCode",
27
+ "ToolDriftResult",
28
+ "ToolPinGuard",
29
+ "canonical_json",
30
+ "definition_digest",
31
+ "sha256_canonical",
32
+ "verify_tools_list",
33
+ ]
@@ -0,0 +1,66 @@
1
+ """Deterministic canonical JSON serialization (fail-closed on NaN/Infinity)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ import math
8
+ from typing import Any
9
+
10
+
11
+ class CanonicalizationError(ValueError):
12
+ """Raised when an input value cannot be canonicalized safely."""
13
+
14
+
15
+ def _validate_str(value: str) -> None:
16
+ # Lone surrogates (U+D800-U+DFFF) cannot be encoded as UTF-8:
17
+ # json.dumps(ensure_ascii=False) emits them raw and the
18
+ # .encode("utf-8") step in callers then raises UnicodeEncodeError
19
+ # outside any CanonicalizationError handler. Reject fail-closed.
20
+ # (A real emoji is a single code point, not a surrogate pair.)
21
+ if any(0xD800 <= ord(ch) <= 0xDFFF for ch in value):
22
+ raise CanonicalizationError("string contains lone surrogate code point(s)")
23
+
24
+
25
+ def _validate_json_value(value: Any, *, depth: int = 0, max_depth: int = 32) -> None:
26
+ if depth > max_depth:
27
+ raise CanonicalizationError(f"maximum nesting depth ({max_depth}) exceeded")
28
+ if value is None or isinstance(value, (bool, int)):
29
+ return
30
+ if isinstance(value, str):
31
+ _validate_str(value)
32
+ return
33
+ if isinstance(value, float):
34
+ if not math.isfinite(value):
35
+ raise CanonicalizationError("non-finite float (NaN/Infinity) rejected fail-closed")
36
+ return
37
+ if isinstance(value, (list, tuple)):
38
+ for item in value:
39
+ _validate_json_value(item, depth=depth + 1, max_depth=max_depth)
40
+ return
41
+ if isinstance(value, dict):
42
+ for k, v in value.items():
43
+ if not isinstance(k, str):
44
+ raise CanonicalizationError(f"object keys must be strings, got {type(k).__name__}")
45
+ _validate_str(k)
46
+ _validate_json_value(v, depth=depth + 1, max_depth=max_depth)
47
+ return
48
+ raise CanonicalizationError(f"unsupported JSON type: {type(value).__name__}")
49
+
50
+
51
+ def canonical_json(value: Any, *, max_depth: int = 32) -> str:
52
+ """Serializes `value` into deterministic compact UTF-8 JSON with sorted keys."""
53
+ _validate_json_value(value, depth=0, max_depth=max_depth)
54
+ return json.dumps(
55
+ value,
56
+ sort_keys=True,
57
+ separators=(",", ":"),
58
+ ensure_ascii=False,
59
+ allow_nan=False,
60
+ )
61
+
62
+
63
+ def sha256_canonical(value: Any, *, max_depth: int = 32) -> str:
64
+ """Returns `sha256:<hex>` of the canonical UTF-8 JSON representation."""
65
+ encoded = canonical_json(value, max_depth=max_depth).encode("utf-8")
66
+ return "sha256:" + hashlib.sha256(encoded).hexdigest()