coreason-manifest 0.1.0__tar.gz → 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.
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/PKG-INFO +50 -27
- coreason_manifest-0.3.0/README.md +55 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/pyproject.toml +8 -2
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/__init__.py +19 -1
- coreason_manifest-0.3.0/src/coreason_manifest/engine.py +181 -0
- coreason_manifest-0.3.0/src/coreason_manifest/errors.py +53 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/integrity.py +12 -7
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/loader.py +55 -22
- coreason_manifest-0.3.0/src/coreason_manifest/main.py +17 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/models.py +73 -9
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/policy.py +15 -9
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/schemas/agent.schema.json +6 -6
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/validator.py +17 -6
- coreason_manifest-0.1.0/README.md +0 -35
- coreason_manifest-0.1.0/src/coreason_manifest/engine.py +0 -117
- coreason_manifest-0.1.0/src/coreason_manifest/errors.py +0 -28
- coreason_manifest-0.1.0/src/coreason_manifest/main.py +0 -16
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/LICENSE +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/NOTICE +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/policies/compliance.rego +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/policies/tbom.json +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/schemas/__init__.py +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/utils/__init__.py +0 -0
- {coreason_manifest-0.1.0 → coreason_manifest-0.3.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.3.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,6 +67,9 @@ 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: httpx (>=0.27.0,<0.28.0)
|
|
70
73
|
Requires-Dist: jsonschema (>=4.25.1,<5.0.0)
|
|
71
74
|
Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
72
75
|
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
@@ -76,39 +79,59 @@ Project-URL: Homepage, https://github.com/CoReason-AI/coreason_manifest
|
|
|
76
79
|
Project-URL: Repository, https://github.com/CoReason-AI/coreason_manifest
|
|
77
80
|
Description-Content-Type: text/markdown
|
|
78
81
|
|
|
79
|
-
#
|
|
82
|
+
# Coreason Manifest
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
The definitive source of truth for CoReason-AI Asset definitions. "The Blueprint."
|
|
82
85
|
|
|
83
|
-
[](https://github.com/CoReason-AI/coreason-manifest)
|
|
87
|
+
[](https://github.com/CoReason-AI/coreason-manifest/actions)
|
|
88
|
+
[](https://github.com/astral-sh/ruff)
|
|
89
|
+
[](docs/product_requirements.md)
|
|
84
90
|
|
|
85
|
-
##
|
|
91
|
+
## Overview
|
|
86
92
|
|
|
87
|
-
|
|
93
|
+
`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
94
|
|
|
89
|
-
|
|
90
|
-
- Poetry
|
|
95
|
+
## Features
|
|
91
96
|
|
|
92
|
-
|
|
97
|
+
* **Open Agent Specification (OAS) Validation:** Parses and validates agent definitions against a strict schema.
|
|
98
|
+
* **Compliance Enforcement:** Uses Open Policy Agent (OPA) / Rego to enforce complex business rules and allowlists.
|
|
99
|
+
* **Integrity Verification:** Calculates and verifies SHA256 hashes of the agent's source code to prevent tampering.
|
|
100
|
+
* **Dependency Pinning:** Enforces strict version pinning for all library dependencies.
|
|
101
|
+
* **Trusted Bill of Materials (TBOM):** Validates libraries against an approved list.
|
|
93
102
|
|
|
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
|
-
```
|
|
103
|
+
## Installation
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
```bash
|
|
106
|
+
pip install coreason-manifest
|
|
107
|
+
```
|
|
105
108
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
Here is how to initialize the engine and validate an agent manifest:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from coreason_manifest import ManifestEngine, ManifestConfig, PolicyViolationError, IntegrityCompromisedError
|
|
115
|
+
|
|
116
|
+
# 1. Initialize configuration with policy path
|
|
117
|
+
config = ManifestConfig(policy_path="./policies/gx_compliant.rego")
|
|
118
|
+
engine = ManifestEngine(config)
|
|
119
|
+
|
|
120
|
+
# 2. Load & Validate Agent Manifest
|
|
121
|
+
try:
|
|
122
|
+
# This runs Schema Validation, Policy Enforcement, and Integrity Checks
|
|
123
|
+
agent_def = engine.load_and_validate(
|
|
124
|
+
manifest_path="./agents/payer_war_game/agent.yaml",
|
|
125
|
+
source_dir="./agents/payer_war_game/src"
|
|
126
|
+
)
|
|
127
|
+
print(f"Agent {agent_def.metadata.name} is compliant and ready to run.")
|
|
128
|
+
|
|
129
|
+
except PolicyViolationError as e:
|
|
130
|
+
print(f"Compliance Failure: {e.violations}")
|
|
131
|
+
|
|
132
|
+
except IntegrityCompromisedError:
|
|
133
|
+
print("CRITICAL: Code has been tampered with after signing.")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
For detailed requirements and architecture, please refer to the [Product Requirements](docs/product_requirements.md).
|
|
114
137
|
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install coreason-manifest
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Here is how to initialize the engine and validate an agent manifest:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from coreason_manifest import ManifestEngine, ManifestConfig, PolicyViolationError, IntegrityCompromisedError
|
|
34
|
+
|
|
35
|
+
# 1. Initialize configuration with policy path
|
|
36
|
+
config = ManifestConfig(policy_path="./policies/gx_compliant.rego")
|
|
37
|
+
engine = ManifestEngine(config)
|
|
38
|
+
|
|
39
|
+
# 2. Load & Validate Agent Manifest
|
|
40
|
+
try:
|
|
41
|
+
# This runs Schema Validation, Policy Enforcement, and Integrity Checks
|
|
42
|
+
agent_def = engine.load_and_validate(
|
|
43
|
+
manifest_path="./agents/payer_war_game/agent.yaml",
|
|
44
|
+
source_dir="./agents/payer_war_game/src"
|
|
45
|
+
)
|
|
46
|
+
print(f"Agent {agent_def.metadata.name} is compliant and ready to run.")
|
|
47
|
+
|
|
48
|
+
except PolicyViolationError as e:
|
|
49
|
+
print(f"Compliance Failure: {e.violations}")
|
|
50
|
+
|
|
51
|
+
except IntegrityCompromisedError:
|
|
52
|
+
print("CRITICAL: Code has been tampered with after signing.")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For detailed requirements and architecture, please refer to the [Product Requirements](docs/product_requirements.md).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "coreason_manifest"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.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,9 @@ 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"
|
|
16
19
|
|
|
17
20
|
[tool.poetry.group.dev.dependencies]
|
|
18
21
|
pytest = "^8.2.2"
|
|
@@ -23,6 +26,8 @@ mkdocs = "^1.6.0"
|
|
|
23
26
|
mkdocs-material = "^9.5.26"
|
|
24
27
|
pydantic = "^2.12.5"
|
|
25
28
|
mypy = "^1.19.1"
|
|
29
|
+
types-aiofiles = "^23.2.0"
|
|
30
|
+
pytest-asyncio = "^0.23.0"
|
|
26
31
|
|
|
27
32
|
[build-system]
|
|
28
33
|
requires = ["poetry-core"]
|
|
@@ -30,7 +35,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
30
35
|
|
|
31
36
|
[project]
|
|
32
37
|
name = "coreason_manifest"
|
|
33
|
-
version = "0.
|
|
38
|
+
version = "0.3.0"
|
|
34
39
|
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
40
|
readme = "README.md"
|
|
36
41
|
requires-python = ">=3.11"
|
|
@@ -66,6 +71,7 @@ plugins = ["pydantic.mypy"]
|
|
|
66
71
|
[tool.pytest.ini_options]
|
|
67
72
|
addopts = "--cov=src --cov-report=term-missing --cov-fail-under=100"
|
|
68
73
|
testpaths = ["tests"]
|
|
74
|
+
asyncio_mode = "auto"
|
|
69
75
|
|
|
70
76
|
[tool.coverage.run]
|
|
71
77
|
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,181 @@
|
|
|
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 load_and_validate(self, manifest_path: Union[str, Path], source_dir: Union[str, Path]) -> AgentDefinition:
|
|
84
|
+
"""Loads, validates, and verifies an Agent Manifest asynchronously.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
manifest_path: Path to the agent.yaml file.
|
|
88
|
+
source_dir: Path to the source code directory.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
AgentDefinition: The fully validated and verified agent definition.
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
ManifestSyntaxError: If structure or schema is invalid.
|
|
95
|
+
PolicyViolationError: If business rules are violated.
|
|
96
|
+
IntegrityCompromisedError: If source code hash does not match.
|
|
97
|
+
FileNotFoundError: If files are missing.
|
|
98
|
+
"""
|
|
99
|
+
manifest_path = Path(manifest_path)
|
|
100
|
+
source_dir = Path(source_dir)
|
|
101
|
+
|
|
102
|
+
logger.info(f"Validating Agent Manifest: {manifest_path}")
|
|
103
|
+
|
|
104
|
+
# 1. Load Raw YAML (I/O)
|
|
105
|
+
raw_data = await ManifestLoader.load_raw_from_file_async(manifest_path)
|
|
106
|
+
|
|
107
|
+
# 2. Schema Validation
|
|
108
|
+
logger.debug("Running Schema Validation...")
|
|
109
|
+
self.schema_validator.validate(raw_data)
|
|
110
|
+
|
|
111
|
+
# 3. Model Conversion (Normalization) (CPU bound)
|
|
112
|
+
logger.debug("Converting to AgentDefinition...")
|
|
113
|
+
agent_def = await anyio.to_thread.run_sync(ManifestLoader.load_from_dict, raw_data)
|
|
114
|
+
logger.info(f"Validating Agent {agent_def.metadata.id} v{agent_def.metadata.version}")
|
|
115
|
+
|
|
116
|
+
# 4. Policy Enforcement (Subprocess / Blocking)
|
|
117
|
+
logger.debug("Enforcing Policies...")
|
|
118
|
+
# We assume policy is checked against the Normalized data (model dumped back to dict)
|
|
119
|
+
normalized_data = agent_def.model_dump(mode="json")
|
|
120
|
+
start_time = time.perf_counter()
|
|
121
|
+
try:
|
|
122
|
+
# PolicyEnforcer.evaluate is synchronous and runs subprocess.run, so we wrap it.
|
|
123
|
+
await anyio.to_thread.run_sync(self.policy_enforcer.evaluate, normalized_data)
|
|
124
|
+
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
125
|
+
logger.info(f"Policy Check: Pass - {duration_ms:.2f}ms")
|
|
126
|
+
except Exception:
|
|
127
|
+
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
128
|
+
logger.info(f"Policy Check: Fail - {duration_ms:.2f}ms")
|
|
129
|
+
raise
|
|
130
|
+
|
|
131
|
+
# 5. Integrity Check (Heavy I/O and CPU)
|
|
132
|
+
logger.debug("Verifying Integrity...")
|
|
133
|
+
# IntegrityChecker.verify is synchronous and does heavy IO, so we wrap it.
|
|
134
|
+
await anyio.to_thread.run_sync(IntegrityChecker.verify, agent_def, source_dir, manifest_path)
|
|
135
|
+
|
|
136
|
+
logger.info("Agent validation successful.")
|
|
137
|
+
return cast(AgentDefinition, agent_def)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class ManifestEngine:
|
|
141
|
+
"""The Sync Facade for ManifestEngineAsync.
|
|
142
|
+
|
|
143
|
+
Allows synchronous usage of the async core via anyio.run.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
def __init__(self, config: ManifestConfig) -> None:
|
|
147
|
+
"""Initialize the ManifestEngine facade.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
config: Configuration including policy path and OPA path.
|
|
151
|
+
"""
|
|
152
|
+
self._async = ManifestEngineAsync(config)
|
|
153
|
+
|
|
154
|
+
def __getattr__(self, name: str) -> Any:
|
|
155
|
+
"""Delegate attribute access to the async engine instance.
|
|
156
|
+
|
|
157
|
+
This ensures backward compatibility for accessing attributes like
|
|
158
|
+
'config', 'schema_validator', and 'policy_enforcer'.
|
|
159
|
+
"""
|
|
160
|
+
return getattr(self._async, name)
|
|
161
|
+
|
|
162
|
+
def __enter__(self) -> ManifestEngine:
|
|
163
|
+
"""Context manager entry."""
|
|
164
|
+
anyio.run(self._async.__aenter__)
|
|
165
|
+
return self
|
|
166
|
+
|
|
167
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
168
|
+
"""Context manager exit."""
|
|
169
|
+
anyio.run(self._async.__aexit__, exc_type, exc_val, exc_tb)
|
|
170
|
+
|
|
171
|
+
def load_and_validate(self, manifest_path: Union[str, Path], source_dir: Union[str, Path]) -> AgentDefinition:
|
|
172
|
+
"""Loads, validates, and verifies an Agent Manifest synchronously.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
manifest_path: Path to the agent.yaml file.
|
|
176
|
+
source_dir: Path to the source code directory.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
AgentDefinition: The fully validated and verified agent definition.
|
|
180
|
+
"""
|
|
181
|
+
return cast(AgentDefinition, anyio.run(self._async.load_and_validate, manifest_path, source_dir))
|
|
@@ -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.
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
+
"""Manifest Loader.
|
|
3
|
+
|
|
4
|
+
This module is responsible for loading the agent manifest from YAML files or
|
|
5
|
+
dictionaries, normalizing the data, and converting it into Pydantic models.
|
|
6
|
+
"""
|
|
7
|
+
|
|
2
8
|
from __future__ import annotations
|
|
3
9
|
|
|
4
10
|
from pathlib import Path
|
|
5
11
|
from typing import Any, Union
|
|
6
12
|
|
|
13
|
+
import aiofiles
|
|
7
14
|
import yaml
|
|
8
15
|
from pydantic import ValidationError
|
|
9
16
|
|
|
@@ -12,8 +19,7 @@ from coreason_manifest.models import AgentDefinition
|
|
|
12
19
|
|
|
13
20
|
|
|
14
21
|
class ManifestLoader:
|
|
15
|
-
"""
|
|
16
|
-
Component A: ManifestLoader (The Parser).
|
|
22
|
+
"""Component A: ManifestLoader (The Parser).
|
|
17
23
|
|
|
18
24
|
Responsibility:
|
|
19
25
|
- Load YAML safely.
|
|
@@ -23,8 +29,7 @@ class ManifestLoader:
|
|
|
23
29
|
|
|
24
30
|
@staticmethod
|
|
25
31
|
def load_raw_from_file(path: Union[str, Path]) -> dict[str, Any]:
|
|
26
|
-
"""
|
|
27
|
-
Loads the raw dict from a YAML file.
|
|
32
|
+
"""Loads the raw dict from a YAML file.
|
|
28
33
|
|
|
29
34
|
Args:
|
|
30
35
|
path: The path to the agent.yaml file.
|
|
@@ -48,15 +53,42 @@ class ManifestLoader:
|
|
|
48
53
|
if not isinstance(data, dict):
|
|
49
54
|
raise ManifestSyntaxError(f"Invalid YAML content in {path}: must be a dictionary.")
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
ManifestLoader._normalize_data(data)
|
|
57
|
+
|
|
58
|
+
return data
|
|
59
|
+
|
|
60
|
+
except yaml.YAMLError as e:
|
|
61
|
+
raise ManifestSyntaxError(f"Failed to parse YAML file {path}: {str(e)}") from e
|
|
62
|
+
except OSError as e:
|
|
63
|
+
if isinstance(e, FileNotFoundError):
|
|
64
|
+
raise
|
|
65
|
+
raise ManifestSyntaxError(f"Error reading file {path}: {str(e)}") from e
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
async def load_raw_from_file_async(path: Union[str, Path]) -> dict[str, Any]:
|
|
69
|
+
"""Loads the raw dict from a YAML file asynchronously.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
path: The path to the agent.yaml file.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
dict: The raw dictionary content.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
ManifestSyntaxError: If YAML is invalid.
|
|
79
|
+
FileNotFoundError: If the file does not exist.
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
path_obj = Path(path)
|
|
83
|
+
if not path_obj.exists():
|
|
84
|
+
raise FileNotFoundError(f"Manifest file not found: {path}")
|
|
85
|
+
|
|
86
|
+
async with aiofiles.open(path_obj, "r", encoding="utf-8") as f:
|
|
87
|
+
content = await f.read()
|
|
88
|
+
data = yaml.safe_load(content)
|
|
89
|
+
|
|
90
|
+
if not isinstance(data, dict):
|
|
91
|
+
raise ManifestSyntaxError(f"Invalid YAML content in {path}: must be a dictionary.")
|
|
60
92
|
|
|
61
93
|
ManifestLoader._normalize_data(data)
|
|
62
94
|
|
|
@@ -71,8 +103,7 @@ class ManifestLoader:
|
|
|
71
103
|
|
|
72
104
|
@staticmethod
|
|
73
105
|
def load_from_file(path: Union[str, Path]) -> AgentDefinition:
|
|
74
|
-
"""
|
|
75
|
-
Loads the agent manifest from a YAML file.
|
|
106
|
+
"""Loads the agent manifest from a YAML file.
|
|
76
107
|
|
|
77
108
|
Args:
|
|
78
109
|
path: The path to the agent.yaml file.
|
|
@@ -89,8 +120,7 @@ class ManifestLoader:
|
|
|
89
120
|
|
|
90
121
|
@staticmethod
|
|
91
122
|
def load_from_dict(data: dict[str, Any]) -> AgentDefinition:
|
|
92
|
-
"""
|
|
93
|
-
Converts a dictionary into an AgentDefinition model.
|
|
123
|
+
"""Converts a dictionary into an AgentDefinition model.
|
|
94
124
|
|
|
95
125
|
Args:
|
|
96
126
|
data: The raw dictionary.
|
|
@@ -115,11 +145,14 @@ class ManifestLoader:
|
|
|
115
145
|
|
|
116
146
|
@staticmethod
|
|
117
147
|
def _normalize_data(data: dict[str, Any]) -> None:
|
|
118
|
-
"""
|
|
119
|
-
|
|
120
|
-
Specifically strips 'v' or 'V' from version strings.
|
|
148
|
+
"""Normalizes the data dictionary in place.
|
|
149
|
+
|
|
150
|
+
Specifically strips 'v' or 'V' from version strings recursively until clean.
|
|
121
151
|
"""
|
|
122
152
|
if "metadata" in data and isinstance(data["metadata"], dict):
|
|
123
153
|
version = data["metadata"].get("version")
|
|
124
|
-
if isinstance(version, str)
|
|
125
|
-
|
|
154
|
+
if isinstance(version, str):
|
|
155
|
+
# Recursively strip leading 'v' or 'V'
|
|
156
|
+
while version and version[0] in ("v", "V"):
|
|
157
|
+
version = version[1:]
|
|
158
|
+
data["metadata"]["version"] = version
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Prosperity-3.0
|
|
2
|
+
"""Main module for coreason_manifest.
|
|
3
|
+
|
|
4
|
+
This module is primarily used for testing and demonstration purposes.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from coreason_manifest.utils.logger import logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def hello_world() -> str:
|
|
11
|
+
"""Returns a hello world string.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
"Hello World!" string.
|
|
15
|
+
"""
|
|
16
|
+
logger.info("Hello World!")
|
|
17
|
+
return "Hello World!"
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
+
"""Pydantic models for the Coreason Manifest system.
|
|
3
|
+
|
|
4
|
+
These models define the structure and validation rules for the Agent Manifest
|
|
5
|
+
(OAS). They represent the source of truth for Agent definitions.
|
|
6
|
+
"""
|
|
7
|
+
|
|
2
8
|
from __future__ import annotations
|
|
3
9
|
|
|
4
10
|
from datetime import datetime
|
|
@@ -27,7 +33,14 @@ SEMVER_REGEX = (
|
|
|
27
33
|
|
|
28
34
|
|
|
29
35
|
def normalize_version(v: str) -> str:
|
|
30
|
-
"""Normalize version string by recursively stripping 'v' or 'V' prefix.
|
|
36
|
+
"""Normalize version string by recursively stripping 'v' or 'V' prefix.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
v: The version string to normalize.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The normalized version string without 'v' prefix.
|
|
43
|
+
"""
|
|
31
44
|
while v.lower().startswith("v"):
|
|
32
45
|
v = v[1:]
|
|
33
46
|
return v
|
|
@@ -56,7 +69,15 @@ StrictUri = Annotated[
|
|
|
56
69
|
|
|
57
70
|
|
|
58
71
|
class AgentMetadata(BaseModel):
|
|
59
|
-
"""Metadata for the Agent.
|
|
72
|
+
"""Metadata for the Agent.
|
|
73
|
+
|
|
74
|
+
Attributes:
|
|
75
|
+
id: Unique Identifier for the Agent (UUID).
|
|
76
|
+
version: Semantic Version of the Agent.
|
|
77
|
+
name: Name of the Agent.
|
|
78
|
+
author: Author of the Agent.
|
|
79
|
+
created_at: Creation timestamp (ISO 8601).
|
|
80
|
+
"""
|
|
60
81
|
|
|
61
82
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
62
83
|
|
|
@@ -68,7 +89,12 @@ class AgentMetadata(BaseModel):
|
|
|
68
89
|
|
|
69
90
|
|
|
70
91
|
class AgentInterface(BaseModel):
|
|
71
|
-
"""Interface definition for the Agent.
|
|
92
|
+
"""Interface definition for the Agent.
|
|
93
|
+
|
|
94
|
+
Attributes:
|
|
95
|
+
inputs: Typed arguments the agent accepts (JSON Schema).
|
|
96
|
+
outputs: Typed structure of the result.
|
|
97
|
+
"""
|
|
72
98
|
|
|
73
99
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
74
100
|
|
|
@@ -77,7 +103,12 @@ class AgentInterface(BaseModel):
|
|
|
77
103
|
|
|
78
104
|
|
|
79
105
|
class Step(BaseModel):
|
|
80
|
-
"""A single step in the execution graph.
|
|
106
|
+
"""A single step in the execution graph.
|
|
107
|
+
|
|
108
|
+
Attributes:
|
|
109
|
+
id: Unique identifier for the step.
|
|
110
|
+
description: Description of the step.
|
|
111
|
+
"""
|
|
81
112
|
|
|
82
113
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
83
114
|
|
|
@@ -86,7 +117,12 @@ class Step(BaseModel):
|
|
|
86
117
|
|
|
87
118
|
|
|
88
119
|
class ModelConfig(BaseModel):
|
|
89
|
-
"""LLM Configuration parameters.
|
|
120
|
+
"""LLM Configuration parameters.
|
|
121
|
+
|
|
122
|
+
Attributes:
|
|
123
|
+
model: The LLM model identifier.
|
|
124
|
+
temperature: Temperature for generation.
|
|
125
|
+
"""
|
|
90
126
|
|
|
91
127
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
92
128
|
|
|
@@ -95,7 +131,12 @@ class ModelConfig(BaseModel):
|
|
|
95
131
|
|
|
96
132
|
|
|
97
133
|
class AgentTopology(BaseModel):
|
|
98
|
-
"""Topology of the Agent execution.
|
|
134
|
+
"""Topology of the Agent execution.
|
|
135
|
+
|
|
136
|
+
Attributes:
|
|
137
|
+
steps: A directed acyclic graph (DAG) of execution steps.
|
|
138
|
+
llm_config: Specific LLM parameters.
|
|
139
|
+
"""
|
|
99
140
|
|
|
100
141
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
101
142
|
|
|
@@ -105,7 +146,17 @@ class AgentTopology(BaseModel):
|
|
|
105
146
|
@field_validator("steps")
|
|
106
147
|
@classmethod
|
|
107
148
|
def validate_unique_step_ids(cls, v: Tuple[Step, ...]) -> Tuple[Step, ...]:
|
|
108
|
-
"""Ensure all step IDs are unique.
|
|
149
|
+
"""Ensure all step IDs are unique.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
v: The tuple of steps to validate.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
The validated tuple of steps.
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
ValueError: If duplicate step IDs are found.
|
|
159
|
+
"""
|
|
109
160
|
ids = [step.id for step in v]
|
|
110
161
|
if len(ids) != len(set(ids)):
|
|
111
162
|
# Find duplicates
|
|
@@ -120,7 +171,12 @@ class AgentTopology(BaseModel):
|
|
|
120
171
|
|
|
121
172
|
|
|
122
173
|
class AgentDependencies(BaseModel):
|
|
123
|
-
"""External dependencies for the Agent.
|
|
174
|
+
"""External dependencies for the Agent.
|
|
175
|
+
|
|
176
|
+
Attributes:
|
|
177
|
+
tools: List of MCP capability URIs required.
|
|
178
|
+
libraries: List of Python packages required (if code execution is allowed).
|
|
179
|
+
"""
|
|
124
180
|
|
|
125
181
|
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
126
182
|
|
|
@@ -133,7 +189,15 @@ class AgentDependencies(BaseModel):
|
|
|
133
189
|
|
|
134
190
|
|
|
135
191
|
class AgentDefinition(BaseModel):
|
|
136
|
-
"""The Root Object for the CoReason Agent Manifest.
|
|
192
|
+
"""The Root Object for the CoReason Agent Manifest.
|
|
193
|
+
|
|
194
|
+
Attributes:
|
|
195
|
+
metadata: Metadata for the Agent.
|
|
196
|
+
interface: Interface definition for the Agent.
|
|
197
|
+
topology: Topology of the Agent execution.
|
|
198
|
+
dependencies: External dependencies for the Agent.
|
|
199
|
+
integrity_hash: SHA256 hash of the source code.
|
|
200
|
+
"""
|
|
137
201
|
|
|
138
202
|
model_config = ConfigDict(
|
|
139
203
|
extra="forbid",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
+
"""Policy enforcement functionality using Open Policy Agent (OPA).
|
|
3
|
+
|
|
4
|
+
This module provides the `PolicyEnforcer` class, which interacts with OPA to
|
|
5
|
+
evaluate agent definitions against compliance policies defined in Rego.
|
|
6
|
+
"""
|
|
7
|
+
|
|
2
8
|
from __future__ import annotations
|
|
3
9
|
|
|
4
10
|
import json
|
|
@@ -11,8 +17,7 @@ from coreason_manifest.errors import PolicyViolationError
|
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
class PolicyEnforcer:
|
|
14
|
-
"""
|
|
15
|
-
Component C: PolicyEnforcer (The Compliance Officer).
|
|
20
|
+
"""Component C: PolicyEnforcer (The Compliance Officer).
|
|
16
21
|
|
|
17
22
|
Responsibility:
|
|
18
23
|
- Evaluate the agent against the compliance.rego policy file using OPA.
|
|
@@ -24,13 +29,15 @@ class PolicyEnforcer:
|
|
|
24
29
|
opa_path: str = "opa",
|
|
25
30
|
data_paths: Optional[List[str | Path]] = None,
|
|
26
31
|
) -> None:
|
|
27
|
-
"""
|
|
28
|
-
Initialize the PolicyEnforcer.
|
|
32
|
+
"""Initialize the PolicyEnforcer.
|
|
29
33
|
|
|
30
34
|
Args:
|
|
31
35
|
policy_path: Path to the Rego policy file.
|
|
32
36
|
opa_path: Path to the OPA executable. Defaults to "opa" (expected in PATH).
|
|
33
37
|
data_paths: List of paths to data files (e.g. JSON/YAML) to be loaded by OPA.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
FileNotFoundError: If OPA, policy file, or data files are not found.
|
|
34
41
|
"""
|
|
35
42
|
self.policy_path = Path(policy_path)
|
|
36
43
|
self.data_paths = [Path(p) for p in data_paths] if data_paths else []
|
|
@@ -38,15 +45,15 @@ class PolicyEnforcer:
|
|
|
38
45
|
# Validate OPA executable
|
|
39
46
|
# If opa_path is a simple name (like "opa"), use shutil.which to find it
|
|
40
47
|
if "/" not in str(opa_path) and "\\" not in str(opa_path):
|
|
41
|
-
resolved_opa = shutil.which(opa_path)
|
|
48
|
+
resolved_opa: Optional[str] = shutil.which(opa_path)
|
|
42
49
|
if not resolved_opa:
|
|
43
50
|
raise FileNotFoundError(f"OPA executable not found in PATH: {opa_path}")
|
|
44
|
-
self.opa_path = resolved_opa
|
|
51
|
+
self.opa_path: str = resolved_opa
|
|
45
52
|
else:
|
|
46
53
|
# If it's a path, check existence
|
|
47
54
|
if not Path(opa_path).exists():
|
|
48
55
|
raise FileNotFoundError(f"OPA executable not found at: {opa_path}")
|
|
49
|
-
self.opa_path = opa_path
|
|
56
|
+
self.opa_path = str(opa_path)
|
|
50
57
|
|
|
51
58
|
if not self.policy_path.exists():
|
|
52
59
|
raise FileNotFoundError(f"Policy file not found: {self.policy_path}")
|
|
@@ -56,8 +63,7 @@ class PolicyEnforcer:
|
|
|
56
63
|
raise FileNotFoundError(f"Data file not found: {path}")
|
|
57
64
|
|
|
58
65
|
def evaluate(self, agent_data: dict[str, Any]) -> None:
|
|
59
|
-
"""
|
|
60
|
-
Evaluates the agent data against the policy.
|
|
66
|
+
"""Evaluates the agent data against the policy.
|
|
61
67
|
|
|
62
68
|
Args:
|
|
63
69
|
agent_data: The dictionary representation of the AgentDefinition.
|
{coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/schemas/agent.schema.json
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$defs": {
|
|
3
3
|
"AgentDependencies": {
|
|
4
4
|
"additionalProperties": false,
|
|
5
|
-
"description": "External dependencies for the Agent.",
|
|
5
|
+
"description": "External dependencies for the Agent.\n\nAttributes:\n tools: List of MCP capability URIs required.\n libraries: List of Python packages required (if code execution is allowed).",
|
|
6
6
|
"properties": {
|
|
7
7
|
"tools": {
|
|
8
8
|
"description": "List of MCP capability URIs required.",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"AgentInterface": {
|
|
30
30
|
"additionalProperties": false,
|
|
31
|
-
"description": "Interface definition for the Agent.",
|
|
31
|
+
"description": "Interface definition for the Agent.\n\nAttributes:\n inputs: Typed arguments the agent accepts (JSON Schema).\n outputs: Typed structure of the result.",
|
|
32
32
|
"properties": {
|
|
33
33
|
"inputs": {
|
|
34
34
|
"additionalProperties": true,
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"AgentMetadata": {
|
|
54
54
|
"additionalProperties": false,
|
|
55
|
-
"description": "Metadata for the Agent.",
|
|
55
|
+
"description": "Metadata for the Agent.\n\nAttributes:\n id: Unique Identifier for the Agent (UUID).\n version: Semantic Version of the Agent.\n name: Name of the Agent.\n author: Author of the Agent.\n created_at: Creation timestamp (ISO 8601).",
|
|
56
56
|
"properties": {
|
|
57
57
|
"id": {
|
|
58
58
|
"description": "Unique Identifier for the Agent (UUID).",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"AgentTopology": {
|
|
99
99
|
"additionalProperties": false,
|
|
100
|
-
"description": "Topology of the Agent execution.",
|
|
100
|
+
"description": "Topology of the Agent execution.\n\nAttributes:\n steps: A directed acyclic graph (DAG) of execution steps.\n llm_config: Specific LLM parameters.",
|
|
101
101
|
"properties": {
|
|
102
102
|
"steps": {
|
|
103
103
|
"description": "A directed acyclic graph (DAG) of execution steps.",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
},
|
|
122
122
|
"ModelConfig": {
|
|
123
123
|
"additionalProperties": false,
|
|
124
|
-
"description": "LLM Configuration parameters.",
|
|
124
|
+
"description": "LLM Configuration parameters.\n\nAttributes:\n model: The LLM model identifier.\n temperature: Temperature for generation.",
|
|
125
125
|
"properties": {
|
|
126
126
|
"model": {
|
|
127
127
|
"description": "The LLM model identifier.",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
},
|
|
146
146
|
"Step": {
|
|
147
147
|
"additionalProperties": false,
|
|
148
|
-
"description": "A single step in the execution graph.",
|
|
148
|
+
"description": "A single step in the execution graph.\n\nAttributes:\n id: Unique identifier for the step.\n description: Description of the step.",
|
|
149
149
|
"properties": {
|
|
150
150
|
"id": {
|
|
151
151
|
"description": "Unique identifier for the step.",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
# Prosperity-3.0
|
|
2
|
+
"""Schema validation functionality.
|
|
3
|
+
|
|
4
|
+
This module provides the `SchemaValidator` class, which uses JSON Schema to
|
|
5
|
+
validate the structure and types of agent definitions.
|
|
6
|
+
"""
|
|
7
|
+
|
|
2
8
|
from __future__ import annotations
|
|
3
9
|
|
|
4
10
|
import json
|
|
@@ -11,8 +17,7 @@ from coreason_manifest.errors import ManifestSyntaxError
|
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
class SchemaValidator:
|
|
14
|
-
"""
|
|
15
|
-
Component B: SchemaValidator (The Structural Engineer).
|
|
20
|
+
"""Component B: SchemaValidator (The Structural Engineer).
|
|
16
21
|
|
|
17
22
|
Responsibility:
|
|
18
23
|
- Validate the dictionary against the Master JSON Schema.
|
|
@@ -24,7 +29,14 @@ class SchemaValidator:
|
|
|
24
29
|
self.schema = self._load_schema()
|
|
25
30
|
|
|
26
31
|
def _load_schema(self) -> dict[str, Any]:
|
|
27
|
-
"""Loads the JSON schema from the package resources.
|
|
32
|
+
"""Loads the JSON schema from the package resources.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
The JSON schema dictionary.
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
ManifestSyntaxError: If the schema file cannot be loaded or is invalid.
|
|
39
|
+
"""
|
|
28
40
|
try:
|
|
29
41
|
schema_path = files("coreason_manifest.schemas").joinpath("agent.schema.json")
|
|
30
42
|
with schema_path.open("r", encoding="utf-8") as f:
|
|
@@ -36,14 +48,13 @@ class SchemaValidator:
|
|
|
36
48
|
raise ManifestSyntaxError(f"Failed to load agent schema: {e}") from e
|
|
37
49
|
|
|
38
50
|
def validate(self, data: dict[str, Any]) -> bool:
|
|
39
|
-
"""
|
|
40
|
-
Validates the given dictionary against the agent schema.
|
|
51
|
+
"""Validates the given dictionary against the agent schema.
|
|
41
52
|
|
|
42
53
|
Args:
|
|
43
54
|
data: The raw dictionary to validate.
|
|
44
55
|
|
|
45
56
|
Returns:
|
|
46
|
-
|
|
57
|
+
True if validation passes.
|
|
47
58
|
|
|
48
59
|
Raises:
|
|
49
60
|
ManifestSyntaxError: If validation fails.
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# coreason-manifest
|
|
2
|
-
|
|
3
|
-
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.
|
|
4
|
-
|
|
5
|
-
[](https://github.com/CoReason-AI/coreason_manifest/actions/workflows/ci.yml)
|
|
6
|
-
|
|
7
|
-
## Getting Started
|
|
8
|
-
|
|
9
|
-
### Prerequisites
|
|
10
|
-
|
|
11
|
-
- Python 3.12+
|
|
12
|
-
- Poetry
|
|
13
|
-
|
|
14
|
-
### Installation
|
|
15
|
-
|
|
16
|
-
1. Clone the repository:
|
|
17
|
-
```sh
|
|
18
|
-
git clone https://github.com/example/example.git
|
|
19
|
-
cd my_python_project
|
|
20
|
-
```
|
|
21
|
-
2. Install dependencies:
|
|
22
|
-
```sh
|
|
23
|
-
poetry install
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Usage
|
|
27
|
-
|
|
28
|
-
- Run the linter:
|
|
29
|
-
```sh
|
|
30
|
-
poetry run pre-commit run --all-files
|
|
31
|
-
```
|
|
32
|
-
- Run the tests:
|
|
33
|
-
```sh
|
|
34
|
-
poetry run pytest
|
|
35
|
-
```
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# Prosperity-3.0
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import time
|
|
5
|
-
from dataclasses import dataclass, field
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from typing import List, Optional, Union
|
|
8
|
-
|
|
9
|
-
from coreason_manifest.integrity import IntegrityChecker
|
|
10
|
-
from coreason_manifest.loader import ManifestLoader
|
|
11
|
-
from coreason_manifest.models import AgentDefinition
|
|
12
|
-
from coreason_manifest.policy import PolicyEnforcer
|
|
13
|
-
|
|
14
|
-
# Import logger from utils to ensure configuration is applied
|
|
15
|
-
from coreason_manifest.utils.logger import logger
|
|
16
|
-
from coreason_manifest.validator import SchemaValidator
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class ManifestConfig:
|
|
21
|
-
"""Configuration for the ManifestEngine."""
|
|
22
|
-
|
|
23
|
-
policy_path: Union[str, Path]
|
|
24
|
-
opa_path: str = "opa"
|
|
25
|
-
tbom_path: Optional[Union[str, Path]] = None
|
|
26
|
-
extra_data_paths: List[Union[str, Path]] = field(default_factory=list)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class ManifestEngine:
|
|
30
|
-
"""
|
|
31
|
-
The main entry point for verifying and loading Agent Manifests.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def __init__(self, config: ManifestConfig) -> None:
|
|
35
|
-
"""
|
|
36
|
-
Initialize the ManifestEngine.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
config: Configuration including policy path and OPA path.
|
|
40
|
-
"""
|
|
41
|
-
self.config = config
|
|
42
|
-
self.schema_validator = SchemaValidator()
|
|
43
|
-
|
|
44
|
-
# Collect data paths
|
|
45
|
-
data_paths = list(config.extra_data_paths)
|
|
46
|
-
if config.tbom_path:
|
|
47
|
-
data_paths.append(config.tbom_path)
|
|
48
|
-
|
|
49
|
-
self.policy_enforcer = PolicyEnforcer(
|
|
50
|
-
policy_path=config.policy_path,
|
|
51
|
-
opa_path=config.opa_path,
|
|
52
|
-
data_paths=data_paths,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
def load_and_validate(self, manifest_path: Union[str, Path], source_dir: Union[str, Path]) -> AgentDefinition:
|
|
56
|
-
"""
|
|
57
|
-
Loads, validates, and verifies an Agent Manifest.
|
|
58
|
-
|
|
59
|
-
Steps:
|
|
60
|
-
1. Load raw YAML.
|
|
61
|
-
2. Validate against JSON Schema.
|
|
62
|
-
3. Convert to AgentDefinition Pydantic model (Normalization).
|
|
63
|
-
4. Enforce Policy (Rego).
|
|
64
|
-
5. Verify Integrity (Hash check).
|
|
65
|
-
|
|
66
|
-
Args:
|
|
67
|
-
manifest_path: Path to the agent.yaml file.
|
|
68
|
-
source_dir: Path to the source code directory.
|
|
69
|
-
|
|
70
|
-
Returns:
|
|
71
|
-
AgentDefinition: The fully validated and verified agent definition.
|
|
72
|
-
|
|
73
|
-
Raises:
|
|
74
|
-
ManifestSyntaxError: If structure or schema is invalid.
|
|
75
|
-
PolicyViolationError: If business rules are violated.
|
|
76
|
-
IntegrityCompromisedError: If source code hash does not match.
|
|
77
|
-
FileNotFoundError: If files are missing.
|
|
78
|
-
"""
|
|
79
|
-
manifest_path = Path(manifest_path)
|
|
80
|
-
source_dir = Path(source_dir)
|
|
81
|
-
|
|
82
|
-
logger.info(f"Validating Agent Manifest: {manifest_path}")
|
|
83
|
-
|
|
84
|
-
# 1. Load Raw YAML
|
|
85
|
-
raw_data = ManifestLoader.load_raw_from_file(manifest_path)
|
|
86
|
-
|
|
87
|
-
# 2. Schema Validation
|
|
88
|
-
logger.debug("Running Schema Validation...")
|
|
89
|
-
self.schema_validator.validate(raw_data)
|
|
90
|
-
|
|
91
|
-
# 3. Model Conversion (Normalization)
|
|
92
|
-
logger.debug("Converting to AgentDefinition...")
|
|
93
|
-
agent_def = ManifestLoader.load_from_dict(raw_data)
|
|
94
|
-
logger.info(f"Validating Agent {agent_def.metadata.id} v{agent_def.metadata.version}")
|
|
95
|
-
|
|
96
|
-
# 4. Policy Enforcement
|
|
97
|
-
logger.debug("Enforcing Policies...")
|
|
98
|
-
# We assume policy is checked against the Normalized data (model dumped back to dict)
|
|
99
|
-
# or raw data? Standard practice: Check against normalized data to prevent bypasses.
|
|
100
|
-
# dump mode='json' converts UUIDs/Dates to strings which is what OPA expects usually.
|
|
101
|
-
normalized_data = agent_def.model_dump(mode="json")
|
|
102
|
-
start_time = time.perf_counter()
|
|
103
|
-
try:
|
|
104
|
-
self.policy_enforcer.evaluate(normalized_data)
|
|
105
|
-
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
106
|
-
logger.info(f"Policy Check: Pass - {duration_ms:.2f}ms")
|
|
107
|
-
except Exception:
|
|
108
|
-
duration_ms = (time.perf_counter() - start_time) * 1000
|
|
109
|
-
logger.info(f"Policy Check: Fail - {duration_ms:.2f}ms")
|
|
110
|
-
raise
|
|
111
|
-
|
|
112
|
-
# 5. Integrity Check
|
|
113
|
-
logger.debug("Verifying Integrity...")
|
|
114
|
-
IntegrityChecker.verify(agent_def, source_dir, manifest_path=manifest_path)
|
|
115
|
-
|
|
116
|
-
logger.info("Agent validation successful.")
|
|
117
|
-
return agent_def
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Prosperity-3.0
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class ManifestError(Exception):
|
|
6
|
-
"""Base exception for coreason_manifest errors."""
|
|
7
|
-
|
|
8
|
-
pass
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ManifestSyntaxError(ManifestError):
|
|
12
|
-
"""Raised when the manifest YAML is invalid or missing required fields."""
|
|
13
|
-
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class PolicyViolationError(ManifestError):
|
|
18
|
-
"""Raised when the agent violates a compliance policy."""
|
|
19
|
-
|
|
20
|
-
def __init__(self, message: str, violations: list[str] | None = None) -> None:
|
|
21
|
-
super().__init__(message)
|
|
22
|
-
self.violations = violations or []
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class IntegrityCompromisedError(ManifestError):
|
|
26
|
-
"""Raised when the source code hash does not match the manifest."""
|
|
27
|
-
|
|
28
|
-
pass
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2025 CoReason, Inc.
|
|
2
|
-
#
|
|
3
|
-
# This software is proprietary and dual-licensed.
|
|
4
|
-
# Licensed under the Prosperity Public License 3.0 (the "License").
|
|
5
|
-
# A copy of the license is available at https://prosperitylicense.com/versions/3.0.0
|
|
6
|
-
# For details, see the LICENSE file.
|
|
7
|
-
# Commercial use beyond a 30-day trial requires a separate license.
|
|
8
|
-
#
|
|
9
|
-
# Source Code: https://github.com/CoReason-AI/coreason_manifest
|
|
10
|
-
|
|
11
|
-
from coreason_manifest.utils.logger import logger
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def hello_world() -> str:
|
|
15
|
-
logger.info("Hello World!")
|
|
16
|
-
return "Hello World!"
|
|
File without changes
|
|
File without changes
|
{coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/policies/compliance.rego
RENAMED
|
File without changes
|
{coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/policies/tbom.json
RENAMED
|
File without changes
|
{coreason_manifest-0.1.0 → coreason_manifest-0.3.0}/src/coreason_manifest/schemas/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|