Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions loopx/control_plane/status/attention_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from collections.abc import Sequence
from typing import Any

from ..todos.contract import (
Expand All @@ -14,6 +15,8 @@
todo_item_is_actionable_open,
)
from ..work_items.attention_queue import (
AttentionQueueItem,
AttentionQueueProjection,
build_attention_queue_projection as _build_attention_queue_projection,
)
from ..work_items.autonomous_candidates import (
Expand Down Expand Up @@ -60,11 +63,11 @@ def autonomous_monitor_candidates(

def build_attention_queue_projection(
*,
items: list[dict[str, Any]],
items: Sequence[AttentionQueueItem],
goal_id_filter: str | None,
autonomous_backlog_candidates: dict[str, Any] | None,
autonomous_monitor_candidates: dict[str, Any] | None,
) -> dict[str, Any]:
autonomous_backlog_candidates: dict[str, object] | None,
autonomous_monitor_candidates: dict[str, object] | None,
) -> AttentionQueueProjection:
return _build_attention_queue_projection(
items=items,
goal_id_filter=goal_id_filter,
Expand Down
7 changes: 4 additions & 3 deletions loopx/control_plane/status/goal_attention_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any
from typing import Any, Literal, get_args

from ...operator_gate import (
DEFAULT_OPERATOR_GATE,
Expand Down Expand Up @@ -47,12 +47,13 @@
PLANNED_CONTROLLER_OPT_IN_RECOMMENDED_ACTION = (
"先在 LoopX 完成 operator 判断;同意后项目 Agent 只执行 read-only map dry-run"
)
REGISTRY_WAITING_ON_OVERRIDES = {
RegistryWaitingOnOverride = Literal[
"user_or_controller",
"controller",
"codex",
"external_evidence",
}
]
REGISTRY_WAITING_ON_OVERRIDES = set(get_args(RegistryWaitingOnOverride))
LEGACY_EXTERNAL_EVIDENCE_CLASSIFICATION_PREFIXES = (
"await_",
"external_evidence_observation_",
Expand Down
5 changes: 3 additions & 2 deletions loopx/control_plane/status/monitor_display_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any
from typing import Any, Literal

from ..scheduler.monitor_display import (
attention_item_is_monitor_quiet_display_candidate as _attention_item_is_monitor_quiet_display_candidate,
Expand All @@ -29,7 +29,8 @@
"No immediate agent work; keep the monitor quiet until a material monitor "
"transition, regression, or concrete blocker appears."
)
MONITOR_SIGNAL_WAITING_ON = "monitor_signal"
MonitorSignalWaitingOn = Literal["monitor_signal"]
MONITOR_SIGNAL_WAITING_ON: MonitorSignalWaitingOn = "monitor_signal"


def build_project_asset(
Expand Down
34 changes: 26 additions & 8 deletions loopx/control_plane/work_items/attention_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
from ..goals.legacy_event_source import RetiredTodoEventSourceError
from .attention_queue_types import (
ACTIONABLE_REGISTRY_SEVERITIES as ACTIONABLE_REGISTRY_SEVERITIES,
ATTENTION_WAITING_ON_VALUES as ATTENTION_WAITING_ON_VALUES,
USER_OR_CONTROLLER_WAIT_STATES as USER_OR_CONTROLLER_WAIT_STATES,
ActiveStateProjectAssetAttacher as ActiveStateProjectAssetAttacher,
ActiveStateTodoAttentionBuilder as ActiveStateTodoAttentionBuilder,
ActiveStateTodoFieldsBuilder as ActiveStateTodoFieldsBuilder,
AttentionItemBuilder as AttentionItemBuilder,
AttentionQueueContext as AttentionQueueContext,
AttentionQueueCounts as AttentionQueueCounts,
AttentionQueueItem as AttentionQueueItem,
AttentionQueueProjection as AttentionQueueProjection,
AttentionWaitingOn as AttentionWaitingOn,
EnrichProjectAssetFn as EnrichProjectAssetFn,
ExternalProgressReviewLoader as ExternalProgressReviewLoader,
GlobalRegistryFindingSeverity as GlobalRegistryFindingSeverity,
GlobalRegistryShadowAttacher as GlobalRegistryShadowAttacher,
GoalChannelProjectionAttacher as GoalChannelProjectionAttacher,
LatestRunRecommendedActionBuilder as LatestRunRecommendedActionBuilder,
Expand Down Expand Up @@ -99,12 +99,12 @@ def merge_global_registry_findings(

def build_attention_queue_projection(
*,
items: list[dict[str, object]],
items: Sequence[AttentionQueueItem],
goal_id_filter: str | None,
autonomous_backlog_candidates: dict[str, object] | None,
autonomous_monitor_candidates: dict[str, object] | None,
monitor_signal_waiting_on: str,
) -> dict[str, object]:
) -> AttentionQueueProjection:
needs_user_or_controller = 0
needs_controller = 0
needs_codex = 0
Expand All @@ -123,15 +123,16 @@ def build_attention_queue_projection(
if waiting_on == monitor_signal_waiting_on:
watching_monitor += 1

queue: dict[str, object] = {
queue_items = items if isinstance(items, list) else list(items)
queue: AttentionQueueProjection = {
"available": True,
"item_count": len(items),
"needs_user_or_controller": needs_user_or_controller,
"needs_controller": needs_controller,
"needs_codex": needs_codex,
"watching_external_evidence": watching_external_evidence,
"watching_monitor": watching_monitor,
"items": items,
"items": queue_items,
}
if goal_id_filter:
queue["goal_filter"] = goal_id_filter
Expand Down Expand Up @@ -449,6 +450,21 @@ def _build_goal_attention_item(
return item


def _validated_queue_items(
items: Sequence[dict[str, object]],
*,
monitor_signal_waiting_on: str,
) -> list[AttentionQueueItem]:
validated: list[AttentionQueueItem] = []
allowed = ATTENTION_WAITING_ON_VALUES | {monitor_signal_waiting_on}
for item in items:
waiting_on = item["waiting_on"]
if not isinstance(waiting_on, str) or waiting_on not in allowed:
raise ValueError(f"unsupported attention queue waiting_on: {waiting_on!r}")
validated.append(cast(AttentionQueueItem, item))
return validated


def build_attention_queue(
*,
contract: dict[str, object],
Expand All @@ -461,7 +477,7 @@ def build_attention_queue(
include_stopped_goal_context: bool = False,
include_goal_channel_projection: bool = True,
agent_lane_id: str | None = None,
) -> dict[str, object]:
) -> AttentionQueueProjection:
"""Build the executable attention queue or a stopped-Goal archive view.

Normal callers omit stopped Goals because they must never become runnable
Expand Down Expand Up @@ -522,7 +538,9 @@ def build_attention_queue(
monitor_candidates = context.autonomous_monitor_candidates(items)

return build_attention_queue_projection(
items=items,
items=_validated_queue_items(
items, monitor_signal_waiting_on=context.monitor_signal_waiting_on
),
goal_id_filter=goal_id_filter,
autonomous_backlog_candidates=backlog_candidates,
autonomous_monitor_candidates=monitor_candidates,
Expand Down
86 changes: 65 additions & 21 deletions loopx/control_plane/work_items/attention_queue_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,86 @@
from collections.abc import Callable, Set as AbstractSet
from dataclasses import dataclass
from pathlib import Path
from typing import Literal, Protocol, TypedDict
from typing import Literal, NotRequired, Protocol, TypedDict, get_args

AttentionWaitingOn = Literal[
"user_or_controller",
"controller",
"codex",
"external_evidence",
]
GlobalRegistryFindingSeverity = Literal["high", "action"]
from ..status.goal_attention_projection import RegistryWaitingOnOverride
from ..status.monitor_display_projection import MonitorSignalWaitingOn

AttentionWaitingOn = Literal[RegistryWaitingOnOverride, MonitorSignalWaitingOn]
ATTENTION_WAITING_ON_VALUES: frozenset[str] = frozenset(get_args(AttentionWaitingOn))

USER_OR_CONTROLLER_WAIT_STATES: frozenset[str] = frozenset(
{"user_or_controller", "controller"}
)
ACTIONABLE_REGISTRY_SEVERITIES: frozenset[str] = frozenset({"high", "action"})


class AttentionQueueCounts(TypedDict):
"""Bucket counts emitted alongside attention queue items."""
class AttentionQueueItem(TypedDict):
"""Typed bucket entry and projected work item for the attention queue."""

waiting_on: AttentionWaitingOn
goal_id: NotRequired[str]
status: NotRequired[str]
severity: NotRequired[str]
recommended_action: NotRequired[str]
source: NotRequired[str]
project_asset: NotRequired[dict[str, object]]
quota: NotRequired[dict[str, object]]
user_todos: NotRequired[dict[str, object]]
agent_todos: NotRequired[dict[str, object]]
todo_state_file: NotRequired[str]
todo_source: NotRequired[str]
activation_state: NotRequired[str]
operator_question: NotRequired[str]
agent_command: NotRequired[str]
controller_stage: NotRequired[str]
missing_gates: NotRequired[list[str]]
next_handoff_condition: NotRequired[str]
lifecycle_phase: NotRequired[str]
lifecycle_flags: NotRequired[list[str]]
dreaming_proposal: NotRequired[dict[str, object]]
dreaming_lane_badge: NotRequired[dict[str, object]]
session_runtime_projection: NotRequired[dict[str, object]]
shadow_finding: NotRequired[object]
latest_run_recommended_action: NotRequired[str]
latest_run_recommended_action_source: NotRequired[str]
autonomous_replan_ack: NotRequired[dict[str, object]]
control_plane: NotRequired[dict[str, object]]
agent_lane_recommendation: NotRequired[dict[str, object]]
stale_latest_run_warning: NotRequired[dict[str, object]]
task_graph_projection: NotRequired[dict[str, object]]
evidence_log_read_receipts: NotRequired[object]
external_progress_review: NotRequired[dict[str, object]]
error_code: NotRequired[str]
authority_read: NotRequired[dict[str, object]]
state_incomplete: NotRequired[dict[str, object]]
execution_waiting_on: NotRequired[str]
monitor_display: NotRequired[dict[str, object]]
goal_objective: NotRequired[object]
active_state_next_action: NotRequired[object]
handoff_readiness: NotRequired[dict[str, object]]
dependency_blockers: NotRequired[list[dict[str, object]]]
agent_lane_id: NotRequired[str]
goal_channel_projection: NotRequired[dict[str, object]]
handoff_mode: NotRequired[str]
long_task_cadence_hint: NotRequired[dict[str, object]]


class AttentionQueueProjection(TypedDict):
"""Structured shape of the serialized ``attention_queue`` projection."""

available: bool
item_count: int
needs_user_or_controller: int
needs_controller: int
needs_codex: int
watching_external_evidence: int
watching_monitor: int


class AttentionQueueProjection(AttentionQueueCounts, total=False):
"""Structured shape of the serialized ``attention_queue`` projection."""

available: bool
items: list[dict[str, object]]
goal_filter: str
goal_filter_applied: bool
autonomous_backlog_candidates: dict[str, object]
autonomous_monitor_candidates: dict[str, object]
items: list[AttentionQueueItem]
goal_filter: NotRequired[str]
goal_filter_applied: NotRequired[bool]
autonomous_backlog_candidates: NotRequired[dict[str, object]]
autonomous_monitor_candidates: NotRequired[dict[str, object]]


class AttentionItemBuilder(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion loopx/control_plane/work_items/attention_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Optional[dict[str, Any]],
]
OperatorQuestionBuilder = Callable[[str, str], str]
OperatorQuestionNormalizer = Callable[..., str]
OperatorQuestionNormalizer = Callable[..., str | None]
RunHasExternalEvidenceWatchSignal = Callable[[dict[str, Any]], bool]
SessionRuntimeProjectionFromRun = Callable[[Optional[dict[str, Any]]], Optional[dict[str, Any]]]
PublicSafeText = Callable[..., Optional[str]]
Expand Down
8 changes: 4 additions & 4 deletions loopx/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
attention_item as _attention_item_read_model,
)
from .control_plane.work_items.attention_queue import (
AttentionQueueContext,
AttentionQueueContext, AttentionQueueItem, AttentionQueueProjection,
build_attention_queue as _build_attention_queue_read_model,
)
from .control_plane.work_items.autonomous_replan_ack import (
Expand Down Expand Up @@ -477,11 +477,11 @@ def autonomous_monitor_candidates(

def build_attention_queue_projection(
*,
items: list[dict[str, object]],
items: Sequence[AttentionQueueItem],
goal_id_filter: str | None,
autonomous_backlog_candidates: dict[str, object] | None,
autonomous_monitor_candidates: dict[str, object] | None,
) -> dict[str, object]:
) -> AttentionQueueProjection:
from .control_plane.status.attention_projection import (
build_attention_queue_projection as _build_attention_queue_projection,
)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def build_attention_queue(
include_goal_channel_projection: bool = True,
tolerate_malformed_settlement_history: bool = False,
agent_lane_id: str | None = None,
) -> dict[str, object]:
) -> AttentionQueueProjection:
def request_active_state_todo_fields(
goal: dict[str, object],
*,
Expand Down
Loading
Loading