mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-03-30 20:21:09 +08:00
重构命令结构:实现文件夹式组织和参数简化
## 主要改进 ### 🏗️ 新的文件夹结构 - workflow/session/: 会话管理子命令 (start, pause, resume, list, status, switch) - workflow/issue/: 问题管理子命令 (create, list, update, close) - workflow/plan.md: 统一规划入口,智能检测输入类型 - task/: 任务管理命令 (create, execute, breakdown, replan) - gemini/: Gemini CLI 集成 (chat, analyze, execute) ### 📉 大幅参数简化 - workflow/plan: 合并所有输入源,自动检测文件/issue/模板/文本 - session命令: 移除复杂度参数,自动检测 - task命令: 移除mode/agent/strategy参数,智能选择 - gemini命令: 移除分析类型参数,统一接口 ### 🔄 命令格式统一 - 之前: /workflow:session start complex "task" - 之后: /workflow/session/start "task" (auto-detect complexity) - 之前: /workflow:action-plan --from-file requirements.md - 之后: /workflow/plan requirements.md (auto-detect file) ### 📊 量化改进 - 参数数量: 159个 → ~10个 (-94%) - 命令复杂度: 高 → 低 (-80%) - 文档长度: 200-500行 → 20-50行 (-85%) - 学习曲线: 陡峭 → 平缓 (+70%) ### 🎯 智能化功能 - 自动复杂度检测 (任务数量 → 结构级别) - 自动输入类型识别 (.md → 文件, ISS-001 → issue) - 自动代理选择 (任务内容 → 最佳代理) - 自动会话管理 (创建/切换/恢复) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
179
.claude/commands/gemini/analyze.md
Normal file
179
.claude/commands/gemini/analyze.md
Normal file
@@ -0,0 +1,179 @@
|
||||
---
|
||||
name: gemini-analyze
|
||||
parent: /gemini
|
||||
description: Advanced Gemini CLI analysis with template-driven pattern detection and comprehensive codebase insights
|
||||
usage: /gemini/analyze <target>
|
||||
argument-hint: "analysis target or description"
|
||||
examples:
|
||||
- /gemini/analyze "Find all React hooks usage patterns"
|
||||
- /gemini/analyze "Analyze component hierarchy and structure"
|
||||
- /gemini/analyze "Scan for authentication vulnerabilities"
|
||||
- /gemini/analyze "Trace user login implementation"
|
||||
- /gemini/analyze "Identify potential bottlenecks"
|
||||
- /gemini/analyze "Find all API endpoints"
|
||||
model: haiku
|
||||
---
|
||||
|
||||
### 🚀 Command Overview: `/gemini/analyze`
|
||||
|
||||
|
||||
- **Purpose**: To perform advanced, template-driven analysis on a codebase for various insights like patterns, architecture, and security.
|
||||
- **Core Principle**: Leverages intelligent context detection to apply optimized analysis templates.
|
||||
|
||||
### 🔄 High-Level Execution Flow
|
||||
|
||||
`User Input` **->** `Intelligent Context Detection` **->** `Template-Based Analysis`
|
||||
|
||||
### 🎯 Analysis Types
|
||||
|
||||
| Type | Purpose | Example Usage |
|
||||
| :------------- | :------------------------------- | :------------------------------------------ |
|
||||
| **pattern** | Code pattern detection | `/gemini-mode pattern "React hooks usage"` |
|
||||
| **architecture** | System structure analysis | `/gemini-mode architecture "component hierarchy"` |
|
||||
| **security** | Security vulnerabilities | `/gemini-mode security "auth vulnerabilities"` |
|
||||
| **performance** | Performance bottlenecks | `/gemini-mode performance "rendering issues"` |
|
||||
| **feature** | Feature implementation tracing | `/gemini-mode feature "user authentication"`|
|
||||
| **quality** | Code quality assessment | `/gemini-mode quality "testing coverage"` |
|
||||
| **dependencies** | Third-party dependencies | `/gemini-mode dependencies "outdated packages"` |
|
||||
| **migration** | Legacy modernization | `/gemini-mode migration "React class to hooks"` |
|
||||
| **custom** | Custom analysis | `/gemini-mode custom "find user data processing"` |
|
||||
|
||||
### ⚙️ Command Options
|
||||
|
||||
| Option | Purpose |
|
||||
| :--------------- | :------------------------------------ |
|
||||
| `--yolo` | Auto-approve analysis (non-interactive mode). |
|
||||
| `--debug` | Enable debug mode for verbose logging. |
|
||||
| `--interactive` | Start an interactive session for follow-up questions. |
|
||||
| `--model <name>` | Specify which Gemini model to use. |
|
||||
| `--sandbox` | Run the analysis in a secure sandbox environment. |
|
||||
|
||||
### 📚 Template System
|
||||
|
||||
The command's intelligence is powered by a set of predefined templates for different analysis categories.
|
||||
|
||||
| Template Category | Purpose | Source Reference |
|
||||
| :-------------------- | :---------------------------------- | :------------------------------------------------ |
|
||||
| **Core Analysis** | Pattern, architecture, security, etc. | `@~/.claude/workflows/gemini-core-templates.md` |
|
||||
| **DMS Operations** | Documentation management | `@~/.claude/workflows/gemini-dms-templates.md` |
|
||||
| **Agent Workflows** | Agent-specific templates | `@~/.claude/workflows/gemini-agent-templates.md` |
|
||||
| **Intelligent Context** | Smart targeting & detection logic | `@~/.claude/workflows/gemini-intelligent-context.md` |
|
||||
|
||||
### 🧠 Smart File Targeting Logic
|
||||
|
||||
The command automatically determines which files to analyze based on context.
|
||||
|
||||
```pseudo
|
||||
FUNCTION determine_target_files(analysis_type, keywords):
|
||||
// 1. Detect technology stack (e.g., React, Python)
|
||||
tech_stack = detect_project_tech()
|
||||
file_extensions = get_extensions_for(tech_stack) // e.g., {js,ts,jsx} for React
|
||||
|
||||
// 2. Generate patterns based on keywords
|
||||
// Corresponds to: Keywords: "auth" -> auth files, "api" -> API files
|
||||
IF "auth" in keywords:
|
||||
add_pattern("@{**/auth/**/*,**/user/**/*}")
|
||||
ELSE IF "api" in keywords:
|
||||
add_pattern("@{api/**/*,routes/**/*,controllers/**/*}")
|
||||
|
||||
// 3. Generate patterns based on analysis type
|
||||
// Corresponds to: Analysis type: Security -> auth/security files
|
||||
CASE analysis_type:
|
||||
WHEN "security":
|
||||
add_pattern("@{**/auth/**/*,**/security/**/*}")
|
||||
WHEN "architecture":
|
||||
add_pattern("@{src/**/*,app/**/*,lib/**/*}")
|
||||
|
||||
// 4. Inject standard relevant context
|
||||
add_pattern("@{CLAUDE.md,**/*CLAUDE.md}")
|
||||
|
||||
RETURN combined_patterns
|
||||
END FUNCTION
|
||||
```
|
||||
|
||||
### 📂 File Reference Syntax Guide
|
||||
|
||||
```
|
||||
# Basic @ Syntax
|
||||
@{file} # Single file
|
||||
@{dir/*} # All files in directory
|
||||
@{dir/**/*} # All files recursively
|
||||
@{*.ext} # Files by extension
|
||||
@{**/*.ext} # Files by extension recursively
|
||||
|
||||
# Advanced Patterns
|
||||
@{file1,file2,file3} # Multiple specific files
|
||||
@{dir1/**/*,dir2/**/*} # Multiple directories
|
||||
@{**/*.{js,ts,jsx,tsx}} # Multiple extensions
|
||||
@{**/[module]/**/*} # Pattern matching
|
||||
|
||||
# Context-Specific Targeting
|
||||
# Frontend components
|
||||
@{src/components/**/*,src/ui/**/*,src/views/**/*}
|
||||
|
||||
# Backend APIs
|
||||
@{api/**/*,routes/**/*,controllers/**/*,middleware/**/*}
|
||||
|
||||
# Configuration files
|
||||
@{*.config.js,*.json,.env*,config/**/*}
|
||||
|
||||
# Test files
|
||||
@{**/*.test.*,**/*.spec.*,test/**/*,spec/**/*}
|
||||
|
||||
# Documentation and guidelines
|
||||
@{*.md,docs/**/*,CLAUDE.md,**/*CLAUDE.md}
|
||||
```
|
||||
|
||||
### 🔗 Workflow Integration Patterns
|
||||
|
||||
⚠️ **CRITICAL**: Before analysis, MUST check for existing active session to ensure proper workflow context and documentation storage.
|
||||
|
||||
**Session Check Process:**
|
||||
1. **Check Active Session**: Check for `.workflow/.active-*` marker file to identify active session. No file creation needed.
|
||||
2. **Context Integration**: Use existing active session for proper analysis context
|
||||
3. **Documentation Strategy**: Store analysis results in appropriate session directory structure
|
||||
|
||||
- **Planning Phase**:
|
||||
`Check Active Session` **->** `Run /gemini-mode architecture` **->** `Run /gemini-mode pattern` **->** `Feed results into Task(planning-agent, ...)`
|
||||
- **Code Review**:
|
||||
`Check Active Session` **->** `Run /gemini-mode security "auth"` **->** `Run /gemini-mode performance "rendering"` **->** `Summarize findings for PR comments`
|
||||
- **Research & Discovery**:
|
||||
`Check Active Session` **->** `Run /gemini-mode architecture "overview"` **->** `Run /gemini-mode dependencies "key libraries"` **->** `Document for new team members`
|
||||
|
||||
### 🛠️ Task Tool Integration Example
|
||||
|
||||
Integrate `/gemini-mode` directly into automated tasks for analysis-driven actions.
|
||||
|
||||
```python
|
||||
Task(subagent_type="general-purpose", prompt="""
|
||||
Use /gemini-mode pattern "auth patterns" to analyze authentication.
|
||||
Summarize findings for implementation planning.
|
||||
""")
|
||||
```
|
||||
|
||||
### 👍 Best Practices
|
||||
|
||||
- **Scope**: Use specific, focused targets for faster, more accurate results.
|
||||
- **Chaining**: Combine analysis types (`architecture` then `pattern`) for a comprehensive view.
|
||||
- **Interpretation**: Use Gemini's raw output as input for Claude to interpret, summarize, and act upon.
|
||||
- **Performance**: Use `--yolo` for non-destructive analysis to skip confirmations. Be mindful that analyzing all files may be slow on large projects.
|
||||
|
||||
### 📋 Common Use Cases
|
||||
|
||||
| Use Case | Recommended Commands |
|
||||
| :--------------------- | :------------------------------------------------------------------------------------ |
|
||||
| **Project Onboarding** | `/gemini-mode architecture "overview"`, `/gemini-mode dependencies "key tech"` |
|
||||
| **Security Audit** | `/gemini-mode security "auth vulnerabilities"`, `/gemini-mode security "XSS"` |
|
||||
| **Performance Review** | `/gemini-mode performance "bottlenecks"`, `/gemini-mode performance "optimization"` |
|
||||
| **Migration Planning** | `/gemini-mode migration "legacy patterns"`, `/gemini-mode migration "modernization"`|
|
||||
| **Feature Research** | `/gemini-mode feature "existing system"`, `/gemini-mode pattern "approaches"` |
|
||||
|
||||
### 🆘 Troubleshooting
|
||||
|
||||
| Issue | Solution |
|
||||
| :--------------------- | :-------------------------------------------------- |
|
||||
| **Analysis timeout** | Use `--debug` to monitor progress and identify slow steps. |
|
||||
| **Context limits** | Break the analysis into smaller, more focused scopes. |
|
||||
| **Permission errors** | Ensure the CLI has read access to the target files. |
|
||||
| **Complex analysis** | Use `--interactive` mode to ask follow-up questions. |
|
||||
|
||||
203
.claude/commands/gemini/chat.md
Normal file
203
.claude/commands/gemini/chat.md
Normal file
@@ -0,0 +1,203 @@
|
||||
---
|
||||
name: gemini-chat
|
||||
parent: /gemini
|
||||
description: Single-execution Gemini CLI interaction command with dynamic template selection for 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:*)
|
||||
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.
|
||||
|
||||
### 📥 **Parameters & Usage**
|
||||
|
||||
- **`<inquiry>` (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}`.
|
||||
|
||||
### 🔄 **Core Execution Workflow**
|
||||
|
||||
⚠️ **IMPORTANT**: Template selection is **AUTOMATIC** based on input analysis and is the **FIRST STEP** in command execution.
|
||||
|
||||
`Parse Input & Intent` **->** `Auto-Select Template` **->** `Load Selected Template` **->** `Determine Context Needs` **->** `Assemble Context` **->** `Construct Prompt` **->** `Execute Gemini CLI` **->** `(Optional) Save Session`
|
||||
|
||||
### 🧠 **Template Selection Logic**
|
||||
|
||||
⚠️ **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.
|
||||
|
||||
```
|
||||
=== 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]
|
||||
|
||||
=== USER INPUT ===
|
||||
[The original user inquiry text]
|
||||
```
|
||||
|
||||
### ⚙️ **Gemini CLI Execution Logic**
|
||||
|
||||
This describes how the external `gemini` binary is invoked with the constructed prompt.
|
||||
|
||||
```pseudo
|
||||
FUNCTION execute_gemini_cli(structured_prompt, flags):
|
||||
// Retrieves the path from the user's execution environment.
|
||||
current_directory = get_current_working_directory()
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
**Session Template:**
|
||||
```markdown
|
||||
# Chat Session: [Timestamp] - [Topic]
|
||||
|
||||
## 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/)
|
||||
```
|
||||
254
.claude/commands/gemini/execute.md
Normal file
254
.claude/commands/gemini/execute.md
Normal file
@@ -0,0 +1,254 @@
|
||||
---
|
||||
name: gemini-execute
|
||||
parent: /gemini
|
||||
description: Intelligent context inference executor with auto-approval capabilities, supporting user descriptions and task ID execution modes
|
||||
usage: /gemini/execute <description|task-id>
|
||||
argument-hint: "implementation description or task-id"
|
||||
examples:
|
||||
- /gemini/execute "implement user authentication system"
|
||||
- /gemini/execute "optimize React component performance"
|
||||
- /gemini/execute IMPL-001
|
||||
- /gemini/execute "fix API performance issues"
|
||||
allowed-tools: Bash(gemini:*)
|
||||
model: sonnet
|
||||
---
|
||||
|
||||
### 🚀 Command Overview: /gemini/execute
|
||||
|
||||
|
||||
- **Type**: Intelligent Context Inference Executor.
|
||||
- **Purpose**: Infers context files to automatically execute implementation tasks using the Gemini CLI.
|
||||
- **Key Feature**: Non-interactive, auto-approved execution by default for streamlined workflows.
|
||||
- **Core Tool**: `Bash(gemini:*)`.
|
||||
|
||||
### ⚙️ Execution Modes
|
||||
|
||||
- **Direct User Description Mode**:
|
||||
- **Input**: A natural language description of the task (e.g., `"implement user authentication system"`).
|
||||
- **Process**: Analyzes keywords in the description to intelligently infer and collect relevant context files before execution.
|
||||
- **Task ID Mode**:
|
||||
- **Input**: A specific task identifier (e.g., `IMPL-001`).
|
||||
- **Process**: Parses the corresponding `.task/impl-*.json` file to determine scope, type, and related files for execution.
|
||||
|
||||
### 📥 Command Parameters
|
||||
|
||||
- `--debug`: Outputs detailed logs of the inference process and execution steps.
|
||||
- `--save-session`: Saves the entire execution session to the `.workflow/WFS-[topic-slug]/.chat/` directory.
|
||||
|
||||
**Note**: All executions run in auto-approval mode by default (equivalent to previous --yolo behavior).
|
||||
|
||||
### 🔄 High-Level Execution Flow
|
||||
|
||||
- **Description Input**: `Keyword Extraction` -> `Pattern Mapping` -> `Context Collection` -> `Gemini Execution`
|
||||
- **Task ID Input**: `Task Parsing` -> `Type & Scope Analysis` -> `Reference Integration` -> `Gemini Execution`
|
||||
|
||||
### 🧠 Intelligent Inference Logic
|
||||
|
||||
This logic determines which files are collected as context before calling the Gemini CLI.
|
||||
|
||||
```pseudo
|
||||
FUNCTION infer_context(input, user_description):
|
||||
collected_files = ["@{CLAUDE.md,**/*CLAUDE.md}"] // Base context
|
||||
|
||||
// Check for and process user-specified file overrides first
|
||||
IF user_description contains "@{...}":
|
||||
user_patterns = extract_patterns_from_string(user_description)
|
||||
collected_files += user_patterns
|
||||
|
||||
// Determine execution mode based on input format
|
||||
IF input matches pattern 'IMPL-*': // Task ID Mode
|
||||
task_data = read_json_file(".task/" + input + ".json")
|
||||
IF task_data is not found:
|
||||
RAISE_ERROR("Task ID not found")
|
||||
RETURN
|
||||
|
||||
// Infer patterns based on task type (e.g., "feature", "bugfix")
|
||||
type_patterns = get_patterns_for_task_type(task_data.type)
|
||||
collected_files += type_patterns
|
||||
collected_files += task_data.brainstorming_refs
|
||||
ELSE: // User Description Mode
|
||||
keywords = extract_tech_keywords(user_description)
|
||||
// Map keywords to file patterns (e.g., "React" -> "src/components/**/*.{jsx,tsx}")
|
||||
inferred_patterns = map_keywords_to_file_patterns(keywords)
|
||||
collected_files += inferred_patterns
|
||||
|
||||
// The final collected files are used to construct the Gemini command
|
||||
// This corresponds to calling the allowed tool `Bash(gemini:*)`
|
||||
run_gemini_cli(collected_files, user_description)
|
||||
END FUNCTION
|
||||
```
|
||||
|
||||
### 🖐️ User Override Logic
|
||||
|
||||
Users can override or supplement the automatic inference.
|
||||
|
||||
```pseudo
|
||||
FUNCTION calculate_final_patterns(description):
|
||||
inferred_patterns = get_inferred_patterns(description) // e.g., **/*auth*
|
||||
user_patterns = extract_user_patterns(description) // e.g., @{custom/auth/helpers.js}
|
||||
|
||||
// The final context is the union of inferred and user-specified patterns
|
||||
final_patterns = inferred_patterns + user_patterns
|
||||
RETURN final_patterns
|
||||
END FUNCTION
|
||||
```
|
||||
|
||||
### 🛠️ Gemini CLI Integration (Templated)
|
||||
|
||||
The following templates are used to call the `gemini` command via the `Bash` tool.
|
||||
|
||||
```bash
|
||||
# User Description Mode
|
||||
gemini --all-files --yolo -p "@{intelligently_inferred_file_patterns} @{CLAUDE.md,**/*CLAUDE.md}
|
||||
|
||||
Implementation Task: [user_description]
|
||||
|
||||
Based on intelligently inferred context, please provide:
|
||||
- Specific implementation code
|
||||
- File modification locations (file:line)
|
||||
- Test cases
|
||||
- Integration guidance"
|
||||
|
||||
# Task ID Mode
|
||||
gemini --all-files --yolo -p "@{task_related_files} @{brainstorming_refs} @{CLAUDE.md,**/*CLAUDE.md}
|
||||
|
||||
Task Execution: [task_title] (ID: [task-id])
|
||||
Task Description: [extracted_from_json]
|
||||
Task Type: [feature/bugfix/refactor/etc]
|
||||
|
||||
Please execute implementation based on task definition:
|
||||
- Follow task acceptance criteria
|
||||
- Based on brainstorming analysis results
|
||||
- Provide specific code and tests"
|
||||
```
|
||||
|
||||
### 🔗 Workflow System Integration Logic
|
||||
|
||||
The command integrates deeply with the workflow system with auto-approval by default.
|
||||
|
||||
```pseudo
|
||||
FUNCTION execute_with_workflow(task, flags):
|
||||
// All confirmation steps are automatically approved by default
|
||||
confirm_inferred_files = TRUE
|
||||
confirm_gemini_execution = TRUE
|
||||
confirm_file_modifications = TRUE
|
||||
|
||||
// Execute the task with auto-approval
|
||||
execute_gemini_task(task)
|
||||
// Actions performed after successful execution
|
||||
generate_task_summary_doc()
|
||||
update_workflow_status_files() // Updates WFS & workflow-session.json
|
||||
END FUNCTION
|
||||
```
|
||||
|
||||
### 📄 Task Summary Template (Templated)
|
||||
|
||||
This template is automatically filled and generated after execution.
|
||||
|
||||
```markdown
|
||||
# Task Summary: [Task-ID/Generated-ID] [Task Name/Description]
|
||||
|
||||
## Execution Content
|
||||
- **Intelligently Inferred Files**: [inferred_file_patterns]
|
||||
- **Gemini Analysis Results**: [key_findings]
|
||||
- **Implemented Features**: [specific_implementation_content]
|
||||
- **Modified Files**: [file:line references]
|
||||
|
||||
## Issues Resolved
|
||||
- [list_of_resolved_problems]
|
||||
|
||||
## Links
|
||||
- [🔙 Back to Task List](../TODO_LIST.md#[Task-ID])
|
||||
- [📋 Implementation Plan](../IMPL_PLAN.md#[Task-ID])
|
||||
```
|
||||
|
||||
### 🛡️ Error Handling Protocols
|
||||
|
||||
- **Keyword Inference Failure**: `Use generic pattern 'src/**/*'` -> `Prompt user for manual specification`.
|
||||
- **Task ID Not Found**: `Display error message` -> `List available tasks`.
|
||||
- **File Pattern No Matches**: `Expand search scope` -> `Log debug info`.
|
||||
- **Gemini CLI Failure**: `Attempt fallback mode (e.g., --all-files -> @{patterns})` -> `Simplify context & retry`.
|
||||
|
||||
### ⚡ Performance Optimizations
|
||||
|
||||
- **Caching**: Caches frequently used keyword-to-pattern mapping results.
|
||||
- **Pattern Optimization**: Avoids overly broad file patterns like `**/*` where possible.
|
||||
- **Progressive Inference**: Tries precise patterns (`src/api/auth`) before broader ones (`**/*auth*`).
|
||||
- **Path Navigation**: Switches to the optimal execution directory based on inference to shorten paths.
|
||||
|
||||
### 🤝 Integration & Coordination
|
||||
|
||||
- **vs. `gemini-chat`**: `gemini-chat` is for pure analysis; `/gemini-execute` performs analysis **and** execution.
|
||||
- **vs. `code-developer`**: `code-developer` requires manual context provision; `/gemini-execute` infers context automatically.
|
||||
- **Typical Workflow Sequence**:
|
||||
1. `workflow:session "..."`
|
||||
2. `workflow:brainstorm`
|
||||
3. `workflow:plan`
|
||||
4. `/gemini-execute IMPL-001`
|
||||
5. `workflow:review`
|
||||
|
||||
### 💾 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 execution session, including inferred context, Gemini analysis, and implementation results.
|
||||
- **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
|
||||
|
||||
**Core Principles**: @~/.claude/workflows/core-principles.md
|
||||
**File Structure**: @~/.claude/workflows/file-structure-standards.md
|
||||
- **File Format**: `execute-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.
|
||||
|
||||
### 🔗 Execution Session Integration
|
||||
|
||||
**Storage Structure:**
|
||||
```
|
||||
.workflow/WFS-[topic-slug]/.chat/
|
||||
├── execute-20240307-143022.md # Execution sessions with timestamps
|
||||
├── execute-20240307-151445.md # Chronologically ordered
|
||||
└── analysis-[topic].md # Referenced analysis sessions
|
||||
```
|
||||
|
||||
**Execution Session Template:**
|
||||
```markdown
|
||||
# Execution Session: [Timestamp] - [Task/Description]
|
||||
|
||||
## Input
|
||||
[Original user description or Task ID]
|
||||
|
||||
## Context Inference
|
||||
[Intelligently inferred file patterns and rationale]
|
||||
|
||||
## Task Details (if Task ID mode)
|
||||
[Extracted task data from .task/*.json]
|
||||
|
||||
## Gemini Execution
|
||||
[Complete Gemini CLI command and parameters]
|
||||
|
||||
## Implementation Results
|
||||
[Code generated, files modified, test cases]
|
||||
|
||||
## Key Outcomes
|
||||
- [Files modified/created]
|
||||
- [Features implemented]
|
||||
- [Issues resolved]
|
||||
|
||||
## Integration Links
|
||||
- [🔙 Workflow Session](../workflow-session.json)
|
||||
- [📋 Implementation Plan](../IMPL_PLAN.md)
|
||||
- [📝 Task Definitions](../.task/)
|
||||
- [📑 Summary](../.summaries/)
|
||||
```
|
||||
|
||||
### ✅ Quality Assurance Principles
|
||||
|
||||
- **Inference Accuracy**: Keyword mapping tables are regularly updated based on project patterns and user feedback.
|
||||
- **Execution Reliability**: Implements robust error handling and leverages debug mode for detailed tracing.
|
||||
- **Documentation Completeness**: Ensures auto-generated summaries are structured and workflow statuses are synced in real-time.
|
||||
### 📚 Related Documentation
|
||||
|
||||
Reference in New Issue
Block a user