You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: natural language parsing and multi-instance for /consult (#223)
* feat: add natural language parsing and multi-instance support to /consult
The /consult command now accepts free-form natural language input in
addition to explicit flags:
- "with codex about my auth approach" → tool=codex, question extracted
- "ask 3 gemini about this design" → tool=gemini, count=3
- "thoroughly ask claude about errors" → tool=claude, effort=high
Multi-instance support (--count=N or "ask N tool") runs N parallel
consultations with the same tool, presenting numbered responses with
a brief synthesis of agreements and differences.
Architecture: command handles NLP parsing + interactive resolution,
agent extended with multi-instance parallel execution, skill unchanged.
* fix: use placeholder timestamp in multi-session state example
Gemini review: hardcoded timestamp in JSON example could mislead
the implementing agent. Use dynamic placeholder instead.
* fix: address Copilot review feedback
- Add count validation (1-5) in Phase 1 and agent Step 2
- Document --continue + --count mutual exclusivity
- Add 5th option to Instances picker (was missing 4-5 range)
<!-- AUTO-GENERATED by scripts/gen-adapters.js - DO NOT EDIT -->
2
2
---
3
3
name: consult
4
-
description: "Use when user asks to \"consult gemini\", \"ask codex\", \"get second opinion\", \"cross-check with claude\", \"consult another AI\", \"ask opencode\", \"copilot opinion\". Queries another AI CLI tool and returns the response."
4
+
description: "Use when user asks to \"consult gemini\", \"ask codex\", \"get second opinion\", \"cross-check with claude\", \"consult another AI\", \"ask opencode\", \"copilot opinion\", \"ask 3 codex\", \"multi-consult\". Queries another AI CLI tool and returns the response."
5
5
---
6
6
7
7
# /consult - Cross-Tool AI Consultation
8
8
9
-
You are executing the /consult command. Your job is to consult another AI CLI tool, get its response, and present the results to the user.
9
+
You are executing the /consult command. Your job is to parse the user's request (natural language or flags), resolve missing parameters interactively, and execute the consultation.
10
10
11
11
## Constraints
12
12
13
13
- NEVER expose API keys in commands or output
14
14
- NEVER run with permission-bypassing flags (`--dangerously-skip-permissions`, `bypassPermissions`)
15
15
- MUST use safe-mode defaults (`-a suggest` for Codex, `--allowedTools "Read,Glob,Grep"` for Claude)
16
16
- MUST enforce 120s timeout on all tool executions
17
-
- MUST validate `--tool` against allow-list: gemini, codex, claude, opencode, copilot (reject all others)
17
+
- MUST validate tool names against allow-list: gemini, codex, claude, opencode, copilot (reject all others)
18
18
- MUST validate `--context=file=PATH` is within the project directory (reject absolute paths outside cwd)
19
19
- MUST quote all user-provided values in shell commands to prevent injection
20
20
- NEVER execute tools the user has not explicitly requested
-**--continue**: Continue last consultation session, or `--continue=SESSION_ID` for specific session
26
+
Parse `$ARGUMENTS` using both explicit flags and natural language extraction. Flags always take priority over NLP when both provide the same parameter.
32
27
33
-
## Execution
28
+
#### Step 1a: Extract explicit flags
29
+
30
+
Look for and remove these flags from `$ARGUMENTS`:
31
+
32
+
1.`--tool=VALUE` or `--tool VALUE` where VALUE is one of: gemini, codex, claude, opencode, copilot
33
+
2.`--effort=VALUE` or `--effort VALUE` where VALUE is one of: low, medium, high, max
34
+
3.`--model=VALUE` or `--model VALUE` (any string, including quoted)
35
+
4.`--context=VALUE` where VALUE is: diff, file=PATH, or none
- "few instances" / "multiple" / "several" -> count=ambiguous (ask user in Phase 2)
38
57
39
-
1. Look for `--tool=VALUE` or `--tool VALUE` where VALUE MUST be one of: gemini, codex, claude, opencode, copilot (reject others)
40
-
2. Look for `--effort=VALUE` or `--effort VALUE` where VALUE MUST be one of: low, medium, high, max
41
-
3. Look for `--model=VALUE` or `--model VALUE` (any string, including quoted strings like `"my model"`)
42
-
4. Look for `--context=VALUE` where VALUE is: diff, file=PATH, or none
43
-
5. Look for `--continue` (optionally `--continue=SESSION_ID`)
44
-
6. Remove all matched flags (including their values) from `$ARGUMENTS`. Handle quoted flag values (e.g., `--model "gpt 4"`) by removing the entire quoted string. Everything remaining is the **question**.
58
+
**Count validation**: After extracting count (from flags or NLP), validate: 1 <= count <= 5. If count < 1 or count > 5, show `[ERROR] Instance count must be 1-5. Got: {count}` and stop.
45
59
46
-
If no question text and no `--continue` flag found, show:
[ERROR] Usage: /consult "your question" or /consult with gemini about your question
49
74
```
50
75
51
-
### Phase 2: Interactive Parameter Selection
76
+
### Phase 2: Interactive Parameter Resolution
52
77
53
-
MUST resolve ALL missing parameters interactively before Phase 3. ONLY skip this phase if ALL of --tool, --effort, AND --model are explicitly provided by the user in $ARGUMENTS. Do NOT silently default any parameter.
78
+
MUST resolve ALL missing parameters interactively. ONLY skip this phase if ALL required params (tool, effort, model) are resolved AND either a question exists or --continue is present. Do NOT silently default any parameter.
54
79
55
80
#### Step 2a: Handle --continue
56
81
82
+
**Note:**`--continue` and `--count > 1` are mutually exclusive. Session resume applies to a single tool session. If both are present, show `[ERROR] Cannot use --continue with --count > 1. Use --continue for single session resume.` and stop.
83
+
57
84
If `--continue` is present:
58
85
1. Read the session file at `{AI_STATE_DIR}/consult/last-session.json`
59
86
@@ -64,9 +91,9 @@ If `--continue` is present:
64
91
2. If the file exists, restore the saved tool, session_id, and model from it
65
92
3. If the file does not exist, show `[WARN] No previous session found` and proceed as a fresh consultation
66
93
67
-
#### Step 2b: Batch Selection (tool + effort)
94
+
#### Step 2b: Detect installed tools
68
95
69
-
First, detect which tools are installed by running all 5 checks **in parallel** via Bash:
96
+
Run all 5 checks **in parallel** via Bash:
70
97
71
98
-`where.exe <tool> 2>nul && echo FOUND || echo NOTFOUND` (Windows)
72
99
-`which <tool> 2>/dev/null && echo FOUND || echo NOTFOUND` (Unix)
If zero tools are installed: `[ERROR] No AI CLI tools found. Install at least one: npm i -g @anthropic-ai/claude-code, npm i -g @openai/codex, npm i -g opencode-ai`
77
104
78
-
Then use a SINGLE request_user_input call to ask all missing parameters at once. Include only the questions for parameters NOT already provided in $ARGUMENTS:
105
+
#### Step 2c: Batch selection for missing params
106
+
107
+
Use a SINGLE request_user_input call to ask all missing parameters at once. Include ONLY questions for parameters NOT already resolved from Phase 1:
79
108
80
109
```
81
110
request_user_input:
82
111
> **Codex**: Each question MUST include a unique `id` field (e.g., `id: "q1"`).
- The user explicitly mentioned multiple instances (e.g., "few", "multiple", "several")
141
+
- The count was set but ambiguous
142
+
Do NOT show Instances question for simple single-tool requests. Default count=1 silently when no multi-instance intent detected.
104
143
105
-
IMPORTANT: Do NOT skip any missing parameter. Do NOT silently default --effort to "medium" or --tool to any value. Present pickers for ALL unresolved parameters.
144
+
Map tool choice to lowercase: "Claude" -> "claude", "Codex" -> "codex", etc.
#### Step 2c: Model Selection (MUST ask if no --model)
148
+
#### Step 2d: Model selection (MUST ask if no --model)
108
149
109
-
After tool is resolved (from Step 2b or $ARGUMENTS), present a model picker with options specific to the selected tool. The user can always type a custom model name via the "Other" option.
150
+
After tool is resolved, present a model picker with options specific to the selected tool. The user can always type a custom model name via the "Other" option.
Map the user's choice to the model string (strip " (Recommended)" suffix if present). Pass the selected model to the skill via `--model`.
221
+
Map the user's choice to the model string (strip " (Recommended)" suffix if present).
181
222
182
-
IMPORTANT: Do NOT skip this step. Do NOT silently use a default model. If --model was not explicitly provided in $ARGUMENTS, you MUST present this picker. The model lists above are current as of Feb 2026 - the user may type any model name supported by their tool via the "Other" option.
223
+
IMPORTANT: Do NOT skip model selection. Do NOT silently use a default model. If --model was not explicitly provided, you MUST present this picker.
183
224
184
-
### Phase 3: Invoke Consult Skill
225
+
### Phase 3: Execute Consultation
185
226
186
-
With all parameters resolved (tool, effort, model, question, and optionally context, continue), invoke the `consult` skill using the Skill tool:
227
+
With all parameters resolved (tool, effort, model, question, count, and optionally context/continue):
228
+
229
+
#### Single instance (count=1, the default)
230
+
231
+
Invoke the `consult` skill directly using the Skill tool:
Example: "Is this the right approach?" --tool=gemini --effort=high --model=gemini-3-pro
193
238
```
194
239
195
-
The skill handles the full consultation lifecycle: it resolves the model from the effort level, builds the CLI command, packages any context, executes the command via Bash with a 120-second timeout, and returns a plain JSON result.
240
+
The skill handles the full consultation lifecycle: model resolution, command building, context packaging, execution with 120s timeout, and returns a plain JSON result.
241
+
242
+
#### Multi-instance (count > 1)
196
243
197
-
### Phase 4: Parse Skill Output
244
+
Spawn the `consult:consult-agent` via the Task tool with all resolved parameters:
198
245
199
-
The skill returns a plain JSON object containing: `tool`, `model`, `effort`, `duration_ms`, `response`, `session_id`, and `continuable`. Parse the JSON directly from the skill output.
246
+
```
247
+
Task:
248
+
subagent_type: "consult:consult-agent"
249
+
prompt: |
250
+
Execute a multi-instance consultation with these pre-resolved parameters:
251
+
- tool: [tool]
252
+
- model: [model]
253
+
- effort: [effort]
254
+
- question: [question]
255
+
- count: [count]
256
+
- context: [context or none]
257
+
258
+
Run [count] parallel consultations with the same tool and parameters.
259
+
Return all responses formatted with numbered headers and a brief synthesis.
260
+
```
261
+
262
+
The agent handles parallel execution, temp file management, result parsing, and synthesis.
200
263
201
-
### Phase 5: Present Results
264
+
### Phase 4: Present Results
202
265
203
-
After parsing the JSON, format and display the result as human-friendly text:
0 commit comments