@event4u/agent-config 2.13.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.agent-src/commands/agents/user/accept.md +117 -0
  2. package/.agent-src/commands/agents/user/init.md +163 -0
  3. package/.agent-src/commands/agents/user/review.md +107 -0
  4. package/.agent-src/commands/agents/user/show.md +109 -0
  5. package/.agent-src/commands/agents/user/update.md +98 -0
  6. package/.agent-src/commands/agents/user.md +66 -0
  7. package/.agent-src/commands/agents.md +2 -0
  8. package/.agent-src/commands/memory/learn-low-impact.md +143 -0
  9. package/.agent-src/rules/ask-when-uncertain.md +10 -6
  10. package/.agent-src/rules/copilot-routing.md +1 -1
  11. package/.agent-src/rules/devcontainer-routing.md +1 -1
  12. package/.agent-src/rules/external-reference-deep-dive.md +1 -1
  13. package/.agent-src/rules/fast-path-marker-visibility.md +38 -0
  14. package/.agent-src/rules/low-impact-corpus-privacy-floor.md +74 -0
  15. package/.agent-src/rules/symfony-routing.md +1 -1
  16. package/.agent-src/skills/ai-council/SKILL.md +208 -8
  17. package/.agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  18. package/.claude-plugin/marketplace.json +8 -1
  19. package/CHANGELOG.md +328 -124
  20. package/README.md +21 -6
  21. package/config/agent-settings.template.yml +4 -0
  22. package/config/gitignore-block.txt +17 -0
  23. package/docs/architecture.md +12 -12
  24. package/docs/archive/CHANGELOG-pre-2.11.0.md +141 -0
  25. package/docs/catalog.md +16 -7
  26. package/docs/contracts/adr-architectural-consensus-mechanism.md +4 -3
  27. package/docs/contracts/adr-level-6-productization.md +7 -9
  28. package/docs/contracts/agent-user-schema.md +165 -0
  29. package/docs/contracts/ai-council-config.md +492 -20
  30. package/docs/contracts/command-clusters.md +2 -2
  31. package/docs/contracts/command-surface-tiers.md +3 -2
  32. package/docs/contracts/cost-profile-defaults.md +5 -0
  33. package/docs/contracts/decision-engine-gates.md +5 -0
  34. package/docs/contracts/decision-trace-v1.md +2 -2
  35. package/docs/contracts/file-ownership-matrix.json +1961 -108
  36. package/docs/contracts/installed-tools-lockfile.md +2 -1
  37. package/docs/contracts/low-impact-corpus-format.md +95 -0
  38. package/docs/contracts/mcp-beta-criteria.md +6 -5
  39. package/docs/contracts/mcp-cloud-scope.md +5 -4
  40. package/docs/contracts/multi-tool-projection-fidelity.md +8 -2
  41. package/docs/contracts/release-trunk-sync.md +4 -3
  42. package/docs/contracts/tier-3-contrib-plugin.md +5 -6
  43. package/docs/examples/agent-user.example.md +21 -0
  44. package/docs/getting-started.md +2 -2
  45. package/docs/guidelines/agent-infra/installed-tools-manifest.md +2 -1
  46. package/docs/installation.md +32 -0
  47. package/package.json +1 -1
  48. package/scripts/_cli/cmd_doctor.py +134 -0
  49. package/scripts/ai_council/airgap.py +165 -0
  50. package/scripts/ai_council/cli_hints.py +123 -0
  51. package/scripts/ai_council/clients.py +787 -5
  52. package/scripts/ai_council/compile_corpus.py +178 -0
  53. package/scripts/ai_council/confidence_gate.py +156 -0
  54. package/scripts/ai_council/config.py +1007 -11
  55. package/scripts/ai_council/consensus.py +41 -2
  56. package/scripts/ai_council/events_log.py +137 -0
  57. package/scripts/ai_council/learn_low_impact_preview.py +252 -0
  58. package/scripts/ai_council/low_impact.py +714 -0
  59. package/scripts/ai_council/low_impact_corpus.py +466 -0
  60. package/scripts/ai_council/low_impact_intake.py +163 -0
  61. package/scripts/ai_council/modes.py +6 -1
  62. package/scripts/ai_council/necessity.py +782 -0
  63. package/scripts/ai_council/orchestrator.py +252 -14
  64. package/scripts/ai_council/probation_gate.py +152 -0
  65. package/scripts/ai_council/redact_low_impact_entry.py +155 -0
  66. package/scripts/ai_council/replay.py +155 -0
  67. package/scripts/ai_council/session.py +19 -1
  68. package/scripts/ai_council/shadow_dispatch.py +235 -0
  69. package/scripts/ai_council/solo_dispatch.py +226 -0
  70. package/scripts/audit_cloud_compatibility.py +74 -0
  71. package/scripts/audit_command_surface.py +363 -0
  72. package/scripts/check_council_layout.py +11 -0
  73. package/scripts/council_cli.py +1046 -15
  74. package/scripts/install.sh +12 -0
@@ -4,17 +4,28 @@ Reads ``agents/.ai-council.yml`` per the contract in
4
4
  ``docs/contracts/ai-council-config.md``. Replaces the fragmented
5
5
  ``.agent-settings.yml`` ``ai_council`` block (Phase 0 migration).
6
6
 
7
- Validation contract (7 rules, all enforced at load time):
7
+ Validation contract (8 rules, all enforced at load time):
8
8
 
9
9
  1. ``enabled`` is a bool.
10
- 2. ``defaults.mode`` ∈ {``api``, ``manual``}; per-member mode same set.
10
+ 2. ``defaults.mode`` ∈ {``api``, ``manual``, ``cli``}; per-member mode
11
+ same set. Semantics: ``api`` = SDK call against a stored key
12
+ (billable); ``manual`` = copy & paste — human transports prompt +
13
+ reply between the agent and an external chat surface (free);
14
+ ``cli`` = shell out to a locally-installed CLI under subscription
15
+ auth (free for first-party CLIs, billable for community wrappers).
11
16
  3. ``members.<name>`` keys are restricted to the known provider set.
12
17
  4. ``cost_budget.*`` numeric fields are >= 0.
13
- 5. Enabled members carry a non-empty ``model`` and ``api_key_ref``.
18
+ 5. Enabled members carry a non-empty ``model`` and ``api_key_ref``
19
+ when their effective mode is ``api``. CLI-mode members do NOT
20
+ require ``api_key_ref`` (subscription auth is provided by the CLI
21
+ binary itself).
14
22
  6. ``api_key_ref`` starts with ``file:`` or ``env:`` — raw keys are
15
23
  refused even if syntactically plausible.
16
24
  7. Resolved ``file:`` key paths must have mode 0o600 (delegated to
17
25
  :func:`resolve_api_key`; runs at use-time, not parse-time).
