governed-objects 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. governed_objects/__init__.py +7 -0
  2. governed_objects/_version.py +38 -0
  3. governed_objects/adapters/base.py +80 -0
  4. governed_objects/adapters/context.py +58 -0
  5. governed_objects/adapters/mandate.py +45 -0
  6. governed_objects/adapters/registry.py +25 -0
  7. governed_objects/agent/session.py +111 -0
  8. governed_objects/applications/registry.py +39 -0
  9. governed_objects/authority/rules.py +63 -0
  10. governed_objects/delegation/configuration.py +74 -0
  11. governed_objects/delegation/mandate.py +44 -0
  12. governed_objects/delegation/materializer.py +152 -0
  13. governed_objects/delegation/projection.py +48 -0
  14. governed_objects/delegation/resolver.py +180 -0
  15. governed_objects/delegation/scope.py +75 -0
  16. governed_objects/delegation/service.py +245 -0
  17. governed_objects/delegation/validator.py +159 -0
  18. governed_objects/domain/__init__.py +21 -0
  19. governed_objects/domain/actor_manifest.py +40 -0
  20. governed_objects/domain/actors.py +55 -0
  21. governed_objects/domain/clock.py +28 -0
  22. governed_objects/domain/command.py +95 -0
  23. governed_objects/domain/command_context.py +35 -0
  24. governed_objects/domain/models.py +110 -0
  25. governed_objects/domain/traversal.py +25 -0
  26. governed_objects/events/lineage.py +71 -0
  27. governed_objects/events/reducers/__init__.py +2 -0
  28. governed_objects/events/reducers/mandate.py +31 -0
  29. governed_objects/events/replay.py +208 -0
  30. governed_objects/idempotency/store.py +160 -0
  31. governed_objects/interchange/__init__.py +49 -0
  32. governed_objects/interchange/artifact.py +310 -0
  33. governed_objects/interchange/export.py +345 -0
  34. governed_objects/interchange/governance.py +26 -0
  35. governed_objects/interchange/importer.py +672 -0
  36. governed_objects/interchange/prc.py +76 -0
  37. governed_objects/interchange/types.py +228 -0
  38. governed_objects/llm/__init__.py +16 -0
  39. governed_objects/llm/loop.py +130 -0
  40. governed_objects/llm/model.py +44 -0
  41. governed_objects/llm/tools/registry.py +87 -0
  42. governed_objects/llm/tools/results.py +53 -0
  43. governed_objects/llm/tools/schemas.py +67 -0
  44. governed_objects/llm/tools/surface.py +252 -0
  45. governed_objects/llm/trace.py +58 -0
  46. governed_objects/materialization/service.py +107 -0
  47. governed_objects/observations/__init__.py +3 -0
  48. governed_objects/observations/ingestion.py +375 -0
  49. governed_objects/observations/mapping.py +48 -0
  50. governed_objects/observations/models.py +81 -0
  51. governed_objects/observations/store.py +214 -0
  52. governed_objects/observations/validation.py +188 -0
  53. governed_objects/outbound/__init__.py +3 -0
  54. governed_objects/outbound/models.py +94 -0
  55. governed_objects/outbound/service.py +502 -0
  56. governed_objects/outbound/store.py +147 -0
  57. governed_objects/persistence/sqlite.py +635 -0
  58. governed_objects/policy/constraints.py +9 -0
  59. governed_objects/policy/context.py +28 -0
  60. governed_objects/policy/evaluator.py +301 -0
  61. governed_objects/policy/outcomes.py +93 -0
  62. governed_objects/policy/reasons.py +43 -0
  63. governed_objects/providers/base.py +26 -0
  64. governed_objects/providers/binding.py +42 -0
  65. governed_objects/providers/capabilities.py +27 -0
  66. governed_objects/providers/errors.py +48 -0
  67. governed_objects/providers/projection.py +25 -0
  68. governed_objects/providers/registry.py +59 -0
  69. governed_objects/query/service.py +171 -0
  70. governed_objects/query/traversal.py +154 -0
  71. governed_objects/reconciliation/service.py +213 -0
  72. governed_objects/registration/detach.py +43 -0
  73. governed_objects/registration/service.py +113 -0
  74. governed_objects/relationships/canonical.py +55 -0
  75. governed_objects/relationships/sync.py +63 -0
  76. governed_objects/relationships/vocabulary.py +12 -0
  77. governed_objects/runtime/runtime.py +1919 -0
  78. governed_objects/types/canonicalizers/base.py +15 -0
  79. governed_objects/types/extensions.py +48 -0
  80. governed_objects/types/lifecycle.py +65 -0
  81. governed_objects/types/registry.py +171 -0
  82. governed_objects/types/schema.py +90 -0
  83. governed_objects/types/validation.py +57 -0
  84. governed_objects-0.2.1.dist-info/METADATA +184 -0
  85. governed_objects-0.2.1.dist-info/RECORD +88 -0
  86. governed_objects-0.2.1.dist-info/WHEEL +4 -0
  87. governed_objects-0.2.1.dist-info/licenses/LICENSE +202 -0
  88. governed_objects-0.2.1.dist-info/licenses/NOTICE +12 -0
