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.
- governed_objects/__init__.py +7 -0
- governed_objects/_version.py +38 -0
- governed_objects/adapters/base.py +80 -0
- governed_objects/adapters/context.py +58 -0
- governed_objects/adapters/mandate.py +45 -0
- governed_objects/adapters/registry.py +25 -0
- governed_objects/agent/session.py +111 -0
- governed_objects/applications/registry.py +39 -0
- governed_objects/authority/rules.py +63 -0
- governed_objects/delegation/configuration.py +74 -0
- governed_objects/delegation/mandate.py +44 -0
- governed_objects/delegation/materializer.py +152 -0
- governed_objects/delegation/projection.py +48 -0
- governed_objects/delegation/resolver.py +180 -0
- governed_objects/delegation/scope.py +75 -0
- governed_objects/delegation/service.py +245 -0
- governed_objects/delegation/validator.py +159 -0
- governed_objects/domain/__init__.py +21 -0
- governed_objects/domain/actor_manifest.py +40 -0
- governed_objects/domain/actors.py +55 -0
- governed_objects/domain/clock.py +28 -0
- governed_objects/domain/command.py +95 -0
- governed_objects/domain/command_context.py +35 -0
- governed_objects/domain/models.py +110 -0
- governed_objects/domain/traversal.py +25 -0
- governed_objects/events/lineage.py +71 -0
- governed_objects/events/reducers/__init__.py +2 -0
- governed_objects/events/reducers/mandate.py +31 -0
- governed_objects/events/replay.py +208 -0
- governed_objects/idempotency/store.py +160 -0
- governed_objects/interchange/__init__.py +49 -0
- governed_objects/interchange/artifact.py +310 -0
- governed_objects/interchange/export.py +345 -0
- governed_objects/interchange/governance.py +26 -0
- governed_objects/interchange/importer.py +672 -0
- governed_objects/interchange/prc.py +76 -0
- governed_objects/interchange/types.py +228 -0
- governed_objects/llm/__init__.py +16 -0
- governed_objects/llm/loop.py +130 -0
- governed_objects/llm/model.py +44 -0
- governed_objects/llm/tools/registry.py +87 -0
- governed_objects/llm/tools/results.py +53 -0
- governed_objects/llm/tools/schemas.py +67 -0
- governed_objects/llm/tools/surface.py +252 -0
- governed_objects/llm/trace.py +58 -0
- governed_objects/materialization/service.py +107 -0
- governed_objects/observations/__init__.py +3 -0
- governed_objects/observations/ingestion.py +375 -0
- governed_objects/observations/mapping.py +48 -0
- governed_objects/observations/models.py +81 -0
- governed_objects/observations/store.py +214 -0
- governed_objects/observations/validation.py +188 -0
- governed_objects/outbound/__init__.py +3 -0
- governed_objects/outbound/models.py +94 -0
- governed_objects/outbound/service.py +502 -0
- governed_objects/outbound/store.py +147 -0
- governed_objects/persistence/sqlite.py +635 -0
- governed_objects/policy/constraints.py +9 -0
- governed_objects/policy/context.py +28 -0
- governed_objects/policy/evaluator.py +301 -0
- governed_objects/policy/outcomes.py +93 -0
- governed_objects/policy/reasons.py +43 -0
- governed_objects/providers/base.py +26 -0
- governed_objects/providers/binding.py +42 -0
- governed_objects/providers/capabilities.py +27 -0
- governed_objects/providers/errors.py +48 -0
- governed_objects/providers/projection.py +25 -0
- governed_objects/providers/registry.py +59 -0
- governed_objects/query/service.py +171 -0
- governed_objects/query/traversal.py +154 -0
- governed_objects/reconciliation/service.py +213 -0
- governed_objects/registration/detach.py +43 -0
- governed_objects/registration/service.py +113 -0
- governed_objects/relationships/canonical.py +55 -0
- governed_objects/relationships/sync.py +63 -0
- governed_objects/relationships/vocabulary.py +12 -0
- governed_objects/runtime/runtime.py +1919 -0
- governed_objects/types/canonicalizers/base.py +15 -0
- governed_objects/types/extensions.py +48 -0
- governed_objects/types/lifecycle.py +65 -0
- governed_objects/types/registry.py +171 -0
- governed_objects/types/schema.py +90 -0
- governed_objects/types/validation.py +57 -0
- governed_objects-0.2.1.dist-info/METADATA +184 -0
- governed_objects-0.2.1.dist-info/RECORD +88 -0
- governed_objects-0.2.1.dist-info/WHEEL +4 -0
- governed_objects-0.2.1.dist-info/licenses/LICENSE +202 -0
- governed_objects-0.2.1.dist-info/licenses/NOTICE +12 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Brafford Labs, LLC
|
|
3
|
+
"""Canonical (accepted) relationship helpers."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from governed_objects.domain.models import Relationship
|
|
8
|
+
from governed_objects.persistence.sqlite import SQLiteStore
|
|
9
|
+
|
|
10
|
+
CANONICAL_SOURCE = "canonical"
|
|
11
|
+
PROVIDER_SOURCE = "provider"
|
|
12
|
+
LOCAL_SOURCE = "local"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def is_canonical(rel: Relationship) -> bool:
|
|
16
|
+
return rel.metadata.get("source") == CANONICAL_SOURCE
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def canonical_relationship(
|
|
20
|
+
source_id: str,
|
|
21
|
+
relation: str,
|
|
22
|
+
target_id: str,
|
|
23
|
+
*,
|
|
24
|
+
target_type: str | None = None,
|
|
25
|
+
extra_metadata: dict | None = None,
|
|
26
|
+
) -> Relationship:
|
|
27
|
+
metadata = {"source": CANONICAL_SOURCE}
|
|
28
|
+
if extra_metadata:
|
|
29
|
+
metadata.update(extra_metadata)
|
|
30
|
+
return Relationship(
|
|
31
|
+
source_id=source_id,
|
|
32
|
+
relation=relation,
|
|
33
|
+
target_id=target_id,
|
|
34
|
+
target_type=target_type,
|
|
35
|
+
metadata=metadata,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def list_canonical_for_object(store: SQLiteStore, object_id: str) -> list[Relationship]:
|
|
40
|
+
rels = store.list_for_source(object_id)
|
|
41
|
+
return [r for r in rels if is_canonical(r)]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def replace_canonical_for_object(
|
|
45
|
+
store: SQLiteStore,
|
|
46
|
+
object_id: str,
|
|
47
|
+
relationships: list[Relationship],
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Replace accepted canonical outgoing edges for an object."""
|
|
50
|
+
existing = store.list_for_source(object_id)
|
|
51
|
+
for rel in existing:
|
|
52
|
+
if is_canonical(rel):
|
|
53
|
+
store.remove(rel.source_id, rel.relation, rel.target_id)
|
|
54
|
+
for rel in relationships:
|
|
55
|
+
store.add(rel)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Brafford Labs, LLC
|
|
3
|
+
"""Relationship synchronization during hydration."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from contextlib import nullcontext
|
|
8
|
+
|
|
9
|
+
from governed_objects.domain.models import Relationship
|
|
10
|
+
from governed_objects.persistence.sqlite import SQLiteStore
|
|
11
|
+
|
|
12
|
+
PROVIDER_SOURCE = "provider"
|
|
13
|
+
LOCAL_SOURCE = "local"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RelationshipSyncService:
|
|
17
|
+
"""Maintain provider-owned outgoing derived cache rows, not canonical admission."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, store: SQLiteStore) -> None:
|
|
20
|
+
self._store = store
|
|
21
|
+
|
|
22
|
+
def sync_provider_relationships(
|
|
23
|
+
self,
|
|
24
|
+
governed_id: str,
|
|
25
|
+
relationships: list[Relationship],
|
|
26
|
+
*,
|
|
27
|
+
provider_name: str,
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Apply a named provider's outgoing snapshot without taking occupied slots."""
|
|
30
|
+
if not provider_name:
|
|
31
|
+
return
|
|
32
|
+
prepared = [rel.model_copy(deep=True) for rel in relationships if rel.source_id == governed_id]
|
|
33
|
+
# Ownership must be inspected only after acquiring the shared connection
|
|
34
|
+
# guard. A foreign owner finishes first; a legitimate same-owner caller
|
|
35
|
+
# participates without ending or committing that caller's transaction.
|
|
36
|
+
with self._store._connection_guard:
|
|
37
|
+
unit = nullcontext() if self._store._observation_transaction_active else self._store.observation_transaction()
|
|
38
|
+
with unit:
|
|
39
|
+
protected = set()
|
|
40
|
+
for rel in self._store.list_for_source(governed_id):
|
|
41
|
+
if rel.metadata.get("source") != PROVIDER_SOURCE or rel.metadata.get("provider") != provider_name:
|
|
42
|
+
protected.add((rel.source_id, rel.relation, rel.target_id))
|
|
43
|
+
continue
|
|
44
|
+
self._store.remove(rel.source_id, rel.relation, rel.target_id)
|
|
45
|
+
for rel in prepared:
|
|
46
|
+
if (rel.source_id, rel.relation, rel.target_id) in protected:
|
|
47
|
+
continue
|
|
48
|
+
tagged = rel.model_copy(
|
|
49
|
+
update={
|
|
50
|
+
"metadata": {
|
|
51
|
+
**rel.metadata,
|
|
52
|
+
"source": PROVIDER_SOURCE,
|
|
53
|
+
"provider": provider_name,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
self._store.add(tagged)
|
|
58
|
+
|
|
59
|
+
def add_local_relationship(self, rel: Relationship) -> None:
|
|
60
|
+
tagged = rel.model_copy(
|
|
61
|
+
update={"metadata": {**rel.metadata, "source": LOCAL_SOURCE}}
|
|
62
|
+
)
|
|
63
|
+
self._store.add(tagged)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Brafford Labs, LLC
|
|
3
|
+
"""Canonical relationship names for governed object graphs."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
DELEGATED_BY = "delegated_by"
|
|
8
|
+
DELEGATED_TO = "delegated_to"
|
|
9
|
+
SCOPED_TO = "scoped_to"
|
|
10
|
+
DERIVED_FROM = "derived_from"
|
|
11
|
+
|
|
12
|
+
CANONICAL_MANDATE_RELATIONS = frozenset({DELEGATED_BY, DELEGATED_TO, SCOPED_TO, DERIVED_FROM})
|