(
self,
phase: str,
thought: str,
session_id: str = "",
is_revision: bool = False,
revises_phase: str = "",
confidence: float = 1.0,
phase_data: dict | list | None = None,
)
| 127 | return self._sessions.get(session_id) |
| 128 | |
| 129 | def process_phase( |
| 130 | self, |
| 131 | phase: str, |
| 132 | thought: str, |
| 133 | session_id: str = "", |
| 134 | is_revision: bool = False, |
| 135 | revises_phase: str = "", |
| 136 | confidence: float = 1.0, |
| 137 | phase_data: dict | list | None = None, |
| 138 | ) -> dict: |
| 139 | if session_id and session_id in self._sessions: |
| 140 | session = self._sessions[session_id] |
| 141 | else: |
| 142 | sid = session_id if session_id else uuid.uuid4().hex[:12] |
| 143 | session = PlanningSession(sid) |
| 144 | self._sessions[sid] = session |
| 145 | |
| 146 | target = revises_phase if is_revision and revises_phase else phase |
| 147 | if target not in PHASE_NAMES: |
| 148 | return {"error": f"Unknown phase: {target}. Valid: {', '.join(PHASE_NAMES)}"} |
| 149 | |
| 150 | if target in _ACCUMULATIVE_LIST_PHASES: |
| 151 | if is_revision: |
| 152 | session.phases[target] = PhaseRecord( |
| 153 | phase=target, thought=thought, |
| 154 | data=[phase_data] if not isinstance(phase_data, list) else phase_data, |
| 155 | confidence=confidence, |
| 156 | ) |
| 157 | elif target in session.phases and isinstance(session.phases[target].data, list): |
| 158 | session.phases[target].data.append(phase_data) |
| 159 | session.phases[target].thought = thought |
| 160 | session.phases[target].confidence = confidence |
| 161 | else: |
| 162 | session.phases[target] = PhaseRecord( |
| 163 | phase=target, thought=thought, data=[phase_data], confidence=confidence, |
| 164 | ) |
| 165 | elif target == _MERGE_STRATEGY_PHASE: |
| 166 | existing = session.phases.get(target) |
| 167 | if is_revision: |
| 168 | session.phases[target] = PhaseRecord( |
| 169 | phase=target, thought=thought, data=phase_data, confidence=confidence, |
| 170 | ) |
| 171 | elif existing and isinstance(existing.data, dict) and isinstance(phase_data, dict): |
| 172 | existing.data.setdefault("search_terms", []).extend(phase_data.get("search_terms", [])) |
| 173 | if phase_data.get("approach"): |
| 174 | existing.data["approach"] = phase_data["approach"] |
| 175 | if phase_data.get("fallback_plan"): |
| 176 | existing.data["fallback_plan"] = phase_data["fallback_plan"] |
| 177 | existing.thought = thought |
| 178 | existing.confidence = confidence |
| 179 | else: |
| 180 | session.phases[target] = PhaseRecord( |
| 181 | phase=target, thought=thought, data=phase_data, confidence=confidence, |
| 182 | ) |
| 183 | else: |
| 184 | session.phases[target] = PhaseRecord( |
| 185 | phase=target, thought=thought, data=phase_data, confidence=confidence, |
| 186 | ) |
no test coverage detected