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,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})