Commit b521d71
authored
* feat(core): route 4 remaining provider sites through llm_resolution chain (#861)
Follow-up to #768 (PR #860) which introduced codeframe/core/llm_resolution.py
as the single source of truth for the provider chain
(CODEFRAME_LLM_PROVIDER -> .codeframe/config.yaml -> anthropic).
Four code paths still constructed providers directly, bypassing the chain.
Sites migrated:
- codeframe/core/conductor.py:SupervisorResolver.llm -- was get_provider()
(bare -> anthropic). Concrete failure fixed: cf work batch run --strategy auto
--llm-provider ollama now uses ollama for blocker auto-resolution instead
of demanding an Anthropic key downstream of a passing pre-flight.
- codeframe/core/dependency_analyzer.py:analyze_dependencies -- the private
_get_default_provider() helper (hardcoded AnthropicProvider + ValueError on
missing key) is dropped; the call site now inlines
create_provider(resolve_llm_settings(workspace.repo_path)) when provider=None.
- codeframe/core/prd_discovery.py:PrdDiscoverySession.__post_init__ -- api_key
remains as a backward-compat field (constructs AnthropicProvider when set,
preserving every existing caller). When api_key is unset the chain is used.
The missing-key check is generalized via LLMSettings.required_key_env so
the existing NoApiKeyError contract is preserved AND extended to any keyed
provider (not just Anthropic).
- codeframe/core/adapters/streaming_chat.py:StreamingChatAdapter -- the
no-provider fallback (used only by tests/external callers; production
session_chat_ws.py already passes provider= explicitly) now uses the chain.
The vestigial api_key parameter is kept for backward compat.
Regression coverage: tests/core/test_provider_resolution_chain.py adds one
test class per site (9 tests total) mirroring the reference pattern in
tests/ui/test_discovery_generate_tasks.py -- set CODEFRAME_LLM_PROVIDER=ollama,
delete ANTHROPIC_API_KEY, mock create_provider, assert the chain is invoked
and the resulting provider is the one used.
All existing tests in the 4 affected areas pass unchanged (67+17=84 tests).
* fix(streaming-chat): preserve api_key= legacy contract + tighten regression tests
Addresses cross-family review (opencode/GLM) on PR for #861:
Major 1 + Major 2: streaming_chat docstring lied about api_key behavior, and
the api_key= legacy contract was asymmetric with PrdDiscoverySession (which
preserves it). Restore the legacy branch: when api_key is set AND provider
is None, construct AnthropicProvider(api_key=...) — mirroring prd_discovery.
Update docstring to describe the new contract accurately.
Suggestion 1: test_explicit_provider_skips_chain for dependency_analyzer
previously passed task_ids=[] which hit the early-return at line ~63 before
the provider was ever consulted. Seed a task and assert explicit_provider.complete
was actually called, so the test fails if explicit-provider handling breaks.
Nitpick 2: lock in model_flag= propagation in streaming_chat (the only site
that threads model into resolve_llm_settings) via an assertion on settings.model.
New test_legacy_api_key_skips_chain locks in the Major 2 fix. Total tests:
10 (was 9).
* chore: gitignore .opencode-tmp scratch dir (review artifacts)
* fix(tests): patch llm_resolution.create_provider in prd_generate CLI tests
The 8 CLI tests in tests/cli/test_prd_generate.py patched
codeframe.core.prd_discovery.AnthropicProvider to substitute a mock LLM.
After #861 migrated PrdDiscoverySession to use the shared llm_resolution
chain, the construction path moved to create_provider -> get_provider ->
codeframe.adapters.llm.anthropic.AnthropicProvider, which the existing
patch target didn't intercept. CI surfaced this as 401 'invalid x-api-key'
errors reaching the real Anthropic API.
Fix: retarget the patch to codeframe.core.llm_resolution.create_provider
across all 8 affected test methods. The mock setup pattern is unchanged
(mock.return_value = mock_llm_provider); only the patch site moved.
This is a contract change documented in issue #861 (PrdDiscoverySession
now resolves via the shared chain) — test patches are updated to reflect
the new contract, per the anti-mutation rule's allowance for documented
contract changes.
* docs(prd-discovery): mark api_key as optional in class docstring
Per claude[bot] review on PR #874: the PrdDiscoverySession class docstring
still claimed api_key is 'required' even though #861 made it optional (when
unset, the provider is resolved via the llm_resolution chain). Aligns with
the streaming_chat docstring fix from the same migration.
1 parent a46f413 commit b521d71
7 files changed
Lines changed: 356 additions & 50 deletions
File tree
- codeframe/core
- adapters
- tests
- cli
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
177 | 183 | | |
178 | 184 | | |
179 | | - | |
180 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
181 | 188 | | |
182 | 189 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
190 | 206 | | |
191 | 207 | | |
192 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
123 | 127 | | |
124 | | - | |
125 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
211 | 214 | | |
212 | 215 | | |
213 | 216 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
226 | 229 | | |
227 | 230 | | |
228 | 231 | | |
| |||
239 | 242 | | |
240 | 243 | | |
241 | 244 | | |
242 | | - | |
243 | | - | |
244 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
245 | 266 | | |
246 | | - | |
| 267 | + | |
| 268 | + | |
247 | 269 | | |
248 | 270 | | |
249 | | - | |
250 | | - | |
| 271 | + | |
251 | 272 | | |
252 | 273 | | |
253 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
| 405 | + | |
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
| |||
0 commit comments