coreason-manifest 0.2.0__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.
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/PKG-INFO +53 -27
- coreason_manifest-0.4.0/README.md +56 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/pyproject.toml +10 -2
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/__init__.py +19 -1
- coreason_manifest-0.4.0/src/coreason_manifest/engine.py +222 -0
- coreason_manifest-0.4.0/src/coreason_manifest/errors.py +53 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/integrity.py +12 -7
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/loader.py +55 -22
- coreason_manifest-0.4.0/src/coreason_manifest/main.py +17 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/models.py +73 -9
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/policy.py +15 -9
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/schemas/agent.schema.json +6 -6
- coreason_manifest-0.4.0/src/coreason_manifest/server.py +123 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/validator.py +17 -6
- coreason_manifest-0.2.0/README.md +0 -35
- coreason_manifest-0.2.0/src/coreason_manifest/engine.py +0 -117
- coreason_manifest-0.2.0/src/coreason_manifest/errors.py +0 -28
- coreason_manifest-0.2.0/src/coreason_manifest/main.py +0 -16
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/LICENSE +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/NOTICE +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/policies/compliance.rego +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/policies/tbom.json +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/schemas/__init__.py +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/utils/__init__.py +0 -0
- {coreason_manifest-0.2.0 → coreason_manifest-0.4.0}/src/coreason_manifest/utils/logger.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coreason_manifest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: This package is the definitive source of truth. If it isn't in the manifest, it doesn't exist. If it violates the manifest, it doesn't run.
|
|
5
5
|
License: # The Prosperity Public License 3.0.0
|
|
6
6
|
|
|
@@ -67,48 +67,74 @@ Requires-Python: >=3.11
|
|
|
67
67
|
Classifier: License :: Other/Proprietary License
|
|
68
68
|
Classifier: Programming Language :: Python :: 3.12
|
|
69
69
|
Classifier: Operating System :: OS Independent
|
|
70
|
+
Requires-Dist: aiofiles (>=23.2.1,<24.0.0)
|
|
71
|
+
Requires-Dist: anyio (>=4.3.0,<5.0.0)
|
|
72
|
+
Requires-Dist: fastapi (>=0.111.0,<0.112.0)
|
|
73
|
+
Requires-Dist: httpx (>=0.27.0,<0.28.0)
|
|
70
74
|
Requires-Dist: jsonschema (>=4.25.1,<5.0.0)
|
|
71
75
|
Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
72
76
|
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
73
77
|
Requires-Dist: pyyaml (>=6.0.3,<7.0.0)
|
|
78
|
+
Requires-Dist: uvicorn (>=0.30.1,<0.31.0)
|
|
74
79
|
Project-URL: Documentation, https://github.com/CoReason-AI/coreason_manifest
|
|
75
80
|
Project-URL: Homepage, https://github.com/CoReason-AI/coreason_manifest
|
|
76
81
|
Project-URL: Repository, https://github.com/CoReason-AI/coreason_manifest
|
|
77
82
|
Description-Content-Type: text/markdown
|
|
78
83
|
|
|
79
|
-
#
|
|
84
|
+
# Coreason Manifest
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
The definitive source of truth for CoReason-AI Asset definitions. "The Blueprint."
|
|
82
87
|
|
|
83
|
-
[](https://github.com/CoReason-AI/coreason-manifest)
|
|
89
|
+
[](https://github.com/CoReason-AI/coreason-manifest/actions)
|
|
90
|
+
[](https://github.com/astral-sh/ruff)
|
|
91
|
+
[](docs/product_requirements.md)
|
|
84
92
|
|
|
85
|
-
##
|
|
93
|
+
## Overview
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
`coreason-manifest` acts as the validator for the "Agent Development Lifecycle" (ADLC). It ensures that every Agent produced meets strict GxP and security standards. If it isn't in the manifest, it doesn't exist. If it violates the manifest, it doesn't run.
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
- Poetry
|
|
97
|
+
## Features
|
|
91
98
|
|
|
92
|
-
|
|
99
|
+
* **Open Agent Specification (OAS) Validation:** Parses and validates agent definitions against a strict schema.
|
|
100
|
+
* **Compliance Enforcement:** Uses Open Policy Agent (OPA) / Rego to enforce complex business rules and allowlists.
|
|
101
|
+
* **Integrity Verification:** Calculates and verifies SHA256 hashes of the agent's source code to prevent tampering.
|
|
102
|
+
* **Dependency Pinning:** Enforces strict version pinning for all library dependencies.
|
|
103
|
+
* **Trusted Bill of Materials (TBOM):** Validates libraries against an approved list.
|
|
104
|
+
* **Compliance Microservice:** Can be run as a standalone API server (Service C) for centralized validation.
|
|
93
105
|
|
|
94
|
-
|
|
95
|
-
```sh
|
|
96
|
-
git clone https://github.com/example/example.git
|
|
97
|
-
cd my_python_project
|
|
98
|
-
```
|
|
99
|
-
2. Install dependencies:
|
|
100
|
-
```sh
|
|
101
|
-
poetry install
|
|
102
|
-
```
|
|
106
|
+
## Installation
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
```bash
|
|
109
|
+
pip install coreason-manifest
|
|
110
|
+
```
|
|
105
111
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
`coreason-manifest` supports two modes: **Library (CLI)** and **Server (Microservice)**.
|
|
115
|
+
|
|
116
|
+
### 1. Library Usage
|
|
117
|
+
|
|
118
|
+
Use the python library to validate local agent files and verify source integrity.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from coreason_manifest import ManifestEngine, ManifestConfig
|
|
122
|
+
|
|
123
|
+
# Initialize and Validate
|
|
124
|
+
config = ManifestConfig(policy_path="./policies/compliance.rego")
|
|
125
|
+
engine = ManifestEngine(config)
|
|
126
|
+
agent_def = engine.load_and_validate("agent.yaml", "./src")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 2. Server Mode
|
|
130
|
+
|
|
131
|
+
Run the package as a FastAPI server to provide a centralized compliance API.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
uvicorn coreason_manifest.server:app --host 0.0.0.0 --port 8000
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
For full details, see the [Usage Documentation](docs/usage.md).
|
|
138
|
+
|
|
139
|
+
For detailed requirements and architecture, please refer to the [Product Requirements](docs/product_requirements.md) or [Requirements](docs/requirements.md).
|
|
114
140
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Coreason Manifest
|
|
2
|
+
|
|
3
|
+
The definitive source of truth for CoReason-AI Asset definitions. "The Blueprint."
|
|
4
|
+
|
|
5
|
+
[](https://github.com/CoReason-AI/coreason-manifest)
|
|
6
|
+
[](https://github.com/CoReason-AI/coreason-manifest/actions)
|
|
7
|
+
[](https://github.com/astral-sh/ruff)
|
|
8
|
+
[](docs/product_requirements.md)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
`coreason-manifest` acts as the validator for the "Agent Development Lifecycle" (ADLC). It ensures that every Agent produced meets strict GxP and security standards. If it isn't in the manifest, it doesn't exist. If it violates the manifest, it doesn't run.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
* **Open Agent Specification (OAS) Validation:** Parses and validates agent definitions against a strict schema.
|
|
17
|
+
* **Compliance Enforcement:** Uses Open Policy Agent (OPA) / Rego to enforce complex business rules and allowlists.
|
|
18
|
+
* **Integrity Verification:** Calculates and verifies SHA256 hashes of the agent's source code to prevent tampering.
|
|
19
|
+
* **Dependency Pinning:** Enforces strict version pinning for all library dependencies.
|
|
20
|
+
* **Trusted Bill of Materials (TBOM):** Validates libraries against an approved list.
|
|
21
|
+
* **Compliance Microservice:** Can be run as a standalone API server (Service C) for centralized validation.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install coreason-manifest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
`coreason-manifest` supports two modes: **Library (CLI)** and **Server (Microservice)**.
|
|
32
|
+
|
|
33
|
+
### 1. Library Usage
|
|
34
|
+
|
|
35
|
+
Use the python library to validate local agent files and verify source integrity.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from coreason_manifest import ManifestEngine, ManifestConfig
|
|
39
|
+
|
|
40
|
+
# Initialize and Validate
|
|
41
|
+
config = ManifestConfig(policy_path="./policies/compliance.rego")
|
|
42
|
+
engine = ManifestEngine(config)
|
|
43
|
+
agent_def = engine.load_and_validate("agent.yaml", "./src")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Server Mode
|
|
47
|
+
|
|
48
|
+
Run the package as a FastAPI server to provide a centralized compliance API.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
uvicorn coreason_manifest.server:app --host 0.0.0.0 --port 8000
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For full details, see the [Usage Documentation](docs/usage.md).
|
|
55
|
+
|
|
56
|
+
For detailed requirements and architecture, please refer to the [Product Requirements](docs/product_requirements.md) or [Requirements](docs/requirements.md).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "coreason_manifest"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "This package is the definitive source of truth. If it isn't in the manifest, it doesn't exist. If it violates the manifest, it doesn't run."
|
|
5
5
|
authors = ["Gowtham A Rao <gowtham.rao@coreason.ai>"]
|
|
6
6
|
license = "Prosperity-3.0"
|
|
@@ -13,6 +13,11 @@ loguru = "^0.7.2"
|
|
|
13
13
|
pydantic = "^2.12.5"
|
|
14
14
|
jsonschema = "^4.25.1"
|
|
15
15
|
pyyaml = "^6.0.3"
|
|
16
|
+
anyio = "^4.3.0"
|
|
17
|
+
httpx = "^0.27.0"
|
|
18
|
+
aiofiles = "^23.2.1"
|
|
19
|
+
fastapi = "^0.111.0"
|
|
20
|
+
uvicorn = "^0.30.1"
|
|
16
21
|
|
|
17
22
|
[tool.poetry.group.dev.dependencies]
|
|
18
23
|
pytest = "^8.2.2"
|
|
@@ -23,6 +28,8 @@ mkdocs = "^1.6.0"
|
|
|
23
28
|
mkdocs-material = "^9.5.26"
|
|
24
29
|
pydantic = "^2.12.5"
|
|
25
30
|
mypy = "^1.19.1"
|
|
31
|
+
types-aiofiles = "^23.2.0"
|
|
32
|
+
pytest-asyncio = "^0.23.0"
|
|
26
33
|
|
|
27
34
|
[build-system]
|
|
28
35
|
requires = ["poetry-core"]
|
|
@@ -30,7 +37,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
30
37
|
|
|
31
38
|
[project]
|
|
32
39
|
name = "coreason_manifest"
|
|
33
|
-
version = "0.
|
|
40
|
+
version = "0.4.0"
|
|
34
41
|
description = "This package is the definitive source of truth. If it isn't in the manifest, it doesn't exist. If it violates the manifest, it doesn't run."
|
|
35
42
|
readme = "README.md"
|
|
36
43
|
requires-python = ">=3.11"
|
|
@@ -66,6 +73,7 @@ plugins = ["pydantic.mypy"]
|
|
|
66
73
|
[tool.pytest.ini_options]
|
|
67
74
|
addopts = "--cov=src --cov-report=term-missing --cov-fail-under=100"
|
|
68
75
|
testpaths = ["tests"]
|
|
76
|
+
asyncio_mode = "auto"
|
|
69
77
|
|
|
70
78
|
[tool.coverage.run]
|
|
71
79
|
omit = ["tests/*", "/tmp/*"]
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
-
|
|
2
|
+
"""Coreason Manifest Package.
|
|
3
|
+
|
|
4
|
+
This package provides the core functionality for the Coreason Manifest system,
|
|
5
|
+
including loading, validation, policy enforcement, and integrity checking of
|
|
6
|
+
agent definitions.
|
|
7
|
+
|
|
8
|
+
The `coreason-manifest` package serves as the definitive source of truth for
|
|
9
|
+
Asset definitions in the CoReason-AI ecosystem.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
from coreason_manifest import ManifestEngine, ManifestConfig
|
|
13
|
+
|
|
14
|
+
config = ManifestConfig(policy_path="./policies/gx_compliant.rego")
|
|
15
|
+
engine = ManifestEngine(config)
|
|
16
|
+
agent_def = engine.load_and_validate("agent.yaml", "./src")
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .engine import ManifestConfig, ManifestEngine, ManifestEngineAsync
|
|
3
20
|
from .errors import (
|
|
4
21
|
IntegrityCompromisedError,
|
|
5
22
|
ManifestError,
|
|
@@ -30,6 +47,7 @@ __all__ = [
|
|
|
30
47
|
"IntegrityCompromisedError",
|
|
31
48
|
"ManifestConfig",
|
|
32
49
|
"ManifestEngine",
|
|
50
|
+
"ManifestEngineAsync",
|
|
33
51
|
"ManifestError",
|
|
34
52
|
"ManifestLoader",
|
|
35
53
|
"ManifestSyntaxError",
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# Prosperity-3.0
|
|
2
|
+
"""Engine for the Coreason Manifest system.
|
|
3
|
+
|
|
4
|
+
This module provides the main entry point for verifying and loading Agent Manifests.
|
|
5
|
+
It coordinates schema validation, policy enforcement, and integrity checking.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, List, Optional, Union, cast
|
|
14
|
+
|
|
15
|
+
import anyio
|
|
16
|
+
import anyio.to_thread
|
|
17
|
+
|
|
18
|
+
from coreason_manifest.integrity import IntegrityChecker
|
|
19
|
+
from coreason_manifest.loader import ManifestLoader
|
|
20
|
+
from coreason_manifest.models import AgentDefinition
|
|
21
|
+
from coreason_manifest.policy import PolicyEnforcer
|
|
22
|
+
from coreason_manifest.utils.logger import logger
|
|
23
|
+
from coreason_manifest.validator import SchemaValidator
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class ManifestConfig:
|
|
28
|
+
"""Configuration for the ManifestEngine.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
policy_path: Path to the Rego policy file.
|
|
32
|
+
opa_path: Path to the OPA executable. Defaults to "opa".
|
|
33
|
+
tbom_path: Optional path to the Trusted Bill of Materials.
|
|
34
|
+
extra_data_paths: Additional data paths to load into OPA.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
policy_path: Union[str, Path]
|
|
38
|
+
opa_path: str = "opa"
|
|
39
|
+
tbom_path: Optional[Union[str, Path]] = None
|
|
40
|
+
extra_data_paths: List[Union[str, Path]] = field(default_factory=list)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ManifestEngineAsync:
|
|
44
|
+
"""The async core for verifying and loading Agent Manifests.
|
|
45
|
+
|
|
46
|
+
This class coordinates the validation process, including:
|
|
47
|
+
1. Loading raw YAML.
|
|
48
|
+
2. Validating against JSON Schema.
|
|
49
|
+
3. Converting to AgentDefinition Pydantic model (Normalization).
|
|
50
|
+
4. Enforcing Policy (Rego).
|
|
51
|
+
5. Verifying Integrity (Hash check).
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, config: ManifestConfig) -> None:
|
|
55
|
+
"""Initialize the ManifestEngineAsync.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
config: Configuration including policy path and OPA path.
|
|
59
|
+
"""
|
|
60
|
+
self.config = config
|
|
61
|
+
self.schema_validator = SchemaValidator()
|
|
62
|
+
|
|
63
|
+
# Collect data paths
|
|
64
|
+
data_paths = list(config.extra_data_paths)
|
|
65
|
+
if config.tbom_path:
|
|
66
|
+
data_paths.append(config.tbom_path)
|
|
67
|
+
|
|
68
|
+
self.policy_enforcer = PolicyEnforcer(
|
|
69
|
+
policy_path=config.policy_path,
|
|
70
|
+
opa_path=config.opa_path,
|
|
71
|
+
data_paths=data_paths,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
async def __aenter__(self) -> ManifestEngineAsync:
|
|
75
|
+
"""Async context manager entry."""
|
|
76
|
+
return self
|
|
77
|
+
|
|
78
|
+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
79
|
+
"""Async context manager exit."""
|
|
80
|
+
# Clean up resources if necessary.
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
async def validate_manifest_dict(self, raw_data: dict[str, Any]) -> AgentDefinition:
|
|
84
|
+
"""Validates an Agent Manifest dictionary in memory.
|
|
85
|
+
|
|
86
|
+
Performs:
|
|
87
|
+
1. Normalization (stripping version prefixes)
|
|
88
|
+
2. Schema Validation
|
|
89
|
+
3. Model Conversion
|
|
90
|
+
4. Policy Enforcement
|
|
91
|
+
|
|
92
|
+
Does NOT perform Integrity Check (hashing).
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
raw_data: The raw dictionary of the manifest.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
AgentDefinition: The fully validated agent definition.
|
|
99
|
+
|
|
100
|
+
Raises:
|
|
101
|
+
ManifestSyntaxError: If structure or schema is invalid.
|
|
102
|
+
PolicyViolationError: If business rules are violated.
|
|
103
|
+
"""
|
|
104
|
+
# 1. Normalization (ensure version string is clean before schema/model validation)
|
|
105
|
+
# We access the static method on ManifestLoader.
|
|
106
|
+
ManifestLoader._normalize_data(raw_data)
|
|
107
|
+
|
|
108
|
+
# 2. Schema Validation
|
|
109
|
+
logger.debug("Running Schema Validation...")
|
|
110
|
+
self.schema_validator.validate(raw_data)
|
|
111
|
+
|
|
112
|
+
# 3. Model Conversion (Normalization) (CPU bound)
|
|
113
|
+
logger.debug("Converting to AgentDefinition...")
|
|
114
|
+
agent_def = await anyio.to_thread.run_sync(ManifestLoader.load_from_dict, raw_data)
|
|
115
|
+
logger.info(f"Validating Agent {agent_def.metadata.id} v{agent_def.metadata.version}")
|
|
116
|
+
|
|
117
|
+
# 4. Policy Enforcement (Subprocess / Blocking)
|
|
118
|
+
logger.debug("Enforcing Policies...")
|
|
119
|
+
# We assume policy is checked against the Normalized data (model dumped back to dict)
|
|
120
|
+
normalized_data = agent_def.model_dump(mode="json")
|
|
121
|
+
start_time = time.perf_counter()
|
|
122
|
+
try:
|
|
123
|
+
# PolicyEnforcer.evaluate is synchronous and runs subprocess.run, so we wrap it.
|
|
124
|
+
await anyio.to_thread.run_sync(self.policy_enforcer.evaluate, normalized_data)
|
|
125
|
+
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
126
|
+
logger.info(f"Policy Check: Pass - {duration_ms:.2f}ms")
|
|
127
|
+
except Exception:
|
|
128
|
+
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
129
|
+
logger.info(f"Policy Check: Fail - {duration_ms:.2f}ms")
|
|
130
|
+
raise
|
|
131
|
+
|
|
132
|
+
return cast(AgentDefinition, agent_def)
|
|
133
|
+
|
|
134
|
+
async def load_and_validate(self, manifest_path: Union[str, Path], source_dir: Union[str, Path]) -> AgentDefinition:
|
|
135
|
+
"""Loads, validates, and verifies an Agent Manifest asynchronously.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
manifest_path: Path to the agent.yaml file.
|
|
139
|
+
source_dir: Path to the source code directory.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
AgentDefinition: The fully validated and verified agent definition.
|
|
143
|
+
|
|
144
|
+
Raises:
|
|
145
|
+
ManifestSyntaxError: If structure or schema is invalid.
|
|
146
|
+
PolicyViolationError: If business rules are violated.
|
|
147
|
+
IntegrityCompromisedError: If source code hash does not match.
|
|
148
|
+
FileNotFoundError: If files are missing.
|
|
149
|
+
"""
|
|
150
|
+
manifest_path = Path(manifest_path)
|
|
151
|
+
source_dir = Path(source_dir)
|
|
152
|
+
|
|
153
|
+
logger.info(f"Validating Agent Manifest: {manifest_path}")
|
|
154
|
+
|
|
155
|
+
# 1. Load Raw YAML (I/O)
|
|
156
|
+
raw_data = await ManifestLoader.load_raw_from_file_async(manifest_path)
|
|
157
|
+
|
|
158
|
+
# 2. Validate Manifest Dict (Schema, Model, Policy)
|
|
159
|
+
agent_def = await self.validate_manifest_dict(raw_data)
|
|
160
|
+
|
|
161
|
+
# 5. Integrity Check (Heavy I/O and CPU)
|
|
162
|
+
logger.debug("Verifying Integrity...")
|
|
163
|
+
# IntegrityChecker.verify is synchronous and does heavy IO, so we wrap it.
|
|
164
|
+
await anyio.to_thread.run_sync(IntegrityChecker.verify, agent_def, source_dir, manifest_path)
|
|
165
|
+
|
|
166
|
+
logger.info("Agent validation successful.")
|
|
167
|
+
return agent_def
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class ManifestEngine:
|
|
171
|
+
"""The Sync Facade for ManifestEngineAsync.
|
|
172
|
+
|
|
173
|
+
Allows synchronous usage of the async core via anyio.run.
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
def __init__(self, config: ManifestConfig) -> None:
|
|
177
|
+
"""Initialize the ManifestEngine facade.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
config: Configuration including policy path and OPA path.
|
|
181
|
+
"""
|
|
182
|
+
self._async = ManifestEngineAsync(config)
|
|
183
|
+
|
|
184
|
+
def __getattr__(self, name: str) -> Any:
|
|
185
|
+
"""Delegate attribute access to the async engine instance.
|
|
186
|
+
|
|
187
|
+
This ensures backward compatibility for accessing attributes like
|
|
188
|
+
'config', 'schema_validator', and 'policy_enforcer'.
|
|
189
|
+
"""
|
|
190
|
+
return getattr(self._async, name)
|
|
191
|
+
|
|
192
|
+
def __enter__(self) -> ManifestEngine:
|
|
193
|
+
"""Context manager entry."""
|
|
194
|
+
anyio.run(self._async.__aenter__)
|
|
195
|
+
return self
|
|
196
|
+
|
|
197
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
198
|
+
"""Context manager exit."""
|
|
199
|
+
anyio.run(self._async.__aexit__, exc_type, exc_val, exc_tb)
|
|
200
|
+
|
|
201
|
+
def load_and_validate(self, manifest_path: Union[str, Path], source_dir: Union[str, Path]) -> AgentDefinition:
|
|
202
|
+
"""Loads, validates, and verifies an Agent Manifest synchronously.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
manifest_path: Path to the agent.yaml file.
|
|
206
|
+
source_dir: Path to the source code directory.
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
AgentDefinition: The fully validated and verified agent definition.
|
|
210
|
+
"""
|
|
211
|
+
return cast(AgentDefinition, anyio.run(self._async.load_and_validate, manifest_path, source_dir))
|
|
212
|
+
|
|
213
|
+
def validate_manifest_dict(self, raw_data: dict[str, Any]) -> AgentDefinition:
|
|
214
|
+
"""Validates an Agent Manifest dictionary synchronously.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
raw_data: The raw dictionary of the manifest.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
AgentDefinition: The fully validated agent definition.
|
|
221
|
+
"""
|
|
222
|
+
return cast(AgentDefinition, anyio.run(self._async.validate_manifest_dict, raw_data))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Prosperity-3.0
|
|
2
|
+
"""Exceptions for the Coreason Manifest system.
|
|
3
|
+
|
|
4
|
+
This module defines the hierarchy of exceptions raised by the package.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ManifestError(Exception):
|
|
11
|
+
"""Base exception for coreason_manifest errors."""
|
|
12
|
+
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ManifestSyntaxError(ManifestError):
|
|
17
|
+
"""Raised when the manifest YAML is invalid or missing required fields.
|
|
18
|
+
|
|
19
|
+
This includes YAML parsing errors and JSON Schema validation failures.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PolicyViolationError(ManifestError):
|
|
26
|
+
"""Raised when the agent violates a compliance policy.
|
|
27
|
+
|
|
28
|
+
This error indicates that the manifest is structurally valid but fails
|
|
29
|
+
business rules or compliance checks (e.g., banned libraries).
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
violations: A list of specific policy violation messages.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, message: str, violations: list[str] | None = None) -> None:
|
|
36
|
+
"""Initialize PolicyViolationError.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
message: The error message.
|
|
40
|
+
violations: Optional list of detailed violation strings.
|
|
41
|
+
"""
|
|
42
|
+
super().__init__(message)
|
|
43
|
+
self.violations = violations or []
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class IntegrityCompromisedError(ManifestError):
|
|
47
|
+
"""Raised when the source code hash does not match the manifest.
|
|
48
|
+
|
|
49
|
+
This indicates that the source code may have been tampered with or changed
|
|
50
|
+
without updating the manifest's integrity hash.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
pass
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
+
"""Integrity checking functionality.
|
|
3
|
+
|
|
4
|
+
This module provides the `IntegrityChecker` class, which is responsible for
|
|
5
|
+
calculating deterministic hashes of source code directories and verifying
|
|
6
|
+
them against the expected hash in the agent manifest.
|
|
7
|
+
"""
|
|
8
|
+
|
|
2
9
|
from __future__ import annotations
|
|
3
10
|
|
|
4
11
|
import hashlib
|
|
@@ -11,8 +18,7 @@ from coreason_manifest.models import AgentDefinition
|
|
|
11
18
|
|
|
12
19
|
|
|
13
20
|
class IntegrityChecker:
|
|
14
|
-
"""
|
|
15
|
-
Component D: IntegrityChecker (The Notary).
|
|
21
|
+
"""Component D: IntegrityChecker (The Notary).
|
|
16
22
|
|
|
17
23
|
Responsibility:
|
|
18
24
|
- Calculate the SHA256 hash of the source code directory.
|
|
@@ -23,8 +29,7 @@ class IntegrityChecker:
|
|
|
23
29
|
|
|
24
30
|
@staticmethod
|
|
25
31
|
def calculate_hash(source_dir: Union[Path, str], exclude_files: Optional[Set[Union[Path, str]]] = None) -> str:
|
|
26
|
-
"""
|
|
27
|
-
Calculates a deterministic SHA256 hash of the source code directory.
|
|
32
|
+
"""Calculates a deterministic SHA256 hash of the source code directory.
|
|
28
33
|
|
|
29
34
|
It walks the directory using os.walk to efficiently prune ignored directories.
|
|
30
35
|
Sorts files by relative path, hashes each file, and then hashes the sequence.
|
|
@@ -34,7 +39,8 @@ class IntegrityChecker:
|
|
|
34
39
|
|
|
35
40
|
Args:
|
|
36
41
|
source_dir: The directory containing source code.
|
|
37
|
-
exclude_files: Optional set of file paths (absolute or relative to CWD)
|
|
42
|
+
exclude_files: Optional set of file paths (absolute or relative to CWD)
|
|
43
|
+
to exclude from hashing.
|
|
38
44
|
|
|
39
45
|
Returns:
|
|
40
46
|
The hex digest of the SHA256 hash.
|
|
@@ -113,8 +119,7 @@ class IntegrityChecker:
|
|
|
113
119
|
source_dir: Union[Path, str],
|
|
114
120
|
manifest_path: Optional[Union[Path, str]] = None,
|
|
115
121
|
) -> None:
|
|
116
|
-
"""
|
|
117
|
-
Verifies the integrity of the source code against the manifest.
|
|
122
|
+
"""Verifies the integrity of the source code against the manifest.
|
|
118
123
|
|
|
119
124
|
Args:
|
|
120
125
|
agent_def: The AgentDefinition containing the expected hash.
|