Artifex/graph/bootstrap.py

133 lines
5.2 KiB
Python
Raw Normal View History

from __future__ import annotations
from django.utils import timezone
2026-08-15 20:03:59 +07:00
from graph.agent_control import agent_investigation_graph_v1
from graph.crypto_venture_cohort import crypto_venture_cohort_graph_v1
from graph.lifecycle import (
project_evolution_graph_v1,
project_exploration_graph_v1,
project_extension_graph_v1,
)
from graph.models import (
ExecutionGraphDefinition,
ExecutionGraphVersion,
ExecutionGraphVersionStatus,
)
2026-08-15 19:46:07 +07:00
from graph.roadmap import project_roadmap_review_graph_v1
from graph.scenario_lab import scenario_lab_graph_v1
2026-08-15 18:44:26 +07:00
from graph.steward import steward_run_graph_v1
from graph.story_authoring import story_authoring_graph_v1, story_authoring_graph_v2
from graph.task_execution import task_execution_graph_v1
2026-08-15 21:42:46 +07:00
from graph.venture_cohort import venture_discovery_cohort_graph_v1
from graph.venture_discovery import venture_discovery_graph_v1
def champion_task_execution_graph_v1() -> ExecutionGraphVersion:
spec = task_execution_graph_v1()
definition, _ = ExecutionGraphDefinition.objects.get_or_create(
name=spec.name,
defaults={"graph_type": spec.graph_type, "description": str(spec.metadata.get("description", ""))},
)
version, created = ExecutionGraphVersion.objects.get_or_create(
graph=definition,
version=spec.version,
defaults={
"status": ExecutionGraphVersionStatus.CHAMPION,
"graph_spec": spec.to_dict(),
"metadata": {"immutable_after_use": True},
"promoted_at": timezone.now(),
},
)
if not created and version.status != ExecutionGraphVersionStatus.CHAMPION:
version.status = ExecutionGraphVersionStatus.CHAMPION
version.promoted_at = timezone.now()
version.save(update_fields=["status", "promoted_at"])
return version
2026-08-15 18:44:26 +07:00
def champion_steward_run_graph_v1() -> ExecutionGraphVersion:
spec = steward_run_graph_v1()
definition, _ = ExecutionGraphDefinition.objects.get_or_create(
name=spec.name,
defaults={"graph_type": spec.graph_type, "description": str(spec.metadata.get("description", ""))},
)
version, created = ExecutionGraphVersion.objects.get_or_create(
graph=definition,
version=spec.version,
defaults={
"status": ExecutionGraphVersionStatus.CHAMPION,
"graph_spec": spec.to_dict(),
"metadata": {"immutable_after_use": True},
"promoted_at": timezone.now(),
},
)
if not created and version.status != ExecutionGraphVersionStatus.CHAMPION:
version.status = ExecutionGraphVersionStatus.CHAMPION
version.promoted_at = timezone.now()
version.save(update_fields=["status", "promoted_at"])
return version
2026-08-15 19:30:02 +07:00
def _champion_graph(spec) -> ExecutionGraphVersion:
definition, _ = ExecutionGraphDefinition.objects.get_or_create(
name=spec.name,
defaults={"graph_type": spec.graph_type, "description": str(spec.metadata.get("description", ""))},
)
2026-08-16 16:41:50 +07:00
ExecutionGraphVersion.objects.filter(graph=definition, status=ExecutionGraphVersionStatus.CHAMPION).exclude(version=spec.version).update(status=ExecutionGraphVersionStatus.RETIRED)
2026-08-15 19:30:02 +07:00
version, created = ExecutionGraphVersion.objects.get_or_create(
graph=definition,
version=spec.version,
defaults={"status": ExecutionGraphVersionStatus.CHAMPION, "graph_spec": spec.to_dict(), "metadata": {"immutable_after_use": True}, "promoted_at": timezone.now()},
)
if not created and version.status != ExecutionGraphVersionStatus.CHAMPION:
2026-08-16 16:41:50 +07:00
ExecutionGraphVersion.objects.filter(graph=definition, status=ExecutionGraphVersionStatus.CHAMPION).exclude(pk=version.pk).update(status=ExecutionGraphVersionStatus.RETIRED)
2026-08-15 19:30:02 +07:00
version.status = ExecutionGraphVersionStatus.CHAMPION
version.promoted_at = timezone.now()
version.save(update_fields=["status", "promoted_at"])
return version
def champion_project_extension_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(project_extension_graph_v1())
def champion_project_evolution_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(project_evolution_graph_v1())
def champion_project_exploration_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(project_exploration_graph_v1())
2026-08-15 19:46:07 +07:00
def champion_project_roadmap_review_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(project_roadmap_review_graph_v1())
def champion_scenario_lab_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(scenario_lab_graph_v1())
2026-08-15 20:03:59 +07:00
def champion_agent_investigation_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(agent_investigation_graph_v1())
def champion_venture_discovery_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(venture_discovery_graph_v1())
2026-08-15 21:42:46 +07:00
def champion_venture_discovery_cohort_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(venture_discovery_cohort_graph_v1())
def champion_crypto_venture_cohort_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(crypto_venture_cohort_graph_v1())
def champion_story_authoring_graph_v1() -> ExecutionGraphVersion:
return _champion_graph(story_authoring_graph_v1())
def champion_story_authoring_graph_v2() -> ExecutionGraphVersion:
return _champion_graph(story_authoring_graph_v2())