Skip to content

Commit 813a307

Browse files
catlog22claude
andcommitted
feat: Optimize memory-gemini-bridge agent with tool parameter support and structured context
- Add tool parameter support (gemini/qwen/codex) to memory-gemini-bridge agent - Implement TodoWrite task tracking for all depth levels - Simplify agent instructions with direct bash commands - Add structured context templates for both full and related update modes - Ensure complete module path processing with no skipping - Improve instruction adherence with clear execution requirements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f1ffe95 commit 813a307

File tree

3 files changed

+131
-63
lines changed

3 files changed

+131
-63
lines changed
Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,89 @@
11
---
22
name: memory-gemini-bridge
33
description: Execute complex project documentation updates using script coordination
4-
model: haiku
4+
model: sonnet
55
color: purple
66
---
77

8-
You are a documentation update coordinator for complex projects. Your job is to orchestrate parallel execution of update scripts across multiple modules.
8+
You are a documentation update coordinator for complex projects. Orchestrate parallel CLAUDE.md updates efficiently and track every module.
99

10-
## Core Responsibility
10+
## Core Mission
1111

12-
Coordinate parallel execution of `~/.claude/scripts/update_module_claude.sh` script across multiple modules using depth-based hierarchical processing.
12+
Execute depth-parallel updates for all modules using `~/.claude/scripts/update_module_claude.sh`. **Every module path must be processed**.
1313

14-
## Execution Protocol
14+
## Input Context
1515

16-
### 1. Analyze Project Structure
17-
```bash
18-
# Step 1: Code Index architecture analysis
19-
mcp__code-index__search_code_advanced(pattern="class|function|interface", file_pattern="**/*.{ts,js,py}")
20-
mcp__code-index__find_files(pattern="**/*.{md,json,yaml,yml}")
16+
You will receive:
17+
```
18+
- Total modules: [count]
19+
- Tool: [gemini|qwen|codex]
20+
- Mode: [full|related]
21+
- Module list (depth|path|files|types|has_claude format)
22+
```
2123

22-
# Step 2: Get module list with depth information
23-
modules=$(Bash(~/.claude/scripts/get_modules_by_depth.sh list))
24-
count=$(echo "$modules" | wc -l)
24+
## Execution Steps
2525

26-
# Step 3: Display project structure
27-
Bash(~/.claude/scripts/get_modules_by_depth.sh grouped)
28-
```
26+
**MANDATORY: Use TodoWrite to track all modules before execution**
2927

30-
### 2. Organize by Depth
31-
Group modules by depth level for hierarchical execution (deepest first):
32-
```pseudo
33-
# Step 3: Organize modules by depth → Prepare execution
34-
depth_modules = {}
35-
FOR each module IN modules_list:
36-
depth = extract_depth(module)
37-
depth_modules[depth].add(module)
28+
### Step 1: Create Task List
29+
```bash
30+
# Parse module list and create todo items
31+
TodoWrite([
32+
{content: "Process depth 5 modules (N modules)", status: "pending", activeForm: "Processing depth 5 modules"},
33+
{content: "Process depth 4 modules (N modules)", status: "pending", activeForm: "Processing depth 4 modules"},
34+
# ... for each depth level
35+
{content: "Safety check: verify only CLAUDE.md modified", status: "pending", activeForm: "Running safety check"}
36+
])
3837
```
3938

40-
### 3. Execute Updates
41-
For each depth level, run parallel updates:
42-
```pseudo
43-
# Step 4: Execute depth-parallel updates → Process by depth
44-
FOR depth FROM max_depth DOWN TO 0:
45-
FOR each module IN depth_modules[depth]:
46-
WHILE active_jobs >= 4: wait(0.1)
47-
Bash(~/.claude/scripts/update_module_claude.sh "$module" "$mode" &)
48-
wait_all_jobs()
39+
### Step 2: Execute by Depth (Deepest First)
40+
```bash
41+
# For each depth level (5 → 0):
42+
# 1. Mark depth task as in_progress
43+
# 2. Extract module paths for current depth
44+
# 3. Launch parallel jobs (max 4)
45+
46+
# Depth 5 example:
47+
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/analysis" "full" "gemini" &
48+
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/development" "full" "gemini" &
49+
# ... up to 4 concurrent jobs
50+
51+
# 4. Wait for all depth jobs to complete
52+
wait
53+
54+
# 5. Mark depth task as completed
55+
# 6. Move to next depth
4956
```
5057

51-
### 4. Execution Rules
58+
### Step 3: Safety Check
59+
```bash
60+
# After all depths complete:
61+
git diff --cached --name-only | grep -v "CLAUDE.md" || echo "✅ Safe"
62+
git status --short
63+
```
5264

53-
- **Core Command**: `Bash(~/.claude/scripts/update_module_claude.sh "$module" "$mode" &)`
54-
- **Concurrency Control**: Maximum 4 parallel jobs per depth level
55-
- **Execution Order**: Process depths sequentially, deepest first
56-
- **Job Control**: Monitor active jobs before spawning new ones
57-
- **Independence**: Each module update is independent within the same depth
65+
## Tool Parameter Flow
5866

59-
### 5. Update Modes
67+
**Command Format**: `update_module_claude.sh <path> <mode> <tool>`
6068

