Skip to content

Commit c90fcc9

Browse files
committed
refactor(status): move run projections into bounded module
1 parent 7524d31 commit c90fcc9

2 files changed

Lines changed: 91 additions & 28 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""Run lifecycle projections inside the `status` bounded context."""
2+
3+
from __future__ import annotations
4+
5+
from typing import Any
6+
7+
from ...history import STATUS_NEUTRAL_CLASSIFICATIONS
8+
from ...state_projection import actions_are_projection_aligned
9+
from ..agents.agent_lane_recommendation import (
10+
compact_agent_lane_recommendation as _compact_agent_lane_recommendation,
11+
is_status_neutral_run as _is_status_neutral_run,
12+
latest_agent_lane_run as _latest_agent_lane_run,
13+
latest_run_recommended_action_for_projection as _latest_run_recommended_action_for_projection,
14+
)
15+
from ..runtime.public_safety import public_safe_compact_text
16+
from ..runtime.run_history import latest_run as _latest_run
17+
from ..runtime.time import parse_timestamp
18+
19+
20+
AGENT_LANE_PROGRESS_SCOPE = "agent_lane"
21+
22+
23+
def is_status_neutral_run(run: dict[str, Any]) -> bool:
24+
return _is_status_neutral_run(
25+
run,
26+
status_neutral_classifications=STATUS_NEUTRAL_CLASSIFICATIONS,
27+
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
28+
)
29+
30+
31+
def latest_agent_lane_run(goal: dict[str, Any]) -> dict[str, Any] | None:
32+
return _latest_agent_lane_run(
33+
goal,
34+
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
35+
)
36+
37+
38+
def compact_agent_lane_recommendation(run: dict[str, Any] | None) -> dict[str, Any] | None:
39+
return _compact_agent_lane_recommendation(
40+
run,
41+
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
42+
public_safe_compact_text=public_safe_compact_text,
43+
)
44+
45+
46+
def latest_run_recommended_action_for_projection(
47+
*,
48+
current_status_run: dict[str, Any] | None,
49+
agent_lane_recommendation: dict[str, Any] | None,
50+
active_state_next_action: Any = None,
51+
preferred_agent_id: str | None = None,
52+
limit: int = 320,
53+
) -> tuple[str | None, str | None]:
54+
return _latest_run_recommended_action_for_projection(
55+
current_status_run=current_status_run,
56+
agent_lane_recommendation=agent_lane_recommendation,
57+
active_state_next_action=active_state_next_action,
58+
preferred_agent_id=preferred_agent_id,
59+
limit=limit,
60+
public_safe_compact_text=public_safe_compact_text,
61+
actions_are_projection_aligned=actions_are_projection_aligned,
62+
parse_timestamp=parse_timestamp,
63+
)
64+
65+
66+
def latest_run(goal: dict[str, Any]) -> dict[str, Any] | None:
67+
return _latest_run(
68+
goal,
69+
is_status_neutral_run=is_status_neutral_run,
70+
)

loopx/status.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@
7070
from .control_plane.work_items.autonomous_candidates import (
7171
MAX_AUTONOMOUS_TODO_CANDIDATES as _MAX_AUTONOMOUS_TODO_CANDIDATES,
7272
)
73-
from .control_plane.agents.agent_lane_recommendation import (
74-
compact_agent_lane_recommendation as _compact_agent_lane_recommendation_read_model,
75-
is_status_neutral_run as _is_status_neutral_run_read_model,
76-
latest_agent_lane_run as _latest_agent_lane_run_read_model,
77-
latest_run_recommended_action_for_projection as _latest_run_recommended_action_for_projection_read_model,
78-
)
7973
from .control_plane.goals.active_state_metadata import (
8074
parse_state_frontmatter,
8175
)
@@ -196,9 +190,6 @@
196190
worker_bridge_ingest_health_note,
197191
)
198192
from .control_plane.runtime.time import parse_timestamp
199-
from .control_plane.runtime.run_history import (
200-
latest_run as _latest_run_read_model,
201-
)
202193
from .control_plane.runtime.decision_freshness import (
203194
DECISION_FRESHNESS_CLASSIFICATION_PREFIXES,
204195
DECISION_FRESHNESS_ITEM_LIMIT,
@@ -288,7 +279,6 @@
288279
from .rollout_event_log import load_rollout_events, rollout_event_log_path
289280
from .state_projection import (
290281
active_state_next_action_entries,
291-
actions_are_projection_aligned,
292282
next_action_projection_warning,
293283
state_projection_gap_warning,
294284
)
@@ -2576,27 +2566,28 @@ def collect_global_registry_health(
25762566

25772567

25782568
def is_status_neutral_run(run: dict[str, Any]) -> bool:
2579-
return _is_status_neutral_run_read_model(
2580-
run,
2581-
status_neutral_classifications=STATUS_NEUTRAL_CLASSIFICATIONS,
2582-
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
2569+
from .control_plane.status.run_projection import (
2570+
is_status_neutral_run as _is_status_neutral_run,
25832571
)
25842572

2573+
return _is_status_neutral_run(run)
2574+
25852575

25862576
def latest_agent_lane_run(goal: dict[str, Any]) -> dict[str, Any] | None:
2587-
return _latest_agent_lane_run_read_model(
2588-
goal,
2589-
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
2577+
from .control_plane.status.run_projection import (
2578+
latest_agent_lane_run as _latest_agent_lane_run,
25902579
)
25912580

2581+
return _latest_agent_lane_run(goal)
2582+
25922583

25932584
def compact_agent_lane_recommendation(run: dict[str, Any] | None) -> dict[str, Any] | None:
2594-
return _compact_agent_lane_recommendation_read_model(
2595-
run,
2596-
agent_lane_progress_scope=AGENT_LANE_PROGRESS_SCOPE,
2597-
public_safe_compact_text=public_safe_compact_text,
2585+
from .control_plane.status.run_projection import (
2586+
compact_agent_lane_recommendation as _compact_agent_lane_recommendation,
25982587
)
25992588

2589+
return _compact_agent_lane_recommendation(run)
2590+
26002591

26012592
def latest_run_recommended_action_for_projection(
26022593
*,
@@ -2606,24 +2597,26 @@ def latest_run_recommended_action_for_projection(
26062597
preferred_agent_id: str | None = None,
26072598
limit: int = 320,
26082599
) -> tuple[str | None, str | None]:
2609-
return _latest_run_recommended_action_for_projection_read_model(
2600+
from .control_plane.status.run_projection import (
2601+
latest_run_recommended_action_for_projection as _latest_run_recommended_action_for_projection,
2602+
)
2603+
2604+
return _latest_run_recommended_action_for_projection(
26102605
current_status_run=current_status_run,
26112606
agent_lane_recommendation=agent_lane_recommendation,
26122607
active_state_next_action=active_state_next_action,
26132608
preferred_agent_id=preferred_agent_id,
26142609
limit=limit,
2615-
public_safe_compact_text=public_safe_compact_text,
2616-
actions_are_projection_aligned=actions_are_projection_aligned,
2617-
parse_timestamp=parse_timestamp,
26182610
)
26192611

26202612

26212613
def latest_run(goal: dict[str, Any]) -> dict[str, Any] | None:
2622-
return _latest_run_read_model(
2623-
goal,
2624-
is_status_neutral_run=is_status_neutral_run,
2614+
from .control_plane.status.run_projection import (
2615+
latest_run as _latest_run,
26252616
)
26262617

2618+
return _latest_run(goal)
2619+
26272620

26282621
def ordered_lifecycle_flags(flags: list[str]) -> list[str]:
26292622
return _ordered_lifecycle_flags_read_model(

0 commit comments

Comments
 (0)