refactor: 更新 update_module_claude.sh 脚本,调整参数顺序并添加模型选择说明

This commit is contained in:
catlog22
2025-10-21 21:02:17 +08:00
parent de3dc35c5b
commit 7783ee0ac5
5 changed files with 102 additions and 61 deletions

View File

@@ -16,7 +16,6 @@ You will receive:
```
- Total modules: [count]
- Tool: [gemini|qwen|codex]
- Mode: [full|related]
- Module list (depth|path|files|types|has_claude format)
```
@@ -43,8 +42,8 @@ TodoWrite([
# 3. Launch parallel jobs (max 4)
# Depth 5 example:
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/analysis" "full" "gemini" &
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/development" "full" "gemini" &
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/analysis" "gemini" &
~/.claude/scripts/update_module_claude.sh "./.claude/workflows/cli-templates/prompts/development" "gemini" &
# ... up to 4 concurrent jobs
# 4. Wait for all depth jobs to complete
@@ -63,18 +62,18 @@ git status --short
## Tool Parameter Flow
**Command Format**: `update_module_claude.sh <path> <mode> <tool>`
**Command Format**: `update_module_claude.sh <path> <tool>`
Examples:
- Gemini: `update_module_claude.sh "./.claude/agents" "full" "gemini" &`
- Qwen: `update_module_claude.sh "./src/api" "full" "qwen" &`
- Codex: `update_module_claude.sh "./tests" "full" "codex" &`
- Gemini: `update_module_claude.sh "./.claude/agents" "gemini" &`
- Qwen: `update_module_claude.sh "./src/api" "qwen" &`
- Codex: `update_module_claude.sh "./tests" "codex" &`
## Execution Rules
1. **Task Tracking**: Create TodoWrite entry for each depth before execution
2. **Parallelism**: Max 4 jobs per depth, sequential across depths
3. **Tool Passing**: Always pass tool parameter as 3rd argument
3. **Tool Passing**: Always pass tool parameter as 2nd argument
4. **Path Accuracy**: Extract exact path from `depth:N|path:X|...` format
5. **Completion**: Mark todo completed only after all depth jobs finish
6. **No Skipping**: Process every module from input list

View File

@@ -141,7 +141,7 @@ for (let depth of sorted_depths.reverse()) { // N → 0
return async () => {
let success = false;
for (let tool of tool_order) {
let exit_code = bash(cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "." "full" "${tool}");
let exit_code = bash(cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "." "${tool}");
if (exit_code === 0) {
report("${module.path} updated with ${tool}");
success = true;
@@ -162,23 +162,23 @@ for (let depth of sorted_depths.reverse()) { // N → 0
**Example execution (7 modules)**:
```bash
# Depth 2 (1 module)
bash(cd ./core/interfaces && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini")
bash(cd ./core/interfaces && ~/.claude/scripts/update_module_claude.sh "." "gemini")
# → Success with gemini
# Depth 1 (5 modules → 2 batches: [4, 1])
# Batch 1 (4 modules in parallel):
bash(cd ./core && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini") &
bash(cd ./models && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini") &
bash(cd ./parametric && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini") &
bash(cd ./results && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini") &
bash(cd ./core && ~/.claude/scripts/update_module_claude.sh "." "gemini") &
bash(cd ./models && ~/.claude/scripts/update_module_claude.sh "." "gemini") &
bash(cd ./parametric && ~/.claude/scripts/update_module_claude.sh "." "gemini") &
bash(cd ./results && ~/.claude/scripts/update_module_claude.sh "." "gemini") &
wait # Wait for batch 1 to complete
# Batch 2 (1 module):
bash(cd ./utils && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini")
bash(cd ./utils && ~/.claude/scripts/update_module_claude.sh "." "gemini")
# → Success with gemini
# Depth 0 (1 module)
bash(cd . && ~/.claude/scripts/update_module_claude.sh "." "full" "gemini")
bash(cd . && ~/.claude/scripts/update_module_claude.sh "." "gemini")
# → Success with gemini
```
@@ -254,15 +254,15 @@ EXECUTION:
For each module above:
1. cd "{{module_path}}"
2. Try tool 1:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "full" "{{tool_1}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_1}}")
→ Success: Report " {{module_path}} updated with {{tool_1}}", proceed to next module
→ Failure: Try tool 2
3. Try tool 2:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "full" "{{tool_2}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_2}}")
→ Success: Report " {{module_path}} updated with {{tool_2}}", proceed to next module
→ Failure: Try tool 3
4. Try tool 3:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "full" "{{tool_3}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_3}}")
→ Success: Report " {{module_path}} updated with {{tool_3}}", proceed to next module
→ Failure: Report "FAILED: {{module_path}} failed all tools", proceed to next module

View File

@@ -108,7 +108,7 @@ for (let depth of sorted_depths.reverse()) { // N → 0
return async () => {
let success = false;
for (let tool of tool_order) {
let exit_code = bash(cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "." "related" "${tool}");
let exit_code = bash(cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "." "${tool}");
if (exit_code === 0) {
report("${module.path} updated with ${tool}");
success = true;
@@ -198,15 +198,15 @@ EXECUTION:
For each module above:
1. cd "{{module_path}}"
2. Try tool 1:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "related" "{{tool_1}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_1}}")
→ Success: Report "{{module_path}} updated with {{tool_1}}", proceed to next module
→ Failure: Try tool 2
3. Try tool 2:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "related" "{{tool_2}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_2}}")
→ Success: Report "{{module_path}} updated with {{tool_2}}", proceed to next module
→ Failure: Try tool 3
4. Try tool 3:
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "related" "{{tool_3}}")
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "." "{{tool_3}}")
→ Success: Report "{{module_path}} updated with {{tool_3}}", proceed to next module
→ Failure: Report "FAILED: {{module_path}} failed all tools", proceed to next module

View File

@@ -1,14 +1,20 @@
#!/bin/bash
# Update CLAUDE.md for a specific module with unified template
# Usage: update_module_claude.sh <module_path> [update_type] [tool]
# Usage: update_module_claude.sh <module_path> [tool] [model]
# module_path: Path to the module directory
# update_type: full|related (default: full)
# tool: gemini|qwen|codex (default: gemini)
# model: Model name (optional, uses tool defaults if not specified)
#
# Default Models:
# gemini: gemini-2.5-flash
# qwen: coder-model (default, -m optional)
# codex: gpt5-codex
#
# Features:
# - Respects .gitignore patterns (current directory or git root)
# - Unified template for all modules (folders and files)
# - Template-based documentation generation
# - Configurable model selection per tool
# Build exclusion filters from .gitignore
build_exclusion_filters() {
@@ -61,13 +67,13 @@ build_exclusion_filters() {
update_module_claude() {
local module_path="$1"
local update_type="${2:-full}"
local tool="${3:-gemini}"
local tool="${2:-gemini}"
local model="$3"
# Validate parameters
if [ -z "$module_path" ]; then
echo "❌ Error: Module path is required"
echo "Usage: update_module_claude.sh <module_path> [update_type]"
echo "Usage: update_module_claude.sh <module_path> [tool] [model]"
return 1
fi
@@ -76,6 +82,24 @@ update_module_claude() {
return 1
fi
# Set default models if not specified
if [ -z "$model" ]; then
case "$tool" in
gemini)
model="gemini-2.5-flash"
;;
qwen)
model="coder-model"
;;
codex)
model="gpt5-codex"
;;
*)
model=""
;;
esac
fi
# Build exclusion filters from .gitignore
local exclusion_filters=$(build_exclusion_filters)
@@ -85,7 +109,7 @@ update_module_claude() {
echo "⚠️ Skipping '$module_path' - no files found (after .gitignore filtering)"
return 0
fi
# Use unified template for all modules
local template_path="$HOME/.claude/workflows/cli-templates/prompts/memory/claude-module-unified.txt"
@@ -93,9 +117,9 @@ update_module_claude() {
local module_name=$(basename "$module_path")
echo "⚡ Updating: $module_path"
echo " Type: $update_type | Tool: $tool | Files: $file_count"
echo " Tool: $tool | Model: $model | Files: $file_count"
echo " Template: $(basename "$template_path")"
# Generate prompt with template injection
local template_content=""
if [ -f "$template_path" ]; then
@@ -104,23 +128,7 @@ update_module_claude() {
echo " ⚠️ Template not found: $template_path, using fallback"
template_content="Update CLAUDE.md documentation for this module: document structure, key components, dependencies, and integration points."
fi
local update_context=""
if [ "$update_type" = "full" ]; then
update_context="
Update Mode: Complete refresh
- Perform comprehensive analysis of all content
- Document module structure, dependencies, and key components
- Follow template guidelines strictly"
else
update_context="
Update Mode: Context-aware update
- Focus on recent changes and affected areas
- Maintain consistency with existing documentation
- Update only relevant sections
- Follow template guidelines for updated content"
fi
local base_prompt="
⚠️ CRITICAL RULES - MUST FOLLOW:
1. Target file: ONLY create/update the file named 'CLAUDE.md' in current directory
@@ -131,8 +139,6 @@ update_module_claude() {
$template_content
$update_context
CONTEXT: @**/*"
# Execute update
@@ -149,18 +155,28 @@ update_module_claude() {
- Tool: $tool"
# Execute with selected tool
# NOTE: Prompt is passed via -p flag for gemini/qwen, first parameter for codex
# NOTE: Model parameter (-m) is placed AFTER the prompt
case "$tool" in
qwen)
qwen -p "$final_prompt" --yolo 2>&1
if [ "$model" = "coder-model" ]; then
# coder-model is default, -m is optional
qwen -p "$final_prompt" --yolo 2>&1
else
qwen -p "$final_prompt" -m "$model" --yolo 2>&1
fi
tool_result=$?
;;
codex)
codex --full-auto exec "$final_prompt" --skip-git-repo-check -s danger-full-access 2>&1
codex --full-auto exec "$final_prompt" -m "$model" --skip-git-repo-check -s danger-full-access 2>&1
tool_result=$?
;;
gemini|*)
gemini -p "$final_prompt" --yolo 2>&1
gemini)
gemini -p "$final_prompt" -m "$model" --yolo 2>&1
tool_result=$?
;;
*)
echo " ⚠️ Unknown tool: $tool, defaulting to gemini"
gemini -p "$final_prompt" -m "$model" --yolo 2>&1
tool_result=$?
;;
esac

View File

@@ -22,6 +22,22 @@ type: strategic-guideline
- **Qwen**: Analysis, understanding, exploration & documentation (fallback, same capabilities as Gemini)
- **Codex**: Development, implementation & automation
### Model Selection (-m parameter)
**Gemini Models**:
- `gemini-2.5-pro` - Analysis tasks (default)
- `gemini-2.5-flash` - Documentation updates
**Qwen Models**:
- `coder-model` - Code analysis (default, -m optional)
- `vision-model` - Image analysis (rare usage)
**Codex Models**:
- `gpt-5` - Analysis & execution (default)
- `gpt5-codex` - Large context tasks
**Usage**: `tool -p "prompt" -m model-name` (NOTE: -m placed AFTER prompt)
### Quick Decision Matrix
| Scenario | Tool | Command Pattern |
@@ -163,6 +179,12 @@ EXPECTED: [expected output]
RULES: [template reference and constraints]
"
# Model Selection Examples (NOTE: -m placed AFTER prompt)
cd [directory] && gemini -p "..." -m gemini-2.5-pro # Analysis (default)
cd [directory] && gemini -p "..." -m gemini-2.5-flash # Documentation updates
cd [directory] && qwen -p "..." # coder-model (default, -m optional)
cd [directory] && qwen -p "..." -m vision-model # Image analysis (rare)
# Write Mode (requires explicit MODE=write)
# NOTE: --approval-mode yolo must be placed AFTER the prompt
cd [directory] && gemini -p "
@@ -172,17 +194,17 @@ MODE: write
CONTEXT: @**/* [default: all files, or specify file patterns]
EXPECTED: [expected output]
RULES: [template reference and constraints]
" --approval-mode yolo
" -m gemini-2.5-flash --approval-mode yolo
# Fallback: Replace 'gemini' with 'qwen' if Gemini unavailable
cd [directory] && qwen -p "..." # Same syntax as gemini
cd [directory] && qwen -p "..." # coder-model default (-m optional)
```
#### Codex Commands
```bash
# Codex Development (requires explicit MODE=auto)
# NOTE: --skip-git-repo-check and -s danger-full-access must be placed at command END
# NOTE: -m, --skip-git-repo-check and -s danger-full-access must be placed at command END
codex -C [directory] --full-auto exec "
PURPOSE: [clear development goal]
TASK: [specific development task]
@@ -190,10 +212,14 @@ MODE: auto
CONTEXT: @**/* [default: all files, or specify file patterns and memory context]
EXPECTED: [expected deliverables]
RULES: [template reference and constraints]
" --skip-git-repo-check -s danger-full-access
" -m gpt-5 --skip-git-repo-check -s danger-full-access
# Model Selection Examples (NOTE: -m placed AFTER prompt, BEFORE flags)
codex -C [directory] --full-auto exec "..." -m gpt-5 --skip-git-repo-check -s danger-full-access # Analysis & execution (default)
codex -C [directory] --full-auto exec "..." -m gpt5-codex --skip-git-repo-check -s danger-full-access # Large context tasks
# Codex Test/Write Mode (requires explicit MODE=write)
# NOTE: --skip-git-repo-check and -s danger-full-access must be placed at command END
# NOTE: -m, --skip-git-repo-check and -s danger-full-access must be placed at command END
codex -C [directory] --full-auto exec "
PURPOSE: [clear goal]
TASK: [specific task]
@@ -201,7 +227,7 @@ MODE: write
CONTEXT: @**/* [default: all files, or specify file patterns and memory context]
EXPECTED: [expected deliverables]
RULES: [template reference and constraints]
" --skip-git-repo-check -s danger-full-access
" -m gpt-5 --skip-git-repo-check -s danger-full-access
```
---