ai-consultants 2.10.1

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 (62) hide show
  1. package/.claude/commands/ai-consultants:consult.md +94 -0
  2. package/.claude/commands/ai-consultants:debate.md +103 -0
  3. package/.claude/commands/ai-consultants:help.md +30 -0
  4. package/CLAUDE.md +839 -0
  5. package/LICENSE +21 -0
  6. package/README.md +758 -0
  7. package/SKILL.md +156 -0
  8. package/bin/ai-consultants +96 -0
  9. package/docs/COST_RATES.md +172 -0
  10. package/docs/JSON_SCHEMA.md +305 -0
  11. package/docs/SETUP.md +879 -0
  12. package/docs/SMART_ROUTING.md +219 -0
  13. package/docs/cost_rates.json +143 -0
  14. package/package.json +47 -0
  15. package/references/configuration.md +141 -0
  16. package/references/details.md +60 -0
  17. package/scripts/build_context.sh +562 -0
  18. package/scripts/classify_question.sh +148 -0
  19. package/scripts/config.sh +753 -0
  20. package/scripts/configure.sh +1093 -0
  21. package/scripts/consult_all.sh +934 -0
  22. package/scripts/debate_round.sh +421 -0
  23. package/scripts/doctor.sh +642 -0
  24. package/scripts/followup.sh +197 -0
  25. package/scripts/install.sh +319 -0
  26. package/scripts/lib/api.sh +640 -0
  27. package/scripts/lib/api_query.sh +228 -0
  28. package/scripts/lib/cache.sh +338 -0
  29. package/scripts/lib/chunking.sh +880 -0
  30. package/scripts/lib/code_optimizer.sh +671 -0
  31. package/scripts/lib/common.sh +1088 -0
  32. package/scripts/lib/costs.sh +674 -0
  33. package/scripts/lib/personas.sh +372 -0
  34. package/scripts/lib/progress.sh +251 -0
  35. package/scripts/lib/reflection.sh +447 -0
  36. package/scripts/lib/routing.sh +566 -0
  37. package/scripts/lib/schema.json +165 -0
  38. package/scripts/lib/session.sh +327 -0
  39. package/scripts/lib/symbol_map.sh +445 -0
  40. package/scripts/lib/voting.sh +495 -0
  41. package/scripts/peer_review.sh +460 -0
  42. package/scripts/preflight_check.sh +452 -0
  43. package/scripts/query_aider.sh +83 -0
  44. package/scripts/query_amp.sh +67 -0
  45. package/scripts/query_claude.sh +99 -0
  46. package/scripts/query_codex.sh +92 -0
  47. package/scripts/query_cursor.sh +72 -0
  48. package/scripts/query_deepseek.sh +17 -0
  49. package/scripts/query_gemini.sh +85 -0
  50. package/scripts/query_glm.sh +17 -0
  51. package/scripts/query_grok.sh +17 -0
  52. package/scripts/query_kilo.sh +140 -0
  53. package/scripts/query_kimi.sh +67 -0
  54. package/scripts/query_minimax.sh +17 -0
  55. package/scripts/query_mistral.sh +97 -0
  56. package/scripts/query_ollama.sh +328 -0
  57. package/scripts/query_qwen3.sh +93 -0
  58. package/scripts/setup_wizard.sh +367 -0
  59. package/scripts/skillport-install.sh +196 -0
  60. package/scripts/synthesize.sh +332 -0
  61. package/templates/consultation_report.md +323 -0
  62. package/templates/synthesis_prompt.md +120 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,839 @@
