diff --git a/.claude/agents/code-developer.md b/.claude/agents/code-developer.md index 1513c50e..0321b7f9 100644 --- a/.claude/agents/code-developer.md +++ b/.claude/agents/code-developer.md @@ -35,21 +35,50 @@ You are a code execution specialist focused on implementing high-quality, produc - Existing documentation and code examples - Project CLAUDE.md standards +**Pre-Analysis: Tech Stack Detection and Loading**: +```bash +# Step 1: Detect project tech stack +TECH_STACK="default" +if find . -name "tsconfig.json" -o -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -1; then + TECH_STACK="typescript-dev" +elif find . -name "package.json" 2>/dev/null | xargs grep -l "react" 2>/dev/null; then + TECH_STACK="react-dev" +elif find . -name "*.py" -o -name "requirements.txt" -o -name "pyproject.toml" 2>/dev/null | head -1; then + TECH_STACK="python-dev" +elif find . -name "*.java" -o -name "pom.xml" -o -name "build.gradle" 2>/dev/null | head -1; then + TECH_STACK="java-dev" +elif find . -name "*.go" -o -name "go.mod" 2>/dev/null | head -1; then + TECH_STACK="go-dev" +elif find . -name "*.js" -o -name "package.json" 2>/dev/null | head -1; then + TECH_STACK="javascript-dev" +fi + +# Step 2: Load tech stack guidelines +TECH_GUIDELINES=$(cat ~/.claude/workflows/cli-templates/tech-stacks/${TECH_STACK}.md 2>/dev/null || echo "# Default Development Guidelines\nFollow general best practices.") +``` + **Context Evaluation**: ``` +MANDATORY FIRST STEP: + → Execute tech stack detection and load guidelines into [tech_guidelines] variable + → All subsequent development must follow loaded tech stack principles + IF context sufficient for implementation: - → Proceed with execution + → Apply [tech_guidelines] to execution + → Proceed with tech-stack-compliant implementation ELIF context insufficient OR task has flow control marker: → Check for [FLOW_CONTROL] marker: - Execute flow_control.pre_analysis steps sequentially for context gathering - Use four flexible context acquisition methods: - * Document references (cat commands) - * Search commands (grep/rg/find) - * CLI analysis (gemini/codex) - * Free exploration (Read/Grep/Search tools) + * Document references (cat commands with tech stack context) + * Search commands (grep/rg/find for tech-specific patterns) + * CLI analysis (gemini/codex with tech stack guidelines) + * Free exploration (Read/Grep/Search tools guided by tech principles) - Pass context between steps via [variable_name] references + - Ensure [tech_guidelines] is available to all steps → Extract patterns and conventions from accumulated context - → Proceed with execution + → Apply tech stack principles to all implementation decisions + → Proceed with tech-stack-compliant execution ``` ### Module Verification Guidelines diff --git a/.claude/agents/code-review-test-agent.md b/.claude/agents/code-review-test-agent.md index d15627bb..d50a6030 100644 --- a/.claude/agents/code-review-test-agent.md +++ b/.claude/agents/code-review-test-agent.md @@ -49,6 +49,29 @@ You will review code changes AND handle test implementation by understanding the ## Analysis CLI Context Activation Rules +**🎯 Pre-Analysis: Tech Stack Detection and Loading** +MANDATORY FIRST STEP for all reviews: +```bash +# Step 1: Detect project tech stack +TECH_STACK="default" +if find . -name "tsconfig.json" -o -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -1; then + TECH_STACK="typescript-dev" +elif find . -name "package.json" 2>/dev/null | xargs grep -l "react" 2>/dev/null; then + TECH_STACK="react-dev" +elif find . -name "*.py" -o -name "requirements.txt" -o -name "pyproject.toml" 2>/dev/null | head -1; then + TECH_STACK="python-dev" +elif find . -name "*.java" -o -name "pom.xml" -o -name "build.gradle" 2>/dev/null | head -1; then + TECH_STACK="java-dev" +elif find . -name "*.go" -o -name "go.mod" 2>/dev/null | head -1; then + TECH_STACK="go-dev" +elif find . -name "*.js" -o -name "package.json" 2>/dev/null | head -1; then + TECH_STACK="javascript-dev" +fi + +# Step 2: Load tech stack guidelines +TECH_GUIDELINES=$(cat ~/.claude/workflows/cli-templates/tech-stacks/${TECH_STACK}.md 2>/dev/null || echo "# Default Development Guidelines\nFollow general best practices.") +``` + **🎯 Flow Control Detection** When task assignment includes flow control marker: - **[FLOW_CONTROL]**: Execute sequential flow control steps with context accumulation and variable passing @@ -62,19 +85,24 @@ When task assignment includes flow control marker: **Context Gathering Decision Logic**: ``` +MANDATORY FIRST STEP: + → Execute tech stack detection and load guidelines into [tech_guidelines] variable + → All subsequent review criteria must align with loaded tech stack principles + IF task contains [FLOW_CONTROL] flag: → Execute each flow control step sequentially for context gathering → Use four flexible context acquisition methods: - * Document references (cat commands) - * Search commands (grep/rg/find) - * CLI analysis (gemini/codex) - * Free exploration (Read/Grep/Search tools) + * Document references (cat commands with tech stack context) + * Search commands (grep/rg/find for tech-specific patterns) + * CLI analysis (gemini/codex with tech stack guidelines) + * Free exploration (Read/Grep/Search tools guided by tech principles) → Process [variable_name] references in commands → Accumulate context through step outputs + → Ensure [tech_guidelines] informs all analysis steps ELIF reviewing >3 files OR security changes OR architecture modifications: - → Execute default flow control analysis (AUTO-TRIGGER) + → Execute default flow control analysis (AUTO-TRIGGER) with tech stack guidelines ELSE: - → Proceed with review using standard quality checks + → Proceed with tech-stack-informed review using standard quality checks ``` ## Review Process (Mode-Adaptive) diff --git a/.claude/commands/codex/mode/auto.md b/.claude/commands/codex/mode/auto.md index 1e4e01b6..58d5d7b0 100644 --- a/.claude/commands/codex/mode/auto.md +++ b/.claude/commands/codex/mode/auto.md @@ -73,7 +73,7 @@ development_type: feature|component|refactor|debug|testing ### Step 1: Template Discovery ```bash # Dynamically discover development templates -cd ~/.claude/workflows/cli-templates/prompts && echo "Discovering development templates..." && for dir in development automation analysis integration; do if [ -d "$dir" ]; then echo "=== $dir templates ==="; for template_file in "$dir"/*.txt; do if [ -f "$template_file" ]; then echo "Template: $(basename "$template_file")"; head -10 "$template_file" 2>/dev/null | grep -E "^(name|description|keywords):" || echo "No metadata"; echo; fi; done; fi; done +cd "~/.claude/workflows/cli-templates/prompts" && echo "Discovering development templates..." && for dir in development automation analysis integration; do if [ -d "$dir" ]; then echo "=== $dir templates ==="; for template_file in "$dir"/*.txt; do if [ -f "$template_file" ]; then echo "Template: $(basename "$template_file")"; head -10 "$template_file" 2>/dev/null | grep -E "^(name|description|keywords):" || echo "No metadata"; echo; fi; done; fi; done ``` ### Step 2: Dynamic Template Analysis & Selection diff --git a/.claude/commands/codex/mode/plan.md b/.claude/commands/codex/mode/plan.md index 5e4b1c16..26fc571a 100644 --- a/.claude/commands/codex/mode/plan.md +++ b/.claude/commands/codex/mode/plan.md @@ -15,7 +15,7 @@ model: sonnet ## Overview Comprehensive development planning and implementation strategy using expert planning templates with Codex CLI. -- **Directory Analysis Rule**: When user intends to analyze specific directory (cd XXX), use: `codex --cd XXX --full-auto exec "prompt" -s danger-full-access` or `cd XXX && codex --full-auto exec "@{**/*} prompt" -s danger-full-access` +- **Directory Analysis Rule**: When user intends to analyze specific directory (cd XXX), use: `codex --cd XXX --full-auto exec "prompt" -s danger-full-access` or `cd "XXX" && codex --full-auto exec "@{**/*} prompt" -s danger-full-access` - **Default Mode**: `--full-auto exec` autonomous development mode (RECOMMENDED for all tasks). diff --git a/.claude/commands/gemini/mode/auto.md b/.claude/commands/gemini/mode/auto.md index d88cc2d7..85d47157 100644 --- a/.claude/commands/gemini/mode/auto.md +++ b/.claude/commands/gemini/mode/auto.md @@ -19,7 +19,7 @@ Automatically analyzes user input to select the most appropriate template and ex **Directory Analysis Rule**: Intelligent detection of directory context intent - automatically navigate to target directory when analysis scope is directory-specific. -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. **Process**: List Templates → Analyze Input → Select Template → Execute with Context @@ -72,7 +72,7 @@ keywords: [keyword1, keyword2, keyword3] ### Step 1: Template Discovery ```bash # Dynamically discover all templates and extract YAML frontmatter -cd ~/.claude/prompt-templates && echo "Discovering templates..." && for template_file in *.md; do echo "=== $template_file ==="; head -6 "$template_file" 2>/dev/null || echo "Error reading $template_file"; echo; done +cd "~/.claude/prompt-templates" && echo "Discovering templates..." && for template_file in *.md; do echo "=== $template_file ==="; head -6 "$template_file" 2>/dev/null || echo "Error reading $template_file"; echo; done ``` ### Step 2: Dynamic Template Analysis & Selection @@ -131,7 +131,7 @@ gemini --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) User Input: [user_input]" # With --cd parameter -cd [specified_directory] && gemini --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) +cd "[specified_directory]" && gemini --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) User Input: [user_input]" ``` diff --git a/.claude/commands/gemini/mode/bug-index.md b/.claude/commands/gemini/mode/bug-index.md index ff5921d1..5e99cbe7 100644 --- a/.claude/commands/gemini/mode/bug-index.md +++ b/.claude/commands/gemini/mode/bug-index.md @@ -18,7 +18,7 @@ Systematic bug analysis and fix suggestions using expert diagnostic template. **Directory Analysis Rule**: Intelligent detection of directory context intent - automatically navigate to target directory when analysis scope is directory-specific. -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. ## Usage @@ -50,7 +50,7 @@ gemini --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) Bug Description: [user_description]" # With --cd parameter -cd [specified_directory] && gemini --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) +cd "[specified_directory]" && gemini --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) Bug Description: [user_description]" ``` diff --git a/.claude/commands/gemini/mode/plan.md b/.claude/commands/gemini/mode/plan.md index 41e4a440..474f371a 100644 --- a/.claude/commands/gemini/mode/plan.md +++ b/.claude/commands/gemini/mode/plan.md @@ -19,7 +19,7 @@ model: sonnet ### Key Features - **Gemini CLI Integration**: Utilizes Gemini CLI's deep codebase analysis for informed planning decisions -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && gemini --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. ## Usage @@ -44,7 +44,7 @@ gemini --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) Planning Topic: [user_description]" # Directory-specific analysis -cd [directory] && gemini --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) +cd "[directory]" && gemini --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) Planning Topic: [user_description]" ``` diff --git a/.claude/commands/qwen/mode/auto.md b/.claude/commands/qwen/mode/auto.md index f61e9e44..99fa68a7 100644 --- a/.claude/commands/qwen/mode/auto.md +++ b/.claude/commands/qwen/mode/auto.md @@ -19,7 +19,7 @@ Automatically analyzes user input to select the most appropriate template and ex **Directory Analysis Rule**: Intelligent detection of directory context intent - automatically navigate to target directory when analysis scope is directory-specific. -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. **Process**: List Templates → Analyze Input → Select Template → Execute with Context @@ -72,7 +72,7 @@ keywords: [keyword1, keyword2, keyword3] ### Step 1: Template Discovery ```bash # Dynamically discover all templates and extract YAML frontmatter -cd ~/.claude/prompt-templates && echo "Discovering templates..." && for template_file in *.md; do echo "=== $template_file ==="; head -6 "$template_file" 2>/dev/null || echo "Error reading $template_file"; echo; done +cd "~/.claude/prompt-templates" && echo "Discovering templates..." && for template_file in *.md; do echo "=== $template_file ==="; head -6 "$template_file" 2>/dev/null || echo "Error reading $template_file"; echo; done ``` ### Step 2: Dynamic Template Analysis & Selection @@ -131,7 +131,7 @@ qwen --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) User Input: [user_input]" # With --cd parameter -cd [specified_directory] && qwen --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) +cd "[specified_directory]" && qwen --all-files -p "$(cat ~/.claude/prompt-templates/[selected_template]) User Input: [user_input]" ``` diff --git a/.claude/commands/qwen/mode/bug-index.md b/.claude/commands/qwen/mode/bug-index.md index 2bef9ece..3a5b2456 100644 --- a/.claude/commands/qwen/mode/bug-index.md +++ b/.claude/commands/qwen/mode/bug-index.md @@ -18,7 +18,7 @@ Systematic bug analysis and fix suggestions using expert diagnostic template. **Directory Analysis Rule**: Intelligent detection of directory context intent - automatically navigate to target directory when analysis scope is directory-specific. -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. ## Usage @@ -50,7 +50,7 @@ qwen --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) Bug Description: [user_description]" # With --cd parameter -cd [specified_directory] && qwen --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) +cd "[specified_directory]" && qwen --all-files -p "$(cat ~/.claude/prompt-templates/bug-fix.md) Bug Description: [user_description]" ``` diff --git a/.claude/commands/qwen/mode/plan.md b/.claude/commands/qwen/mode/plan.md index 5394dcda..c1cda9ca 100644 --- a/.claude/commands/qwen/mode/plan.md +++ b/.claude/commands/qwen/mode/plan.md @@ -19,7 +19,7 @@ model: sonnet ### Key Features - **qwen CLI Integration**: Utilizes qwen CLI's deep codebase analysis for informed planning decisions -**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd [path] && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. +**--cd Parameter Rule**: When `--cd` parameter is provided, always execute `cd "[path]" && qwen --all-files -p "prompt"` to ensure analysis occurs in the specified directory context. ## Usage @@ -44,7 +44,7 @@ qwen --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) Planning Topic: [user_description]" # Directory-specific analysis -cd [directory] && qwen --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) +cd "[directory]" && qwen --all-files -p "$(cat ~/.claude/prompt-templates/plan.md) Planning Topic: [user_description]" ``` diff --git a/.claude/commands/workflow/plan.md b/.claude/commands/workflow/plan.md index 458bf1c1..1eb56873 100644 --- a/.claude/commands/workflow/plan.md +++ b/.claude/commands/workflow/plan.md @@ -41,7 +41,7 @@ The command performs comprehensive analysis through: - **Simple tasks** (≤3 modules): Direct CLI tools with intelligent path navigation and multi-round analysis ```bash # Analyze specific directory - ~/.claude/scripts/gemini-wrapper -C src/auth -p " + cd "src/auth" && ~/.claude/scripts/gemini-wrapper -p " PURPOSE: Analyze authentication patterns TASK: Review auth implementation for security patterns CONTEXT: Focus on JWT handling and user validation @@ -106,7 +106,7 @@ The following pre_analysis steps are generated for agent execution: { "step": "analyze_patterns", "action": "Analyze codebase patterns and architecture using CLI tools with directory context", - "command": "bash(~/.claude/scripts/gemini-wrapper -C [target_directory] -p \"PURPOSE: Analyze existing patterns TASK: Identify implementation patterns for [task_type] CONTEXT: [planning_context] [dependency_context] EXPECTED: Pattern analysis and recommendations RULES: Focus on architectural consistency\")", + "command": "bash(cd \"[target_directory]\" && ~/.claude/scripts/gemini-wrapper -p \"PURPOSE: Analyze existing patterns TASK: Identify implementation patterns for [task_type] CONTEXT: [planning_context] [dependency_context] EXPECTED: Pattern analysis and recommendations RULES: Focus on architectural consistency\")", "output_to": "pattern_analysis", "on_error": "skip_optional" }, diff --git a/.claude/scripts/gemini-wrapper b/.claude/scripts/gemini-wrapper index fa69f4b4..81ab4d40 100644 --- a/.claude/scripts/gemini-wrapper +++ b/.claude/scripts/gemini-wrapper @@ -3,8 +3,8 @@ # Location: ~/.claude/scripts/gemini-wrapper # # This wrapper automatically manages --all-files flag based on project token count -# Usage: gemini-wrapper [-C ] [all gemini options] -# -C Change to specified directory before analysis (relative or absolute path) +# Usage: gemini-wrapper [all gemini options] +# Note: Executes in current working directory set -e @@ -18,20 +18,72 @@ GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color -# Function to count tokens (approximate: chars/4) +# Function to count tokens (approximate: chars/4) - optimized version count_tokens() { local total_chars=0 local file_count=0 - - # Count characters in common source files - while IFS= read -r -d '' file; do - if [[ -f "$file" && -r "$file" ]]; then - local chars=$(wc -c < "$file" 2>/dev/null || echo 0) - total_chars=$((total_chars + chars)) - file_count=$((file_count + 1)) + + # Use single find with bulk wc for better performance + # Common source file extensions + local extensions="py js ts tsx jsx java cpp c h rs go md txt json yaml yml xml html css scss sass php rb sh bash" + + # Build find command with extension patterns + local find_cmd="find . -type f \(" + local first=true + for ext in $extensions; do + if [[ "$first" == true ]]; then + find_cmd+=" -name \"*.$ext\"" + first=false + else + find_cmd+=" -o -name \"*.$ext\"" fi - done < <(find . -type f \( -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.tsx" -o -name "*.jsx" -o -name "*.java" -o -name "*.cpp" -o -name "*.c" -o -name "*.h" -o -name "*.rs" -o -name "*.go" -o -name "*.md" -o -name "*.txt" -o -name "*.json" -o -name "*.yaml" -o -name "*.yml" -o -name "*.xml" -o -name "*.html" -o -name "*.css" -o -name "*.scss" -o -name "*.sass" -o -name "*.php" -o -name "*.rb" -o -name "*.sh" -o -name "*.bash" \) -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" -not -path "*/build/*" -not -path "*/.next/*" -not -path "*/.nuxt/*" -not -path "*/target/*" -not -path "*/vendor/*" -print0 2>/dev/null) - + done + find_cmd+=" \)" + + # Exclude common build/cache directories + find_cmd+=" -not -path \"*/node_modules/*\"" + find_cmd+=" -not -path \"*/.git/*\"" + find_cmd+=" -not -path \"*/dist/*\"" + find_cmd+=" -not -path \"*/build/*\"" + find_cmd+=" -not -path \"*/.next/*\"" + find_cmd+=" -not -path \"*/.nuxt/*\"" + find_cmd+=" -not -path \"*/target/*\"" + find_cmd+=" -not -path \"*/vendor/*\"" + find_cmd+=" -not -path \"*/__pycache__/*\"" + find_cmd+=" -not -path \"*/.cache/*\"" + find_cmd+=" 2>/dev/null" + + # Use efficient bulk processing with wc + if command -v wc >/dev/null 2>&1; then + # Try bulk wc first - much faster for many files + local wc_output + wc_output=$(eval "$find_cmd" | xargs wc -c 2>/dev/null | tail -n 1) + + # Parse the total line (last line of wc output when processing multiple files) + if [[ -n "$wc_output" && "$wc_output" =~ ^[[:space:]]*([0-9]+)[[:space:]]+total[[:space:]]*$ ]]; then + total_chars="${BASH_REMATCH[1]}" + file_count=$(eval "$find_cmd" | wc -l 2>/dev/null || echo 0) + else + # Fallback: single file processing + while IFS= read -r file; do + if [[ -f "$file" && -r "$file" ]]; then + local chars=$(wc -c < "$file" 2>/dev/null || echo 0) + total_chars=$((total_chars + chars)) + file_count=$((file_count + 1)) + fi + done < <(eval "$find_cmd") + fi + else + # No wc available - fallback method + while IFS= read -r file; do + if [[ -f "$file" && -r "$file" ]]; then + local chars=$(stat -c%s "$file" 2>/dev/null || echo 0) + total_chars=$((total_chars + chars)) + file_count=$((file_count + 1)) + fi + done < <(eval "$find_cmd") + fi + local estimated_tokens=$((total_chars / 4)) echo "$estimated_tokens $file_count" } @@ -39,13 +91,10 @@ count_tokens() { # Parse arguments to check for flags has_all_files=false has_approval_mode=false -change_dir="" args=() -# Check for existing flags and -c parameter -i=0 -while [[ $i -lt $# ]]; do - arg="${!i}" +# Check for existing flags +for arg in "$@"; do case "$arg" in "--all-files") has_all_files=true @@ -55,39 +104,14 @@ while [[ $i -lt $# ]]; do has_approval_mode=true args+=("$arg") ;; - "-C") - # Next argument is the directory - i=$((i + 1)) - if [[ $i -lt $# ]]; then - change_dir="${!i}" - echo -e "${YELLOW}📁 Directory change requested: $change_dir${NC}" >&2 - else - echo -e "${RED}❌ Error: -C requires a directory path${NC}" >&2 - exit 1 - fi - ;; *) args+=("$arg") ;; esac - i=$((i + 1)) done -# Change directory if requested -original_dir="" -if [[ -n "$change_dir" ]]; then - original_dir=$(pwd) - if [[ -d "$change_dir" ]]; then - echo -e "${GREEN}📁 Changing to directory: $change_dir${NC}" >&2 - cd "$change_dir" || { - echo -e "${RED}❌ Error: Cannot change to directory: $change_dir${NC}" >&2 - exit 1 - } - else - echo -e "${RED}❌ Error: Directory does not exist: $change_dir${NC}" >&2 - exit 1 - fi -fi +# Analyze current working directory +echo -e "${GREEN}📁 Analyzing current directory: $(pwd)${NC}" >&2 # Count tokens (in the target directory if -c was used) echo -e "${YELLOW}🔍 Analyzing project size...${NC}" >&2 @@ -137,5 +161,5 @@ fi # Show final command (for transparency) echo -e "${YELLOW}🚀 Executing: gemini ${args[*]}${NC}" >&2 -# Execute gemini with adjusted arguments -exec gemini "${args[@]}" \ No newline at end of file +# Execute gemini with adjusted arguments (we're already in the right directory) +gemini "${args[@]}" \ No newline at end of file diff --git a/.claude/scripts/qwen-wrapper b/.claude/scripts/qwen-wrapper index 7ac38bf1..4e51f549 100644 --- a/.claude/scripts/qwen-wrapper +++ b/.claude/scripts/qwen-wrapper @@ -3,8 +3,8 @@ # Location: ~/.claude/scripts/qwen-wrapper # # This wrapper automatically manages --all-files flag based on project token count -# Usage: qwen-wrapper [-C ] [all qwen options] -# -C Change to specified directory before analysis (relative or absolute path) +# Usage: qwen-wrapper [all qwen options] +# Note: Executes in current working directory set -e @@ -39,13 +39,10 @@ count_tokens() { # Parse arguments to check for flags has_all_files=false has_approval_mode=false -change_dir="" args=() -# Check for existing flags and -c parameter -i=0 -while [[ $i -lt $# ]]; do - arg="${!i}" +# Check for existing flags +for arg in "$@"; do case "$arg" in "--all-files") has_all_files=true @@ -55,39 +52,14 @@ while [[ $i -lt $# ]]; do has_approval_mode=true args+=("$arg") ;; - "-C") - # Next argument is the directory - i=$((i + 1)) - if [[ $i -lt $# ]]; then - change_dir="${!i}" - echo -e "${YELLOW}📁 Directory change requested: $change_dir${NC}" >&2 - else - echo -e "${RED}❌ Error: -C requires a directory path${NC}" >&2 - exit 1 - fi - ;; *) args+=("$arg") ;; esac - i=$((i + 1)) done -# Change directory if requested -original_dir="" -if [[ -n "$change_dir" ]]; then - original_dir=$(pwd) - if [[ -d "$change_dir" ]]; then - echo -e "${GREEN}📁 Changing to directory: $change_dir${NC}" >&2 - cd "$change_dir" || { - echo -e "${RED}❌ Error: Cannot change to directory: $change_dir${NC}" >&2 - exit 1 - } - else - echo -e "${RED}❌ Error: Directory does not exist: $change_dir${NC}" >&2 - exit 1 - fi -fi +# Analyze current working directory +echo -e "${GREEN}📁 Analyzing current directory: $(pwd)${NC}" >&2 # Count tokens (in the target directory if -c was used) echo -e "${YELLOW}🔍 Analyzing project size...${NC}" >&2 @@ -137,5 +109,5 @@ fi # Show final command (for transparency) echo -e "${YELLOW}🚀 Executing: qwen ${args[*]}${NC}" >&2 -# Execute qwen with adjusted arguments -exec qwen "${args[@]}" \ No newline at end of file +# Execute qwen with adjusted arguments (we're already in the right directory) +qwen "${args[@]}" \ No newline at end of file diff --git a/.claude/workflows/intelligent-tools-strategy.md b/.claude/workflows/intelligent-tools-strategy.md index 1fc2597d..5bfa216f 100644 --- a/.claude/workflows/intelligent-tools-strategy.md +++ b/.claude/workflows/intelligent-tools-strategy.md @@ -29,7 +29,7 @@ type: strategic-guideline ### Core Execution Rules - **Default Timeout**: Bash commands default execution time = 20 minutes (1200000ms) - **Apply to All Tools**: All bash() wrapped commands including Gemini, Qwen wrapper and Codex executions use this timeout -- **Command Examples**: `bash(~/.claude/scripts/gemini-wrapper -p "prompt")`, `bash(~/.claude/scripts/qwen-wrapper -p "prompt")`, `bash(codex --full-auto exec "task")` +- **Command Examples**: `bash(cd target/directory && ~/.claude/scripts/gemini-wrapper -p "prompt")`, `bash(cd target/directory && ~/.claude/scripts/qwen-wrapper -p "prompt")`, `bash(codex -C directory --full-auto exec "task")` - **Override When Needed**: Specify custom timeout for longer operations ## 🎯 Universal Command Template @@ -37,7 +37,7 @@ type: strategic-guideline ### Standard Format (REQUIRED) ```bash # Gemini Analysis -~/.claude/scripts/gemini-wrapper -C [directory] -p " +cd [directory] && ~/.claude/scripts/gemini-wrapper -p " PURPOSE: [clear analysis goal] TASK: [specific analysis task] CONTEXT: [file references and memory context] @@ -46,7 +46,7 @@ RULES: [template reference and constraints] " # Qwen Architecture & Code Generation -~/.claude/scripts/qwen-wrapper -C [directory] -p " +cd [directory] && ~/.claude/scripts/qwen-wrapper -p " PURPOSE: [clear architecture/code goal] TASK: [specific architecture/code task] CONTEXT: [file references and memory context] @@ -71,13 +71,13 @@ RULES: [template reference and constraints] - [ ] **EXPECTED** - Clear expected results - [ ] **RULES** - Template reference and constraints -### Directory Context (-C parameter) -All tools support changing working directory before execution: -- **Gemini**: `~/.claude/scripts/gemini-wrapper -C path/to/project -p "prompt"` -- **Qwen**: `~/.claude/scripts/qwen-wrapper -C path/to/project -p "prompt"` -- **Codex**: `codex -C path/to/project --full-auto exec "task"` +### Directory Context +Tools execute in current working directory: +- **Gemini**: `cd path/to/project && ~/.claude/scripts/gemini-wrapper -p "prompt"` +- **Qwen**: `cd path/to/project && ~/.claude/scripts/qwen-wrapper -p "prompt"` +- **Codex**: `codex -C path/to/project --full-auto exec "task"` (Codex still supports -C) - **Path types**: Supports both relative (`../project`) and absolute (`/full/path`) paths -- **Token analysis**: For gemini-wrapper and qwen-wrapper, token counting happens in target directory +- **Token analysis**: For gemini-wrapper and qwen-wrapper, token counting happens in current directory ### Rules Field Format ```bash @@ -155,7 +155,7 @@ RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/architecture.txt " # Project Analysis (in different directory) -~/.claude/scripts/gemini-wrapper -C ../other-project -p " +cd ../other-project && ~/.claude/scripts/gemini-wrapper -p " PURPOSE: Compare authentication patterns TASK: Analyze auth implementation in related project CONTEXT: @{src/auth/**/*} Current project context from session memory @@ -164,7 +164,7 @@ RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/pattern.txt) | F " # Architecture Design (with Qwen) -~/.claude/scripts/qwen-wrapper -C src/auth -p " +cd src/auth && ~/.claude/scripts/qwen-wrapper -p " PURPOSE: Design authentication system architecture TASK: Create modular JWT-based auth system design CONTEXT: @{src/auth/**/*} Existing patterns and requirements @@ -236,20 +236,20 @@ For every development task: - **Document context** - Always reference CLAUDE.md for context ### Context Optimization Strategy -**Directory Navigation**: Use `-C [directory]` parameter when analyzing specific areas to reduce irrelevant context +**Directory Navigation**: Use `cd [directory] &&` pattern when analyzing specific areas to reduce irrelevant context -**When to use `-C`**: -- Specific directory mentioned → Use `-C directory` parameter -- Focused analysis needed → Target specific directory with `-C` +**When to change directory**: +- Specific directory mentioned → Use `cd directory &&` pattern +- Focused analysis needed → Target specific directory with cd - Multi-directory scope → Stay in root, use explicit paths or multiple commands **Example**: ```bash # Focused analysis (preferred) -~/.claude/scripts/gemini-wrapper -C src/auth -p "analyze auth patterns" +cd src/auth && ~/.claude/scripts/gemini-wrapper -p "analyze auth patterns" # Focused architecture (Qwen) -~/.claude/scripts/qwen-wrapper -C src/auth -p "design auth architecture" +cd src/auth && ~/.claude/scripts/qwen-wrapper -p "design auth architecture" # Focused implementation (Codex) codex -C src/auth --full-auto exec "analyze auth implementation"