Skip to content

Commit fbad2a9

Browse files
authored
refactor(status): move lifecycle projections into bounded module (#2973)
1 parent 52d3caa commit fbad2a9

2 files changed

Lines changed: 138 additions & 46 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"""Goal lifecycle projections inside the `status` bounded context."""
2+
3+
from __future__ import annotations
4+
5+
from typing import Any
6+
7+
from ..runtime.run_compaction import (
8+
compact_controller_readiness,
9+
compact_human_reward,
10+
compact_operator_gate,
11+
)
12+
from ..work_items.attention_fields import (
13+
operator_gate_attention_fields as _operator_gate_attention_fields,
14+
readiness_attention_fields as _readiness_attention_fields,
15+
)
16+
from ..work_items.lifecycle import (
17+
goal_lifecycle_fields as _goal_lifecycle_fields,
18+
ordered_lifecycle_flags as _ordered_lifecycle_flags,
19+
primary_lifecycle_phase as _primary_lifecycle_phase,
20+
run_lifecycle_flags as _run_lifecycle_flags,
21+
run_lifecycle_phase as _run_lifecycle_phase,
22+
)
23+
from ...operator_gate import (
24+
DEFAULT_OPERATOR_GATE,
25+
normalize_operator_question,
26+
)
27+
28+
29+
CONNECTED_ADAPTER_STATUSES = {
30+
"connected",
31+
"connected-read-only",
32+
"pre-tick-runnable",
33+
}
34+
LIFECYCLE_PRIORITY = (
35+
"controller_ready",
36+
"reward_judged",
37+
"operator_approved",
38+
"controller_gated",
39+
"operator_gated",
40+
"adapter_inspected",
41+
"mapped",
42+
"refreshed",
43+
"connected",
44+
"registered",
45+
"planned",
46+
"run_recorded",
47+
)
48+
49+
50+
def ordered_lifecycle_flags(flags: list[str]) -> list[str]:
51+
return _ordered_lifecycle_flags(
52+
flags,
53+
lifecycle_priority=LIFECYCLE_PRIORITY,
54+
)
55+
56+
57+
def primary_lifecycle_phase(flags: list[str], fallback: str = "registered") -> str:
58+
return _primary_lifecycle_phase(
59+
flags,
60+
lifecycle_priority=LIFECYCLE_PRIORITY,
61+
fallback=fallback,
62+
)
63+
64+
65+
def run_lifecycle_flags(run: dict[str, Any] | None) -> list[str]:
66+
return _run_lifecycle_flags(
67+
run,
68+
lifecycle_priority=LIFECYCLE_PRIORITY,
69+
compact_human_reward=compact_human_reward,
70+
compact_operator_gate=compact_operator_gate,
71+
compact_controller_readiness=compact_controller_readiness,
72+
)
73+
74+
75+
def run_lifecycle_phase(run: dict[str, Any] | None) -> str:
76+
return _run_lifecycle_phase(
77+
run,
78+
lifecycle_priority=LIFECYCLE_PRIORITY,
79+
compact_human_reward=compact_human_reward,
80+
compact_operator_gate=compact_operator_gate,
81+
compact_controller_readiness=compact_controller_readiness,
82+
)
83+
84+
85+
def goal_lifecycle_fields(goal: dict[str, Any], current_run: dict[str, Any] | None) -> dict[str, Any]:
86+
return _goal_lifecycle_fields(
87+
goal,
88+
current_run,
89+
lifecycle_priority=LIFECYCLE_PRIORITY,
90+
connected_adapter_statuses=CONNECTED_ADAPTER_STATUSES,
91+
compact_human_reward=compact_human_reward,
92+
compact_operator_gate=compact_operator_gate,
93+
compact_controller_readiness=compact_controller_readiness,
94+
)
95+
96+
97+
def readiness_attention_fields(run: dict[str, Any] | None) -> dict[str, Any]:
98+
return _readiness_attention_fields(
99+
run,
100+
compact_controller_readiness=compact_controller_readiness,
101+
)
102+
103+
104+
def operator_gate_attention_fields(run: dict[str, Any] | None) -> dict[str, Any]:
105+
return _operator_gate_attention_fields(
106+
run,
107+
compact_operator_gate=compact_operator_gate,
108+
normalize_operator_question=normalize_operator_question,
109+
default_operator_gate=DEFAULT_OPERATOR_GATE,
110+
)

loopx/status.py

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
from .control_plane.work_items.attention_routing import (
9292
goal_attention as _goal_attention_read_model,
9393
)
94-
from .control_plane.work_items.attention_fields import (
95-
operator_gate_attention_fields as _operator_gate_attention_fields_read_model,
96-
readiness_attention_fields as _readiness_attention_fields_read_model,
97-
)
9894
from .control_plane.work_items.autonomous_replan_ack import (
9995
AUTONOMOUS_REPLAN_ACK_MATERIAL_RUN_WINDOW,
10096
compact_autonomous_replan_ack,
@@ -217,13 +213,6 @@
217213
from .control_plane.goals.goal_vision import (
218214
compact_goal_vision_packet as _compact_goal_vision_packet_read_model,
219215
)
220-
from .control_plane.work_items.lifecycle import (
221-
goal_lifecycle_fields as _goal_lifecycle_fields_read_model,
222-
ordered_lifecycle_flags as _ordered_lifecycle_flags_read_model,
223-
primary_lifecycle_phase as _primary_lifecycle_phase_read_model,
224-
run_lifecycle_flags as _run_lifecycle_flags_read_model,
225-
run_lifecycle_phase as _run_lifecycle_phase_read_model,
226-
)
227216
from .control_plane.runtime.session_runtime import (
228217
compact_session_runtime_projection_from_run,
229218
legacy_runtime_goal_attention as _legacy_runtime_goal_attention_read_model,
@@ -2619,67 +2608,60 @@ def latest_run(goal: dict[str, Any]) -> dict[str, Any] | None:
26192608

26202609

26212610
def ordered_lifecycle_flags(flags: list[str]) -> list[str]:
2622-
return _ordered_lifecycle_flags_read_model(
2623-
flags,
2624-
lifecycle_priority=LIFECYCLE_PRIORITY,
2611+
from .control_plane.status.lifecycle_projection import (
2612+
ordered_lifecycle_flags as _ordered_lifecycle_flags,
26252613
)
26262614

2615+
return _ordered_lifecycle_flags(flags)
2616+
26272617

26282618
def primary_lifecycle_phase(flags: list[str], fallback: str = "registered") -> str:
2629-
return _primary_lifecycle_phase_read_model(
2630-
flags,
2631-
lifecycle_priority=LIFECYCLE_PRIORITY,
2632-
fallback=fallback,
2619+
from .control_plane.status.lifecycle_projection import (
2620+
primary_lifecycle_phase as _primary_lifecycle_phase,
26332621
)
26342622

2623+
return _primary_lifecycle_phase(flags, fallback=fallback)
2624+
26352625

26362626
def run_lifecycle_flags(run: dict[str, Any] | None) -> list[str]:
2637-
return _run_lifecycle_flags_read_model(
2638-
run,
2639-
lifecycle_priority=LIFECYCLE_PRIORITY,
2640-
compact_human_reward=compact_human_reward,
2641-
compact_operator_gate=compact_operator_gate,
2642-
compact_controller_readiness=compact_controller_readiness,
2627+
from .control_plane.status.lifecycle_projection import (
2628+
run_lifecycle_flags as _run_lifecycle_flags,
26432629
)
26442630

2631+
return _run_lifecycle_flags(run)
2632+
26452633

26462634
def run_lifecycle_phase(run: dict[str, Any] | None) -> str:
2647-
return _run_lifecycle_phase_read_model(
2648-
run,
2649-
lifecycle_priority=LIFECYCLE_PRIORITY,
2650-
compact_human_reward=compact_human_reward,
2651-
compact_operator_gate=compact_operator_gate,
2652-
compact_controller_readiness=compact_controller_readiness,
2635+
from .control_plane.status.lifecycle_projection import (
2636+
run_lifecycle_phase as _run_lifecycle_phase,
26532637
)
26542638

2639+
return _run_lifecycle_phase(run)
2640+
26552641

26562642
def goal_lifecycle_fields(goal: dict[str, Any], current_run: dict[str, Any] | None) -> dict[str, Any]:
2657-
return _goal_lifecycle_fields_read_model(
2658-
goal,
2659-
current_run,
2660-
lifecycle_priority=LIFECYCLE_PRIORITY,
2661-
connected_adapter_statuses=CONNECTED_ADAPTER_STATUSES,
2662-
compact_human_reward=compact_human_reward,
2663-
compact_operator_gate=compact_operator_gate,
2664-
compact_controller_readiness=compact_controller_readiness,
2643+
from .control_plane.status.lifecycle_projection import (
2644+
goal_lifecycle_fields as _goal_lifecycle_fields,
26652645
)
26662646

2647+
return _goal_lifecycle_fields(goal, current_run)
2648+
26672649

26682650
def readiness_attention_fields(run: dict[str, Any] | None) -> dict[str, Any]:
2669-
return _readiness_attention_fields_read_model(
2670-
run,
2671-
compact_controller_readiness=compact_controller_readiness,
2651+
from .control_plane.status.lifecycle_projection import (
2652+
readiness_attention_fields as _readiness_attention_fields,
26722653
)
26732654

2655+
return _readiness_attention_fields(run)
2656+
26742657

26752658
def operator_gate_attention_fields(run: dict[str, Any] | None) -> dict[str, Any]:
2676-
return _operator_gate_attention_fields_read_model(
2677-
run,
2678-
compact_operator_gate=compact_operator_gate,
2679-
normalize_operator_question=normalize_operator_question,
2680-
default_operator_gate=DEFAULT_OPERATOR_GATE,
2659+
from .control_plane.status.lifecycle_projection import (
2660+
operator_gate_attention_fields as _operator_gate_attention_fields,
26812661
)
26822662

2663+
return _operator_gate_attention_fields(run)
2664+
26832665

26842666
def compact_server_planning_contract(value: Any) -> dict[str, Any]:
26852667
return _compact_server_planning_contract_read_model(

0 commit comments

Comments
 (0)