Skip to content

Commit cf70dd1

Browse files
committed
Initialize Tier Protocol plan and update tasks
1 parent 1f554aa commit cf70dd1

7 files changed

Lines changed: 304 additions & 0 deletions

File tree

.gemini/commands/brainstorm.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
description = "Interactive brainstorming session to challenge ideas, identify risks, and explore alternatives without making changes."
2+
3+
prompt = """
4+
You are an expert critical thinking partner and strategic advisor. You are executing the custom `/brainstorm` command.
5+
6+
**CRITICAL MANDATE:** This command is strictly for exploration, risk assessment, and creative problem-solving. You MUST NOT modify, create, or delete any files in the repository. Your goal is to provide high-signal feedback and challenging questions.
7+
8+
Follow this interactive workflow:
9+
10+
### Phase 1: Context & Discovery (Optional)
11+
1. If the brainstorming topic relates to existing code or documentation, use `list_directory`, `read_file`, `grep_search`, or `glob` to gather relevant context.
12+
2. If external information is needed, use `web_search` and `web_fetch` to research state-of-the-art practices or similar problems.
13+
3. Use `run_shell_command` only for read-only operations (e.g., `find`, `grep`, `ls`).
14+
15+
NOTE: Keep this phase very short and focused, no more than 2-3 tool calls. If more context is necessary, instruct the user to provide it or suggest they use /research to gather it themselves before returning to brainstorming.
16+
17+
### Phase 2: Critical Exploration (The Loop)
18+
1. **Analyze:** Evaluate the user's idea or problem statement. Look for hidden assumptions, potential edge cases, and architectural risks.
19+
2. **Challenge:** Do not simply agree. Provide critical advice. If an idea seems flawed, explain why and suggest alternatives.
20+
3. **Question:** Ask 1-3 hard, targeted follow-up questions to push the user's thinking further.
21+
4. **Interactive Dialogue:** Use `ask_user` to present your critique and questions. Keep the interaction fast and focused. Continue this loop until the user is satisfied or a natural conclusion is reached.
22+
23+
### Phase 3: Synthesis & Next Steps
24+
1. Once the brainstorming session concludes, provide a concise summary of:
25+
- **Key Insights:** The most valuable takeaways from the session.
26+
- **Identified Risks:** Potential pitfalls or blockers discovered.
27+
- **Recommendations:** Actionable advice for the next phase.
28+
2. **Propose Action:** Suggest that the user transition from brainstorming to planning by using the `/plan` command to turn these insights into a concrete technical strategy.
29+
30+
Start by asking the user for the topic or idea they want to brainstorm.
31+
"""

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The `.gemini/commands/` directory defines specialized workflows that automate ev
5959
### 🔍 Phase 1: Planning & Discovery
6060
* **`/research <topic>`**: A deep, 3-phase investigation (Planning -> Data Gathering -> Reporting) that produces exhaustive Markdown reports in the `research/` directory. **Crucial for gathering technical requirements and state-of-the-art context.**
6161
* **`/learn <topic>`**: A grounded learning lifecycle (Audit -> Strategic Mapping -> Execution -> Codification) for mastering new technologies and building a permanent, machine-readable knowledge base in `.gemini/skills/` using the specialized `learner` subagent.
62+
* **`/brainstorm`**: An interactive, high-signal brainstorming session. The agent acts as a critical partner—challenging your assumptions, identifying architectural risks, and asking hard follow-up questions—without making any changes to the codebase.
6263
* **`/plan`**: The **Architectural Bridge**. This interactive workflow translates ideas into actionable execution plans:
6364
* **Phase 1 (Clarification):** The agent interviews you to resolve ambiguities before planning.
6465
* **Phase 2 (Agentic Analysis):** A specialized `planner` subagent scans the codebase and generates a detailed technical strategy.

TASKS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ Put done tasks into the Archive.
1818

1919
## Active Tasks
2020

21+
- [ ] Implement the three-tier model routing protocol (Orchestrator, Thinker, Executioner) with semantic signaling and automated tier switching. (See plan: plans/tier-protocol-implementation.md)
22+
2123
---
2224

2325
## Archive
2426

27+
- [x] Implement the new `/brainstorm` command to facilitate interactive, critical-thinking sessions and architectural risk assessment. (2026-03-24) (See plan: plans/add-brainstorm-command.md)
28+
2529
- [x] Integrate `coder` subagent into `/task work` workflow to delegate granular implementation steps. (2026-03-23) (See plan: plans/implement-coder-agent.md)
2630

2731
- [x] Implement dynamic structural testing suite and finalize documentation sync. (2026-03-23) (See plan: plans/implement-maintenance-v2.md)

