|
| 1 | +# Product Story: Fix High-Priority Tools CLI Compatibility |
| 2 | + |
| 3 | +## Epic |
| 4 | + |
| 5 | +CLI Tool Compatibility - Phase 2: High-Priority Tool Fixes |
| 6 | + |
| 7 | +## Story Title |
| 8 | + |
| 9 | +As a CLI user, I want all high-priority tools to work in batch mode so that I can perform comprehensive automated workflows without interruption |
| 10 | + |
| 11 | +## User Story |
| 12 | + |
| 13 | +**As a** CLI user running automated workflows |
| 14 | +**I want** executeCommand, attemptCompletion, and askFollowupQuestion tools to work in non-interactive mode |
| 15 | +**So that** I can create complete end-to-end automation without manual intervention |
| 16 | + |
| 17 | +## Background |
| 18 | + |
| 19 | +After fixing the search_and_replace tool, several other high-priority tools have been identified that use similar problematic patterns with hardcoded `cline.ask()` calls. These tools are essential for comprehensive CLI automation workflows. |
| 20 | + |
| 21 | +## Problem Statement |
| 22 | + |
| 23 | +- Multiple critical tools hang in CLI batch mode |
| 24 | +- Tools use hardcoded interactive approval requests |
| 25 | +- Prevents end-to-end automation workflows |
| 26 | +- Inconsistent behavior across tools |
| 27 | + |
| 28 | +## Affected Tools Analysis |
| 29 | + |
| 30 | +### 1. executeCommandTool.ts (Critical Impact) |
| 31 | + |
| 32 | +**Issue Location**: Line 211 |
| 33 | + |
| 34 | +```typescript |
| 35 | +const { response, text, images } = await cline.ask("command_output", "") |
| 36 | +``` |
| 37 | + |
| 38 | +**Impact**: Commands that need user interaction hang in CLI mode |
| 39 | +**Usage**: Core functionality for running system commands |
| 40 | + |
| 41 | +### 2. attemptCompletionTool.ts (Critical Impact) |
| 42 | + |
| 43 | +**Issue Location**: Line 119 |
| 44 | + |
| 45 | +```typescript |
| 46 | +const { response, text, images } = await cline.ask("completion_result", "", false) |
| 47 | +``` |
| 48 | + |
| 49 | +**Impact**: Task completion requires user confirmation, breaks automation |
| 50 | +**Usage**: Final step in task execution workflows |
| 51 | + |
| 52 | +### 3. askFollowupQuestionTool.ts (Medium Impact) |
| 53 | + |
| 54 | +**Issue Location**: Line 59 |
| 55 | + |
| 56 | +```typescript |
| 57 | +const { text, images } = await cline.ask("followup", JSON.stringify(follow_up_json), false) |
| 58 | +``` |
| 59 | + |
| 60 | +**Impact**: Information gathering workflows hang waiting for user input |
| 61 | +**Usage**: Interactive clarification and information gathering |
| 62 | + |
| 63 | +## Technical Analysis |
| 64 | + |
| 65 | +### Current CLI Auto-Approval Pattern (Working) |
| 66 | + |
| 67 | +From Task.ts line 864: |
| 68 | + |
| 69 | +```typescript |
| 70 | +const askApproval = async () => true // Auto-approve in CLI |
| 71 | +``` |
| 72 | + |
| 73 | +### Correct Implementation Pattern |
| 74 | + |
| 75 | +From readFileTool.ts: |
| 76 | + |
| 77 | +```typescript |
| 78 | +const approved = await askApproval("tool", completeMessage) |
| 79 | +if (!approved) { |
| 80 | + cline.didRejectTool = true |
| 81 | + return |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +## Acceptance Criteria |
| 86 | + |
| 87 | +### Functional Requirements |
| 88 | + |
| 89 | +- [ ] All high-priority tools work in CLI batch mode without hanging |
| 90 | +- [ ] Tools auto-approve operations in CLI mode |
| 91 | +- [ ] Tools maintain interactive behavior in VSCode mode |
| 92 | +- [ ] Consistent approval patterns across all tools |
| 93 | +- [ ] Proper error handling and fallback behavior |
| 94 | + |
| 95 | +### Technical Requirements |
| 96 | + |
| 97 | +- [ ] Replace hardcoded `cline.ask()` calls with appropriate CLI-compatible patterns |
| 98 | +- [ ] Implement proper auto-approval for CLI mode |
| 99 | +- [ ] Maintain backward compatibility with VSCode interactive mode |
| 100 | +- [ ] Follow established patterns from successfully converted tools |
| 101 | +- [ ] Consistent error handling and user feedback |
| 102 | + |
| 103 | +### Quality Requirements |
| 104 | + |
| 105 | +- [ ] All existing tests continue to pass |
| 106 | +- [ ] No regression in VSCode functionality |
| 107 | +- [ ] Comprehensive test coverage for CLI scenarios |
| 108 | +- [ ] Consistent behavior and user experience |
| 109 | + |
| 110 | +## Implementation Tasks |
| 111 | + |
| 112 | +### Task 1: Fix executeCommandTool.ts |
| 113 | + |
| 114 | +**Estimated Time**: 4 hours |
| 115 | +**Priority**: Critical |
| 116 | + |
| 117 | +#### Analysis |
| 118 | + |
| 119 | +The command output approval mechanism needs to handle: |
| 120 | + |
| 121 | +- Background process management |
| 122 | +- Interactive command scenarios |
| 123 | +- Output capture and display |
| 124 | +- User interruption handling |
| 125 | + |
| 126 | +#### Implementation Strategy |
| 127 | + |
| 128 | +```typescript |
| 129 | +// Current problematic code: |
| 130 | +const { response, text, images } = await cline.ask("command_output", "") |
| 131 | +runInBackground = true |
| 132 | + |
| 133 | +// Proposed fix: |
| 134 | +// For CLI mode: Auto-approve background execution |
| 135 | +// For VSCode mode: Show interactive prompt |
| 136 | +const shouldRunInBackground = await askApproval("command_output", "") |
| 137 | +if (shouldRunInBackground) { |
| 138 | + runInBackground = true |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +#### Specific Changes |
| 143 | + |
| 144 | +- [ ] Replace interactive prompt with CLI-compatible approval |
| 145 | +- [ ] Ensure background process handling works in CLI |
| 146 | +- [ ] Maintain interrupt capability in VSCode mode |
| 147 | +- [ ] Handle command output appropriately in both modes |
| 148 | + |
| 149 | +### Task 2: Fix attemptCompletionTool.ts |
| 150 | + |
| 151 | +**Estimated Time**: 3 hours |
| 152 | +**Priority**: Critical |
| 153 | + |
| 154 | +#### Analysis |
| 155 | + |
| 156 | +The completion result approval affects: |
| 157 | + |
| 158 | +- Task completion workflows |
| 159 | +- Final result confirmation |
| 160 | +- Command execution for result demonstration |
| 161 | +- User feedback collection |
| 162 | + |
| 163 | +#### Implementation Strategy |
| 164 | + |
| 165 | +```typescript |
| 166 | +// Current problematic code: |
| 167 | +const { response, text, images } = await cline.ask("completion_result", "", false) |
| 168 | + |
| 169 | +// Proposed fix: |
| 170 | +// For CLI mode: Auto-approve completion |
| 171 | +// For VSCode mode: Show completion dialog |
| 172 | +const completionApproved = await askApproval("completion_result", "") |
| 173 | +if (completionApproved) { |
| 174 | + // Handle auto-approval logic |
| 175 | +} else { |
| 176 | + // Handle rejection/modification requests |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +#### Specific Changes |
| 181 | + |
| 182 | +- [ ] Replace completion prompt with CLI-compatible approval |
| 183 | +- [ ] Ensure task completion works in automated scenarios |
| 184 | +- [ ] Maintain user feedback capability in VSCode mode |
| 185 | +- [ ] Handle command execution properly in both modes |
| 186 | + |
| 187 | +### Task 3: Fix askFollowupQuestionTool.ts |
| 188 | + |
| 189 | +**Estimated Time**: 3 hours |
| 190 | +**Priority**: High |
| 191 | + |
| 192 | +#### Analysis |
| 193 | + |
| 194 | +The followup question mechanism needs special handling: |
| 195 | + |
| 196 | +- Information gathering workflows |
| 197 | +- User clarification requests |
| 198 | +- Multiple choice options |
| 199 | +- Fallback behavior for automation |
| 200 | + |
| 201 | +#### Implementation Strategy |
| 202 | + |
| 203 | +```typescript |
| 204 | +// Current problematic code: |
| 205 | +const { text, images } = await cline.ask("followup", JSON.stringify(follow_up_json), false) |
| 206 | + |
| 207 | +// Proposed fix: |
| 208 | +// For CLI mode: Use first suggested option or skip |
| 209 | +// For VSCode mode: Show interactive question dialog |
| 210 | +const followupResponse = await handleFollowupQuestion(follow_up_json, askApproval) |
| 211 | +``` |
| 212 | + |
| 213 | +#### Specific Changes |
| 214 | + |
| 215 | +- [ ] Create smart fallback logic for CLI mode |
| 216 | +- [ ] Use first suggested option as default in automation |
| 217 | +- [ ] Maintain full interactive capability in VSCode mode |
| 218 | +- [ ] Implement graceful degradation for automation scenarios |
| 219 | + |
| 220 | +### Task 4: Pattern Standardization |
| 221 | + |
| 222 | +**Estimated Time**: 2 hours |
| 223 | +**Priority**: High |
| 224 | + |
| 225 | +#### Create Reusable Utilities |
| 226 | + |
| 227 | +- [ ] Create `CliCompatibleApproval` utility function |
| 228 | +- [ ] Create `AutomationFallback` helper for question handling |
| 229 | +- [ ] Create consistent error handling patterns |
| 230 | +- [ ] Document standard patterns for future tools |
| 231 | + |
| 232 | +#### Implementation |
| 233 | + |
| 234 | +```typescript |
| 235 | +// Utility for CLI-compatible approvals |
| 236 | +export async function createCliCompatibleApproval( |
| 237 | + askApproval: AskApproval, |
| 238 | + messageType: string, |
| 239 | + message: string, |
| 240 | + fallbackValue: boolean = true, |
| 241 | +): Promise<boolean> { |
| 242 | + try { |
| 243 | + return await askApproval(messageType, message) |
| 244 | + } catch (error) { |
| 245 | + // Fallback for CLI mode or error scenarios |
| 246 | + return fallbackValue |
| 247 | + } |
| 248 | +} |
| 249 | +``` |
| 250 | + |
| 251 | +### Task 5: Testing and Validation |
| 252 | + |
| 253 | +**Estimated Time**: 4 hours |
| 254 | +**Priority**: High |
| 255 | + |
| 256 | +#### CLI Mode Testing |
| 257 | + |
| 258 | +- [ ] Test command execution workflows |
| 259 | +- [ ] Test task completion scenarios |
| 260 | +- [ ] Test followup question fallback behavior |
| 261 | +- [ ] Test error handling and edge cases |
| 262 | +- [ ] Verify no hanging or timeout issues |
| 263 | + |
| 264 | +#### VSCode Mode Testing |
| 265 | + |
| 266 | +- [ ] Verify all interactive prompts still work |
| 267 | +- [ ] Test user approval/rejection scenarios |
| 268 | +- [ ] Test command interruption capabilities |
| 269 | +- [ ] Verify no regression in existing behavior |
| 270 | + |
| 271 | +#### Integration Testing |
| 272 | + |
| 273 | +- [ ] Test complete workflows using multiple tools |
| 274 | +- [ ] Test complex automation scenarios |
| 275 | +- [ ] Verify proper state management across tools |
| 276 | +- [ ] Test error propagation and handling |
| 277 | + |
| 278 | +## Definition of Done |
| 279 | + |
| 280 | +### Functional DoD |
| 281 | + |
| 282 | +- ✅ All high-priority tools work without hanging in CLI batch mode |
| 283 | +- ✅ Tools handle automation scenarios appropriately |
| 284 | +- ✅ Interactive functionality preserved in VSCode mode |
| 285 | +- ✅ Consistent behavior across all fixed tools |
| 286 | + |
| 287 | +### Technical DoD |
| 288 | + |
| 289 | +- ✅ Standardized CLI compatibility patterns implemented |
| 290 | +- ✅ Proper error handling and fallback mechanisms |
| 291 | +- ✅ Maintained backward compatibility |
| 292 | +- ✅ Reusable utilities created for future tools |
| 293 | + |
| 294 | +### Quality DoD |
| 295 | + |
| 296 | +- ✅ Comprehensive test coverage for all scenarios |
| 297 | +- ✅ All existing tests continue to pass |
| 298 | +- ✅ Code review completed and approved |
| 299 | +- ✅ Documentation updated with new patterns |
| 300 | + |
| 301 | +## Test Scenarios |
| 302 | + |
| 303 | +### Scenario 1: End-to-End CLI Workflow |
| 304 | + |
| 305 | +```bash |
| 306 | +npm run start:cli -- --batch "Create a new file, execute a command to process it, and complete the task" |
| 307 | +``` |
| 308 | + |
| 309 | +**Expected**: Complete workflow runs without hanging |
| 310 | + |
| 311 | +### Scenario 2: Command Execution in CLI |
| 312 | + |
| 313 | +```bash |
| 314 | +npm run start:cli -- --batch "Run 'ls -la' command and capture output" |
| 315 | +``` |
| 316 | + |
| 317 | +**Expected**: Command executes and completes automatically |
| 318 | + |
| 319 | +### Scenario 3: Task Completion in CLI |
| 320 | + |
| 321 | +```bash |
| 322 | +npm run start:cli -- --batch "Create a simple task and mark it as completed" |
| 323 | +``` |
| 324 | + |
| 325 | +**Expected**: Task completes without requiring user confirmation |
| 326 | + |
| 327 | +### Scenario 4: VSCode Interactive Preservation |
| 328 | + |
| 329 | +1. Use executeCommand tool in VSCode |
| 330 | +2. Run command that might need interruption |
| 331 | +3. Verify interactive prompts appear |
| 332 | + **Expected**: Full interactive capability preserved |
| 333 | + |
| 334 | +## Risk Assessment |
| 335 | + |
| 336 | +### High Risk |
| 337 | + |
| 338 | +- **Command Execution**: Background processes and interruption handling |
| 339 | +- **Task Completion**: Workflow completion logic complexity |
| 340 | +- **Backward Compatibility**: Preserving VSCode interactive features |
| 341 | + |
| 342 | +### Medium Risk |
| 343 | + |
| 344 | +- **Error Handling**: Consistent error handling across different tool types |
| 345 | +- **State Management**: Proper cleanup and state management |
| 346 | +- **Integration**: Interaction between multiple fixed tools |
| 347 | + |
| 348 | +### Mitigation |
| 349 | + |
| 350 | +- Incremental implementation and testing |
| 351 | +- Thorough testing in both CLI and VSCode modes |
| 352 | +- Code review focusing on compatibility and error handling |
| 353 | +- Rollback plan for each tool individually |
| 354 | + |
| 355 | +## Dependencies |
| 356 | + |
| 357 | +- Completion of Phase 1 (search_and_replace tool fix) |
| 358 | +- Understanding of CLI auto-approval mechanisms |
| 359 | +- Access to comprehensive testing environment |
| 360 | + |
| 361 | +## Related Stories |
| 362 | + |
| 363 | +- Previous: Fix Search and Replace Tool CLI Compatibility |
| 364 | +- Next: Comprehensive Tool Audit and Standardization |
| 365 | +- Epic: CLI Tool Compatibility Comprehensive Plan |
| 366 | + |
| 367 | +## Success Metrics |
| 368 | + |
| 369 | +- Zero hanging issues in CLI batch mode for high-priority tools |
| 370 | +- 100% backward compatibility with VSCode mode |
| 371 | +- Consistent patterns established for future tool development |
| 372 | +- Comprehensive automation workflows functional in CLI mode |
0 commit comments