generated from coulomb/repo-seed
Add profile-driven lifecycle rules
This commit is contained in:
@@ -17,7 +17,7 @@ from .adapters import (
|
||||
)
|
||||
from .bridge import MARKITECT_PACKAGE_REQUEST_SCHEMA, package_request_from_selection, package_response_envelope
|
||||
from .contracts import ContractIngressResult, graph_from_markitect, profile_from_markitect
|
||||
from .lifecycle import plan_compaction, plan_refresh, plan_retention
|
||||
from .lifecycle import LifecycleRuleConfig, plan_compaction, plan_lifecycle_from_profile, plan_refresh, plan_retention
|
||||
from .models import (
|
||||
Diagnostic,
|
||||
LifecycleAction,
|
||||
@@ -150,6 +150,57 @@ class PhaseMemoryRuntime:
|
||||
},
|
||||
)
|
||||
|
||||
def plan_lifecycle_with_profile(
|
||||
self,
|
||||
profile_data: dict[str, Any],
|
||||
graph_data: dict[str, Any],
|
||||
*,
|
||||
source_ref: str = "mapping",
|
||||
profile_source_ref: str = "profile",
|
||||
refresh_digests: dict[str, str] | None = None,
|
||||
compact_node_ids: tuple[str, ...] = (),
|
||||
now: datetime | None = None,
|
||||
) -> dict[str, Any]:
|
||||
profile_result = profile_from_markitect(profile_data)
|
||||
graph_result = graph_from_markitect(graph_data)
|
||||
diagnostics = list(profile_result.diagnostics) + list(graph_result.diagnostics)
|
||||
actions: tuple[LifecycleAction, ...] = ()
|
||||
rule_config = None
|
||||
|
||||
if profile_result.valid and graph_result.valid:
|
||||
profile: ProfileIntent = profile_result.value
|
||||
graph: MemoryGraph = graph_result.value
|
||||
rule_config = LifecycleRuleConfig.from_profile(profile)
|
||||
actions = plan_lifecycle_from_profile(
|
||||
graph,
|
||||
profile,
|
||||
refresh_digests=refresh_digests or {},
|
||||
compact_node_ids=compact_node_ids,
|
||||
now=now,
|
||||
)
|
||||
|
||||
return self._envelope(
|
||||
"graph.lifecycle.plan",
|
||||
subject_kind="memory_graph",
|
||||
subject_id=graph_result.subject_id,
|
||||
valid=profile_result.valid and graph_result.valid,
|
||||
diagnostics=diagnostics,
|
||||
source_ref=source_ref,
|
||||
data={
|
||||
"graph_id": graph_result.subject_id,
|
||||
"profile_id": profile_result.subject_id,
|
||||
"dry_run_actions": [action.to_dict() for action in actions],
|
||||
"rule_config": rule_config.to_dict() if rule_config else None,
|
||||
"parameters": compact_dict(
|
||||
{
|
||||
"profile_source_ref": profile_source_ref,
|
||||
"refresh_digests": refresh_digests or {},
|
||||
"compact_node_ids": list(compact_node_ids),
|
||||
}
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
def plan_activation(
|
||||
self,
|
||||
data: dict[str, Any],
|
||||
|
||||
Reference in New Issue
Block a user