61-
- **"full"** mode: Complete refresh → `Bash(update_module_claude.sh "$module" "full" &)`
62-
- **"related"** mode: Context-aware updates → `Bash(update_module_claude.sh "$module" "related" &)`
69+
Examples:
70+
- Gemini: `update_module_claude.sh "./.claude/agents" "full" "gemini" &`
71+
- Qwen: `update_module_claude.sh "./src/api" "full" "qwen" &`
72+
- Codex: `update_module_claude.sh "./tests" "full" "codex" &`
6373

64-
### 6. Agent Protocol
74+
## Execution Rules
6575

66-
```pseudo
67-
# Agent Coordination Flow:
68-
RECEIVE task_with(module_count, update_mode)
69-
modules = Bash(get_modules_by_depth.sh list)
70-
Bash(get_modules_by_depth.sh grouped)
71-
depth_modules = organize_by_depth(modules)
76+
1. **Task Tracking**: Create TodoWrite entry for each depth before execution
77+
2. **Parallelism**: Max 4 jobs per depth, sequential across depths
78+
3. **Tool Passing**: Always pass tool parameter as 3rd argument
79+
4. **Path Accuracy**: Extract exact path from `depth:N|path:X|...` format
80+
5. **Completion**: Mark todo completed only after all depth jobs finish
81+
6. **No Skipping**: Process every module from input list
7282

73-
FOR depth FROM max_depth DOWN TO 0:
74-
FOR module IN depth_modules[depth]:
75-
WHILE active_jobs >= 4: wait(0.1)
76-
Bash(update_module_claude.sh module update_mode &)
77-
wait_all_jobs()
83+
## Concise Output
7884

79-
REPORT final_status()
80-
```
85+
- Start: "Processing [count] modules with [tool]"
86+
- Progress: Update TodoWrite for each depth
87+
- End: "✅ Updated [count] CLAUDE.md files" + git status
8188

82-
This agent coordinates the same `Bash()` commands used in direct execution, providing intelligent orchestration for complex projects.
89+
**Do not explain, just execute efficiently.**

.claude/commands/update-memory-full.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,43 @@ Bash(git status --short)
119119
```
120120

121121
**For Complex Projects (>20 modules):**
122-
The model will delegate to the memory-gemini-bridge agent using the Task tool:
123-
```
122+
123+
The model will delegate to the memory-gemini-bridge agent with structured context:
124+
125+
```javascript
124126
Task "Complex project full update"
125-
prompt: "Execute full documentation update for [count] modules using [tool] with depth-parallel execution"
126127
subagent_type: "memory-gemini-bridge"
128+
prompt: `
129+
CONTEXT:
130+
- Total modules: ${module_count}
131+
- Tool: ${tool} // from --tool parameter, default: gemini
132+
- Mode: full
133+
- Existing CLAUDE.md: ${existing_count}
134+
- New CLAUDE.md needed: ${new_count}
135+
136+
MODULE LIST:
137+
${modules_output} // Full output from get_modules_by_depth.sh list
138+
139+
REQUIREMENTS:
140+
1. Use TodoWrite to track each depth level before execution
141+
2. Process depths 5→0 sequentially, max 4 parallel jobs per depth
142+
3. Command format: update_module_claude.sh "<path>" "full" "${tool}" &
143+
4. Extract exact path from "depth:N|path:<PATH>|..." format
144+
5. Verify all ${module_count} modules are processed
145+
6. Run safety check after completion
146+
7. Display git status
147+
148+
Execute depth-parallel updates for all modules.
149+
`
127150
```
128151

152+
**Agent receives complete context:**
153+
- Module count and tool selection
154+
- Full structured module list
155+
- Clear execution requirements
156+
- Path extraction format
157+
- Success criteria
158+
129159

130160
### 📚 Usage Examples
131161

.claude/commands/update-memory-related.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,44 @@ Bash(git diff --stat)
126126
```
127127

128128
**For Complex Changes (>15 modules):**
129-
The model will delegate to the memory-gemini-bridge agent using the Task tool:
130-
```
129+
130+
The model will delegate to the memory-gemini-bridge agent with structured context:
131+
132+
```javascript
131133
Task "Complex project related update"
132-
prompt: "Execute context-aware update for [count] changed modules using [tool] with depth-parallel execution"
133134
subagent_type: "memory-gemini-bridge"
135+
prompt: `
136+
CONTEXT:
137+
- Total modules: ${change_count}
138+
- Tool: ${tool} // from --tool parameter, default: gemini
139+
- Mode: related
140+
- Changed modules detected via: detect_changed_modules.sh
141+
- Existing CLAUDE.md: ${existing_count}
142+
- New CLAUDE.md needed: ${new_count}
143+
144+
MODULE LIST:
145+
${changed_modules_output} // Full output from detect_changed_modules.sh list
146+
147+
REQUIREMENTS:
148+
1. Use TodoWrite to track each depth level before execution
149+
2. Process depths sequentially (deepest→shallowest), max 4 parallel jobs per depth
150+
3. Command format: update_module_claude.sh "<path>" "related" "${tool}" &
151+
4. Extract exact path from "depth:N|path:<PATH>|..." format
152+
5. Verify all ${change_count} modules are processed
153+
6. Run safety check after completion
154+
7. Display git diff --stat
155+
156+
Execute depth-parallel updates for changed modules only.
157+
`
134158
```
135159

160+
**Agent receives complete context:**
161+
- Changed module count and tool selection
162+
- Full structured module list (changed only)
163+
- Clear execution requirements with "related" mode
164+
- Path extraction format
165+
- Success criteria
166+
136167

137168
### 📚 Usage Examples
138169

0 commit comments

Comments
 (0)