@@ -0,0 +1,15 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Type-specific canonicalization at the Governed Object boundary."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any, Protocol
8
+
9
+
10
+ class TypeCanonicalizer(Protocol):
11
+ """Normalize type-specific aliases into canonical object data."""
12
+
13
+ def canonicalize_create(self, data: dict[str, Any]) -> dict[str, Any]: ...
14
+
15
+ def canonicalize_update(self, data: dict[str, Any]) -> dict[str, Any]: ...
@@ -0,0 +1,48 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Event reducer protocol and type extension registry."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Protocol
8
+
9
+ from governed_objects.domain.models import GovernedObject, GovernanceEvent
10
+ from governed_objects.types.canonicalizers.base import TypeCanonicalizer
11
+
12
+
13
+ class EventReducer(Protocol):
14
+ def reduce(
15
+ self,
16
+ obj: GovernedObject | None,
17
+ event: GovernanceEvent,
18
+ ) -> GovernedObject | None: ...
19
+
20
+
21
+ class TypeExtensionRegistry:
22
+ """Registers type-specific extension points (reducers, canonicalizers)."""
23
+
24
+ def __init__(self) -> None:
25
+ self._reducers: dict[str, EventReducer] = {}
26
+ self._canonicalizers: dict[str, TypeCanonicalizer] = {}
27
+
28
+ def register_reducer(self, object_type: str, reducer: EventReducer) -> None:
29
+ self._reducers[object_type] = reducer
30
+
31
+ def register_canonicalizer(self, object_type: str, canonicalizer: TypeCanonicalizer) -> None:
32
+ self._canonicalizers[object_type] = canonicalizer
33
+
34
+ def reducer_for(self, object_type: str) -> EventReducer | None:
35
+ return self._reducers.get(object_type)
36
+
37
+ def canonicalizer_for(self, object_type: str, type_registry=None) -> TypeCanonicalizer | None:
38
+ if object_type in self._canonicalizers:
39
+ return self._canonicalizers[object_type]
40
+ if type_registry is None:
41
+ return None
42
+ try:
43
+ type_def = type_registry.get(object_type)
44
+ except KeyError:
45
+ return None
46
+ if type_def.extends:
47
+ return self.canonicalizer_for(type_def.extends, type_registry)
48
+ return None
@@ -0,0 +1,65 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Lifecycle validation for governed object types."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from governed_objects.domain.models import ValidationCheck
8
+ from governed_objects.types.schema import ObjectTypeDefinition
9
+
10
+
11
+ class LifecycleValidator:
12
+ """Validates state transitions against a type definition."""
13
+
14
+ def validate_transition(
15
+ self,
16
+ type_def: ObjectTypeDefinition,
17
+ current_state: str,
18
+ action: str,
19
+ ) -> tuple[bool, str, ValidationCheck]:
20
+ if type_def.is_terminal(current_state):
21
+ check = ValidationCheck(
22
+ name="lifecycle",
23
+ passed=False,
24
+ message=f"state {current_state!r} is terminal",
25
+ )
26
+ return False, f"cannot transition from terminal state {current_state!r}", check
27
+
28
+ target = type_def.transition_target(current_state, action)
29
+ if target is None:
30
+ check = ValidationCheck(
31
+ name="lifecycle",
32
+ passed=False,
33
+ message=f"action {action!r} not allowed from state {current_state!r}",
34
+ )
35
+ return (
36
+ False,
37
+ f"action {action!r} not permitted in state {current_state!r}",
38
+ check,
39
+ )
40
+
41
+ check = ValidationCheck(
42
+ name="lifecycle",
43
+ passed=True,
44
+ message=f"{current_state} --{action}--> {target}",
45
+ )
46
+ return True, "", check
47
+
48
+ def can_reach_state(
49
+ self,
50
+ object_type: str,
51
+ current_state: str,
52
+ target_state: str,
53
+ type_registry,
54
+ ) -> bool:
55
+ """Check whether target_state is reachable from current_state in one hop."""
56
+ if current_state == target_state:
57
+ return True
58
+ try:
59
+ type_def = type_registry.get(object_type)
60
+ except KeyError:
61
+ return False
62
+ state_def = type_def.states.get(current_state)
63
+ if state_def is None:
64
+ return False
65
+ return target_state in state_def.transitions.values()
@@ -0,0 +1,171 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Type registry — loads declarative object type definitions."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from pathlib import Path
8
+
9
+ import yaml
10
+
11
+ from governed_objects.types.schema import ActionDef, FieldAccessRule, FieldSchema, ObjectTypeDefinition, StateDef
12
+
13
+ # Python reference-runtime compatibility default — not normative for the specification.
14
+ REFERENCE_RUNTIME_DEFAULT_TYPE_VERSION = "1"
15
+
16
+
17
+ class TypeRegistry:
18
+ """Registry of governed object type definitions with optional inheritance."""
19
+
20
+ def __init__(self) -> None:
21
+ self._types: dict[str, ObjectTypeDefinition] = {}
22
+ self._raw: dict[str, dict] = {}
23
+
24
+ def register(self, type_def: ObjectTypeDefinition) -> None:
25
+ self._types[type_def.kind] = type_def
26
+
27
+ def get(self, kind: str) -> ObjectTypeDefinition:
28
+ if kind not in self._types:
29
+ raise KeyError(f"unknown object type: {kind}")
30
+ return self._types[kind]
31
+
32
+ def list_types(self) -> list[str]:
33
+ return sorted(self._types)
34
+
35
+ def is_subtype(self, child_kind: str, ancestor_kind: str) -> bool:
36
+ if child_kind == ancestor_kind:
37
+ return True
38
+ try:
39
+ child = self.get(child_kind)
40
+ except KeyError:
41
+ return False
42
+ if not child.extends:
43
+ return False
44
+ if child.extends == ancestor_kind:
45
+ return True
46
+ return self.is_subtype(child.extends, ancestor_kind)
47
+
48
+ def subtypes_of(self, ancestor_kind: str) -> list[str]:
49
+ return sorted(
50
+ kind for kind in self._types if kind != ancestor_kind and self.is_subtype(kind, ancestor_kind)
51
+ )
52
+
53
+ def kinds_matching(self, kind: str, *, include_subtypes: bool = False) -> list[str]:
54
+ if include_subtypes:
55
+ return [kind] + self.subtypes_of(kind)
56
+ return [kind]
57
+
58
+ def supports_type_version(self, kind: str, type_version: str) -> bool:
59
+ try:
60
+ type_def = self.get(kind)
61
+ except KeyError:
62
+ return False
63
+ return type_def.type_version == type_version
64
+
65
+ def canonical_state(self, object_type: str, domain_state: str) -> str:
66
+ type_def = self.get(object_type)
67
+ current = domain_state
68
+ visited: set[str] = set()
69
+ while type_def.kind not in visited:
70
+ visited.add(type_def.kind)
71
+ mapped = type_def.canonical_state(current)
72
+ if mapped != current:
73
+ return mapped
74
+ if not type_def.extends:
75
+ break
76
+ type_def = self.get(type_def.extends)
77
+ return current
78
+
79
+ def load_directory(self, types_dir: Path) -> None:
80
+ paths = sorted(types_dir.glob("*.yaml"))
81
+ self._raw = {p.stem: (yaml.safe_load(p.read_text()) or {}) for p in paths}
82
+ for path in paths:
83
+ raw = self._raw[path.stem]
84
+ self.register(_resolve_type(raw["kind"], self._raw))
85
+
86
+ def load_type_definition(path: Path) -> ObjectTypeDefinition:
87
+ raw = yaml.safe_load(path.read_text()) or {}
88
+ types_dir = path.parent
89
+ all_raw = {p.stem: (yaml.safe_load(p.read_text()) or {}) for p in types_dir.glob("*.yaml")}
90
+ return _resolve_type(raw["kind"], all_raw)
91
+
92
+
93
+ def _resolve_type(kind: str, all_raw: dict[str, dict]) -> ObjectTypeDefinition:
94
+ raw = _find_raw_by_kind(kind, all_raw)
95
+ parent_kind = raw.get("extends")
96
+ if parent_kind:
97
+ parent = _resolve_type(parent_kind, all_raw)
98
+ fields = {**parent.fields, **_parse_schema(raw.get("schema") or {})}
99
+ states = {**parent.states, **_parse_states(raw.get("states") or {})}
100
+ actions = {**parent.actions, **_parse_actions(raw.get("actions") or {})}
101
+ field_access = {**parent.field_access, **_parse_field_access(raw.get("field_access") or {})}
102
+ if "read_requires" in raw:
103
+ read_requires = raw.get("read_requires") or []
104
+ else:
105
+ read_requires = list(parent.read_requires)
106
+ read_open = raw.get("read_open") if "read_open" in raw else parent.read_open
107
+ canonical_state_map = {**parent.canonical_state_map, **(raw.get("canonical_state_map") or {})}
108
+ initial_state = raw.get("initial_state") or parent.initial_state
109
+ else:
110
+ fields = _parse_schema(raw.get("schema") or {})
111
+ states = _parse_states(raw.get("states") or {})
112
+ actions = _parse_actions(raw.get("actions") or {})
113
+ field_access = _parse_field_access(raw.get("field_access") or {})
114
+ read_requires = raw.get("read_requires") or []
115
+ read_open = bool(raw.get("read_open") or False)
116
+ canonical_state_map = raw.get("canonical_state_map") or {}
117
+ initial_state = raw.get("initial_state")
118
+
119
+ consumed = {
120
+ "kind", "extends", "schema", "states", "actions", "field_access",
121
+ "initial_state", "read_requires", "read_open", "canonical_state_map", "version",
122
+ }
123
+ type_version = str(raw.get("version") or REFERENCE_RUNTIME_DEFAULT_TYPE_VERSION)
124
+ if parent_kind and "version" not in raw:
125
+ type_version = parent.type_version
126
+ return ObjectTypeDefinition(
127
+ kind=kind,
128
+ type_version=type_version,
129
+ extends=parent_kind,
130
+ fields=fields,
131
+ states=states,
132
+ actions=actions,
133
+ field_access=field_access,
134
+ initial_state=initial_state,
135
+ read_requires=read_requires,
136
+ read_open=read_open,
137
+ canonical_state_map=canonical_state_map,
138
+ extra={k: v for k, v in raw.items() if k not in consumed},
139
+ )
140
+
141
+
142
+ def _find_raw_by_kind(kind: str, all_raw: dict[str, dict]) -> dict:
143
+ for raw in all_raw.values():
144
+ if raw.get("kind") == kind:
145
+ return raw
146
+ raise KeyError(f"type definition not found: {kind}")
147
+
148
+
149
+ def _parse_schema(raw_schema: dict) -> dict[str, FieldSchema]:
150
+ return {
151
+ name: FieldSchema(**spec) if isinstance(spec, dict) else FieldSchema(type=str(spec))
152
+ for name, spec in raw_schema.items()
153
+ }
154
+
155
+
156
+ def _parse_states(raw_states: dict) -> dict[str, StateDef]:
157
+ return {
158
+ name: StateDef(**spec) if isinstance(spec, dict) else StateDef()
159
+ for name, spec in raw_states.items()
160
+ }
161
+
162
+
163
+ def _parse_actions(raw_actions: dict) -> dict[str, ActionDef]:
164
+ return {
165
+ name: ActionDef(**spec) if isinstance(spec, dict) else ActionDef()
166
+ for name, spec in raw_actions.items()
167
+ }
168
+
169
+
170
+ def _parse_field_access(raw_fa: dict) -> dict[str, FieldAccessRule]:
171
+ return {name: FieldAccessRule(**spec) for name, spec in raw_fa.items()}
@@ -0,0 +1,90 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Declarative type definitions for governed objects."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ from pydantic import BaseModel, Field
10
+
11
+
12
+ class FieldSchema(BaseModel):
13
+ type: str
14
+ required: bool = False
15
+
16
+
17
+ class ActionDef(BaseModel):
18
+ requires: list[str] = Field(default_factory=list)
19
+ open: bool = False
20
+
21
+
22
+ class StateDef(BaseModel):
23
+ transitions: dict[str, str] = Field(default_factory=dict)
24
+ terminal: bool = False
25
+
26
+
27
+ class FieldAccessRule(BaseModel):
28
+ read: list[str] = Field(default_factory=list)
29
+
30
+
31
+ class ObjectTypeDefinition(BaseModel):
32
+ """Declarative definition for a governed object type."""
33
+
34
+ kind: str
35
+ type_version: str = "1"
36
+ extends: str | None = None
37
+ fields: dict[str, FieldSchema] = Field(default_factory=dict, alias="schema")
38
+ states: dict[str, StateDef] = Field(default_factory=dict)
39
+ actions: dict[str, ActionDef] = Field(default_factory=dict)
40
+ field_access: dict[str, FieldAccessRule] = Field(default_factory=dict)
41
+ initial_state: str | None = None
42
+ read_requires: list[str] = Field(default_factory=list)
43
+ read_open: bool = False
44
+ canonical_state_map: dict[str, str] = Field(default_factory=dict)
45
+ extra: dict[str, Any] = Field(default_factory=dict)
46
+
47
+ model_config = {"populate_by_name": True}
48
+
49
+ @property
50
+ def schema(self) -> dict[str, FieldSchema]:
51
+ """Alias for fields — matches YAML key name."""
52
+ return self.fields
53
+
54
+ def default_state(self) -> str:
55
+ if self.initial_state:
56
+ return self.initial_state
57
+ if self.states:
58
+ return next(iter(self.states))
59
+ return "active"
60
+
61
+ def required_capabilities(self, action: str) -> list[str]:
62
+ if action == "read":
63
+ return self.read_requires
64
+ action_def = self.actions.get(action)
65
+ if action_def:
66
+ return action_def.requires
67
+ return []
68
+
69
+ def is_open(self, action: str) -> bool:
70
+ """Whether ``action`` (or ``"read"``) is explicitly opened to every
71
+ actor regardless of declared capabilities. An undeclared or empty
72
+ requirement list denies unless this marker is set."""
73
+ if action == "read":
74
+ return self.read_open
75
+ action_def = self.actions.get(action)
76
+ return bool(action_def and action_def.open)
77
+
78
+ def transition_target(self, current_state: str, action: str) -> str | None:
79
+ state_def = self.states.get(current_state)
80
+ if not state_def:
81
+ return None
82
+ return state_def.transitions.get(action)
83
+
84
+ def is_terminal(self, state: str) -> bool:
85
+ state_def = self.states.get(state)
86
+ return bool(state_def and state_def.terminal)
87
+
88
+ def canonical_state(self, domain_state: str) -> str:
89
+ """Map domain-specific lifecycle state to canonical primitive state."""
90
+ return self.canonical_state_map.get(domain_state, domain_state)
@@ -0,0 +1,57 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Schema validation for governed object data."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from datetime import datetime
8
+ from typing import Any
9
+
10
+ from governed_objects.domain.models import ValidationCheck
11
+ from governed_objects.types.schema import ObjectTypeDefinition
12
+
13
+
14
+ class SchemaValidator:
15
+ """Validates object data against a type schema."""
16
+
17
+ def validate(self, type_def: ObjectTypeDefinition, data: dict[str, Any]) -> tuple[bool, list[ValidationCheck], list[str]]:
18
+ checks: list[ValidationCheck] = []
19
+ errors: list[str] = []
20
+
21
+ for field_name, field_schema in type_def.schema.items():
22
+ value = data.get(field_name)
23
+ if field_schema.required and (value is None or value == ""):
24
+ msg = f"missing required field: {field_name}"
25
+ checks.append(ValidationCheck(name=field_name, passed=False, message=msg))
26
+ errors.append(msg)
27
+ continue
28
+
29
+ if value is None:
30
+ checks.append(ValidationCheck(name=field_name, passed=True))
31
+ continue
32
+
33
+ if not self._type_matches(field_schema.type, value):
34
+ msg = f"field {field_name}: expected {field_schema.type}, got {type(value).__name__}"
35
+ checks.append(ValidationCheck(name=field_name, passed=False, message=msg))
36
+ errors.append(msg)
37
+ else:
38
+ checks.append(ValidationCheck(name=field_name, passed=True))
39
+
40
+ return len(errors) == 0, checks, errors
41
+
42
+ @staticmethod
43
+ def _type_matches(expected: str, value: Any) -> bool:
44
+ mapping: dict[str, tuple[type, ...]] = {
45
+ "string": (str,),
46
+ "integer": (int,),
47
+ "number": (int, float),
48
+ "float": (float, int),
49
+ "double": (float, int),
50
+ "boolean": (bool,),
51
+ "datetime": (str, datetime),
52
+ "date": (str,),
53
+ "array": (list,),
54
+ "object": (dict,),
55
+ }
56
+ allowed = mapping.get(expected, (str, int, float, bool))
57
+ return isinstance(value, allowed)
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.5
2
+ Name: governed-objects
3
+ Version: 0.2.1
4
+ Summary: Governed Objects runtime — a reusable primitive for policy-aware organizational assets
5
+ Project-URL: Source, https://github.com/governedobjects/governed-objects-python
6
+ Project-URL: Issues, https://github.com/governedobjects/governed-objects-python/issues
7
+ Project-URL: Specification, https://github.com/governedobjects/governed-objects-spec
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: pydantic>=2.10.0
19
+ Requires-Dist: pyyaml>=6.0.2
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest-cov>=6.0.0; extra == 'dev'
22
+ Requires-Dist: pytest>=8.3.0; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # Governed Objects Python runtime
26
+
27
+ Governed Objects is a policy-aware primitive for organizational assets: every
28
+ object has a declarative type, a canonical state, and an accepted-history
29
+ log, and every create/read/action goes through an explicit capability check
30
+ before it is accepted. This package is the Python reference runtime. See the
31
+ [specification](https://github.com/governedobjects/governed-objects-spec) and
32
+ the [conformance suite](https://github.com/governedobjects/governed-objects-conformance)
33
+ for the normative rules this runtime implements and tests against.
34
+
35
+ ## Status
36
+
37
+ Experimental, version 0.2.1, `0.x`. This is not a production product,
38
+ conformance certification, or interoperability approval. It targets
39
+ specification revision `draft2.2` and self-reports 76/0/2/0 (pass/not
40
+ applicable/not executable/fail) against Core conformance suite 0.1.0 for that revision;
41
+ see the conformance adapter below to reproduce that result yourself. The
42
+ suite's own claim text for that run:
43
+
44
+ > governed-objects-python 0.2.1 passes the Governed Objects Conformance Suite
45
+ > 0.1.0 for v0alpha1 draft2.2 Core (self-attested; not certified). Not
46
+ > executed by suite 0.1.0: D22-CON-001, D22-CS4-003. Conditional capabilities
47
+ > claimed: create_with_relationships, governance_reconfiguration,
48
+ > mutable_objects, relationship_add, relationship_remove, replay, restart,
49
+ > restoration, semantic_portability_view, type_version_exposed,
50
+ > unconditional_mutation.
51
+
52
+ ## Install
53
+
54
+ ```sh
55
+ pip install governed-objects
56
+ ```
57
+
58
+ ### From a source checkout
59
+
60
+ ```sh
61
+ python3 -m venv .venv
62
+ . .venv/bin/activate
63
+ pip install .
64
+ ```
65
+
66
+ Requires Python >=3.11. The distribution name is `governed-objects`; the
67
+ import package is `governed_objects`. The version is defined once, in
68
+ `pyproject.toml`, and exposed as `governed_objects.__version__`.
69
+
70
+ ## Example
71
+
72
+ Defining a type, creating an actor and an object, and performing one accepted
73
+ and one denied operation:
74
+
75
+ ```python
76
+ from pathlib import Path
77
+
78
+ from governed_objects.applications.registry import ApplicationRegistry
79
+ from governed_objects.domain.command import CreateObject
80
+ from governed_objects.domain.models import Actor, ActorType
81
+ from governed_objects.persistence.sqlite import SQLiteStore
82
+ from governed_objects.providers.registry import ProviderRegistry
83
+ from governed_objects.runtime.runtime import GovernedObjectRuntime
84
+ from governed_objects.types.extensions import TypeExtensionRegistry
85
+ from governed_objects.types.registry import TypeRegistry
86
+ from governed_objects.types.schema import FieldSchema, ObjectTypeDefinition
87
+
88
+ types = TypeRegistry()
89
+ types.register(ObjectTypeDefinition(
90
+ kind="example.widget", initial_state="active",
91
+ states={"active": {}},
92
+ fields={"label": FieldSchema(type="string", required=True)},
93
+ actions={"create": {"requires": ["widget.create"]}},
94
+ read_requires=["widget.read"],
95
+ ))
96
+
97
+ store = SQLiteStore(Path(":memory:"))
98
+ runtime = GovernedObjectRuntime.configured(
99
+ store=store, type_registry=types, adapters=[],
100
+ extension_registry=TypeExtensionRegistry(), providers=ProviderRegistry(),
101
+ application_registry=ApplicationRegistry(),
102
+ )
103
+
104
+ writer = Actor(id="writer", type=ActorType.SERVICE, capabilities=["widget.create", "widget.read"])
105
+ result = runtime.execute(CreateObject("w-1", "example.widget", {"label": "first"}), actor=writer)
106
+ print("accepted create:", result.decision, result.object_version)
107
+ # accepted create: ALLOW 1
108
+
109
+ stranger = Actor(id="stranger", type=ActorType.SERVICE)
110
+ result = runtime.execute(CreateObject("w-2", "example.widget", {"label": "second"}), actor=stranger)
111
+ print("denied create:", result.decision, result.deny_reason)
112
+ # denied create: DENY ACTOR_CAPABILITY_MISSING
113
+
114
+ store.close()
115
+ ```
116
+
117
+ A type opens an action or a read to every actor only with an explicit
118
+ `open: true` marker on the action (or `read_open: true` on the type) — an
119
+ action or read with no declared capabilities and no such marker denies every
120
+ actor, as above.
121
+
122
+ ## Running the tests and the conformance adapter
123
+
124
+ ```sh
125
+ pip install '.[dev]'
126
+ pytest
127
+ ```
128
+
129
+ The full test run takes several minutes. `uv.lock` is provided for `uv`
130
+ users (`uv sync --extra dev`); it is optional.
131
+
132
+ The conformance adapter under `conformance-adapter/` speaks the suite's
133
+ adapter protocol on stdin/stdout. The runner is in the
134
+ [`governed-objects-conformance`](https://github.com/governedobjects/governed-objects-conformance)
135
+ repository. Run these commands from the root of that repository, with the
136
+ adapter path pointing into this checkout:
137
+
138
+ ```sh
139
+ python -m runner --adapter-command "path/to/governed-objects-python/conformance-adapter/launch.sh" --output-dir results-python
140
+ python -m runner --verify-bundle results-python
141
+ ```
142
+
143
+ The adapter runs the source in this checkout; the interpreter only needs
144
+ `pydantic` and `pyyaml`. Set `CONFORMANCE_PYTHON` to an interpreter that has
145
+ them if it differs from `python3` on `PATH`. An activated virtual environment
146
+ from the install step above already satisfies this.
147
+
148
+ Tested on Linux. macOS is expected to work but is untested. On Windows, use
149
+ WSL. The adapters are `bash` scripts.
150
+
151
+ ## Known limits
152
+
153
+ - Experimental, `0.x`: no production, conformance-certification or
154
+ interoperability claim.
155
+ - The following public methods change or read canonical state without a
156
+ policy check and are for trusted integration code, not untrusted callers:
157
+ `resolve_review`, `replay`, `detach_provider`, `replace_provider`,
158
+ `apply_repair`, `ingest_observation`, registration, `get_object`,
159
+ `history`, `canonical_relationships`. Capabilities for every policy check
160
+ are taken from the `Actor` object the caller passes in; the runtime does
161
+ not authenticate actors itself.
162
+ - `governed_objects.agent.session` and `governed_objects.llm` are shipped for
163
+ experimental optional use, not a model-provider integration or a default
164
+ service; they accept a caller-supplied `ReasoningModel` and install no
165
+ provider SDK or live model call.
166
+ - `governed_objects.interchange` (artifact export/import, PRC) is a
167
+ provisional, representation-limited, non-normative experiment, not an
168
+ official wire standard.
169
+ - The SQLite store serializes operations on one store instance with a
170
+ per-instance connection guard, and `create`/`add_relationship`/
171
+ `remove_relationship`/transition commands re-check the expected Object
172
+ Version and write state plus history in one transaction (two connections
173
+ to the same file never both commit against the same prior version). This
174
+ does not cover multi-store or distributed-transaction guarantees, and
175
+ provider/adapter I/O runs outside the transaction.
176
+ - Query/traversal/delegation/provider/agent features and the conformance
177
+ adapter are implementation-specific; this is not a cross-runtime wire
178
+ protocol.
179
+
180
+ ## License
181
+
182
+ This runtime is licensed under Apache 2.0; see [LICENSE](https://github.com/governedobjects/governed-objects-python/blob/main/LICENSE), [NOTICE](https://github.com/governedobjects/governed-objects-python/blob/main/NOTICE) and
183
+ [LICENSING.md](https://github.com/governedobjects/governed-objects-python/blob/main/LICENSING.md). Contribution terms are in [CONTRIBUTING.md](https://github.com/governedobjects/governed-objects-python/blob/main/CONTRIBUTING.md).
184
+ Report security issues as described in [SECURITY.md](https://github.com/governedobjects/governed-objects-python/blob/main/SECURITY.md).