refactor: enhance prompt generation process with direct output and improved internal analysis

This commit is contained in:
catlog22
2025-10-18 22:33:29 +08:00
parent 49c2b189d4
commit b8935777e7
2 changed files with 141 additions and 125 deletions

View File

@@ -338,29 +338,3 @@ const agentContext = {
mcp_analysis: executeMcpDiscovery() mcp_analysis: executeMcpDiscovery()
} }
``` ```
## Usage Examples
```bash
# Agent Mode (default) - steps without command field
/workflow:tools:task-generate-agent --session WFS-auth
# CLI Execute Mode - steps with command field
/workflow:tools:task-generate-agent --session WFS-auth --cli-execute
# Called by /workflow:plan (default mode)
SlashCommand(command="/workflow:tools:task-generate-agent --session WFS-[id]")
# Called by /workflow:plan --cli-execute (CLI mode)
SlashCommand(command="/workflow:tools:task-generate-agent --session WFS-[id] --cli-execute")
```
## Related Commands
- `/workflow:plan` - Orchestrates planning and calls this command
- `/workflow:plan --cli-execute` - Planning with CLI execution mode
- `/workflow:tools:task-generate` - Manual version without agent
- `/workflow:tools:context-gather` - Provides context package
- `/workflow:tools:concept-enhanced` - Provides analysis results
- `/workflow:execute` - Executes generated tasks

View File