26
+ 8. ``binary:`` is only valid when the member's effective mode is
27
+ ``cli``; ``cli_call_budget.max_calls_per_day.<provider>`` keys
28
+ must be valid providers.
18
29
  """
19
30
 
20
31
  from __future__ import annotations
@@ -30,7 +41,7 @@ import yaml
30
41
  from scripts._lib import user_global_paths
31
42
 
32
43
  _VALID_PROVIDERS = frozenset({"anthropic", "openai", "gemini", "xai", "perplexity"})
33
- _VALID_MODES = frozenset({"api", "manual"})
44
+ _VALID_MODES = frozenset({"api", "manual", "cli"})
34
45
 
35
46
  #: Prefixes that signal "this is a raw API key" so we refuse it loudly
36
47
  #: even when the user accidentally inlined it in ``api_key_ref``.
@@ -44,6 +55,7 @@ class CouncilConfigError(RuntimeError):
44
55
  @dataclass(frozen=True)
45
56
  class DefaultsConfig:
46
57
  mode: str = "api"
58
+ member_mode: str = "cli"
47
59
  min_rounds: int = 2
48
60
  deep_min_rounds: int = 3
49
61
  max_output_tokens: int = 0
@@ -66,6 +78,9 @@ class MemberConfig:
66
78
  model: str
67
79
  api_key_ref: str | None
68
80
  mode: str | None = None
81
+ binary: str | None = None
82
+ model_ladder: tuple[str, ...] = ()
83
+ participate_low_impact: bool = False
69
84
 
70
85
 
71
86
  @dataclass(frozen=True)
@@ -102,6 +117,311 @@ class ConsensusScoringConfig:
102
117
  lenses: tuple[str, ...] = ("analysis",)
103
118
 
104
119
 
120
+ _VALID_NECESSITY_MODES = frozenset({"off", "educate", "block", "warn-only"})
121
+ _VALID_DISCLOSURE_MODES = frozenset({"always", "above_threshold", "off"})
122
+
123
+
124
+ @dataclass(frozen=True)
125
+ class NecessityClassifierConfig:
126
+ """Council-necessity classifier toggle (Phase 6).
127
+
128
+ ``mode`` controls the **agent** invocation path; ``user_explicit_mode``
129
+ controls the **user-explicit** invocation path (step-8 D2 tier split).
130
+
131
+ Valid modes ∈ ``{"off", "educate", "block", "warn-only"}``:
132
+
133
+ - ``off`` — legacy behaviour: classifier never runs, every request
134
+ proceeds to deliberation.
135
+ - ``educate`` — agent-initiated `unnecessary` skips silently;
136
+ user-explicit `unnecessary` emits the educate paragraph and
137
+ requires ``--proceed-anyway`` (CLI) or a numbered-options
138
+ confirmation (agent surface) before firing members.
139
+ - ``block`` — power-user opt-in: `unnecessary` skips silently
140
+ regardless of override flag.
141
+ - ``warn-only`` — classifier verdict annotated in stdout but
142
+ **never** skips. Default for ``user_explicit_mode`` (step-8 D2).
143
+
144
+ Default ``mode`` (agent path) = ``educate``;
145
+ default ``user_explicit_mode`` = ``warn-only``. Reconciles
146
+ "Council always active when called" with "skip trivial agent-side
147
+ requests".
148
+
149
+ Per-lens overrides live in :class:`CouncilConfig.lens_overrides`;
150
+ this dataclass carries only the global default.
151
+ """
152
+
153
+ enabled: bool = True
154
+ mode: str = "educate"
155
+ user_explicit_mode: str = "warn-only"
156
+
157
+
158
+ @dataclass(frozen=True)
159
+ class ModelDowngradeConfig:
160
+ """Model-size downgrade-suggestion toggle (Phase 7).
161
+
162
+ When ``enabled`` is true, the dispatcher runs the size-fit
163
+ classifier (:func:`scripts.ai_council.necessity.classify_size_fit`)
164
+ before deliberation. ``fit=False`` triggers a single
165
+ numbered-options prompt offering the suggested cheaper model.
166
+
167
+ ``auto_apply`` toggles agent-initiated invocations to silently
168
+ accept the suggested model (logged in ``session.md`` as a
169
+ ``downgraded`` event). User-explicit invocations always see the
170
+ prompt regardless. Default global ON per the roadmap spec; per-lens
171
+ override lives in :class:`LensOverridesConfig`.
172
+ """
173
+
174
+ enabled: bool = True
175
+ auto_apply: bool = False
176
+
177
+
178
+ @dataclass(frozen=True)
179
+ class CostDisclosureConfig:
180
+ """Pre-flight cost-disclosure toggle (Phase 8).
181
+
182
+ ``mode`` ∈ ``{"always", "above_threshold", "off"}``:
183
+
184
+ - ``always`` — always emit the disclosure block before deliberation.
185
+ - ``above_threshold`` — emit only when the expected USD spend exceeds
186
+ ``threshold_usd``. Useful for cheap lenses (analysis / default)
187
+ where the prompt would be friction.
188
+ - ``off`` — power-user opt-out, never emit. The hard refusal cap
189
+ still fires regardless (cost ceilings are not optional).
190
+
191
+ ``show_per_member`` toggles whether the per-member breakdown is
192
+ surfaced or just the rolled-up totals.
193
+ """
194
+
195
+ mode: str = "always"
196
+ threshold_usd: float = 1.00
197
+ show_per_member: bool = True
198
+
199
+
200
+ @dataclass(frozen=True)
201
+ class DebateConfig:
202
+ """Debate cost-visibility + hard refusal cap (Phase 8).
203
+
204
+ ``max_cost_usd`` is the unconditional refusal cap — when the
205
+ pre-flight ``high_usd`` estimate exceeds this value, the dispatcher
206
+ refuses to start the debate (no prompt, exit non-zero). Mirrored
207
+ mid-run: running spend > cap aborts cleanly after the current round.
208
+
209
+ ``cost_disclosure`` controls the pre-flight disclosure block. Both
210
+ are independent — disclosure off + cap on still refuses over-budget
211
+ debates; cap=0 disables the refusal but disclosure still fires.
212
+ """
213
+
214
+ max_cost_usd: float = 5.00
215
+ cost_disclosure: CostDisclosureConfig = field(
216
+ default_factory=CostDisclosureConfig,
217
+ )
218
+
219
+
220
+ @dataclass(frozen=True)
221
+ class DecisionReplayConfig:
222
+ """Decision-replay artefact toggle (Phase 9).
223
+
224
+ ``enabled`` controls whether ``decision-replay.md`` is written
225
+ alongside the session JSON. ``include_member_arguments`` toggles
226
+ the redacted view: when ``False`` the artefact emits consensus +
227
+ dissent COUNT only — no per-member arguments — for sharing without
228
+ leaking which model framed which point.
229
+ """
230
+
231
+ enabled: bool = True
232
+ include_member_arguments: bool = True
233
+
234
+
235
+ @dataclass(frozen=True)
236
+ class DecisionResolutionEntry:
237
+ """Routing entry for one impact class (Phase 10).
238
+
239
+ Attributes:
240
+ mode: One of ``agent`` / ``council`` / ``user``. ``high_impact``
241
+ and ``user_required`` are LOCKED to ``user`` at parse-time
242
+ — overrides are rejected with a CouncilConfigError.
243
+ confidence_threshold: When the classifier's confidence is BELOW
244
+ this value, the entry's ``mode`` is upgraded by one rung
245
+ (agent → council, council → user). ``user`` mode ignores
246
+ the threshold. Default ``0.6``.
247
+ """
248
+
249
+ mode: str = "user"
250
+ confidence_threshold: float = 0.6
251
+
252
+
253
+ @dataclass(frozen=True)
254
+ class FuzzyMatchConfig:
255
+ """Opt-in fuzzy matching for the corpus-aware classifier (step-9 P5).
256
+
257
+ Lives under ``decision_resolution.fast_path.fuzzy_match`` in the
258
+ YAML. When ``enabled`` is ``False`` the classifier uses
259
+ exact-after-normalisation matching only (Phase 12 default).
260
+
261
+ Attributes:
262
+ enabled: Master switch. Default ``False`` — exact match only.
263
+ threshold: ``difflib.SequenceMatcher.ratio()`` cutoff in the
264
+ range ``(0.0, 1.0]``. Default ``0.92``. Two safety vetoes
265
+ apply on top of the ratio test (Iron Law preserved):
266
+ high-impact trigger tokens in the query short-circuit to
267
+ the base verdict, and anti-example similarity at or above
268
+ the validated similarity rejects the match.
269
+ """
270
+
271
+ enabled: bool = False
272
+ threshold: float = 0.92
273
+
274
+
275
+ @dataclass(frozen=True)
276
+ class LowImpactFastPathConfig:
277
+ """Hard caps for the lightweight-QA fast-path (Phase 11).
278
+
279
+ Lives under ``decision_resolution.fast_path`` in the YAML. Used by
280
+ :mod:`scripts.ai_council.low_impact` to assemble the fast-path
281
+ ``CostBudget`` when a ``low_impact`` question routes to ``council``.
282
+
283
+ Attributes:
284
+ max_members: Upper bound on opted-in members invoked per
285
+ resolution. Default ``2``. ``1`` skips quick-consensus
286
+ and returns the single responder's answer; ``2`` runs the
287
+ agreement / disagreement check.
288
+ max_rounds: Locked to ``1`` — the fast-path strips debate.
289
+ Surfaced for documentation; the loader rejects any other
290
+ value with a hard schema error.
291
+ max_tokens: Combined input+output token budget per resolution.
292
+ Default ``2500``. Passed through to ``CostBudget``.
293
+ max_cost_usd: USD cap per resolution. Default ``0.05``.
294
+ fuzzy_match: Opt-in fuzzy corpus matching (step-9 P5). Off by
295
+ default — exact-after-normalisation matching only.
296
+ """
297
+
298
+ max_members: int = 2
299
+ max_rounds: int = 1
300
+ max_tokens: int = 2500
301
+ max_cost_usd: float = 0.05
302
+ fuzzy_match: FuzzyMatchConfig = field(default_factory=FuzzyMatchConfig)
303
+
304
+
305
+ @dataclass(frozen=True)
306
+ class DecisionResolutionConfig:
307
+ """Impact-class → routing map (Phase 10).
308
+
309
+ Keyed by impact class (``trivial`` / ``low_impact`` / ``medium_impact``
310
+ / ``high_impact`` / ``user_required``). The Iron Law rule for
311
+ ``high_impact`` and ``user_required`` is enforced by
312
+ :func:`_build_decision_resolution` — those classes MUST route to
313
+ ``user`` and any other value is a hard schema error.
314
+
315
+ ``fast_path`` carries the Phase 11 hard caps for the lightweight-QA
316
+ resolver. Only consulted when a ``low_impact`` question routes to
317
+ ``council``.
318
+ """
319
+
320
+ enabled: bool = True
321
+ classes: dict[str, DecisionResolutionEntry] = field(default_factory=dict)
322
+ fast_path: LowImpactFastPathConfig = field(
323
+ default_factory=LowImpactFastPathConfig,
324
+ )
325
+
326
+
327
+ @dataclass(frozen=True)
328
+ class LensOverridesConfig:
329
+ """Per-lens overrides keyed by lens name (Phase 6+).
330
+
331
+ Carries necessity-classifier mode overrides (Phase 6),
332
+ model-downgrade overrides (Phase 7), cost-disclosure overrides
333
+ (Phase 8), and decision-replay overrides (Phase 9).
334
+ """
335
+
336
+ necessity_classifier_mode: dict[str, str] = field(default_factory=dict)
337
+ necessity_classifier_user_explicit_mode: dict[str, str] = field(
338
+ default_factory=dict,
339
+ )
340
+ model_downgrade: dict[str, ModelDowngradeConfig] = field(default_factory=dict)
341
+ cost_disclosure: dict[str, CostDisclosureConfig] = field(default_factory=dict)
342
+ decision_replay: dict[str, DecisionReplayConfig] = field(default_factory=dict)
343
+
344
+
345
+ @dataclass(frozen=True)
346
+ class RoutingConfig:
347
+ """Solo-member dispatch fallback chain (step-9 P8/P9 · U2).
348
+
349
+ ``solo_member_fallback_chain`` is the ordered list of provider names
350
+ consulted when the dispatcher resolves a single-member invocation
351
+ (CLI ``--single`` flag or ``low_impact.dispatch: single``). The
352
+ first chain entry whose member is enabled AND has cached-valid auth
353
+ wins. An empty tuple disables solo dispatch — any caller that
354
+ requests it falls back to the full council with a WARN log.
355
+
356
+ ``auth_check_timeout_seconds`` bounds the lazy auth probe per
357
+ member (default ``3``). Loader rejects values outside ``[1, 30]``
358
+ so a misconfigured CLI cannot stall the dispatcher.
359
+ """
360
+
361
+ solo_member_fallback_chain: tuple[str, ...] = ()
362
+ auth_check_timeout_seconds: int = 3
363
+
364
+
365
+ @dataclass(frozen=True)
366
+ class LowImpactConfig:
367
+ """Low-impact dispatch + shadow-mode config (step-9 P8/P10 · U3).
368
+
369
+ ``dispatch`` switches the low-impact resolution shape:
370
+
371
+ - ``full`` (default) — the existing fast-path quick-consensus over
372
+ opted-in members (caps from ``decision_resolution.fast_path``).
373
+ - ``single`` — solo-member dispatch via
374
+ :class:`RoutingConfig.solo_member_fallback_chain`. The loader
375
+ rejects ``single`` when the chain is empty or contains only
376
+ disabled members, so a misconfigured opt-in cannot silently
377
+ escalate to the full council on every call.
378
+
379
+ ``shadow_sample_rate`` is the per-decision sampling probability
380
+ for shadow-mode logging (Phase 10). At ``0.0`` shadow is off; at
381
+ ``1.0`` every solo decision is also dispatched to the full
382
+ council and the verdicts are compared in
383
+ ``agents/council-shadow-log.jsonl``. Must be in ``[0.0, 1.0]``.
384
+
385
+ ``solo_confidence_floor`` is the auto-escalation threshold for
386
+ solo-member responses (step-9 P13). When the dispatcher extracts
387
+ a confidence signal below the floor — or detects a split /
388
+ refusal response — the decision escalates to the full council
389
+ on this invocation, independent of shadow sampling. Default
390
+ ``0.7``; must be in ``[0.0, 1.0]``. The floor is irrelevant when
391
+ ``dispatch=full`` (no solo step to gate).
392
+ """
393
+
394
+ dispatch: str = "full"
395
+ shadow_sample_rate: float = 0.1
396
+ solo_confidence_floor: float = 0.7
397
+
398
+
399
+ @dataclass(frozen=True)
400
+ class CliCallBudgetConfig:
401
+ """Per-day call-count guard for ``mode: cli`` members (Phase 0).
402
+
403
+ The standard ``cost_budget`` gate skips CLI calls because they are
404
+ ``billable=False`` — but provider subscriptions still carry their
405
+ own quotas (Claude Pro 5h windows, ChatGPT Plus message caps,
406
+ Gemini free-tier per-day limits). Users opt into a per-provider
407
+ cap; default unset = unlimited from this loader's perspective.
408
+
409
+ Counter state persists under
410
+ ``~/.event4u/agent-config/cli-calls.json`` with daily UTC reset
411
+ (wired in Phase 1).
412
+
413
+ ``warn_at`` is the fractional threshold (0.0–1.0) at which the
414
+ pre-run quota summary in :func:`council_cli.cmd_run` flips its
415
+ prefix to ``⚠️`` and surfaces a ``council:quota · WARN`` line
416
+ (step-8 P1). Default ``0.8`` is the standard ops-monitoring 80 %
417
+ threshold (step-8 D4). Providers without a configured cap are
418
+ omitted from the summary regardless.
419
+ """
420
+
421
+ max_calls_per_day: dict[str, int] = field(default_factory=dict)
422
+ warn_at: float = 0.8
423
+
424
+
105
425
  @dataclass(frozen=True)
106
426
  class CouncilConfig:
107
427
  enabled: bool
@@ -112,6 +432,27 @@ class CouncilConfig:
112
432
  consensus_scoring: ConsensusScoringConfig = field(
113
433
  default_factory=ConsensusScoringConfig,
114
434
  )
435
+ cli_call_budget: CliCallBudgetConfig = field(
436
+ default_factory=CliCallBudgetConfig,
437
+ )
438
+ necessity_classifier: NecessityClassifierConfig = field(
439
+ default_factory=NecessityClassifierConfig,
440
+ )
441
+ model_downgrade: ModelDowngradeConfig = field(
442
+ default_factory=ModelDowngradeConfig,
443
+ )
444
+ debate: DebateConfig = field(default_factory=DebateConfig)
445
+ decision_replay: DecisionReplayConfig = field(
446
+ default_factory=DecisionReplayConfig,
447
+ )
448
+ decision_resolution: DecisionResolutionConfig = field(
449
+ default_factory=DecisionResolutionConfig,
450
+ )
451
+ routing: RoutingConfig = field(default_factory=RoutingConfig)
452
+ low_impact: LowImpactConfig = field(default_factory=LowImpactConfig)
453
+ lens_overrides: LensOverridesConfig = field(
454
+ default_factory=LensOverridesConfig,
455
+ )
115
456
  source_path: Path | None = None
116
457
 
117
458
 
@@ -144,7 +485,7 @@ def _build_config(raw: dict[str, Any], *, source_path: Path) -> CouncilConfig:
144
485
  raise CouncilConfigError("`members` must be a mapping.")
145
486
  members: dict[str, MemberConfig] = {}
146
487
  for name, cfg in members_raw.items():
147
- members[name] = _build_member(name, cfg or {})
488
+ members[name] = _build_member(name, cfg or {}, default_mode=defaults.mode)
148
489
 
149
490
  advisors_raw = raw.get("advisors") or {}
150
491
  if not isinstance(advisors_raw, dict):
@@ -174,6 +515,26 @@ def _build_config(raw: dict[str, Any], *, source_path: Path) -> CouncilConfig:
174
515
  )
175
516
 
176
517
  consensus = _build_consensus_scoring(raw.get("consensus_scoring") or {})
518
+ cli_call_budget = _build_cli_call_budget(raw.get("cli_call_budget") or {})
519
+ necessity_classifier = _build_necessity_classifier(
520
+ raw.get("necessity_classifier") or {},
521
+ )
522
+ model_downgrade = _build_model_downgrade(raw.get("model_downgrade") or {})
523
+ debate = _build_debate(raw.get("debate") or {})
524
+ decision_replay = _build_decision_replay(
525
+ raw.get("decision_replay") or {}, path="decision_replay",
526
+ )
527
+ decision_resolution = _build_decision_resolution(
528
+ raw.get("decision_resolution") or {},
529
+ )
530
+ routing = _build_routing(raw.get("routing") or {}, members=members)
531
+ low_impact = _build_low_impact(
532
+ raw.get("low_impact") or {},
533
+ members=members,
534
+ routing=routing,
535
+ )
536
+ _reject_top_level_locked_dispatch(raw)
537
+ lens_overrides = _build_lens_overrides(raw.get("lenses") or {})
177
538
 
178
539
  return CouncilConfig(
179
540
  enabled=enabled,
@@ -182,10 +543,381 @@ def _build_config(raw: dict[str, Any], *, source_path: Path) -> CouncilConfig:
182
543
  members=members,
183
544
  advisors=advisors,
184
545
  consensus_scoring=consensus,
546
+ cli_call_budget=cli_call_budget,
547
+ necessity_classifier=necessity_classifier,
548
+ model_downgrade=model_downgrade,
549
+ debate=debate,
550
+ decision_replay=decision_replay,
551
+ decision_resolution=decision_resolution,
552
+ routing=routing,
553
+ low_impact=low_impact,
554
+ lens_overrides=lens_overrides,
185
555
  source_path=source_path,
186
556
  )
187
557
 
188
558
 
559
+ def _build_necessity_classifier(d: dict[str, Any]) -> NecessityClassifierConfig:
560
+ if not isinstance(d, dict):
561
+ raise CouncilConfigError("`necessity_classifier` must be a mapping.")
562
+ enabled = d.get("enabled", True)
563
+ if not isinstance(enabled, bool):
564
+ raise CouncilConfigError("`necessity_classifier.enabled` must be a bool.")
565
+ mode = d.get("mode", "educate")
566
+ if mode not in _VALID_NECESSITY_MODES:
567
+ raise CouncilConfigError(
568
+ f"necessity_classifier.mode={mode!r} not in "
569
+ f"{sorted(_VALID_NECESSITY_MODES)}."
570
+ )
571
+ user_explicit_mode = d.get("user_explicit_mode", "warn-only")
572
+ if user_explicit_mode not in _VALID_NECESSITY_MODES:
573
+ raise CouncilConfigError(
574
+ f"necessity_classifier.user_explicit_mode="
575
+ f"{user_explicit_mode!r} not in "
576
+ f"{sorted(_VALID_NECESSITY_MODES)}."
577
+ )
578
+ return NecessityClassifierConfig(
579
+ enabled=bool(enabled),
580
+ mode=mode,
581
+ user_explicit_mode=user_explicit_mode,
582
+ )
583
+
584
+
585
+ def _build_model_downgrade(d: dict[str, Any]) -> ModelDowngradeConfig:
586
+ if not isinstance(d, dict):
587
+ raise CouncilConfigError("`model_downgrade` must be a mapping.")
588
+ enabled = d.get("enabled", True)
589
+ if not isinstance(enabled, bool):
590
+ raise CouncilConfigError("`model_downgrade.enabled` must be a bool.")
591
+ auto_apply = d.get("auto_apply", False)
592
+ if not isinstance(auto_apply, bool):
593
+ raise CouncilConfigError("`model_downgrade.auto_apply` must be a bool.")
594
+ return ModelDowngradeConfig(enabled=bool(enabled), auto_apply=bool(auto_apply))
595
+
596
+
597
+ def _build_cost_disclosure(
598
+ d: dict[str, Any], *, path: str,
599
+ ) -> CostDisclosureConfig:
600
+ if not isinstance(d, dict):
601
+ raise CouncilConfigError(f"`{path}` must be a mapping.")
602
+ mode = d.get("mode", "always")
603
+ if mode not in _VALID_DISCLOSURE_MODES:
604
+ raise CouncilConfigError(
605
+ f"{path}.mode={mode!r} not in {sorted(_VALID_DISCLOSURE_MODES)}."
606
+ )
607
+ threshold = float(d.get("threshold_usd", 1.00))
608
+ if threshold < 0:
609
+ raise CouncilConfigError(
610
+ f"{path}.threshold_usd must be >= 0 (got {threshold!r})."
611
+ )
612
+ show_per_member = d.get("show_per_member", True)
613
+ if not isinstance(show_per_member, bool):
614
+ raise CouncilConfigError(
615
+ f"`{path}.show_per_member` must be a bool."
616
+ )
617
+ return CostDisclosureConfig(
618
+ mode=mode,
619
+ threshold_usd=threshold,
620
+ show_per_member=bool(show_per_member),
621
+ )
622
+
623
+
624
+ def _build_debate(d: dict[str, Any]) -> DebateConfig:
625
+ if not isinstance(d, dict):
626
+ raise CouncilConfigError("`debate` must be a mapping.")
627
+ cap = float(d.get("max_cost_usd", 5.00))
628
+ if cap < 0:
629
+ raise CouncilConfigError(
630
+ f"debate.max_cost_usd must be >= 0 (got {cap!r}; "
631
+ f"use 0 to disable the cap)."
632
+ )
633
+ disclosure_raw = d.get("cost_disclosure") or {}
634
+ disclosure = _build_cost_disclosure(
635
+ disclosure_raw, path="debate.cost_disclosure",
636
+ )
637
+ return DebateConfig(max_cost_usd=cap, cost_disclosure=disclosure)
638
+
639
+
640
+ def _build_decision_replay(
641
+ d: dict[str, Any], *, path: str,
642
+ ) -> DecisionReplayConfig:
643
+ if not isinstance(d, dict):
644
+ raise CouncilConfigError(f"`{path}` must be a mapping.")
645
+ enabled = d.get("enabled", True)
646
+ if not isinstance(enabled, bool):
647
+ raise CouncilConfigError(f"`{path}.enabled` must be a bool.")
648
+ include_args = d.get("include_member_arguments", True)
649
+ if not isinstance(include_args, bool):
650
+ raise CouncilConfigError(
651
+ f"`{path}.include_member_arguments` must be a bool."
652
+ )
653
+ return DecisionReplayConfig(
654
+ enabled=bool(enabled),
655
+ include_member_arguments=bool(include_args),
656
+ )
657
+
658
+
659
+ _VALID_RESOLUTION_MODES = frozenset({"agent", "council", "user"})
660
+ _IMPACT_CLASSES = (
661
+ "trivial", "low_impact", "medium_impact", "high_impact", "user_required",
662
+ )
663
+ _LOCKED_IMPACT_CLASSES = frozenset({"high_impact", "user_required"})
664
+
665
+ _DEFAULT_RESOLUTION_MODES: dict[str, str] = {
666
+ "trivial": "agent",
667
+ "low_impact": "agent",
668
+ "medium_impact": "council",
669
+ "high_impact": "user",
670
+ "user_required": "user",
671
+ }
672
+
673
+
674
+ def _build_decision_resolution(
675
+ d: dict[str, Any],
676
+ ) -> DecisionResolutionConfig:
677
+ """Build the impact-class → routing map (Phase 10).
678
+
679
+ Enforces the Iron Law: ``high_impact`` and ``user_required`` MUST
680
+ route to ``user``. Any other value is a hard schema error — no
681
+ silent fall-back, no override path.
682
+ """
683
+ if not isinstance(d, dict):
684
+ raise CouncilConfigError("`decision_resolution` must be a mapping.")
685
+ enabled = d.get("enabled", True)
686
+ if not isinstance(enabled, bool):
687
+ raise CouncilConfigError(
688
+ "`decision_resolution.enabled` must be a bool."
689
+ )
690
+ classes_raw = d.get("classes") or {}
691
+ if not isinstance(classes_raw, dict):
692
+ raise CouncilConfigError(
693
+ "`decision_resolution.classes` must be a mapping."
694
+ )
695
+ classes: dict[str, DecisionResolutionEntry] = {}
696
+ for cls in _IMPACT_CLASSES:
697
+ entry_raw = classes_raw.get(cls) or {}
698
+ if not isinstance(entry_raw, dict):
699
+ raise CouncilConfigError(
700
+ f"`decision_resolution.classes.{cls}` must be a mapping."
701
+ )
702
+ mode = entry_raw.get("mode", _DEFAULT_RESOLUTION_MODES[cls])
703
+ if mode not in _VALID_RESOLUTION_MODES:
704
+ raise CouncilConfigError(
705
+ f"decision_resolution.classes.{cls}.mode={mode!r} not in "
706
+ f"{sorted(_VALID_RESOLUTION_MODES)}."
707
+ )
708
+ # Iron Law: high_impact + user_required are locked to user.
709
+ if cls in _LOCKED_IMPACT_CLASSES and mode != "user":
710
+ raise CouncilConfigError(
711
+ f"decision_resolution.classes.{cls}.mode={mode!r}: "
712
+ f"class `{cls}` is LOCKED to `user` (Iron Law) — "
713
+ f"high-impact and user-required decisions never bypass "
714
+ f"the user."
715
+ )
716
+ # Iron Law: `dispatch` is not configurable for locked classes
717
+ # (step-9 P8/P11 · U3). Any nested `dispatch` key — including
718
+ # smuggled-in YAML anchor merges — is a hard schema error.
719
+ if cls in _LOCKED_IMPACT_CLASSES and "dispatch" in entry_raw:
720
+ raise CouncilConfigError(
721
+ f"decision_resolution.classes.{cls}.dispatch="
722
+ f"{entry_raw['dispatch']!r}: dispatch is not "
723
+ f"configurable for high-impact / user-required "
724
+ f"decisions — always full council."
725
+ )
726
+ threshold = float(entry_raw.get("confidence_threshold", 0.6))
727
+ if not 0.0 <= threshold <= 1.0:
728
+ raise CouncilConfigError(
729
+ f"decision_resolution.classes.{cls}.confidence_threshold "
730
+ f"must be in [0.0, 1.0] (got {threshold!r})."
731
+ )
732
+ classes[cls] = DecisionResolutionEntry(
733
+ mode=mode,
734
+ confidence_threshold=threshold,
735
+ )
736
+ fast_path_raw = d.get("fast_path") or {}
737
+ if not isinstance(fast_path_raw, dict):
738
+ raise CouncilConfigError(
739
+ "`decision_resolution.fast_path` must be a mapping."
740
+ )
741
+ fast_path = _build_fast_path(fast_path_raw)
742
+ return DecisionResolutionConfig(
743
+ enabled=bool(enabled),
744
+ classes=classes,
745
+ fast_path=fast_path,
746
+ )
747
+
748
+
749
+ def _build_fast_path(d: dict[str, Any]) -> LowImpactFastPathConfig:
750
+ """Parse `decision_resolution.fast_path` into a frozen config.
751
+
752
+ Hard caps for the lightweight-QA resolver (Phase 11). ``max_rounds``
753
+ is locked to ``1`` — any other value is a hard schema error. The
754
+ other fields are positive numbers within sane bounds; out-of-range
755
+ values are rejected to prevent silent token / cost blow-ups.
756
+ """
757
+ max_members = d.get("max_members", 2)
758
+ if not isinstance(max_members, int) or isinstance(max_members, bool):
759
+ raise CouncilConfigError(
760
+ "decision_resolution.fast_path.max_members must be an int "
761
+ f"(got {type(max_members).__name__})."
762
+ )
763
+ if max_members < 1 or max_members > 2:
764
+ raise CouncilConfigError(
765
+ "decision_resolution.fast_path.max_members must be 1 or 2 "
766
+ f"(got {max_members}). Fast-path is by design a 1-2 member "
767
+ "lookup — wider fan-out belongs in the standard council path."
768
+ )
769
+ max_rounds = d.get("max_rounds", 1)
770
+ if max_rounds != 1:
771
+ raise CouncilConfigError(
772
+ "decision_resolution.fast_path.max_rounds is LOCKED to 1 "
773
+ f"(got {max_rounds!r}). Multi-round fast-paths defeat the "
774
+ "purpose — escalate to standard council instead."
775
+ )
776
+ max_tokens = d.get("max_tokens", 2500)
777
+ if (
778
+ not isinstance(max_tokens, int)
779
+ or isinstance(max_tokens, bool)
780
+ or max_tokens <= 0
781
+ ):
782
+ raise CouncilConfigError(
783
+ "decision_resolution.fast_path.max_tokens must be a positive "
784
+ f"int (got {max_tokens!r})."
785
+ )
786
+ max_cost_raw = d.get("max_cost_usd", 0.05)
787
+ if isinstance(max_cost_raw, bool) or not isinstance(
788
+ max_cost_raw, (int, float)
789
+ ):
790
+ raise CouncilConfigError(
791
+ "decision_resolution.fast_path.max_cost_usd must be a "
792
+ f"number (got {type(max_cost_raw).__name__})."
793
+ )
794
+ max_cost = float(max_cost_raw)
795
+ if max_cost <= 0.0:
796
+ raise CouncilConfigError(
797
+ "decision_resolution.fast_path.max_cost_usd must be > 0 "
798
+ f"(got {max_cost!r})."
799
+ )
800
+ fuzzy_match = _build_fuzzy_match(d.get("fuzzy_match") or {})
801
+ return LowImpactFastPathConfig(
802
+ max_members=max_members,
803
+ max_rounds=1,
804
+ max_tokens=max_tokens,
805
+ max_cost_usd=max_cost,
806
+ fuzzy_match=fuzzy_match,
807
+ )
808
+
809
+
810
+ def _build_fuzzy_match(d: dict[str, Any]) -> FuzzyMatchConfig:
811
+ """Parse ``decision_resolution.fast_path.fuzzy_match`` (step-9 P5).
812
+
813
+ Opt-in only: defaults to ``enabled=False, threshold=0.92``. A
814
+ threshold outside ``(0.0, 1.0]`` is a hard schema error — sub-0.5
815
+ matches are noise; ``0.0`` would auto-match anything; ``> 1.0`` is
816
+ impossible by definition of the ratio.
817
+ """
818
+ if not isinstance(d, dict):
819
+ raise CouncilConfigError(
820
+ "decision_resolution.fast_path.fuzzy_match must be a mapping."
821
+ )
822
+ enabled = d.get("enabled", False)
823
+ if not isinstance(enabled, bool):
824
+ raise CouncilConfigError(
825
+ "decision_resolution.fast_path.fuzzy_match.enabled must be a bool "
826
+ f"(got {type(enabled).__name__})."
827
+ )
828
+ threshold_raw = d.get("threshold", 0.92)
829
+ if isinstance(threshold_raw, bool) or not isinstance(
830
+ threshold_raw, (int, float)
831
+ ):
832
+ raise CouncilConfigError(
833
+ "decision_resolution.fast_path.fuzzy_match.threshold must be a "
834
+ f"number (got {type(threshold_raw).__name__})."
835
+ )
836
+ threshold = float(threshold_raw)
837
+ if not (0.0 < threshold <= 1.0):
838
+ raise CouncilConfigError(
839
+ "decision_resolution.fast_path.fuzzy_match.threshold must be in "
840
+ f"(0.0, 1.0] (got {threshold!r})."
841
+ )
842
+ return FuzzyMatchConfig(enabled=enabled, threshold=threshold)
843
+
844
+
845
+
846
+ def _build_lens_overrides(d: dict[str, Any]) -> LensOverridesConfig:
847
+ if not isinstance(d, dict):
848
+ raise CouncilConfigError("`lenses` must be a mapping.")
849
+ nc_overrides: dict[str, str] = {}
850
+ nc_user_overrides: dict[str, str] = {}
851
+ md_overrides: dict[str, ModelDowngradeConfig] = {}
852
+ cd_overrides: dict[str, CostDisclosureConfig] = {}
853
+ dr_overrides: dict[str, DecisionReplayConfig] = {}
854
+ for lens_name, lens_cfg in d.items():
855
+ if not isinstance(lens_cfg, dict):
856
+ raise CouncilConfigError(
857
+ f"`lenses.{lens_name}` must be a mapping."
858
+ )
859
+ nc_block = lens_cfg.get("necessity_classifier")
860
+ if nc_block is not None:
861
+ if not isinstance(nc_block, dict):
862
+ raise CouncilConfigError(
863
+ f"`lenses.{lens_name}.necessity_classifier` must be a mapping."
864
+ )
865
+ mode = nc_block.get("mode")
866
+ if mode is not None:
867
+ if mode not in _VALID_NECESSITY_MODES:
868
+ raise CouncilConfigError(
869
+ f"lenses.{lens_name}.necessity_classifier.mode={mode!r} "
870
+ f"not in {sorted(_VALID_NECESSITY_MODES)}."
871
+ )
872
+ nc_overrides[lens_name] = mode
873
+ user_mode = nc_block.get("user_explicit_mode")
874
+ if user_mode is not None:
875
+ if user_mode not in _VALID_NECESSITY_MODES:
876
+ raise CouncilConfigError(
877
+ f"lenses.{lens_name}.necessity_classifier."
878
+ f"user_explicit_mode={user_mode!r} "
879
+ f"not in {sorted(_VALID_NECESSITY_MODES)}."
880
+ )
881
+ nc_user_overrides[lens_name] = user_mode
882
+ md_block = lens_cfg.get("model_downgrade")
883
+ if md_block is not None:
884
+ if not isinstance(md_block, dict):
885
+ raise CouncilConfigError(
886
+ f"`lenses.{lens_name}.model_downgrade` must be a mapping."
887
+ )
888
+ md_enabled = md_block.get("enabled", True)
889
+ if not isinstance(md_enabled, bool):
890
+ raise CouncilConfigError(
891
+ f"`lenses.{lens_name}.model_downgrade.enabled` must be a bool."
892
+ )
893
+ md_auto = md_block.get("auto_apply", False)
894
+ if not isinstance(md_auto, bool):
895
+ raise CouncilConfigError(
896
+ f"`lenses.{lens_name}.model_downgrade.auto_apply` must be a bool."
897
+ )
898
+ md_overrides[lens_name] = ModelDowngradeConfig(
899
+ enabled=bool(md_enabled),
900
+ auto_apply=bool(md_auto),
901
+ )
902
+ cd_block = lens_cfg.get("cost_disclosure")
903
+ if cd_block is not None:
904
+ cd_overrides[lens_name] = _build_cost_disclosure(
905
+ cd_block, path=f"lenses.{lens_name}.cost_disclosure",
906
+ )
907
+ dr_block = lens_cfg.get("decision_replay")
908
+ if dr_block is not None:
909
+ dr_overrides[lens_name] = _build_decision_replay(
910
+ dr_block, path=f"lenses.{lens_name}.decision_replay",
911
+ )
912
+ return LensOverridesConfig(
913
+ necessity_classifier_mode=nc_overrides,
914
+ necessity_classifier_user_explicit_mode=nc_user_overrides,
915
+ model_downgrade=md_overrides,
916
+ cost_disclosure=cd_overrides,
917
+ decision_replay=dr_overrides,
918
+ )
919
+
920
+
189
921
  def _build_consensus_scoring(d: dict[str, Any]) -> ConsensusScoringConfig:
190
922
  if not isinstance(d, dict):
191
923
  raise CouncilConfigError("`consensus_scoring` must be a mapping.")
@@ -207,6 +939,9 @@ def _build_consensus_scoring(d: dict[str, Any]) -> ConsensusScoringConfig:
207
939
  )
208
940
 
209
941
 
942
+ _VALID_MEMBER_MODES = frozenset({"cli", "api"})
943
+
944
+
210
945
  def _build_defaults(d: dict[str, Any]) -> DefaultsConfig:
211
946
  if not isinstance(d, dict):
212
947
  raise CouncilConfigError("`defaults` must be a mapping.")
@@ -215,8 +950,18 @@ def _build_defaults(d: dict[str, Any]) -> DefaultsConfig:
215
950
  raise CouncilConfigError(
216
951
  f"defaults.mode={mode!r} not in {sorted(_VALID_MODES)}."
217
952
  )
953
+ # `member_mode` (step-9 P8 · U1) — global preference for solo /
954
+ # CLI-mode invocations. Narrower set than `defaults.mode` because
955
+ # `manual` makes no sense as a per-member dispatch default.
956
+ member_mode = d.get("member_mode", "cli")
957
+ if member_mode not in _VALID_MEMBER_MODES:
958
+ raise CouncilConfigError(
959
+ f"defaults.member_mode={member_mode!r} not in "
960
+ f"{sorted(_VALID_MEMBER_MODES)}."
961
+ )
218
962
  return DefaultsConfig(
219
963
  mode=mode,
964
+ member_mode=member_mode,
220
965
  min_rounds=int(d.get("min_rounds", 2)),
221
966
  deep_min_rounds=int(d.get("deep_min_rounds", 3)),
222
967
  max_output_tokens=int(d.get("max_output_tokens", 0)),
@@ -225,6 +970,168 @@ def _build_defaults(d: dict[str, Any]) -> DefaultsConfig:
225
970
  )
226
971
 
227
972
 
973
+ _VALID_DISPATCH_MODES = frozenset({"full", "single"})
974
+
975
+
976
+ def _build_routing(
977
+ d: dict[str, Any],
978
+ *,
979
+ members: dict[str, MemberConfig],
980
+ ) -> RoutingConfig:
981
+ """Parse ``routing`` block (step-9 P8 · U2).
982
+
983
+ Validates the solo-member fallback chain shape:
984
+
985
+ - Must be a list of strings.
986
+ - Each entry must be a configured member name.
987
+ - Duplicate entries are rejected — a chain is an order, not a set.
988
+
989
+ Auth-check timeout must be in ``[1, 30]`` seconds. Empty chain
990
+ is legal; it just disables solo dispatch.
991
+ """
992
+ if not isinstance(d, dict):
993
+ raise CouncilConfigError("`routing` must be a mapping.")
994
+ chain_raw = d.get("solo_member_fallback_chain", [])
995
+ if not isinstance(chain_raw, list):
996
+ raise CouncilConfigError(
997
+ "`routing.solo_member_fallback_chain` must be a list "
998
+ f"(got {type(chain_raw).__name__})."
999
+ )
1000
+ chain: list[str] = []
1001
+ seen: set[str] = set()
1002
+ for idx, entry in enumerate(chain_raw):
1003
+ if not isinstance(entry, str) or not entry.strip():
1004
+ raise CouncilConfigError(
1005
+ f"routing.solo_member_fallback_chain[{idx}]: each "
1006
+ f"entry must be a non-empty string (got {entry!r})."
1007
+ )
1008
+ if entry in seen:
1009
+ raise CouncilConfigError(
1010
+ f"routing.solo_member_fallback_chain[{idx}]: "
1011
+ f"duplicate entry {entry!r} — chain order must be "
1012
+ f"unique."
1013
+ )
1014
+ if entry not in members:
1015
+ raise CouncilConfigError(
1016
+ f"routing.solo_member_fallback_chain[{idx}]={entry!r}: "
1017
+ f"no such member in the `members` block."
1018
+ )
1019
+ seen.add(entry)
1020
+ chain.append(entry)
1021
+ timeout_raw = d.get("auth_check_timeout_seconds", 3)
1022
+ if (
1023
+ not isinstance(timeout_raw, int)
1024
+ or isinstance(timeout_raw, bool)
1025
+ or not 1 <= timeout_raw <= 30
1026
+ ):
1027
+ raise CouncilConfigError(
1028
+ "routing.auth_check_timeout_seconds must be an int in "
1029
+ f"[1, 30] (got {timeout_raw!r})."
1030
+ )
1031
+ return RoutingConfig(
1032
+ solo_member_fallback_chain=tuple(chain),
1033
+ auth_check_timeout_seconds=timeout_raw,
1034
+ )
1035
+
1036
+
1037
+ def _build_low_impact(
1038
+ d: dict[str, Any],
1039
+ *,
1040
+ members: dict[str, MemberConfig],
1041
+ routing: RoutingConfig,
1042
+ ) -> LowImpactConfig:
1043
+ """Parse ``low_impact`` block (step-9 P8 · U3).
1044
+
1045
+ ``dispatch: single`` is only legal when the routing fallback
1046
+ chain has at least one enabled member — otherwise the loader
1047
+ rejects with a clear error. A misconfigured opt-in must not
1048
+ silently escalate to the full council on every call.
1049
+ """
1050
+ if not isinstance(d, dict):
1051
+ raise CouncilConfigError("`low_impact` must be a mapping.")
1052
+ # Iron Law: `dispatch` is the only place where dispatch shape
1053
+ # is configurable. Reject any `dispatch` key on the locked
1054
+ # impact classes — covered separately at top-level by
1055
+ # `_reject_top_level_locked_dispatch`.
1056
+ dispatch = d.get("dispatch", "full")
1057
+ if dispatch not in _VALID_DISPATCH_MODES:
1058
+ raise CouncilConfigError(
1059
+ f"low_impact.dispatch={dispatch!r} not in "
1060
+ f"{sorted(_VALID_DISPATCH_MODES)}."
1061
+ )
1062
+ if dispatch == "single":
1063
+ enabled_in_chain = [
1064
+ name
1065
+ for name in routing.solo_member_fallback_chain
1066
+ if members.get(name) is not None and members[name].enabled
1067
+ ]
1068
+ if not enabled_in_chain:
1069
+ raise CouncilConfigError(
1070
+ "low_impact.dispatch='single' requires at least one "
1071
+ "enabled member in routing.solo_member_fallback_chain "
1072
+ f"(chain={list(routing.solo_member_fallback_chain)!r}). "
1073
+ "Enable a chain member or set dispatch back to 'full'."
1074
+ )
1075
+ shadow_raw = d.get("shadow_sample_rate", 0.1)
1076
+ if isinstance(shadow_raw, bool) or not isinstance(shadow_raw, (int, float)):
1077
+ raise CouncilConfigError(
1078
+ "low_impact.shadow_sample_rate must be a number "
1079
+ f"(got {type(shadow_raw).__name__})."
1080
+ )
1081
+ shadow = float(shadow_raw)
1082
+ if not 0.0 <= shadow <= 1.0:
1083
+ raise CouncilConfigError(
1084
+ "low_impact.shadow_sample_rate must be in [0.0, 1.0] "
1085
+ f"(got {shadow!r})."
1086
+ )
1087
+ floor_raw = d.get("solo_confidence_floor", 0.7)
1088
+ if isinstance(floor_raw, bool) or not isinstance(floor_raw, (int, float)):
1089
+ raise CouncilConfigError(
1090
+ "low_impact.solo_confidence_floor must be a number "
1091
+ f"(got {type(floor_raw).__name__})."
1092
+ )
1093
+ floor = float(floor_raw)
1094
+ if not 0.0 <= floor <= 1.0:
1095
+ raise CouncilConfigError(
1096
+ "low_impact.solo_confidence_floor must be in [0.0, 1.0] "
1097
+ f"(got {floor!r})."
1098
+ )
1099
+ return LowImpactConfig(
1100
+ dispatch=dispatch,
1101
+ shadow_sample_rate=shadow,
1102
+ solo_confidence_floor=floor,
1103
+ )
1104
+
1105
+
1106
+ def _reject_top_level_locked_dispatch(raw: dict[str, Any]) -> None:
1107
+ """Iron Law (step-9 P8/P11/P13 · U3) — reject locked-class dispatch keys.
1108
+
1109
+ Some authors will write `high_impact.dispatch: single` at the top
1110
+ level (mirroring `low_impact.dispatch`) rather than nested under
1111
+ `decision_resolution.classes`. Catch that shape too so the Iron
1112
+ Law cannot be bypassed by surface choice. Also covers
1113
+ `solo_confidence_floor` — meaningless on locked classes (they
1114
+ never dispatch solo) and a confusing knob to leave reachable.
1115
+ """
1116
+ for cls in _LOCKED_IMPACT_CLASSES:
1117
+ block = raw.get(cls)
1118
+ if not isinstance(block, dict):
1119
+ continue
1120
+ if "dispatch" in block:
1121
+ raise CouncilConfigError(
1122
+ f"{cls}.dispatch={block['dispatch']!r}: dispatch is "
1123
+ f"not configurable for high-impact / user-required "
1124
+ f"decisions — always full council."
1125
+ )
1126
+ if "solo_confidence_floor" in block:
1127
+ raise CouncilConfigError(
1128
+ f"{cls}.solo_confidence_floor="
1129
+ f"{block['solo_confidence_floor']!r}: irrelevant on "
1130
+ f"high-impact / user-required classes — they never "
1131
+ f"dispatch solo. Set on `low_impact` instead."
1132
+ )
1133
+
1134
+
228
1135
  def _build_cost_budget(d: dict[str, Any]) -> CostBudgetConfig:
229
1136
  if not isinstance(d, dict):
230
1137
  raise CouncilConfigError("`cost_budget` must be a mapping.")
@@ -243,7 +1150,12 @@ def _build_cost_budget(d: dict[str, Any]) -> CostBudgetConfig:
243
1150
  return cb
244
1151
 
245
1152
 
246
- def _build_member(name: str, cfg: dict[str, Any]) -> MemberConfig:
1153
+ def _build_member(
1154
+ name: str,
1155
+ cfg: dict[str, Any],
1156
+ *,
1157
+ default_mode: str = "api",
1158
+ ) -> MemberConfig:
247
1159
  if name not in _VALID_PROVIDERS:
248
1160
  raise CouncilConfigError(
249
1161
  f"members.{name}: unknown provider; valid: {sorted(_VALID_PROVIDERS)}."
@@ -251,21 +1163,67 @@ def _build_member(name: str, cfg: dict[str, Any]) -> MemberConfig:
251
1163
  member_enabled = bool(cfg.get("enabled", False))
252
1164
  model = cfg.get("model") or ""
253
1165
  api_key_ref = cfg.get("api_key_ref")
1166
+ member_mode = cfg.get("mode")
1167
+ if member_mode is not None and member_mode not in _VALID_MODES:
1168
+ raise CouncilConfigError(
1169
+ f"members.{name}.mode={member_mode!r} not in {sorted(_VALID_MODES)}."
1170
+ )
1171
+ effective_mode = member_mode or default_mode
1172
+ binary = cfg.get("binary")
1173
+ if binary is not None:
1174
+ if not isinstance(binary, str) or not binary.strip():
1175
+ raise CouncilConfigError(
1176
+ f"members.{name}.binary must be a non-empty string when set."
1177
+ )
1178
+ if effective_mode != "cli":
1179
+ raise CouncilConfigError(
1180
+ f"members.{name}.binary is only valid when the member's "
1181
+ f"effective mode is 'cli' (got {effective_mode!r}). Set "
1182
+ f"`mode: cli` on the member or `defaults.mode: cli` to use "
1183
+ f"this field."
1184
+ )
254
1185
  if member_enabled:
255
1186
  if not model:
256
1187
  raise CouncilConfigError(
257
1188
  f"members.{name}: enabled members require a non-empty `model`."
258
1189
  )
259
- if not api_key_ref:
1190
+ # CLI-mode members authenticate via the subscription bound to
1191
+ # the local CLI binary; api_key_ref is not required for them.
1192
+ # Manual mode is human-transported and also key-free. Only
1193
+ # api-mode members must supply an api_key_ref.
1194
+ if effective_mode == "api" and not api_key_ref:
260
1195
  raise CouncilConfigError(
261
- f"members.{name}: enabled members require an `api_key_ref`."
1196
+ f"members.{name}: enabled api-mode members require an `api_key_ref`."
262
1197
  )
263
1198
  if api_key_ref is not None:
264
1199
  _validate_api_key_ref(f"members.{name}", api_key_ref)
265
- member_mode = cfg.get("mode")
266
- if member_mode is not None and member_mode not in _VALID_MODES:
1200
+ ladder_raw = cfg.get("model_ladder") or ()
1201
+ if not isinstance(ladder_raw, (list, tuple)):
267
1202
  raise CouncilConfigError(
268
- f"members.{name}.mode={member_mode!r} not in {sorted(_VALID_MODES)}."
1203
+ f"members.{name}.model_ladder must be a list (got "
1204
+ f"{type(ladder_raw).__name__})."
1205
+ )
1206
+ ladder: tuple[str, ...] = ()
1207
+ if ladder_raw:
1208
+ entries: list[str] = []
1209
+ for entry in ladder_raw:
1210
+ if not isinstance(entry, str) or not entry.strip():
1211
+ raise CouncilConfigError(
1212
+ f"members.{name}.model_ladder entries must be non-empty "
1213
+ f"strings (got {entry!r})."
1214
+ )
1215
+ entries.append(entry)
1216
+ if member_enabled and model and model not in entries:
1217
+ raise CouncilConfigError(
1218
+ f"members.{name}.model_ladder must include the active "
1219
+ f"`model` ({model!r}); got {entries!r}."
1220
+ )
1221
+ ladder = tuple(entries)
1222
+ participate_raw = cfg.get("participate_low_impact", False)
1223
+ if not isinstance(participate_raw, bool):
1224
+ raise CouncilConfigError(
1225
+ f"members.{name}.participate_low_impact must be a bool "
1226
+ f"(got {type(participate_raw).__name__})."
269
1227
  )
270
1228
  return MemberConfig(
271
1229
  name=name,
@@ -273,9 +1231,47 @@ def _build_member(name: str, cfg: dict[str, Any]) -> MemberConfig:
273
1231
  model=model,
274
1232
  api_key_ref=api_key_ref,
275
1233
  mode=member_mode,
1234
+ binary=binary,
1235
+ model_ladder=ladder,
1236
+ participate_low_impact=participate_raw,
276
1237
  )
277
1238
 
278
1239
 
1240
+ def _build_cli_call_budget(d: dict[str, Any]) -> CliCallBudgetConfig:
1241
+ if not isinstance(d, dict):
1242
+ raise CouncilConfigError("`cli_call_budget` must be a mapping.")
1243
+ raw_caps = d.get("max_calls_per_day") or {}
1244
+ if not isinstance(raw_caps, dict):
1245
+ raise CouncilConfigError(
1246
+ "`cli_call_budget.max_calls_per_day` must be a mapping."
1247
+ )
1248
+ caps: dict[str, int] = {}
1249
+ for provider, value in raw_caps.items():
1250
+ if provider not in _VALID_PROVIDERS:
1251
+ raise CouncilConfigError(
1252
+ f"cli_call_budget.max_calls_per_day.{provider}: unknown "
1253
+ f"provider; valid: {sorted(_VALID_PROVIDERS)}."
1254
+ )
1255
+ if not isinstance(value, int) or isinstance(value, bool) or value < 0:
1256
+ raise CouncilConfigError(
1257
+ f"cli_call_budget.max_calls_per_day.{provider} must be a "
1258
+ f"non-negative integer (got {value!r})."
1259
+ )
1260
+ caps[provider] = value
1261
+ warn_at_raw = d.get("warn_at", 0.8)
1262
+ if isinstance(warn_at_raw, bool) or not isinstance(warn_at_raw, (int, float)):
1263
+ raise CouncilConfigError(
1264
+ f"cli_call_budget.warn_at must be a number in [0.0, 1.0] "
1265
+ f"(got {warn_at_raw!r})."
1266
+ )
1267
+ warn_at = float(warn_at_raw)
1268
+ if not 0.0 <= warn_at <= 1.0:
1269
+ raise CouncilConfigError(
1270
+ f"cli_call_budget.warn_at must be in [0.0, 1.0] (got {warn_at})."
1271
+ )
1272
+ return CliCallBudgetConfig(max_calls_per_day=caps, warn_at=warn_at)
1273
+
1274
+
279
1275
  def _build_advisor(name: str, cfg: dict[str, Any]) -> AdvisorConfig:
280
1276
  if not isinstance(cfg, dict):
281
1277
  raise CouncilConfigError(f"advisors.{name}: must be a mapping.")