1
+ # AI Consultants - Claude Code Instructions
2
+
3
+ ## Project Overview
4
+
5
+ AI Consultants is a multi-model AI deliberation system that queries up to 15 AI consultants (Gemini, Codex, Mistral, Kilo, Cursor, Aider, Amp, Kimi, Claude, Qwen3, GLM, Grok, DeepSeek, MiniMax, Ollama) to obtain diverse perspectives on coding problems.
6
+
7
+ **Self-Exclusion**: The invoking agent is automatically excluded from the panel to prevent self-consultation. Claude Code won't query Claude, Codex CLI won't query Codex, etc.
8
+
9
+ **Version**: 2.10.1
10
+
11
+ ## Distribution
12
+
13
+ Two distribution methods are supported:
14
+
15
+ 1. **npx** (recommended): `npx ai-consultants "question"` - uses npm as distribution mechanism only (zero dependencies)
16
+ 2. **curl | bash**: `curl -fsSL .../install.sh | bash` - git clone into `~/.claude/skills/`
17
+
18
+ ### npm Architecture
19
+
20
+ `bin/ai-consultants` is a bash wrapper that npm registers as the CLI entry point. npm creates a symlink in `node_modules/.bin/` pointing to this file. The wrapper:
21
+
22
+ 1. Resolves its own path through symlinks (portable `readlink` loop for macOS/Linux)
23
+ 2. Computes `PROJECT_ROOT` and `SCRIPTS_DIR` from the resolved path
24
+ 3. Fixes `chmod +x` on first run (npm can strip execute permissions)
25
+ 4. Routes subcommands (`doctor`, `install`, `version`, `help`) or delegates to `consult_all.sh` via `exec`
26
+
27
+ **Key insight**: Because the wrapper resolves symlinks before calling scripts, `BASH_SOURCE[0]` in every script points to the real file. This means **zero modifications** to the 28 existing scripts.
28
+
29
+ ## Structure
30
+
31
+ ```
32
+ ai-consultants/
33
+ ├── bin/
34
+ │ └── ai-consultants # npm/npx entry point (bash wrapper)
35
+ ├── package.json # npm distribution metadata (zero dependencies)
36
+ ├── .npmignore # Excludes dev artifacts from npm package
37
+ ├── scripts/
38
+ │ ├── consult_all.sh # Main orchestrator - entry point
39
+ │ ├── config.sh # Centralized configuration
40
+ │ ├── doctor.sh # Diagnostic and auto-fix tool (v2.2)
41
+ │ ├── peer_review.sh # Anonymous peer review (v2.2)
42
+ │ ├── install.sh # One-liner installer (v2.2)
43
+ │ ├── query_*.sh # Wrapper for each consultant
44
+ │ ├── query_claude.sh # Claude consultant (v2.2)
45
+ │ ├── query_ollama.sh # Local model support (v2.2)
46
+ │ ├── synthesize.sh # Auto-synthesis of responses
47
+ │ ├── debate_round.sh # Multi-Agent Debate
48
+ │ ├── classify_question.sh # Question classifier
49
+ │ ├── followup.sh # Follow-up queries
50
+ │ ├── preflight_check.sh # Health check
51
+ │ └── lib/
52
+ │ ├── common.sh # Shared utilities (logging, panic mode)
53
+ │ ├── personas.sh # Consultant persona definitions
54
+ │ ├── schema.json # JSON output schema
55
+ │ ├── voting.sh # Voting/consensus + confidence intervals
56
+ │ ├── routing.sh # Smart routing + cost-aware routing
57
+ │ ├── session.sh # Session management
58
+ │ ├── costs.sh # Cost tracking + response limits
59
+ │ ├── cache.sh # Semantic caching (v2.3)
60
+ │ ├── api_query.sh # API mode query execution (v2.6)
61
+ │ ├── progress.sh # Progress bars
62
+ │ └── reflection.sh # Self-reflection + judge step
63
+ ├── references/
64
+ │ ├── configuration.md # Full configuration reference
65
+ │ └── details.md # Presets, strategies, best practices
66
+ └── templates/
67
+ └── synthesis_prompt.md # Synthesis prompt
68
+ ```
69
+
70
+ ## Claude Skills Compliance
71
+
72
+ **IMPORTANT**: This project is a Claude Skill following the [agentskills.io](https://agentskills.io) open standard.
73
+
74
+ **Key Requirements:**
75
+ - SKILL.md `name`: max 64 chars, lowercase letters/numbers/hyphens only
76
+ - SKILL.md `description`: max 1024 chars, must include WHAT and WHEN to use
77
+ - Keep SKILL.md body under 500 lines
78
+ - Use progressive disclosure: reference separate files for detailed content
79
+ - Scripts are executed via bash, not loaded into context
80
+ - Test with all models (Haiku, Sonnet, Opus)
81
+
82
+ ## Language Policy
83
+
84
+ **IMPORTANT**: The entire codebase MUST remain in English. This includes:
85
+ - All code comments
86
+ - All user-facing messages (log_info, log_error, echo, etc.)
87
+ - All documentation (README, CLAUDE.md, docs/, etc.)
88
+ - All prompt templates
89
+ - Variable names and function names
90
+
91
+ Do NOT introduce Italian or other languages in any part of the codebase.
92
+
93
+ ## Code Conventions
94
+
95
+ ### Bash Scripts
96
+ - Always use `set -euo pipefail` at the beginning
97
+ - Source `lib/common.sh` for logging (`log_info`, `log_error`, `log_success`, `log_warn`)
98
+ - Source `config.sh` for configuration
99
+ - JSON output must follow `lib/schema.json`
100
+ - Use environment variables for configuration override
101
+
102
+ ### Logging
103
+ ```bash
104
+ log_info "Informational message"
105
+ log_success "Operation completed"
106
+ log_warn "Warning"
107
+ log_error "Critical error"
108
+ log_debug "Debug message" # Only shown when LOG_LEVEL=DEBUG
109
+ ```
110
+
111
+ ### Shared Response Processing
112
+ Query scripts should use `process_consultant_response()` from `lib/common.sh` for DRY response handling:
113
+ ```bash
114
+ source "$SCRIPT_DIR/lib/common.sh"
115
+ process_consultant_response "$raw_output" "$consultant_name" "$model" "$persona" "$output_file"
116
+ ```
117
+
118
+ ### JSON Output
119
+ Each consultant must produce JSON with this minimum structure:
120
+ ```json
121
+ {
122
+ "consultant": "ConsultantName",
123
+ "model": "model-used",
124
+ "persona": "The Architect|Pragmatist|Devil's Advocate|Innovator",
125
+ "response": {
126
+ "summary": "TL;DR",
127
+ "detailed": "Full response",
128
+ "approach": "Approach name",
129
+ "pros": ["advantage 1", "advantage 2"],
130
+ "cons": ["disadvantage 1"],
131
+ "caveats": ["important note"]
132
+ },
133
+ "confidence": {
134
+ "score": 1-10,
135
+ "reasoning": "Justification",
136
+ "uncertainty_factors": ["what could affect this"]
137
+ },
138
+ "metadata": {
139
+ "tokens_used": 1234,
140
+ "latency_ms": 5600,
141
+ "timestamp": "ISO-8601"
142
+ }
143
+ }
144
+ ```
145
+
146
+ ## Main Flow
147
+
148
+ 1. `consult_all.sh` receives query, optional files, and flags (`--preset`, `--strategy`)
149
+ 2. Applies preset if specified (`apply_preset()` in config.sh)
150
+ 3. Classifies the question (`classify_question.sh`)
151
+ 4. Selects consultants (smart routing or all)
152
+ 5. Launches parallel queries (`query_*.sh`)
153
+ 6. Calculates voting/consensus with confidence intervals (`lib/voting.sh`)
154
+ 7. Checks for panic mode triggers (`lib/common.sh`)
155
+ 8. Generates synthesis with selected strategy (`synthesize.sh`)
156
+ 9. Optionally runs peer review (`peer_review.sh`)
157
+ 10. Produces final report
158
+
159
+ ## v2.2 Features
160
+
161
+ ### Self-Exclusion
162
+ The invoking agent is automatically excluded from the panel:
163
+
164
+ ```bash
165
+ # From Claude Code slash commands (automatic)
166
+ # Claude is excluded, all others participate
167
+
168
+ # Manual bash usage
169
+ INVOKING_AGENT=claude ./scripts/consult_all.sh "question" # Claude excluded
170
+ INVOKING_AGENT=codex ./scripts/consult_all.sh "question" # Codex excluded
171
+ ./scripts/consult_all.sh "question" # No exclusion
172
+ ```
173
+
174
+ Functions in `lib/common.sh`:
175
+ - `get_self_consultant_name()` - Maps invoking agent to consultant name
176
+ - `should_skip_consultant()` - Returns true if consultant should be excluded
177
+ - `log_self_exclusion_status()` - Debug logging for exclusion
178
+
179
+ ### Configuration Presets
180
+ ```bash
181
+ # Quality Tier Presets (v2.5)
182
+ ./scripts/consult_all.sh --preset max_quality "question" # All + premium models + debate
183
+ ./scripts/consult_all.sh --preset medium "question" # 4 consultants + standard models
184
+ ./scripts/consult_all.sh --preset fast "question" # 2 consultants + economy models
185
+
186
+ # Use Case Presets
187
+ ./scripts/consult_all.sh --preset minimal "question" # Gemini + Codex
188
+ ./scripts/consult_all.sh --preset balanced "question" # + Mistral + Kilo
189
+ ./scripts/consult_all.sh --preset high-stakes "question" # All + debate
190
+ ./scripts/consult_all.sh --preset local "question" # Ollama only
191
+ ```
192
+
193
+ Presets are defined in `config.sh` via `apply_preset()` function.
194
+
195
+ ### Synthesis Strategies
196
+ ```bash
197
+ ./scripts/consult_all.sh --strategy majority "question" # Default
198
+ ./scripts/consult_all.sh --strategy risk_averse "question" # Conservative
199
+ ./scripts/consult_all.sh --strategy security_first "question" # Security focus
200
+ ./scripts/consult_all.sh --strategy compare_only "question" # No recommendation
201
+ ```
202
+
203
+ Strategies are implemented in `synthesize.sh` via `get_strategy_instructions()`.
204
+
205
+ ### Doctor Command
206
+ ```bash
207
+ ./scripts/doctor.sh # Full diagnostic
208
+ ./scripts/doctor.sh --fix # Auto-fix issues
209
+ ./scripts/doctor.sh --json # JSON output
210
+ ./scripts/doctor.sh --verbose # Detailed output
211
+ ```
212
+
213
+ ### Ollama Local Models
214
+ ```bash
215
+ ENABLE_OLLAMA=true ./scripts/consult_all.sh "question"
216
+ OLLAMA_MODEL=codellama ./scripts/consult_all.sh "question"
217
+ ```
218
+
219
+ Configuration in `config.sh`:
220
+ - `OLLAMA_MODEL` - Model to use (default: qwen2.5-coder:32b)
221
+ - `OLLAMA_HOST` - Server URL (default: http://localhost:11434)
222
+ - `OLLAMA_TIMEOUT` - Timeout in seconds (default: 300)
223
+
224
+ ### Panic Button Mode
225
+ Automatically adds rigor when uncertainty detected:
226
+ - Average confidence below `PANIC_CONFIDENCE_THRESHOLD` (default: 5)
227
+ - Uncertainty keywords detected in responses
228
+
229
+ Configuration in `config.sh`:
230
+ - `ENABLE_PANIC_MODE` - "auto", "always", or "never"
231
+ - `PANIC_CONFIDENCE_THRESHOLD` - Trigger threshold
232
+ - `PANIC_EXTRA_DEBATE_ROUNDS` - Additional debate rounds
233
+
234
+ ### Confidence Intervals
235
+ Functions in `lib/voting.sh`:
236
+ - `calculate_confidence_stddev()` - Returns stddev scaled by 10
237
+ - `calculate_confidence_interval()` - Returns JSON with mean, stddev, interval
238
+ - `has_high_confidence_variance()` - Returns 0 if variance > 2.0
239
+ - `format_confidence_range()` - Returns "7 ± 1.5" format
240
+
241
+ ### Anonymous Peer Review
242
+ ```bash
243
+ ./scripts/peer_review.sh <responses_dir> <output_dir>
244
+ ```
245
+
246
+ Process:
247
+ 1. Anonymize all responses (remove consultant names)
248
+ 2. Each consultant ranks and critiques responses
249
+ 3. Aggregate peer scores to identify strongest arguments
250
+ 4. De-anonymize in final report
251
+
252
+ ### Judge Step (Overconfidence Detection)
253
+ Functions in `lib/reflection.sh`:
254
+ - `judge_response()` - Evaluates single response for overconfidence
255
+ - `heuristic_overconfidence_check()` - Fast fallback without LLM
256
+ - `judge_all_responses()` - Batch evaluation
257
+
258
+ ## v2.8 Features
259
+
260
+ ### Amp CLI Support
261
+ Amp Code is now supported as a CLI-based consultant with "The Systems Thinker" persona.
262
+
263
+ ```bash
264
+ # Enable Amp consultant
265
+ export ENABLE_AMP=true
266
+ ./scripts/consult_all.sh "question"
267
+ ```
268
+
269
+ **CLI Installation:**
270
+ ```bash
271
+ curl -fsSL https://ampcode.com/install.sh | bash
272
+ ```
273
+
274
+ **Environment Variables:**
275
+ - `ENABLE_AMP` - Enable Amp consultant (default: false)
276
+ - `AMP_CMD` - CLI command (default: amp)
277
+ - `AMP_TIMEOUT` - Timeout in seconds (default: 180)
278
+ - `AMP_API_KEY` - API key for authentication
279
+
280
+ **Persona:** The Systems Thinker - Focuses on holistic system design, component interactions, and emergent behaviors.
281
+
282
+ ## v2.9 Features
283
+
284
+ ### Kimi CLI Support
285
+ Kimi (MoonshotAI) is now supported as a CLI-based consultant with "The Eastern Sage" persona.
286
+
287
+ ```bash
288
+ # Enable Kimi consultant
289
+ export ENABLE_KIMI=true
290
+ ./scripts/consult_all.sh "question"
291
+ ```
292
+
293
+ **CLI Installation:**
294
+ ```bash
295
+ curl -L code.kimi.com/install.sh | bash
296
+ ```
297
+
298
+ **Environment Variables:**
299
+ - `ENABLE_KIMI` - Enable Kimi consultant (default: false)
300
+ - `KIMI_CMD` - CLI command (default: kimi)
301
+ - `KIMI_TIMEOUT` - Timeout in seconds (default: 180)
302
+ - `KIMI_MODEL` - Model identifier (default: kimi-code/kimi-for-coding)
303
+
304
+ **Persona:** The Eastern Sage - Focuses on holistic understanding, balance of perspectives, and wisdom from diverse viewpoints.
305
+
306
+ ## v2.7 Features
307
+
308
+ ### Qwen CLI Support (qwen-code)
309
+ Qwen3 now supports CLI/API mode switching using the qwen-code CLI.
310
+
311
+ ```bash
312
+ # CLI mode (new in v2.7)
313
+ export QWEN3_USE_API=false
314
+ ./scripts/consult_all.sh "question"
315
+
316
+ # API mode (default, preserves v2.6 behavior)
317
+ export QWEN3_USE_API=true
318
+ export QWEN3_API_KEY="your-dashscope-key"
319
+ ./scripts/consult_all.sh "question"
320
+ ```
321
+
322
+ **CLI Installation:**
323
+ ```bash
324
+ npm install -g @qwen-code/qwen-code@latest
325
+ ```
326
+
327
+ **Note:** `QWEN3_USE_API` defaults to `false` to use the qwen CLI by default.
328
+
329
+ ## v2.6 Features
330
+
331
+ ### CLI/API Mode Switching
332
+ Five consultants can now switch between CLI and API mode: **Gemini, Codex, Claude, Mistral, Qwen3**.
333
+
334
+ When API mode is enabled for an agent, CLI mode is disabled (mutual exclusivity).
335
+
336
+ ```bash
337
+ # Enable API mode for individual consultants
338
+ export GEMINI_USE_API=true
339
+ export GEMINI_API_KEY="your-google-ai-key"
340
+ ./scripts/consult_all.sh "question"
341
+
342
+ export CODEX_USE_API=true
343
+ export OPENAI_API_KEY="sk-..."
344
+ ./scripts/consult_all.sh "question"
345
+
346
+ export CLAUDE_USE_API=true
347
+ export ANTHROPIC_API_KEY="sk-ant-..."
348
+ ./scripts/consult_all.sh "question"
349
+
350
+ export MISTRAL_USE_API=true
351
+ export MISTRAL_API_KEY="your-mistral-key"
352
+ ./scripts/consult_all.sh "question"
353
+
354
+ export QWEN3_USE_API=true # Enable API mode (CLI is default)
355
+ export QWEN3_API_KEY="your-dashscope-key"
356
+ ./scripts/consult_all.sh "question"
357
+ ```
358
+
359
+ ### API Mode Configuration
360
+ New environment variables in `config.sh`:
361
+
362
+ | Variable | Default | Description |
363
+ |----------|---------|-------------|
364
+ | `GEMINI_USE_API` | false | Use Google AI API instead of gemini CLI |
365
+ | `CODEX_USE_API` | false | Use OpenAI API instead of codex CLI |
366
+ | `CLAUDE_USE_API` | false | Use Anthropic API instead of claude CLI |
367
+ | `MISTRAL_USE_API` | false | Use Mistral API instead of vibe CLI |
368
+ | `QWEN3_USE_API` | false | Use DashScope API instead of qwen CLI (v2.7) |
369
+ | `GEMINI_API_URL` | https://generativelanguage.googleapis.com/v1beta/models | Google AI endpoint |
370
+ | `CODEX_API_URL` | https://api.openai.com/v1/chat/completions | OpenAI endpoint |
371
+ | `CLAUDE_API_URL` | https://api.anthropic.com/v1/messages | Anthropic endpoint |
372
+ | `MISTRAL_API_URL` | https://api.mistral.ai/v1/chat/completions | Mistral endpoint |
373
+
374
+ ### API Keys for API Mode
375
+
376
+ | Agent | API Key Variable | Notes |
377
+ |-------|------------------|-------|
378
+ | Gemini | `GEMINI_API_KEY` | Google AI API key |
379
+ | Codex | `OPENAI_API_KEY` | Same as existing OpenAI key |
380
+ | Claude | `ANTHROPIC_API_KEY` | Anthropic API key |
381
+ | Mistral | `MISTRAL_API_KEY` | Same as existing Mistral key |
382
+ | Qwen3 | `QWEN3_API_KEY` | DashScope API key |
383
+
384
+ ### Mode Checking Functions
385
+ New functions in `lib/common.sh`:
386
+ - `is_api_mode()` - Check if agent is in API mode
387
+ - `validate_api_mode()` - Validate API key is set
388
+ - `get_api_key_var()` - Get API key variable name
389
+ - `get_api_url()` - Get API endpoint URL
390
+ - `get_api_format()` - Get response format (openai, anthropic, google_ai)
391
+
392
+ ### Doctor Diagnostics
393
+ The `doctor.sh` script now shows CLI/API mode status:
394
+ ```bash
395
+ ./scripts/doctor.sh --verbose
396
+ # Shows:
397
+ # ✓ Gemini: API mode (key: AIza...1234)
398
+ # ○ Codex: CLI mode
399
+ # ○ Claude: CLI mode
400
+ # ○ Mistral: CLI mode
401
+ # ✓ Qwen3: API mode (key: sk-...1234)
402
+ ```
403
+
404
+ ## v2.5 Features
405
+
406
+ ### Model Quality Tiers
407
+ Three tiers of models are available for each consultant, configurable via `apply_model_tier()`:
408
+
409
+ | Tier | Description | Example Models |
410
+ |------|-------------|----------------|
411
+ | **premium** | Latest flagship models | opus-4.6, gemini-3.1-pro-preview, gpt-5.3-codex |
412
+ | **standard** | Good quality at reasonable cost | sonnet-4.6, gemini-3-flash-preview, gpt-5.3 |
413
+ | **economy** | Optimized for speed and low cost | haiku-4.5, gemini-2.0-flash, gpt-4o-mini |
414
+
415
+ **Default models are now premium tier** for maximum quality.
416
+
417
+ ```bash
418
+ # Programmatic usage
419
+ source scripts/config.sh
420
+ apply_model_tier "premium" # Set all consultants to premium models
421
+ apply_model_tier "standard" # Set all consultants to standard models
422
+ apply_model_tier "economy" # Set all consultants to economy models
423
+
424
+ # Get model for a specific consultant and tier (v2.8.1)
425
+ get_model_for_tier "gemini" "premium" # → gemini-3.1-pro-preview
426
+ get_model_for_tier "claude" "economy" # → haiku-4.5
427
+ ```
428
+
429
+ ### Quality Tier Presets
430
+ Three new presets leverage the model tiers:
431
+
432
+ ```bash
433
+ # Maximum quality - all premium models + debate + reflection
434
+ ./scripts/consult_all.sh --preset max_quality "critical architecture decision"
435
+
436
+ # Balanced quality - standard models, 4 consultants, light debate
437
+ ./scripts/consult_all.sh --preset medium "general coding question"
438
+
439
+ # Super fast - economy models, 2 consultants, no debate
440
+ ./scripts/consult_all.sh --preset fast "quick syntax question"
441
+ ```
442
+
443
+ ### Premium Model Defaults (March 2026)
444
+ All consultants now use premium models by default:
445
+
446
+ | Consultant | Default Model |
447
+ |------------|---------------|
448
+ | Claude | opus-4.6 |
449
+ | Gemini | gemini-3.1-pro-preview |
450
+ | Codex | gpt-5.3-codex |
451
+ | Mistral | mistral-large-3 |
452
+ | Cursor | composer-1.5 |
453
+ | DeepSeek | deepseek-reasoner |
454
+ | GLM | glm-5 |
455
+ | Grok | grok-4-1-fast-reasoning |
456
+ | Qwen3 | qwen3.5-plus |
457
+ | Kimi | kimi-code/kimi-for-coding |
458
+ | Aider | gpt-5.3-codex |
459
+ | MiniMax | MiniMax-M2.5 |
460
+ | Kilo | auto |
461
+ | Ollama | qwen2.5-coder:32b |
462
+
463
+ Override with environment variables: `CLAUDE_MODEL`, `GEMINI_MODEL`, `CODEX_MODEL`, `KIMI_MODEL`, etc.
464
+
465
+ ## v2.4 Features
466
+
467
+ ### Budget Enforcement (Opt-in)
468
+ Optional budget limits to prevent consultations from exceeding configurable cost limits.
469
+
470
+ ```bash
471
+ # Enable budget enforcement
472
+ ENABLE_BUDGET_LIMIT=true
473
+ MAX_SESSION_COST=1.00
474
+ BUDGET_ACTION=warn # or "stop"
475
+ ```
476
+
477
+ **BUDGET_ACTION options:**
478
+ - `warn` - Log warning but continue consultation
479
+ - `stop` - Halt consultation and return partial results
480
+
481
+ **Enforcement Points:**
482
+ 1. Before Round 1 - Check estimated cost vs budget
483
+ 2. After Round 1 - Check actual cost vs warning threshold
484
+ 3. Before Debate - Check cumulative + debate estimate
485
+ 4. Before Synthesis - Check cumulative + synthesis estimate
486
+
487
+ Functions in `lib/costs.sh`:
488
+ - `is_budget_enabled()` - Check if budget enforcement is enabled
489
+ - `enforce_budget()` - Check budget and take action based on BUDGET_ACTION
490
+ - `get_remaining_budget()` - Get remaining budget
491
+ - `format_budget_status()` - Format budget status for display
492
+ - `estimate_phase_cost()` - Estimate cost for a specific phase
493
+
494
+ Configuration via environment variables or natural language.
495
+
496
+ ## v2.3 Features
497
+
498
+ ### Semantic Caching
499
+ Reduces redundant API calls by caching responses based on query + context fingerprints.
500
+
501
+ ```bash
502
+ # Configuration in config.sh
503
+ ENABLE_SEMANTIC_CACHE=true # Enable caching (default: true)
504
+ CACHE_TTL_HOURS=24 # Cache expiration
505
+ CACHE_DIR=/tmp/ai_consultants_cache
506
+ ```
507
+
508
+ Functions in `lib/cache.sh`:
509
+ - `generate_fingerprint()` - Creates hash from query + category + context
510
+ - `check_cache()` - Returns cached response if valid
511
+ - `store_cache()` - Stores response with metadata
512
+ - `cleanup_cache()` - Removes expired entries
513
+ - `get_cache_stats()` - Returns cache statistics as JSON
514
+
515
+ ### Response Length Limits (Opt-in)
516
+ Limits output tokens by question category to reduce costs.
517
+
518
+ ```bash
519
+ ENABLE_RESPONSE_LIMITS=false # Default: false (opt-in per quality review)
520
+ MAX_RESPONSE_TOKENS_BY_CATEGORY="QUICK_SYNTAX:200,CODE_REVIEW:800,ARCHITECTURE:1000,SECURITY:1000,GENERAL:500"
521
+ ```
522
+
523
+ Functions in `lib/costs.sh`:
524
+ - `get_max_response_tokens()` - Returns limit for category
525
+ - `is_response_limits_enabled()` - Check if enabled
526
+
527
+ ### Cost-Aware Routing
528
+ Routes simple queries to cheaper models, complex queries to premium models.
529
+
530
+ ```bash
531
+ ENABLE_COST_AWARE_ROUTING=false # Enable cost-based routing
532
+ USE_ECONOMIC_MODELS_FOR_SIMPLE=true
533
+ COMPLEXITY_THRESHOLD_SIMPLE=3 # Score 1-3 = simple
534
+ COMPLEXITY_THRESHOLD_MEDIUM=6 # Score 4-6 = medium, 7-10 = complex
535
+ ```
536
+
537
+ Functions in `lib/routing.sh`:
538
+ - `select_consultants_cost_aware()` - Selects consultants based on complexity
539
+ - `get_cost_aware_model()` - Returns economic model for simple queries
540
+ - `calculate_query_complexity()` - Scores query 1-10
541
+
542
+ Functions in `lib/costs.sh`:
543
+ - `get_economic_model()` - Maps consultant to cheaper model
544
+ - `get_model_tier()` - Returns economy/standard/premium
545
+
546
+ ### Fallback Escalation
547
+ Automatically re-queries with premium models if confidence is too low.
548
+
549
+ ```bash
550
+ FALLBACK_CONFIDENCE_THRESHOLD=7 # Escalate if confidence < 7
551
+ ```
552
+
553
+ Functions in `lib/routing.sh`:
554
+ - `needs_escalation()` - Returns true if response needs premium model
555
+ - `get_premium_model()` - Returns premium model for consultant
556
+ - `get_escalation_summary()` - Returns escalation info as JSON
557
+
558
+ ### Debate Optimization (Opt-in)
559
+ Skips debate if confidence spread is low (all consultants agree).
560
+
561
+ ```bash
562
+ ENABLE_DEBATE_OPTIMIZATION=false # Default: false (opt-in per quality review)
563
+ DEBATE_CONFIDENCE_SPREAD_THRESHOLD=3 # Min spread to trigger debate
564
+ DEBATE_USE_SUMMARIES=true # Use summaries in debate rounds
565
+ ```
566
+
567
+ **Category Exceptions**: SECURITY and ARCHITECTURE always trigger debate regardless of confidence spread.
568
+
569
+ Functions in `debate_round.sh`:
570
+ - `is_mandatory_debate_category()` - Returns true for SECURITY/ARCHITECTURE
571
+ - `should_skip_debate()` - Returns true if debate can be skipped
572
+ - `extract_compact_summary()` - Token-optimized summary for debates
573
+
574
+ ### Quality Monitoring
575
+ Logs optimization metrics and saves to output directory.
576
+
577
+ ```bash
578
+ # In LOG_LEVEL=DEBUG mode, shows optimization status
579
+ # Always saves optimization_metrics.json to output directory
580
+ ```
581
+
582
+ Output file `optimization_metrics.json`:
583
+ ```json
584
+ {
585
+ "optimization_settings": {
586
+ "cache_enabled": true,
587
+ "cache_hits": 2,
588
+ "response_limits_enabled": false,
589
+ "cost_aware_routing": false,
590
+ "debate_optimization": false,
591
+ "compact_report": true
592
+ },
593
+ "quality_metrics": {
594
+ "consensus_score": 75,
595
+ "consensus_level": "medium",
596
+ "successful_responses": 4,
597
+ "total_consultants": 4,
598
+ "category": "ARCHITECTURE"
599
+ },
600
+ "timestamp": "2026-01-17T10:30:00Z"
601
+ }
602
+ ```
603
+
604
+ ### Compact Reports
605
+ Generates shorter reports by default (summaries only, no full JSON).
606
+
607
+ ```bash
608
+ ENABLE_COMPACT_REPORT=true # Default: true
609
+ REPORT_MAX_JSON_LINES=50 # Max JSON lines in full report
610
+ ```
611
+
612
+ ## Testing
613
+
614
+ ```bash
615
+ # Full diagnostic
616
+ ./scripts/doctor.sh
617
+
618
+ # Basic test
619
+ ./scripts/consult_all.sh "How to optimize a SQL query?"
620
+
621
+ # Test with preset
622
+ ./scripts/consult_all.sh --preset minimal "Quick question"
623
+
624
+ # Test with debate
625
+ ENABLE_DEBATE=true ./scripts/consult_all.sh "Microservices or monolith?"
626
+
627
+ # Test with strategy
628
+ ./scripts/consult_all.sh --strategy risk_averse "Security question"
629
+
630
+ # Syntax validation (all scripts)
631
+ for f in scripts/*.sh scripts/lib/*.sh; do bash -n "$f" && echo "OK: $f"; done
632
+ ```
633
+
634
+ ## Key Environment Variables
635
+
636
+ | Variable | Default | Description |
637
+ |----------|---------|-------------|
638
+ | `INVOKING_AGENT` | unknown | Agent invoking the skill (for self-exclusion) |
639
+ | `ENABLE_CLAUDE` | false | Enable Claude consultant |
640
+ | `ENABLE_DEBATE` | false | Enable Multi-Agent Debate |
641
+ | `DEBATE_ROUNDS` | 1 | Number of debate rounds |
642
+ | `ENABLE_SYNTHESIS` | true | Auto-synthesis of responses |
643
+ | `ENABLE_SMART_ROUTING` | false | Intelligent routing |
644
+ | `ENABLE_COST_TRACKING` | true | Track costs |
645
+ | `MAX_SESSION_COST` | 1.00 | Max budget ($) |
646
+ | `ENABLE_PANIC_MODE` | auto | Panic mode trigger (v2.2) |
647
+ | `PANIC_CONFIDENCE_THRESHOLD` | 5 | Panic threshold (v2.2) |
648
+ | `ENABLE_OLLAMA` | false | Local model support (v2.2) |
649
+ | `OLLAMA_MODEL` | qwen2.5-coder:32b | Ollama model (v2.5 - premium default) |
650
+ | `CLAUDE_MODEL` | opus-4.6 | Claude model (v2.5) |
651
+ | `GEMINI_MODEL` | gemini-3.1-pro-preview | Gemini model (v2.5) |
652
+ | `CODEX_MODEL` | gpt-5.3-codex | Codex model (v2.5) |
653
+ | `MISTRAL_MODEL` | mistral-large-3 | Mistral model (v2.5) |
654
+ | `SYNTHESIS_STRATEGY` | majority | Synthesis strategy (v2.2) |
655
+ | `ENABLE_SEMANTIC_CACHE` | true | Semantic response caching (v2.3) |
656
+ | `CACHE_TTL_HOURS` | 24 | Cache expiration in hours (v2.3) |
657
+ | `ENABLE_RESPONSE_LIMITS` | false | Response token limits (v2.3, opt-in) |
658
+ | `ENABLE_COST_AWARE_ROUTING` | false | Cost-based model routing (v2.3) |
659
+ | `ENABLE_DEBATE_OPTIMIZATION` | false | Skip debate if all agree (v2.3, opt-in) |
660
+ | `ENABLE_COMPACT_REPORT` | true | Compact report format (v2.3) |
661
+ | `ENABLE_BUDGET_LIMIT` | false | Budget enforcement (v2.4, opt-in) |
662
+ | `BUDGET_ACTION` | warn | Action on budget exceeded: warn/stop (v2.4) |
663
+ | `QWEN3_USE_API` | false | Use DashScope API instead of qwen CLI (v2.7) |
664
+ | `QWEN3_CMD` | qwen | Qwen CLI command (v2.7) |
665
+ | `ENABLE_KIMI` | false | Enable Kimi consultant (v2.9) |
666
+ | `KIMI_CMD` | kimi | Kimi CLI command (v2.9) |
667
+ | `KIMI_MODEL` | kimi-code/kimi-for-coding | Kimi model (v2.9) |
668
+ | `ENABLE_MINIMAX` | false | Enable MiniMax consultant (v2.10) |
669
+ | `MINIMAX_API_KEY` | - | MiniMax API key (v2.10) |
670
+ | `MINIMAX_MODEL` | MiniMax-M2.5 | MiniMax model (v2.10) |
671
+
672
+ ## External Dependencies
673
+
674
+ - `gemini` CLI - Google Gemini
675
+ - `codex` CLI - OpenAI Codex
676
+ - `vibe` CLI - Mistral Vibe
677
+ - `kilocode` CLI - Kilo Code
678
+ - `agent` CLI - Cursor
679
+ - `aider` CLI - Aider
680
+ - `amp` CLI - Amp Code (v2.8)
681
+ - `kimi` CLI - Kimi Code (v2.9)
682
+ - `claude` CLI - Claude (v2.2, also used for synthesis)
683
+ - `qwen` CLI - Qwen via qwen-code (v2.7, optional)
684
+ - `ollama` CLI - Local models (v2.2)
685
+ - `jq` - JSON parsing
686
+
687
+ ## Error Handling and Retry
688
+
689
+ The system handles errors with:
690
+
691
+ - **Automatic retry**: `MAX_RETRIES` attempts (default: 2)
692
+ - **Delay between retries**: `RETRY_DELAY_SECONDS` (default: 5s)
693
+ - **Cross-platform timeout**: Supports Linux (`timeout`), macOS (`gtimeout`), and POSIX fallback
694
+ - **Exit codes**: 0 = success, 1 = error, 124 = timeout
695
+
696
+ ```bash
697
+ # Retry configuration
698
+ MAX_RETRIES=3
699
+ RETRY_DELAY_SECONDS=10
700
+
701
+ # Per-consultant timeout
702
+ GEMINI_TIMEOUT=240
703
+ CODEX_TIMEOUT=180
704
+ OLLAMA_TIMEOUT=300 # Longer for local inference
705
+ ```
706
+
707
+ ## Extended Documentation
708
+
709
+ For detailed information, see:
710
+ - [docs/SETUP.md](docs/SETUP.md) - Installation, authentication, Ollama setup
711
+ - [docs/COST_RATES.md](docs/COST_RATES.md) - Rates and budget management
712
+ - [docs/SMART_ROUTING.md](docs/SMART_ROUTING.md) - Affinity matrix and routing
713
+ - [docs/JSON_SCHEMA.md](docs/JSON_SCHEMA.md) - Complete output schema
714
+
715
+ ## Development Notes
716
+
717
+ - Scripts in `lib/` are libraries, not standalone executables
718
+ - Output goes to `/tmp/ai_consultations/TIMESTAMP/`
719
+ - Session state in `/tmp/ai_consultants_sessions/`
720
+ - All timeouts are configurable in `config.sh`
721
+ - Consultants can be disabled individually (`ENABLE_GEMINI=false`, etc.)
722
+ - Use `.env.example` as template for environment configuration
723
+ - Run `./scripts/doctor.sh` to verify configuration
724
+
725
+ ## Changelog
726
+
727
+ ### v2.10.1
728
+ - Slash command quality improvements: file context handling, result presentation templates, error recovery guidance
729
+ - debate_round.sh hardening: Amp/Kimi/MiniMax case entries, `((count++)) || true` fixes, `*` default case, stderr to `.err` files, ROUND_NUMBER validation
730
+ - Token efficiency: SKILL.md trimmed (-17%), help.md slimmed (-77%), content moved to `references/details.md`
731
+ - Self-exclusion consistency in slash command descriptions
732
+
733
+ ### v2.10.0
734
+ - MiniMax M2.5 API support via OpenAI-compatible endpoint
735
+ - New consultant: MiniMax with "The Pragmatic Optimizer" persona (ID: 21)
736
+ - New environment variables: `ENABLE_MINIMAX`, `MINIMAX_API_KEY`, `MINIMAX_MODEL`, `MINIMAX_API_URL`
737
+ - Model tiers: premium (MiniMax-M2.5), standard (MiniMax-M2.1), economy (MiniMax-M2.5-highspeed)
738
+ - npx distribution: `npx ai-consultants "question"` (zero dependencies)
739
+ - New `bin/ai-consultants` wrapper with symlink resolution and subcommand routing
740
+ - Now supports 15 consultants total
741
+
742
+ ### v2.9.1
743
+ - Fixed Gemini model names to use real API names
744
+ - Premium: `gemini-3.1-pro-preview`, Standard: `gemini-3-flash-preview`, Economy: `gemini-2.0-flash`
745
+
746
+ ### v2.9.0
747
+ - Kimi CLI support via kimi-cli (`curl -L code.kimi.com/install.sh | bash`)
748
+ - New consultant: Kimi with "The Eastern Sage" persona (ID: 20)
749
+ - New environment variables: `ENABLE_KIMI`, `KIMI_CMD`, `KIMI_TIMEOUT`, `KIMI_MODEL`
750
+ - Updated doctor.sh diagnostics for Kimi CLI
751
+ - Now supports 14 consultants total
752
+
753
+ ### v2.8.1
754
+ - CRITICAL: Fixed `((count++))` abort under `set -e` in consult_all.sh and routing.sh
755
+ - Fixed missing integer validation for jq confidence values in escalation
756
+ - Fixed Amp missing from `_consultant_map` in consult_all.sh
757
+ - Fixed hardcoded `"claude"` in synthesize.sh (now uses `$CLAUDE_CMD`)
758
+ - Security: Variable name validation before `export` in escalation and cost-aware routing
759
+ - DRY: Rewrote `query_kilo.sh` and `query_cursor.sh` using `process_consultant_response()`
760
+ - DRY: Added `get_model_for_tier()` as single source of truth for model tier mappings
761
+ - Removed hardcoded version numbers from script headers
762
+
763
+ ### v2.8.0
764
+ - Amp CLI support via ampcode (`curl -fsSL https://ampcode.com/install.sh | bash`)
765
+ - New consultant: Amp with "The Systems Thinker" persona (ID: 19)
766
+ - New environment variables: `ENABLE_AMP`, `AMP_CMD`, `AMP_TIMEOUT`
767
+ - Updated doctor.sh diagnostics for Amp CLI
768
+
769
+ ### v2.7.0
770
+ - Qwen CLI support via qwen-code (`npm install -g @qwen-code/qwen-code@latest`)
771
+ - CLI/API mode switching for Qwen3 (now 5 agents support switching)
772
+ - New environment variables: `QWEN3_USE_API`, `QWEN3_CMD`
773
+ - `QWEN3_USE_API` defaults to `false` to use the qwen CLI by default
774
+ - Updated `validate_api_mode()` to support Qwen3
775
+ - Moved Qwen3 from API-only to CLI/API switchable consultant
776
+ - Updated doctor.sh diagnostics for Qwen3 CLI/API mode
777
+
778
+ ### v2.6.0
779
+ - CLI/API mode switching for Gemini, Codex, Claude, and Mistral
780
+ - New environment variables: `*_USE_API`, `*_API_URL`
781
+ - API request builders for Anthropic and Google AI formats
782
+ - Response parsers for all API formats (OpenAI, Anthropic, Google AI)
783
+ - New `lib/api_query.sh` module for unified API query execution
784
+ - Mode checking functions in `lib/common.sh`
785
+ - Doctor diagnostics for CLI/API mode status
786
+ - Updated query scripts with CLI/API branching
787
+
788
+ ### v2.5.0
789
+ - Model quality tiers: premium, standard, economy
790
+ - New `apply_model_tier()` function for programmatic tier selection
791
+ - Quality tier presets: `max_quality`, `medium`, `fast`
792
+ - Premium model defaults for all consultants (January 2026 models)
793
+ - Updated docs/cost_rates.json with tier-based model rates
794
+
795
+ ### v2.4.0
796
+ - Budget enforcement (opt-in) with configurable limits
797
+ - ENABLE_BUDGET_LIMIT and BUDGET_ACTION configuration
798
+ - Budget checks at 4 enforcement points (before/after consultation, debate, synthesis)
799
+ - `/ai-consultants:config-budget` slash command
800
+ - Updated doctor.sh to display budget status
801
+
802
+ ### v2.3.0
803
+ - Semantic caching with fingerprint-based cache keys
804
+ - Response length limits (opt-in, per category)
805
+ - Cost-aware routing (economic models for simple queries)
806
+ - Fallback escalation (premium model if confidence < 7)
807
+ - Debate optimization (opt-in, skip if all agree)
808
+ - Mandatory debate for SECURITY/ARCHITECTURE categories
809
+ - Quality monitoring with `optimization_metrics.json`
810
+ - Compact reports (summaries only by default)
811
+ - Code simplification (extracted helper functions)
812
+
813
+ ### v2.2.0
814
+ - Claude consultant with "The Synthesizer" persona
815
+ - Self-exclusion logic (invoking agent excluded from panel)
816
+ - Configuration presets (`--preset minimal/balanced/high-stakes/local`)
817
+ - Doctor command with auto-fix
818
+ - Synthesis strategies (`--strategy majority/risk_averse/security_first`)
819
+ - Confidence intervals with statistical ranges
820
+ - Anonymous peer review
821
+ - Ollama local model support
822
+ - Panic button mode for uncertainty detection
823
+ - Judge step for overconfidence detection
824
+ - One-liner installation
825
+
826
+ ### v2.1.0
827
+ - New consultants: Aider, DeepSeek
828
+ - 17 configurable personas
829
+ - Token optimization with AST extraction
830
+
831
+ ### v2.0.0
832
+ - Personas for each consultant (The Architect, The Pragmatist, etc.)
833
+ - Confidence scoring 1-10 on every response
834
+ - Auto-synthesis with weighted recommendation
835
+ - Multi-Agent Debate with cross-critique
836
+ - Smart routing based on category
837
+ - Session management for follow-up
838
+ - Cost tracking and budget limits
839
+ - Interactive progress bars