@@ -1,12 +1,12 @@
--- ---
name: Prompt Enhancer name: Prompt Enhancer
description: Transform vague prompts into actionable specs using session memory ONLY (no file analysis). AUTO-TRIGGER on (1) -e/--enhance flags, (2) vague keywords (fix/improve/refactor/修复/优化/重构), (3) unclear refs (it/that/这个/那个), (4) multi-module scope. Supports English + Chinese semantic recognition. description: Transform vague prompts into actionable specs using session memory ONLY (no file analysis). AUTO-TRIGGER on (1) -e/--enhance flags, (2) vague keywords (fix/improve/refactor/修复/优化/重构), (3) unclear refs (it/that/这个/那个), (4) multi-module scope. Supports English + Chinese semantic recognition.
allowed-tools: AskUserQuestion allowed-tools: (none)
--- ---
# Prompt Enhancer # Prompt Enhancer
**Transform**: Vague intent → Structured specification (Memory-based) **Transform**: Vague intent → Structured specification (Memory-based, Direct Output)
**Languages**: English + Chinese (中英文语义识别) **Languages**: English + Chinese (中英文语义识别)
@@ -19,160 +19,202 @@ allowed-tools: AskUserQuestion
| **P3** | Unclear references | EN: it/that/the code<br>CN: 这个/那个/它/代码 | Context extraction | | **P3** | Unclear references | EN: it/that/the code<br>CN: 这个/那个/它/代码 | Context extraction |
| **P4** | Multi-module scope | >3 modules or critical systems | Dependency analysis | | **P4** | Multi-module scope | >3 modules or critical systems | Dependency analysis |
## Process (3 Steps - Streamlined) ## Process (Internal → Direct Output)
### 1. Semantic Analysis (Quick) **Internal Analysis (Silent)**:
Identify: Intent keywords (EN/CN) → Scope (file/module/system) → Domain (auth/API/DB/UI)
**English**: fix, improve, add, refactor, update, migrate 1. **Semantic Analysis**
**Chinese**: 修复, 优化, 添加, 重构, 更新, 迁移, 改进, 清理 - Intent keywords (EN/CN): fix/修复, improve/优化, add/添加, refactor/重构
- Scope identification: file → module → system
- Domain mapping: auth/API/DB/UI/Performance
### 2. Memory-Only Extraction (NO File Reading) 2. **Memory Extraction** (NO File Reading)
Extract from **conversation memory ONLY**: - Recent user requests and context
- Recent user requests and context - Tech stack mentioned in session (frameworks, libraries, patterns)
- Previous implementations/patterns discussed - Design patterns discussed or implied
- Known dependencies from session - User preferences and constraints
- User preferences and constraints - Known dependencies from conversation
**SKIP**: File reading, codebase scanning, Glob/Grep operations 3. **Enhancement Dimensions**
**FOCUS**: Pure memory-based context extraction - **Structure**: Convert to INTENT/CONTEXT/ACTION/ATTENTION format
- **Supplement**: Add tech stack, design patterns, testing requirements
- **Clarify**: Make intent explicit, resolve ambiguous references
### 3. User Confirmation with Optimization Direction (REQUIRED) **Output**: Direct structured prompt (no intermediate steps shown)
Present structured prompt → Ask: Continue? + Optimization suggestions needed?
## Output Format ## Output Format
``` ```
📋 ENHANCED PROMPT 📋 ENHANCED PROMPT
INTENT: [One-sentence technical goal / 明确技术目标] INTENT: [One-sentence technical goal with tech stack / 明确技术目标含技术栈]
TECH STACK: [Relevant technologies from memory / 相关技术栈]
- [Framework/Library: Purpose]
CONTEXT: [Session memory findings / 会话记忆发现] CONTEXT: [Session memory findings / 会话记忆发现]
- [Key context point 1] - [Key context point 1]
- [Key context point 2] - [Key context point 2]
- [...] - [Design patterns/constraints from session]
ACTION: ACTION:
1. [Concrete step / 具体步骤] 1. [Concrete step with technical details / 具体步骤含技术细节]
2. [Concrete step / 具体步骤] 2. [Concrete step with technical details]
3. [...] 3. [Testing/validation step]
ATTENTION: [Critical constraints / 关键约束] ATTENTION: [Critical constraints / 关键约束]
- [Security/compatibility/testing concerns] - [Security/compatibility/performance concerns]
- [Design pattern requirements]
``` ```
## Semantic Patterns (EN + CN) ## Semantic Patterns (EN + CN)
| Intent (EN/CN) | Semantic Meaning | Focus | | Intent (EN/CN) | Semantic Meaning | Enhancement Focus |
|----------------|------------------|-------| |----------------|------------------|-------------------|
| fix/修复 + vague target | Debug & resolve | Root cause → preserve behavior | | fix/修复 + vague target | Debug & resolve | Root cause + tech stack + testing |
| improve/优化 + no metrics | Enhance/optimize | Performance/readability | | improve/优化 + no metrics | Enhance/optimize | Performance metrics + patterns + benchmarks |
| add/添加 + feature | Implement feature | Integration + edge cases | | add/添加 + feature | Implement feature | Integration points + edge cases + tests |
| refactor/重构 + module | Restructure | Maintain behavior | | refactor/重构 + module | Restructure | Design patterns + backward compatibility |
| update/更新 + version | Modernize | Version compatibility | | update/更新 + version | Modernize | Migration path + breaking changes |
| clean up/清理 + area | Simplify/organize | Remove redundancy | | clean up/清理 + area | Simplify/organize | Code quality patterns + tech debt |
## Workflow ## Workflow
``` ```
Trigger → Analyze → Extract → Present → Confirm → Execute Trigger → Internal Analysis → Direct Output
↓ ↓ ↓ ↓ ↓
P1-4 EN/CN Memory Struct Ask User Direct P1-4 Semantic+Memory Enhanced Prompt
detect only prompt or refine (3 dimensions) (Structured)
``` ```
1. **Detect**: Check triggers (P1-P4) 1. **Detect**: Check triggers (P1-P4)
2. **Analyze**: Semantic (EN/CN) analysis of user intent 2. **Internal Analysis**:
3. **Extract**: Memory-only context extraction (NO file reading) - Semantic (EN/CN) intent analysis
4. **Present**: Generate structured prompt output - Memory extraction (tech stack, patterns, constraints)
5. **Confirm**: AskUserQuestion (Continue/Modify/Cancel) - Enhancement (structure + supplement + clarify)
6. **Execute**: Proceed based on user choice 3. **Output**: Present enhanced structured prompt directly
## Confirmation (AskUserQuestion) ## Enhancement Checklist (Internal)
**Question**: "Enhanced prompt ready. Proceed or need adjustments? (已生成增强提示词,是否继续或需要调整?)" **Structure**:
- [ ] INTENT: Clear, one-sentence technical goal
- [ ] TECH STACK: Relevant technologies from session
- [ ] CONTEXT: Key session findings and constraints
- [ ] ACTION: Concrete steps with technical details
- [ ] ATTENTION: Critical constraints and patterns
**Options**: **Supplement**:
1. **Continue as-is / 按此继续** - Proceed with current specification - [ ] Add tech stack/frameworks mentioned in session
2. **Suggest optimizations / 建议优化方向** - I need guidance on how to improve this - [ ] Include design patterns if relevant
3. **Modify requirements / 修改需求** - Let me provide specific changes - [ ] Add testing/validation requirements
- [ ] Specify performance metrics if applicable
```typescript **Clarify**:
AskUserQuestion({ - [ ] Make vague intent explicit
questions: [{ - [ ] Resolve ambiguous references (it/that/这个/那个)
question: "Enhanced prompt ready. Proceed or need adjustments? (已生成增强提示词,是否继续或需要调整?)", - [ ] Expand multi-module scope with dependencies
header: "Next Step", - [ ] Add missing context from memory
multiSelect: false,
options: [
{
label: "Continue as-is",
description: "Proceed with current specification (按此继续)"
},
{
label: "Suggest optimizations",
description: "I need guidance on how to improve this (建议优化方向)"
},
{
label: "Modify requirements",
description: "Let me provide specific changes (修改需求)"
}
]
}]
})
```
## Best Practices ## Best Practices
- ✅ Detect `-e`/`--enhance` flags first (P1) - ✅ Detect `-e`/`--enhance` flags first (P1)
- ✅ Support EN + CN semantic keywords - ✅ Support EN + CN semantic keywords
- ✅ Extract **memory context ONLY** (no file reading) - ✅ Extract **memory context ONLY** (no file reading)
-Use INTENT/CONTEXT/ACTION/ATTENTION format -Add tech stack, design patterns, testing requirements
-ALWAYS confirm with AskUserQuestion -Direct output (no intermediate steps)
-Offer optimization guidance option -Use INTENT/TECH STACK/CONTEXT/ACTION/ATTENTION format
- ❌ NO tool calls (AskUserQuestion removed)
- ❌ NO Bash, Read, Glob, Grep operations - ❌ NO Bash, Read, Glob, Grep operations
- ❌ NO direct file analysis - ❌ NO file analysis or codebase scanning
## Key Changes from Previous Version ## Key Changes
1. **Removed file analysis** - Memory extraction only 1. **Removed all tools** - Pure analysis and output
2. **Simplified to 3 steps** - Faster workflow 2. **Removed user confirmation** - Direct output for speed
3. **Updated confirmation options** - Added "Suggest optimizations" 3. **Added tech stack section** - Supplement with technologies
4. **Removed file tools** - Only AskUserQuestion allowed 4. **Enhanced internal analysis** - 3 dimensions (structure + supplement + clarify)
5. **Focus on speed** - Quick semantic analysis + memory extraction 5. **Focus on memory** - Session context only, no file reading
## Examples ## Examples
**Input**: "fix auth -e" / "优化性能 --enhance" ### Example 1: Vague Fix Request
**Process**: **Input**: "fix auth -e" / "修复认证 --enhance"
1. Detect P1 trigger (`-e` flag)
2. Semantic analysis: "fix/优化" intent **Internal Analysis**:
3. Extract from memory: Recent auth/performance discussions - Semantic: "fix/修复" → debug intent
4. Generate structured prompt - Memory: Recent mention of JWT, token expiration issues
5. Ask user: Continue/Suggest optimizations/Modify - Tech stack: JWT, Express.js middleware (from session)
- Enhancement: Add testing, security patterns
**Output**: **Output**:
``` ```
📋 ENHANCED PROMPT 📋 ENHANCED PROMPT
INTENT: Fix authentication module issues based on recent session context INTENT: Fix authentication token expiration handling in JWT-based auth system
TECH STACK:
- JWT: Token generation and validation
- Express.js: Middleware implementation
- Jest: Unit testing framework
CONTEXT: CONTEXT:
- User mentioned auth token expiration problems - User reported token expiration issues in previous conversation
- Previous discussion about JWT validation - Session indicates JWT-based authentication system
- Session indicates preference for backward compatibility - Preference for backward compatibility with existing tokens
ACTION: ACTION:
1. Review authentication token handling logic 1. Analyze JWT token lifecycle and expiration validation logic
2. Implement proper JWT validation with expiration checks 2. Implement proper token refresh mechanism with sliding expiration
3. Add unit tests for token refresh flow 3. Add middleware for token validation with detailed error handling
4. Update documentation for auth changes 4. Write unit tests for token expiration and refresh scenarios
5. Update API documentation for token refresh endpoints
ATTENTION: ATTENTION:
- Must maintain backward compatibility with existing tokens - Must maintain backward compatibility with existing valid tokens
- Security: Follow JWT best practices - Security: Follow JWT best practices (HS256/RS256, secure secret storage)
- Testing: Ensure no breaking changes to API contracts - Testing: Cover edge cases (expired, malformed, missing tokens)
- Performance: Consider token validation caching for high-traffic endpoints
``` ```
**Then ask**: Continue as-is / Suggest optimizations / Modify requirements ### Example 2: Vague Optimization Request
**Input**: "optimize performance --enhance" / "优化性能 -e"
**Internal Analysis**:
- Semantic: "optimize/优化" → performance intent
- Memory: Previous discussion about API response times, React rendering
- Tech stack: React, Node.js, PostgreSQL (from session)
- Enhancement: Add metrics, profiling, specific optimizations
**Output**:
```
📋 ENHANCED PROMPT
INTENT: Optimize API response times and React component rendering performance
TECH STACK:
- React: Component optimization (memo, useMemo, useCallback)
- Node.js: API endpoint optimization
- PostgreSQL: Query optimization and indexing
CONTEXT:
- User mentioned slow API responses (>2s) in previous conversation
- React app shows rendering performance issues on large lists
- PostgreSQL database queries identified as bottleneck
ACTION:
1. Profile API endpoints using Node.js profiler to identify slow queries
2. Optimize PostgreSQL queries with proper indexing and query analysis (EXPLAIN)
3. Implement React.memo for expensive list components
4. Add useMemo/useCallback for derived data and event handlers
5. Implement pagination/virtualization for large data lists
6. Add performance monitoring with metrics (response time, render time)
7. Write performance benchmarks and regression tests
ATTENTION:
- Metrics: Target <500ms API response, <100ms render time
- Patterns: Use React.memo judiciously (avoid over-optimization)
- Testing: Add performance regression tests with benchmarks
- Compatibility: Ensure optimizations don't break existing functionality
```