docs/user-guide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Your primary tool for forensic, scientific investigation.
3434
- **How it works:** When a bug is detected, the `/debug` command implements a principled approach to problem-solving using the specialized `debugger` subagent. It moves through four distinct phases: Context Analysis, Hypothesis Formulation, Isolated Testing on a temporary branch (`debug/hyp-*`), and finally a Synthesis of the findings into a **Root Cause Analysis (RCA)** report.
3535
- **Why it works:** It forces the agent to identify the root cause *before* attempting a fix, preventing "guess-and-check" coding that can lead to regressions.
3636

37+
### `/brainstorm`
38+
39+
Your tool for interactive, critical-thinking sessions.
40+
41+
- **How it works:** You present an idea, problem, or architectural choice. The agent uses discovery tools to gather context and then enters a "challenge loop" where it pushes back on weak points, identifies hidden risks, and asks tough questions.
42+
- **Why it works:** It forces you to defend your ideas and refine them *before* they even reach the planning stage, ensuring higher-quality strategies.
43+
3744
---
3845

3946
## 🌉 Phase 2: Strategy & Planning

journal/2026-03-24.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[2026-03-24T10:45:17] - Plan: Tier Protocol Model Routing System and brainstorm command

plans/add-brainstorm-command.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Execution Plan: Add `/brainstorm` Command
2+
3+
This plan outlines the steps to add a new `/brainstorm` command to the Gemini CLI framework. This command is designed for high-signal, critical-thinking sessions, providing a dedicated space for exploration and risk assessment without making any changes to the codebase.
4+
5+
## Objective
6+
Implement a new `/brainstorm` command in `.gemini/commands/brainstorm.toml` that acts as a critical thinking partner, challenging ideas and identifying risks while strictly adhering to a "no side effects" mandate.
7+
8+
## Architectural Impact
9+
- **Discovery Layer Enhancement**: Adds a dedicated tool for the "Discovery & Audit" phase of the project lifecycle.
10+
- **Safety**: Reinforces the framework's philosophy of separating discovery/analysis from implementation/execution.
11+
- **Documentation**: Updates the project's documentation to reflect the new capability.
12+
13+
## File Operations
14+
15+
### Create
16+
- **`.gemini/commands/brainstorm.toml`**: The command definition file.
17+
18+
### Modify
19+
- **`README.md`**: Update the "Phase 1: Planning & Discovery" section.
20+
- **`docs/user-guide.md`**: Update the "Phase 1: Discovery & Audit" section.
21+
22+
---
23+
24+
## Step-by-Step Execution
25+
26+
### Step 1: Create the Command Definition
27+
Create the file `.gemini/commands/brainstorm.toml` with the following content:
28+
29+
```toml
30+
description = "Interactive brainstorming session to challenge ideas, identify risks, and explore alternatives without making changes."
31+
32+
prompt = \"\"\"
33+
You are an expert critical thinking partner and strategic advisor. You are executing the custom `/brainstorm` command.
34+
35+
**CRITICAL MANDATE:** This command is strictly for exploration, risk assessment, and creative problem-solving. You MUST NOT modify, create, or delete any files in the repository. Your goal is to provide high-signal feedback and challenging questions.
36+
37+
Follow this interactive workflow:
38+
39+
### Phase 1: Context & Discovery (Optional)
40+
1. If the brainstorming topic relates to existing code or documentation, use `list_directory`, `read_file`, `grep_search`, or `glob` to gather relevant context.
41+
2. If external information is needed, use `web_search` and `web_fetch` to research state-of-the-art practices or similar problems.
42+
3. Use `run_shell_command` only for read-only operations (e.g., `find`, `grep`, `ls`).
43+
44+
### Phase 2: Critical Exploration (The Loop)
45+
1. **Analyze:** Evaluate the user's idea or problem statement. Look for hidden assumptions, potential edge cases, and architectural risks.
46+
2. **Challenge:** Do not simply agree. Provide critical advice. If an idea seems flawed, explain why and suggest alternatives.
47+
3. **Question:** Ask 1-3 hard, targeted follow-up questions to push the user's thinking further.
48+
4. **Interactive Dialogue:** Use `ask_user` to present your critique and questions if they are structured. Or ask general questions. Keep the interaction fast and focused. Continue this loop until the user is satisfied or a natural conclusion is reached.
49+
50+
### Phase 3: Synthesis & Next Steps
51+
1. Once the brainstorming session concludes, provide a concise summary of:
52+
- **Key Insights:** The most valuable takeaways from the session.
53+
- **Identified Risks:** Potential pitfalls or blockers discovered.
54+
- **Recommendations:** Actionable advice for the next phase.
55+
2. **Propose Action:** Suggest that the user transition from brainstorming to planning by using the `/plan` command to turn these insights into a concrete technical strategy.
56+
57+
Start by asking the user for the topic or idea they want to brainstorm or infer from context if provided.
58+
\"\"\"
59+
```
60+
61+
### Step 2: Update Main README
62+
Modify `README.md` to include `/brainstorm` in the "Phase 1: Planning & Discovery" section, after `/learn`:
63+
64+
```markdown
65+
* **`/brainstorm`**: An interactive, high-signal brainstorming session. The agent acts as a critical partner—challenging your assumptions, identifying architectural risks, and asking hard follow-up questions—without making any changes to the codebase.
66+
```
67+
68+
### Step 3: Update User Guide
69+
Modify `docs/user-guide.md` to include `/brainstorm` in the "Phase 1: Discovery & Audit" section, after `/debug`:
70+
71+
```markdown
72+
### `/brainstorm`
73+
74+
Your tool for interactive, critical-thinking sessions.
75+
76+
- **How it works:** You present an idea, problem, or architectural choice. The agent uses discovery tools to gather context and then enters a "challenge loop" where it pushes back on weak points, identifies hidden risks, and asks tough questions.
77+
- **Why it works:** It forces you to defend your ideas and refine them *before* they even reach the planning stage, ensuring higher-quality strategies.
78+
```
79+
80+
---
81+
82+
## Testing Strategy
83+
84+
### 1. Functional Verification
85+
Invoke the command:
86+
```bash
87+
gemini /brainstorm "Adding a new caching layer to the API"
88+
```
89+
**Expected Results:**
90+
- The agent asks for more details or begins analyzing existing code using `list_directory` or `read_file`.
91+
- The agent provides at least one critical observation (e.g., cache invalidation risks).
92+
- The agent asks targeted follow-up questions.
93+
- The agent *never* attempts to create or modify files.
94+
95+
### 2. Workflow Verification
96+
- Ensure the session ends with a summary of insights and risks.
97+
- Ensure the agent explicitly suggests using `/plan` at the end of the summary.
98+
99+
### 3. Documentation Verification
100+
- Verify that the new command is listed correctly in the `README.md` and `docs/user-guide.md`.
101+
- Verify that `gemini --help` (or equivalent) correctly displays the new command description if the CLI supports it.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Implementation Plan: Tier Protocol Model Routing System
2+
3+
This plan outlines the implementation of the "Tier Protocol" for the Gemini CLI, enabling dynamic model routing based on task complexity (Orchestration, Thinking, Execution).
4+
5+
## Objective
6+
Establish a three-tier model routing system to optimize performance, cost, and reasoning quality by using specialized models for different phases of the agent's workflow.
7+
8+
## Architectural Impact
9+
- **Middleware Integration**: Adds a `BeforeModel` hook (`tier_router.py`) that acts as a traffic controller for model selection.
10+
- **Semantic Signaling**: Uses explicit `[Tier: *]` tags in assistant messages to communicate routing intent to the framework.
11+
- **Centralized Configuration**: Standardizes model mapping and default settings in `.gemini/settings.json`.
12+
- **System-level Feedback**: Integrates `notify-send` for real-time user visibility of tier switches.
13+
14+
## File Operations
15+
16+
| Action | File | Description |
17+
| :--- | :--- | :--- |
18+
| **Modify** | `GEMINI.md` | Define the Tier Protocol, models, signals, and usage guidelines. |
19+
| **Create** | `.gemini/hooks/tier_router.py` | Implement the logic to parse signals and route models. |
20+
| **Modify** | `.gemini/settings.json` | Register the `BeforeModel` hook and set the default model. |
21+
| **Modify** | `.gemini/commands/*.toml` | Update command prompts to include tier signaling instructions. |
22+
23+
## Step-by-Step Execution
24+
25+
### Step 1: Document the Tier Protocol in `GEMINI.md`
26+
Add a new section to `GEMINI.md` defining the protocol:
27+
28+
```markdown
29+
## Tier Protocol
30+
31+
To optimize reasoning and execution, this project uses a multi-tier model routing system:
32+
33+
| Tier | Model | Use Case | Signal |
34+
| :--- | :--- | :--- | :--- |
35+
| **Orchestrator** | `gemini-3-flash-preview` | Default routing, task management, and fast orchestration. | `[Tier: Orchestrator]` |
36+
| **Thinker** | `gemini-3.1-pro-preview` | Deep architectural planning, RCA, and complex logic. | `[Tier: Thinker]` |
37+
| **Executioner** | `gemini-2.5-flash` | High-velocity coding, boilerplate, and tool-heavy tasks. | `[Tier: Executioner]` |
38+
39+
**Guidelines:**
40+
- **Implicit Default:** All sessions start in Orchestrator tier.
41+
- **Explicit Switching:** Always emit the signal (e.g., `[Tier: Thinker]`) at the end of your response to route the *next* turn to that model.
42+
- **Phase Transition:** Switch to **Thinker** for discovery/planning and **Executioner** for task implementation.
43+
```
44+
45+
### Step 2: Implement the `tier_router` Hook
46+
Create `.gemini/hooks/tier_router.py` with the following logic:
47+
48+
```python
49+
import sys
50+
import json
51+
import re
52+
import os
53+
import subprocess
54+
55+
# Model Mapping
56+
TIER_MAPPING = {
57+
"Orchestrator": "gemini-3-flash-preview",
58+
"Thinker": "gemini-3.1-pro-preview",
59+
"Executioner": "gemini-2.5-flash"
60+
}
61+
62+
def main():
63+
try:
64+
input_data = sys.stdin.read()
65+
if not input_data:
66+
print(json.dumps({"decision": "allow"}))
67+
return
68+
69+
data = json.loads(input_data)
70+
history = data.get("history", [])
71+
72+
# Identify target tier from last assistant message
73+
target_tier = None
74+
for message in reversed(history):
75+
if message.get("role") == "assistant":
76+
content = message.get("content", "")
77+
match = re.search(r"\[Tier:\s*(Orchestrator|Thinker|Executioner)\]", content)
78+
if match:
79+
target_tier = match.group(1)
80+
break
81+
82+
# Prepare response
83+
response = {"decision": "allow"}
84+
85+
if target_tier and target_tier in TIER_MAPPING:
86+
model_id = TIER_MAPPING[target_tier]
87+
response["model"] = model_id
88+
response["systemMessage"] = f"Tier Protocol: Active ({target_tier})"
89+
90+
# User Notification
91+
try:
92+
subprocess.run([
93+
"notify-send",
94+
"Gemini Tier Switch",
95+
f"Routing to {target_tier}: {model_id}",
96+
"-i", "dialog-information", "-t", "2000"
97+
], check=False)
98+
except:
99+
pass
100+
101+
print(json.dumps(response))
102+
103+
except Exception as e:
104+
sys.stderr.write(f"Error in tier_router: {str(e)}\n")
105+
print(json.dumps({"decision": "allow"}))
106+
107+
if __name__ == "__main__":
108+
main()
109+
```
110+
111+
### Step 3: Update `settings.json` Configuration
112+
Register the hook and set the default model:
113+
114+
```json
115+
{
116+
"model": "gemini-3-flash-preview",
117+
"hooks": {
118+
"BeforeModel": [
119+
{
120+
"matcher": "*",
121+
"hooks": [
122+
{
123+
"name": "tier-router",
124+
"type": "command",
125+
"command": "python3 .gemini/hooks/tier_router.py"
126+
}
127+
]
128+
}
129+
]
130+
}
131+
}
132+
```
133+
134+
### Step 4: Update Command Prompts for Signaling
135+
Update `.gemini/commands/*.toml` to incorporate tier instructions.
136+
137+
#### Thinker-Heavy Commands
138+
Add `[Tier: Thinker]` requirement to:
139+
- `brainstorm.toml`: "Start by switching to `[Tier: Thinker]` to engage deep reasoning."
140+
- `plan.toml`: "Use `[Tier: Thinker]` for architectural analysis phases."
141+
- `research.toml`, `review.toml`, `learn.toml`, `issues.toml`, `document.toml`, `draft.toml`: Update to prioritize Thinker.
142+
143+
#### Executioner-Heavy Commands
144+
Add `[Tier: Executioner]` requirement to:
145+
- `commit.toml`: "Switch to `[Tier: Executioner]` for rapid change grouping and committing."
146+
- `scaffold.toml`: "Use `[Tier: Executioner]` for boilerplate generation."
147+
148+
#### Hybrid Commands (Phase-based Routing)
149+
- `debug.toml`:
150+
- **Phase 2 (Hypothesis):** Switch to `[Tier: Thinker]`.
151+
- **Phase 3 (Testing):** Switch to `[Tier: Executioner]` for diagnostic branch work.
152+
- `task.toml`:
153+
- **Phase 3 (TCR Loop):** Instruct the Orchestrator to switch to `[Tier: Executioner]` for implementation steps.
154+
155+
## Testing Strategy
156+
1. **Routing Logic Validation**: Use a mock session JSON (containing `[Tier: Thinker]`) and pipe it into `tier_router.py` to verify the output contains `"model": "gemini-3.1-pro-preview"`.
157+
2. **Notification Test**: Trigger the hook and verify the `notify-send` desktop alert appears.
158+
3. **End-to-End Command Test**: Run `/plan` and verify the first assistant turn ends with `[Tier: Thinker]`, followed by the model switch in the subsequent turn.
159+
4. **Integration Test**: Verify `settings.json` registration doesn't interfere with existing hooks (e.g., `log.py`, `notify.py`).

0 commit comments

Comments
 (0)