diff --git a/.claude/commands/gemini/chat.md b/.claude/commands/gemini/chat.md index 7371d935..c4b1df95 100644 --- a/.claude/commands/gemini/chat.md +++ b/.claude/commands/gemini/chat.md @@ -1,203 +1,93 @@ --- name: gemini-chat parent: /gemini -description: Single-execution Gemini CLI interaction command with dynamic template selection for codebase analysis +description: Simple Gemini CLI interaction command for direct codebase analysis usage: /gemini:chat "inquiry" argument-hint: "your question or analysis request" examples: - /gemini:chat "analyze the authentication flow" - /gemini:chat "how can I optimize this React component performance?" - /gemini:chat "review security vulnerabilities in src/auth/" - - /gemini:chat "comprehensive code quality assessment" -allowed-tools: Bash(gemini:*), Bash(~/.claude/scripts/chat-template-load.sh:*) +allowed-tools: Bash(gemini:*) model: sonnet --- ### 🚀 **Command Overview: `/gemini:chat`** - -- **Type**: Gemini CLI Execution Wrapper -- **Purpose**: To provide direct interaction with the `gemini` CLI, enhanced with intelligent, dynamic prompt template selection for codebase analysis. -- **Core Tools**: - - `Bash(gemini:*)`: Executes the external Gemini CLI tool. - - `Bash(~/.claude/scripts/chat-template-load.sh:*)`: Manages all template discovery and selection logic. +- **Type**: Basic Gemini CLI Wrapper +- **Purpose**: Direct interaction with the `gemini` CLI for simple codebase analysis +- **Core Tool**: `Bash(gemini:*)` - Executes the external Gemini CLI tool ### 📥 **Parameters & Usage** -- **`` (Required)**: Your primary question or analysis request. -- **`--all-files` (Optional)**: Includes the entire codebase in the analysis context. -- **`--compress` (Optional)**: Applies context compression for large prompts. -- **`--save-session` (Optional)**: Saves the full interaction to current workflow session directory. -- **File References**: Explicitly specify files or patterns within the inquiry using `@{path/to/file}`. +- **`` (Required)**: Your question or analysis request +- **`--all-files` (Optional)**: Includes the entire codebase in the analysis context +- **`--save-session` (Optional)**: Saves the interaction to current workflow session directory +- **File References**: Specify files or patterns using `@{path/to/file}` syntax -### 🔄 **Core Execution Workflow** +### 🔄 **Execution Workflow** -⚠️ **IMPORTANT**: Template selection is **AUTOMATIC** based on input analysis and is the **FIRST STEP** in command execution. +`Parse Input` **->** `Assemble Context` **->** `Construct Prompt` **->** `Execute Gemini CLI` **->** `(Optional) Save Session` -`Parse Input & Intent` **->** `Auto-Select Template` **->** `Load Selected Template` **->** `Determine Context Needs` **->** `Assemble Context` **->** `Construct Prompt` **->** `Execute Gemini CLI` **->** `(Optional) Save Session` +### 📚 **Context Assembly** -### 🧠 **Template Selection Logic** +Context is gathered from: +1. **Project Guidelines**: Always includes `@{CLAUDE.md,**/*CLAUDE.md}` +2. **User-Explicit Files**: Files specified by the user (e.g., `@{src/auth/*.js}`) +3. **All Files Flag**: The `--all-files` flag includes the entire codebase -⚠️ **CRITICAL**: Templates are selected **AUTOMATICALLY** by analyzing user input. The command execution calls script methods to discover and select the best template. - -**Script Methods Available:** -- `~/.claude/scripts/chat-template-load.sh list` - Lists all available templates -- `~/.claude/scripts/chat-template-load.sh load "template_name"` - Loads a specific template - -```pseudo -FUNCTION automatic_template_selection(user_inquiry): - // STEP 1: Command execution calls list method to discover templates - available_templates = call_script_method("list") - - // STEP 2: Analyze user input to determine best template match - analyzed_intent = analyze_input_keywords_and_context(user_inquiry) - best_template = match_template_to_intent(analyzed_intent, available_templates) - - // STEP 3: Command execution calls load method with selected template - IF best_template is FOUND: - template_content = call_script_method("load", best_template.name) - log_info("Auto-selected template: " + best_template.name) - ELSE: - // Fallback to default template if no clear match - template_content = call_script_method("load", "default") - log_warning("No clear template match, using default template") - - RETURN template_content -END FUNCTION -``` - -**Automatic Selection Flow:** -1. **Command starts** → Calls `list` method to discover available templates -2. **Input analysis** → Analyzes user inquiry for keywords, intent, and context -3. **Template matching** → Automatically selects best template based on analysis -4. **Template loading** → Command calls `load` method with selected template name -5. **Continue execution** → Process the inquiry with loaded template - -### 📚 **Context Assembly Priority** - -Context is gathered based on a clear hierarchy of sources. - -1. **Template Requirements**: The primary driver. The selected template defines a default set of required file patterns. -2. **User-Explicit Files**: Files specified by the user (e.g., `@{src/auth/*.js}`) override or add to the template's requirements. -3. **Command-Level Flags**: The `--all-files` flag overrides all other file specifications to scope the context to the entire project. - -### 📝 **Structured Prompt Format** - -The final prompt sent to the `gemini` CLI is assembled in three distinct parts. +### 📝 **Prompt Format** ``` -=== SYSTEM PROMPT === -[Content from the selected template file is placed here] - === CONTEXT === -@{CLAUDE.md,**/*CLAUDE.md} [Project guidelines, always included] -@{target_files} [File context gathered based on the assembly priority] +@{CLAUDE.md,**/*CLAUDE.md} [Project guidelines] +@{target_files} [User-specified files or all files if --all-files is used] === USER INPUT === -[The original user inquiry text] +[The user inquiry text] ``` -### ⚙️ **Gemini CLI Execution Logic** - -This describes how the external `gemini` binary is invoked with the constructed prompt. +### ⚙️ **Execution Implementation** ```pseudo -FUNCTION execute_gemini_cli(structured_prompt, flags): - // Retrieves the path from the user's execution environment. - current_directory = get_current_working_directory() - +FUNCTION execute_gemini_chat(user_inquiry, flags): + // Construct basic prompt + prompt = "=== CONTEXT ===\n" + prompt += "@{CLAUDE.md,**/*CLAUDE.md}\n" + + // Add user-specified files or all files IF flags contain "--all-files": - // For --all-files, it may be necessary to navigate to the correct directory first. - navigate_to_project_root(current_directory) - // Executes the gemini tool using the --all-files flag. - result = execute_tool("Bash(gemini:*)", "--all-files", "-p", structured_prompt) + result = execute_tool("Bash(gemini:*)", "--all-files", "-p", prompt + user_inquiry) ELSE: - // Default execution relies on @{file_patterns} resolved by the Gemini CLI. - // The prompt already contains the necessary @{...} references. - result = execute_tool("Bash(gemini:*)", "-p", structured_prompt) - - IF result is 'FAILED' AND flags contain "--all-files": - // Implements the fallback strategy if --all-files fails. - log_warning("`--all-files` failed. Falling back to pattern-based context.") - prompt_with_fallback = add_file_patterns_to_prompt(structured_prompt) - result = execute_tool("Bash(gemini:*)", "-p", prompt_with_fallback) - + prompt += "\n=== USER INPUT ===\n" + user_inquiry + result = execute_tool("Bash(gemini:*)", "-p", prompt) + + // Save session if requested + IF flags contain "--save-session": + save_chat_session(user_inquiry, result) + RETURN result END FUNCTION ``` ### 💾 **Session Persistence** -⚠️ **CRITICAL**: Before saving, MUST check for existing active session to avoid creating duplicate sessions. - -- **Trigger**: Activated by the `--save-session` flag. -- **Action**: Saves the complete interaction, including the template used, context, and Gemini's output. -- **Session Check**: Check for `.workflow/.active-*` marker file to identify current active session. No file creation needed. -- **Location Strategy**: - - **IF active session exists**: Save to existing `.workflow/WFS-[topic-slug]/.chat/` directory - - **IF no active session**: Create new session directory following WFS naming convention - -**File Structure**: @~/.claude/workflows/file-structure-standards.md -- **File Format**: `chat-YYYYMMDD-HHMMSS.md` with timestamp for unique identification. -- **Structure**: Integrates with session management system using WFS-[topic-slug] format for consistency. -- **Coordination**: Session files coordinate with workflow-session.json and maintain document-state separation. - -### 🔗 **Chat Session Integration** - -**Session Detection Workflow:** -```pseudo -FUNCTION determine_save_location(): - // STEP 1: Check for active session marker - active_marker = find_file(".workflow/.active-*") - - // STEP 2: Extract session name if marker exists - active_session_name = extract_session_name(active_marker) - - IF active_sessions.count > 0: - // Use existing active session directory - session_dir = active_sessions[0].session_path + "/.chat/" - ensure_directory_exists(session_dir) - RETURN session_dir - ELSE: - // No active session - create new one only if necessary - new_session_slug = generate_topic_slug(user_inquiry) - session_dir = ".workflow/WFS-" + new_session_slug + "/.chat/" - create_session_structure(session_dir) - RETURN session_dir -END FUNCTION -``` - -**Storage Structure:** -``` -.workflow/WFS-[topic-slug]/.chat/ -├── chat-20240307-143022.md # Individual chat sessions -├── chat-20240307-151445.md # Timestamped for chronological order -└── analysis-security.md # Named analysis sessions -``` +When `--save-session` flag is used: +- Check for existing active session (`.workflow/.active-*` markers) +- Save to existing session's `.chat/` directory or create new session +- File format: `chat-YYYYMMDD-HHMMSS.md` +- Include query, context, and response in saved file **Session Template:** ```markdown -# Chat Session: [Timestamp] - [Topic] +# Chat Session: [Timestamp] ## Query [Original user inquiry] -## Template Used -[Auto-selected template name and rationale] - ## Context [Files and patterns included in analysis] ## Gemini Response [Complete response from Gemini CLI] - -## Key Insights -- [Important findings] -- [Architectural insights] -- [Implementation recommendations] - -## Integration Links -- [🔙 Workflow Session](../workflow-session.json) -- [📋 Implementation Plan](../IMPL_PLAN.md) -- [📝 Task Definitions](../.task/) ``` \ No newline at end of file diff --git a/.claude/commands/gemini/chat/bug-fix.md b/.claude/commands/gemini/chat/bug-fix.md new file mode 100644 index 00000000..d0fd2386 --- /dev/null +++ b/.claude/commands/gemini/chat/bug-fix.md @@ -0,0 +1,113 @@ +--- +name: bug-fix +parent: /gemini/chat +description: Bug analysis and fix suggestions using specialized template +usage: /gemini:chat:bug-fix "bug description" +argument-hint: "description of the bug or error you're experiencing" +examples: + - /gemini:chat:bug-fix "authentication null pointer error in login flow" + - /gemini:chat:bug-fix "React component not re-rendering after state change" + - /gemini:chat:bug-fix "database connection timeout in production" +allowed-tools: Bash(gemini:*) +model: sonnet +--- + +### 🐛 **Command Overview: `/gemini:chat:bug-fix`** + +- **Type**: Template-based Gemini CLI Wrapper +- **Purpose**: Specialized bug analysis and fix suggestions using expert diagnostic template +- **Template**: Bug fix analysis template for systematic problem diagnosis +- **Core Tool**: `Bash(gemini:*)` - Executes Gemini CLI with bug-fix template + +### 📥 **Parameters & Usage** + +- **`` (Required)**: Description of the bug, error, or unexpected behavior +- **`--all-files` (Optional)**: Includes entire codebase for comprehensive analysis +- **`--save-session` (Optional)**: Saves the bug analysis to current workflow session + +### 🔄 **Execution Workflow** + +`Parse Bug Description` **->** `Load Bug-Fix Template` **->** `Assemble Context` **->** `Execute Gemini CLI` **->** `(Optional) Save Session` + +### 📋 **Bug Analysis Focus** + +The bug-fix template provides structured analysis covering: +- **Root Cause Analysis**: Systematic investigation of underlying issues +- **Code Path Tracing**: Following execution flow to identify failure points +- **Hypothesis Validation**: Testing theories about bug origins +- **Targeted Solutions**: Specific, minimal fixes rather than broad refactoring +- **Impact Assessment**: Understanding side effects of proposed fixes + +### 📚 **Context Assembly** + +Context includes: +1. **Bug-Fix Template**: `@D:\Claude_dms3\.claude\prompt-templates\bug-fix.md` +2. **Project Guidelines**: `@{CLAUDE.md,**/*CLAUDE.md}` +3. **Relevant Files**: User-specified files or all files if `--all-files` used + +### 📝 **Prompt Structure** + +``` +=== SYSTEM PROMPT === +@D:\Claude_dms3\.claude\prompt-templates\bug-fix.md + +=== CONTEXT === +@{CLAUDE.md,**/*CLAUDE.md} +@{target_files} + +=== USER INPUT === +[Bug description and any relevant details] +``` + +### ⚙️ **Implementation** + +```pseudo +FUNCTION execute_bug_fix_analysis(bug_description, flags): + // Load bug-fix template + template = load_file("D:\Claude_dms3\.claude\prompt-templates\bug-fix.md") + + // Construct prompt with template + prompt = "=== SYSTEM PROMPT ===\n" + template + "\n\n" + prompt += "=== CONTEXT ===\n" + prompt += "@{CLAUDE.md,**/*CLAUDE.md}\n" + + // Execute with appropriate context + IF flags contain "--all-files": + result = execute_tool("Bash(gemini:*)", "--all-files", "-p", prompt + bug_description) + ELSE: + prompt += "\n=== USER INPUT ===\n" + bug_description + result = execute_tool("Bash(gemini:*)", "-p", prompt) + + // Save session if requested + IF flags contain "--save-session": + save_bug_analysis_session(bug_description, result) + + RETURN result +END FUNCTION +``` + +### 💾 **Session Integration** + +When `--save-session` is used: +- Saves to `.workflow/WFS-[topic]/.chat/` directory +- File named: `bug-fix-YYYYMMDD-HHMMSS.md` +- Includes template used, bug description, analysis, and recommendations + +**Session Template:** +```markdown +# Bug Fix Analysis: [Timestamp] + +## Bug Description +[Original bug description] + +## Template Used +bug-fix.md - Expert diagnostic analysis template + +## Analysis Results +[Complete Gemini response with root cause analysis and fix suggestions] + +## Recommended Actions +- [Immediate fixes] +- [Prevention measures] +- [Testing recommendations] +``` \ No newline at end of file diff --git a/.claude/commands/gemini/chat/plan.md b/.claude/commands/gemini/chat/plan.md new file mode 100644 index 00000000..c20cbefd --- /dev/null +++ b/.claude/commands/gemini/chat/plan.md @@ -0,0 +1,118 @@ +--- +name: plan +parent: /gemini/chat +description: Project planning and architecture analysis using specialized template +usage: /gemini:chat:plan "planning topic" +argument-hint: "planning topic or architectural challenge to analyze" +examples: + - /gemini:chat:plan "design user dashboard feature architecture" + - /gemini:chat:plan "plan microservices migration strategy" + - /gemini:chat:plan "implement real-time notification system" +allowed-tools: Bash(gemini:*) +model: sonnet +--- + +### 📋 **Command Overview: `/gemini:chat:plan`** + +- **Type**: Template-based Gemini CLI Wrapper +- **Purpose**: Comprehensive project planning and architecture analysis using expert planning template +- **Template**: Planning analysis template for systematic feature and system design +- **Core Tool**: `Bash(gemini:*)` - Executes Gemini CLI with planning template + +### 📥 **Parameters & Usage** + +- **`` (Required)**: Description of the feature, system, or architectural challenge to plan +- **`--all-files` (Optional)**: Includes entire codebase for comprehensive planning context +- **`--save-session` (Optional)**: Saves the planning analysis to current workflow session + +### 🔄 **Execution Workflow** + +`Parse Planning Topic` **->** `Load Planning Template` **->** `Assemble Context` **->** `Execute Gemini CLI` **->** `(Optional) Save Session` + +### 📋 **Planning Analysis Focus** + +The planning template provides structured analysis covering: +- **Requirements Analysis**: Understanding functional and non-functional requirements +- **Architecture Design**: System structure, components, and interactions +- **Implementation Strategy**: Step-by-step development approach +- **Risk Assessment**: Identifying potential challenges and mitigation strategies +- **Resource Planning**: Time, effort, and technology requirements + +### 📚 **Context Assembly** + +Context includes: +1. **Planning Template**: `@D:\Claude_dms3\.claude\prompt-templates\plan.md` +2. **Project Guidelines**: `@{CLAUDE.md,**/*CLAUDE.md}` +3. **Relevant Files**: User-specified files or all files if `--all-files` used + +### 📝 **Prompt Structure** + +``` +=== SYSTEM PROMPT === +@D:\Claude_dms3\.claude\prompt-templates\plan.md + +=== CONTEXT === +@{CLAUDE.md,**/*CLAUDE.md} +@{target_files} + +=== USER INPUT === +[Planning topic and any specific requirements or constraints] +``` + +### ⚙️ **Implementation** + +```pseudo +FUNCTION execute_planning_analysis(planning_topic, flags): + // Load planning template + template = load_file("D:\Claude_dms3\.claude\prompt-templates\plan.md") + + // Construct prompt with template + prompt = "=== SYSTEM PROMPT ===\n" + template + "\n\n" + prompt += "=== CONTEXT ===\n" + prompt += "@{CLAUDE.md,**/*CLAUDE.md}\n" + + // Execute with appropriate context + IF flags contain "--all-files": + result = execute_tool("Bash(gemini:*)", "--all-files", "-p", prompt + planning_topic) + ELSE: + prompt += "\n=== USER INPUT ===\n" + planning_topic + result = execute_tool("Bash(gemini:*)", "-p", prompt) + + // Save session if requested + IF flags contain "--save-session": + save_planning_session(planning_topic, result) + + RETURN result +END FUNCTION +``` + +### 💾 **Session Integration** + +When `--save-session` is used: +- Saves to `.workflow/WFS-[topic]/.chat/` directory +- File named: `plan-YYYYMMDD-HHMMSS.md` +- Includes template used, planning topic, analysis, and implementation roadmap + +**Session Template:** +```markdown +# Planning Analysis: [Timestamp] + +## Planning Topic +[Original planning topic description] + +## Template Used +plan.md - Expert planning and architecture analysis template + +## Analysis Results +[Complete Gemini response with requirements, architecture, and implementation plan] + +## Implementation Roadmap +- [Phase 1: Foundation work] +- [Phase 2: Core implementation] +- [Phase 3: Integration and testing] + +## Key Decisions +- [Architecture choices] +- [Technology selections] +- [Risk mitigation strategies] +``` \ No newline at end of file diff --git a/README.md b/README.md index 7e11a628..3d6239b1 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,9 @@ Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/cat | Command | Syntax | Description | |---------|--------|-------------| | `/enhance-prompt` | `/enhance-prompt ` | Enhance and structure user inputs with technical context | -| `/gemini-chat` | `/gemini-chat [--all-files] [--compress]` | Interactive dialogue with Gemini CLI using smart templates | +| `/gemini:chat` | `/gemini:chat [--all-files] [--save-session]` | Simple direct interaction with Gemini CLI without templates | +| `/gemini:chat:bug-fix` | `/gemini:chat:bug-fix [--all-files] [--save-session]` | Bug analysis using specialized diagnostic template | +| `/gemini:chat:plan` | `/gemini:chat:plan [--all-files] [--save-session]` | Project planning using specialized architecture template | | `/gemini-execute` | `/gemini-execute [--yolo] [--debug]` | Intelligent executor with automatic file context inference | | `/gemini-mode` | `/gemini-mode [options]` | Template-driven codebase analysis (pattern, architecture, security) | | `/update-memory` | `/update-memory [related\|full]` | Intelligent CLAUDE.md documentation system with context-aware updates and strict hierarchy preservation | diff --git a/README_CN.md b/README_CN.md index bc910e1c..fbe1f507 100644 --- a/README_CN.md +++ b/README_CN.md @@ -104,7 +104,9 @@ Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/cat | 命令 | 语法 | 描述 | |---------|--------|-------------| | `/enhance-prompt` | `/enhance-prompt <输入>` | 增强和构造用户输入,添加技术上下文 | -| `/gemini-chat` | `/gemini-chat <查询> [--all-files] [--compress]` | 使用智能模板与 Gemini CLI 进行交互对话 | +| `/gemini:chat` | `/gemini:chat <查询> [--all-files] [--save-session]` | 与 Gemini CLI 的简单直接交互,不使用模板 | +| `/gemini:chat:bug-fix` | `/gemini:chat:bug-fix <错误描述> [--all-files] [--save-session]` | 使用专门的诊断模板进行错误分析 | +| `/gemini:chat:plan` | `/gemini:chat:plan <规划主题> [--all-files] [--save-session]` | 使用专门的架构模板进行项目规划 | | `/gemini-execute` | `/gemini-execute <任务ID\|描述> [--yolo] [--debug]` | 智能执行器,自动推断文件上下文 | | `/gemini-mode` | `/gemini-mode <分析类型> <目标> [选项]` | 模板驱动的代码库分析(模式、架构、安全) | | `/update-memory` | `/update-memory [full\|fast\|deep] [路径]` | 分布式记忆系统管理,维护层级化 CLAUDE.md |