Coverage for src/orchestration/types.py: 0%

1"""Shared types for orchestrator components.

2

3 This module contains dataclasses and constants shared between

4 orchestrator.py and orchestrator_factory.py to break circular imports.

5

6 Design principles:

7- OrchestratorConfig: All scalar configuration (timeouts, flags, limits)

8- OrchestratorDependencies: All protocol implementations (DI for testability)

9- _DerivedConfig: Internal computed configuration values

10- DEFAULT_AGENT_TIMEOUT_MINUTES: Default timeout constant

11"""

12

13 from __future__ import annotations

14

15 from dataclasses import dataclass

16 from pathlib import Path # noqa: TC003 - needed at runtime for dataclass field

17 from typing import TYPE_CHECKING

18

19 if TYPE_CHECKING:

20 from src.core.protocols import (

21 CodeReviewer,

22 GateChecker,

23 IssueProvider,

24 LogProvider,

25 MalaEventSink,

26 )

27 from src.infra.telemetry import TelemetryProvider

28

29# Default timeout for agent execution (protects against hung MCP server subprocesses)

30 DEFAULT_AGENT_TIMEOUT_MINUTES = 60

31

32

33@dataclass

34 class OrchestratorConfig:

35 """Configuration for MalaOrchestrator.

36

37 All scalar configuration values that control orchestrator behavior.

38 These are typically derived from CLI arguments or environment.

39

40 Attributes:

41 repo_path: Path to the repository with beads issues.

42 max_agents: Maximum concurrent agents (None = unlimited).

43 timeout_minutes: Timeout per agent in minutes (None = default 60).

44 max_issues: Maximum issues to process (None = unlimited).

45 epic_id: Only process tasks under this epic.

46 only_ids: Comma-separated list of issue IDs to process exclusively.

47 braintrust_enabled: Enable Braintrust tracing.

48 max_gate_retries: Maximum quality gate retry attempts per issue.

49 max_review_retries: Maximum code review retry attempts per issue.

50 disable_validations: Set of validation types to disable.

51 coverage_threshold: Minimum coverage percentage (None = no-decrease mode).

52 prioritize_wip: Prioritize in_progress issues before open issues.

53 focus: Group tasks by epic for focused work.

54 cli_args: CLI arguments for logging and metadata.

55 epic_override_ids: Epic IDs to close without verification.

56 orphans_only: Only process issues with no parent epic.

57 context_restart_threshold: Ratio (0.0-1.0) at which to restart agent.

58 context_limit: Maximum context tokens (default 200K for Claude).

59 """

60

61 repo_path: Path

62 max_agents: int | None = None

63 timeout_minutes: int | None = None

64 max_issues: int | None = None

65 epic_id: str | None = None

66 only_ids: set[str] | None = None

67 braintrust_enabled: bool | None = None

68 max_gate_retries: int = 3

69 max_review_retries: int = 3

70 disable_validations: set[str] | None = None

71 coverage_threshold: float | None = None

72 prioritize_wip: bool = False

73 focus: bool = True

74 cli_args: dict[str, object] | None = None

75 epic_override_ids: set[str] | None = None

76 orphans_only: bool = False

77 # Context exhaustion handling thresholds

78 context_restart_threshold: float = 0.90

79 context_limit: int = 200_000

80

81

82@dataclass

83 class OrchestratorDependencies:

84 """Protocol implementations for MalaOrchestrator.

85

86 All injected dependencies that implement the orchestrator's protocols.

87 When None, the factory creates default implementations.

88

89 Note: AgentSessionRunner is NOT included here because it's constructed

90 per-issue in run_implementer with issue-specific callbacks.

91

92 Attributes:

93 issue_provider: IssueProvider for issue tracking operations.

94 code_reviewer: CodeReviewer for post-commit code reviews.

95 gate_checker: GateChecker for quality gate validation.

96 log_provider: LogProvider for session log access.

97 telemetry_provider: TelemetryProvider for tracing.

98 event_sink: MalaEventSink for run lifecycle logging.

99 """

100

101 issue_provider: IssueProvider | None = None

102 code_reviewer: CodeReviewer | None = None

103 gate_checker: GateChecker | None = None

104 log_provider: LogProvider | None = None

105 telemetry_provider: TelemetryProvider | None = None

106 event_sink: MalaEventSink | None = None

107

108

109@dataclass

110 class _DerivedConfig:

111 """Derived configuration values computed from OrchestratorConfig and MalaConfig.

112

113 Internal class used to pass computed values to the orchestrator.

114 """

115

116 timeout_seconds: int

117 braintrust_enabled: bool

118 disabled_validations: set[str]

119 review_disabled_reason: str | None = None

120 braintrust_disabled_reason: str | None = None