claude-code-workflow 6.3.2 → 6.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.claude/CLAUDE.md +9 -1
  2. package/.claude/commands/workflow/lite-plan.md +1 -1
  3. package/.claude/workflows/cli-tools-usage.md +515 -516
  4. package/ccw/dist/cli.d.ts.map +1 -1
  5. package/ccw/dist/cli.js +6 -1
  6. package/ccw/dist/cli.js.map +1 -1
  7. package/ccw/dist/commands/cli.d.ts +1 -1
  8. package/ccw/dist/commands/cli.d.ts.map +1 -1
  9. package/ccw/dist/commands/cli.js +71 -7
  10. package/ccw/dist/commands/cli.js.map +1 -1
  11. package/ccw/dist/tools/cli-executor.d.ts.map +1 -1
  12. package/ccw/dist/tools/cli-executor.js +19 -7
  13. package/ccw/dist/tools/cli-executor.js.map +1 -1
  14. package/ccw/dist/tools/cli-history-store.d.ts +33 -0
  15. package/ccw/dist/tools/cli-history-store.d.ts.map +1 -1
  16. package/ccw/dist/tools/cli-history-store.js +89 -5
  17. package/ccw/dist/tools/cli-history-store.js.map +1 -1
  18. package/ccw/src/cli.ts +263 -258
  19. package/ccw/src/commands/cli.ts +967 -884
  20. package/ccw/src/tools/cli-executor.ts +20 -7
  21. package/ccw/src/tools/cli-history-store.ts +125 -5
  22. package/codex-lens/src/codexlens/__pycache__/config.cpython-313.pyc +0 -0
  23. package/codex-lens/src/codexlens/config.py +3 -0
  24. package/codex-lens/src/codexlens/search/__pycache__/chain_search.cpython-313.pyc +0 -0
  25. package/codex-lens/src/codexlens/search/__pycache__/hybrid_search.cpython-313.pyc +0 -0
  26. package/codex-lens/src/codexlens/search/__pycache__/ranking.cpython-313.pyc +0 -0
  27. package/codex-lens/src/codexlens/search/chain_search.py +71 -1
  28. package/codex-lens/src/codexlens/search/ranking.py +274 -274
  29. package/codex-lens/src/codexlens/semantic/__pycache__/chunker.cpython-313.pyc +0 -0
  30. package/codex-lens/src/codexlens/storage/__pycache__/dir_index.cpython-313.pyc +0 -0
  31. package/codex-lens/src/codexlens/storage/__pycache__/global_index.cpython-313.pyc +0 -0
  32. package/codex-lens/src/codexlens/storage/__pycache__/index_tree.cpython-313.pyc +0 -0
  33. package/codex-lens/src/codexlens/storage/dir_index.py +1888 -1850
  34. package/codex-lens/src/codexlens/storage/global_index.py +365 -0
  35. package/codex-lens/src/codexlens/storage/index_tree.py +83 -10
  36. package/package.json +1 -1
@@ -1,516 +1,515 @@
1
- # Intelligent Tools Selection Strategy
2
-
3
- ## Table of Contents
4
- 1. [Quick Reference](#quick-reference)
5
- 2. [Tool Specifications](#tool-specifications)
6
- 3. [Prompt Template](#prompt-template)
7
- 4. [CLI Execution](#cli-execution)
8
- 5. [Configuration](#configuration)
9
- 6. [Best Practices](#best-practices)
10
-
11
- ---
12
-
13
- ## Quick Reference
14
-
15
- ## Quick Decision Tree
16
-
17
- ```
18
- ┌─ Task Analysis/Documentation?
19
- │ └─→ Use Gemini (Fallback: Codex,Qwen)
20
- │ └─→ MODE: analysis (read-only)
21
-
22
- └─ Task Implementation/Bug Fix?
23
- └─→ Use Codex (Fallback: Gemini,Qwen)
24
- └─→ MODE: write (file operations)
25
- ```
26
-
27
-
28
- ### Universal Prompt Template
29
-
30
- ```
31
- PURPOSE: [what] + [why] + [success criteria] + [constraints/scope]
32
- TASK: • [step 1: specific action] • [step 2: specific action] • [step 3: specific action]
33
- MODE: [analysis|write]
34
- CONTEXT: @[file patterns] | Memory: [session/tech/module context]
35
- EXPECTED: [deliverable format] + [quality criteria] + [structure requirements]
36
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/[mode]-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/[category]/[template].txt) | [domain constraints]
37
- ```
38
-
39
- ### Intent Capture Checklist (Before CLI Execution)
40
-
41
- **⚠️ CRITICAL**: Before executing any CLI command, verify these intent dimensions:
42
- **Intent Validation Questions**:
43
- - [ ] Is the objective specific and measurable?
44
- - [ ] Are success criteria defined?
45
- - [ ] Is the scope clearly bounded?
46
- - [ ] Are constraints and limitations stated?
47
- - [ ] Is the expected output format clear?
48
- - [ ] Is the action level (read/write) explicit?
49
-
50
- ## Tool Selection Matrix
51
-
52
- - **Read/Analyze**
53
- - Tool: Gemini/Qwen
54
- - MODE: `analysis`
55
- - When to Use: Code review, architecture analysis, pattern discovery, exploration
56
-
57
- - **Write/Implement**
58
- - Tool: Codex (Fallback: Gemini/Qwen)
59
- - MODE: `write`
60
- - When to Use: Feature implementation, bug fixes, test creation, refactoring, documentation generation, file creation
61
-
62
- ## Essential Command Structure
63
-
64
- ```bash
65
- ccw cli -p "<PROMPT>" --tool <gemini|qwen|codex> --mode <analysis|write>
66
- ```
67
-
68
- **⚠️ CRITICAL**: `--mode` parameter is **MANDATORY** for all CLI executions. No defaults are assumed.
69
-
70
- ### Core Principles
71
-
72
- - **Use tools early and often** - Tools are faster and more thorough
73
- - **Unified CLI** - Always use `ccw cli -p` for consistent parameter handling
74
- - **Mode is MANDATORY** - ALWAYS explicitly specify `--mode analysis|write` (no implicit defaults)
75
- - **One template required** - ALWAYS reference exactly ONE template in RULES (use universal fallback if no specific match)
76
- - **Write protection** - Require EXPLICIT `--mode write` for file operations
77
- - **Use double quotes for shell expansion** - Always wrap prompts in double quotes `"..."` to enable `$(cat ...)` command substitution; NEVER use single quotes or escape characters (`\$`, `\"`, `\'`)
78
-
79
- ---
80
-
81
- ## Tool Specifications
82
-
83
- ### MODE Options
84
-
85
- - **`analysis`**
86
- - Permission: Read-only
87
- - Use For: Code review, architecture analysis, pattern discovery, exploration
88
- - Specification: Safe for all tools (Gemini/Qwen/Codex)
89
-
90
- - **`write`**
91
- - Permission: Create/Modify/Delete
92
- - Use For: Feature implementation, bug fixes, documentation, code creation, file modifications
93
- - Specification: Requires explicit `--mode write`
94
-
95
- ### Mode Protocol References (MANDATORY)
96
-
97
- **⚠️ REQUIRED**: Every CLI execution MUST include the corresponding mode protocol in RULES:
98
-
99
- #### Mode Rule= Templates
100
-
101
- **Purpose**: Mode protocols define permission boundaries and operational constraints for each execution mode.
102
-
103
- **Protocol Mapping**:
104
-
105
- - **`analysis`** mode
106
- - Protocol: `$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md)`
107
- - Permission: Read-only operations
108
- - Enforces: No file creation/modification/deletion
109
-
110
- - **`write`** mode
111
- - Protocol: `$(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md)`
112
- - Permission: Create/Modify/Delete files
113
- - Enforces: Explicit write authorization and full workflow execution capability
114
-
115
- **RULES Format** (protocol MUST be included):
116
- ```bash
117
- # Analysis mode - MUST include analysis-protocol.md
118
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/...) | constraints
119
-
120
- # Write mode - MUST include write-protocol.md
121
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/...) | constraints
122
- ```
123
-
124
- **Validation**: CLI execution without mode protocol reference is INVALID
125
-
126
- **Why Mode Rules Are Required**:
127
- - Ensures consistent permission enforcement across all tools (Gemini/Qwen/Codex)
128
- - Prevents accidental file modifications during analysis tasks
129
- - Provides explicit authorization trail for write operations
130
- - Enables safe automation with clear boundaries
131
-
132
- ### Gemini & Qwen
133
-
134
- **Via CCW**: `ccw cli -p "<prompt>" --tool gemini --mode analysis` or `--tool qwen --mode analysis`
135
-
136
- **Characteristics**:
137
- - Large context window, pattern recognition
138
- - Best for: Analysis, documentation, code exploration, architecture review
139
- - Recommended MODE: `analysis` (read-only) for analysis tasks, `write` for file creation
140
- - Priority: Prefer Gemini; use Qwen as fallback
141
-
142
-
143
-
144
- **Error Handling**: HTTP 429 may show error but still return results - check if results exist
145
-
146
- ### Codex
147
-
148
- **Via CCW**: `ccw cli -p "<prompt>" --tool codex --mode write`
149
-
150
- **Characteristics**:
151
- - Autonomous development, mathematical reasoning
152
- - Best for: Implementation, testing, automation, bug fixes
153
- - No default MODE - must explicitly specify `--mode analysis` or `--mode write`
154
-
155
-
156
- ### Session Resume
157
-
158
- **When to Use**:
159
- - Multi-round planning (analysis → planning → implementation)
160
- - Multi-model collaboration (Gemini → Codex on same topic)
161
- - Topic continuity (building on previous findings)
162
-
163
- **Usage**:
164
-
165
- ```bash
166
- ccw cli -p "Continue analyzing" --tool gemini --mode analysis --resume # Resume last
167
- ccw cli -p "Fix issues found" --tool codex --mode write --resume <id> # Resume specific
168
- ccw cli -p "Merge findings" --tool gemini --mode analysis --resume <id1>,<id2> # Merge multiple
169
- ```
170
-
171
- - **`--resume`**: Last session
172
- - **`--resume <id>`**: Specific session
173
- - **`--resume <id1>,<id2>`**: Merge sessions (comma-separated)
174
-
175
- **Context Assembly** (automatic):
176
- ```
177
- === PREVIOUS CONVERSATION ===
178
- USER PROMPT: [Previous prompt]
179
- ASSISTANT RESPONSE: [Previous output]
180
- === CONTINUATION ===
181
- [Your new prompt]
182
- ```
183
-
184
- **Tool Behavior**: Codex uses native `codex resume`; Gemini/Qwen assembles context as single prompt
185
-
186
- ---
187
-
188
- ## Prompt Template
189
-
190
- ### Template Structure
191
-
192
- Every command MUST include these fields:
193
-
194
- - **PURPOSE**
195
- - Purpose: Goal + motivation + success
196
- - Components: What + Why + Success Criteria + Constraints
197
- - Bad Example: "Analyze code"
198
- - Good Example: "Identify security vulnerabilities in auth module to pass compliance audit; success = all OWASP Top 10 addressed; scope = src/auth/** only"
199
-
200
- - **TASK**
201
- - Purpose: Actionable steps
202
- - Components: Specific verbs + targets
203
- - Bad Example: "• Review codeFind issues"
204
- - Good Example: "• Scan for SQL injection in query builders • Check XSS in template rendering • Verify CSRF token validation"
205
-
206
- - **MODE**
207
- - Purpose: Permission level
208
- - Components: analysis / write / auto
209
- - Bad Example: (missing)
210
- - Good Example: "analysis" or "write"
211
-
212
- - **CONTEXT**
213
- - Purpose: File scope + history
214
- - Components: File patterns + Memory
215
- - Bad Example: "@**/*"
216
- - Good Example: "@src/auth/**/*.ts @shared/utils/security.ts \| Memory: Previous auth refactoring (WFS-001)"
217
-
218
- - **EXPECTED**
219
- - Purpose: Output specification
220
- - Components: Format + Quality + Structure
221
- - Bad Example: "Report"
222
- - Good Example: "Markdown report with: severity levels (Critical/High/Medium/Low), file:line references, remediation code snippets, priority ranking"
223
-
224
- - **RULES**
225
- - Purpose: Protocol + template + constraints
226
- - Components: $(cat protocol) + $(cat template) + domain rules
227
- - Bad Example: (missing)
228
- - Good Example: "$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt) \| Focus on authentication \| Ignore test files"
229
-
230
- ### CONTEXT Configuration
231
-
232
- **Format**: `CONTEXT: [file patterns] | Memory: [memory context]`
233
-
234
- #### File Patterns
235
-
236
- - **`@**/*`**: All files (default)
237
- - **`@src/**/*.ts`**: TypeScript in src
238
- - **`@../shared/**/*`**: Sibling directory (requires `--includeDirs`)
239
- - **`@CLAUDE.md`**: Specific file
240
-
241
- #### Memory Context
242
-
243
- Include when building on previous work:
244
-
245
- ```bash
246
- # Cross-task reference
247
- Memory: Building on auth refactoring (commit abc123), implementing refresh tokens
248
-
249
- # Cross-module integration
250
- Memory: Integration with auth module, using shared error patterns from @shared/utils/errors.ts
251
- ```
252
-
253
- **Memory Sources**:
254
- - **Related Tasks**: Previous refactoring, extensions, conflict resolution
255
- - **Tech Stack Patterns**: Framework conventions, security guidelines
256
- - **Cross-Module References**: Integration points, shared utilities, type dependencies
257
-
258
- #### Pattern Discovery Workflow
259
-
260
- For complex requirements, discover files BEFORE CLI execution:
261
-
262
- ```bash
263
- # Step 1: Discover files
264
- rg "export.*Component" --files-with-matches --type ts
265
-
266
- # Step 2: Build CONTEXT
267
- CONTEXT: @components/Auth.tsx @types/auth.d.ts | Memory: Previous type refactoring
268
-
269
- # Step 3: Execute CLI
270
- ccw cli -p "..." --tool gemini --mode analysis --cd src
271
- ```
272
-
273
- ### RULES Configuration
274
-
275
- **Format**: `RULES: $(cat ~/.claude/workflows/cli-templates/prompts/[category]/[template].txt) | [constraints]`
276
-
277
- **⚠️ MANDATORY**: Exactly ONE template reference is REQUIRED. Select from Task-Template Matrix or use universal fallback:
278
- - `universal/00-universal-rigorous-style.txt` - For precision-critical tasks (default fallback)
279
- - `universal/00-universal-creative-style.txt` - For exploratory tasks
280
-
281
- **Command Substitution Rules**:
282
- - Use `$(cat ...)` directly in **double quotes** - command substitution executes in your local shell BEFORE passing to ccw
283
- - Shell expands `$(cat ...)` into file content automatically - do NOT read template content first
284
- - NEVER use escape characters (`\$`, `\"`, `\'`) or single quotes - these prevent shell expansion
285
- - Tilde (`~`) expands correctly in prompt context
286
-
287
- **Critical**: Use double quotes `"..."` around the entire prompt to enable `$(cat ...)` expansion:
288
- ```bash
289
- # CORRECT - double quotes allow shell expansion
290
- ccw cli -p "RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ..." --tool gemini
291
-
292
- # WRONG - single quotes prevent expansion
293
- ccw cli -p 'RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ...' --tool gemini
294
-
295
- # WRONG - escaped $ prevents expansion
296
- ccw cli -p "RULES: \$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ..." --tool gemini
297
- ```
298
-
299
- ### Template System
300
-
301
- **Base Path**: `~/.claude/workflows/cli-templates/prompts/`
302
-
303
- **Naming Convention**:
304
- - `00-*` - Universal fallbacks (when no specific match)
305
- - `01-*` - Universal, high-frequency
306
- - `02-*` - Common specialized
307
- - `03-*` - Domain-specific
308
-
309
- **Universal Templates**:
310
-
311
- - **`universal/00-universal-rigorous-style.txt`**: Precision-critical, systematic methodology
312
- - **`universal/00-universal-creative-style.txt`**: Exploratory, innovative solutions
313
-
314
- **Task-Template Matrix**:
315
-
316
- **Analysis**:
317
- - Execution Tracing: `analysis/01-trace-code-execution.txt`
318
- - Bug Diagnosis: `analysis/01-diagnose-bug-root-cause.txt`
319
- - Code Patterns: `analysis/02-analyze-code-patterns.txt`
320
- - Document Analysis: `analysis/02-analyze-technical-document.txt`
321
- - Architecture Review: `analysis/02-review-architecture.txt`
322
- - Code Review: `analysis/02-review-code-quality.txt`
323
- - Performance: `analysis/03-analyze-performance.txt`
324
- - Security: `analysis/03-assess-security-risks.txt`
325
-
326
- **Planning**:
327
- - Architecture: `planning/01-plan-architecture-design.txt`
328
- - Task Breakdown: `planning/02-breakdown-task-steps.txt`
329
- - Component Design: `planning/02-design-component-spec.txt`
330
- - Migration: `planning/03-plan-migration-strategy.txt`
331
-
332
- **Development**:
333
- - Feature: `development/02-implement-feature.txt`
334
- - Refactoring: `development/02-refactor-codebase.txt`
335
- - Tests: `development/02-generate-tests.txt`
336
- - UI Component: `development/02-implement-component-ui.txt`
337
- - Debugging: `development/03-debug-runtime-issues.txt`
338
-
339
- ---
340
-
341
- ## CLI Execution
342
-
343
- ### Command Options
344
-
345
- - **`--tool <tool>`**
346
- - Description: gemini, qwen, codex
347
- - Default: gemini
348
-
349
- - **`--mode <mode>`**
350
- - Description: **REQUIRED**: analysis, write
351
- - Default: **NONE** (must specify)
352
-
353
- - **`--model <model>`**
354
- - Description: Model override
355
- - Default: auto-select
356
-
357
- - **`--cd <path>`**
358
- - Description: Working directory
359
- - Default: current
360
-
361
- - **`--includeDirs <dirs>`**
362
- - Description: Additional directories (comma-separated)
363
- - Default: none
364
-
365
- - **`--resume [id]`**
366
- - Description: Resume previous session
367
- - Default: -
368
-
369
- ### Directory Configuration
370
-
371
- #### Working Directory (`--cd`)
372
-
373
- When using `--cd`:
374
- - `@**/*` = Files within working directory tree only
375
- - CANNOT reference parent/sibling via @ alone
376
- - Must use `--includeDirs` for external directories
377
-
378
- #### Include Directories (`--includeDirs`)
379
-
380
- **TWO-STEP requirement for external files**:
381
- 1. Add `--includeDirs` parameter
382
- 2. Reference in CONTEXT with @ patterns
383
-
384
- ```bash
385
- # Single directory
386
- ccw cli -p "CONTEXT: @**/* @../shared/**/*" --tool gemini --mode analysis --cd src/auth --includeDirs ../shared
387
-
388
- # Multiple directories
389
- ccw cli -p "..." --tool gemini --mode analysis --cd src/auth --includeDirs ../shared,../types,../utils
390
- ```
391
-
392
- **Rule**: If CONTEXT contains `@../dir/**/*`, MUST include `--includeDirs ../dir`
393
-
394
- **Benefits**: Excludes unrelated directories, reduces token usage
395
-
396
- ### CCW Parameter Mapping
397
-
398
- CCW automatically maps to tool-specific syntax:
399
-
400
- - **`--cd <path>`**
401
- - Gemini/Qwen: `cd <path> &&`
402
- - Codex: `-C <path>`
403
-
404
- - **`--includeDirs <dirs>`**
405
- - Gemini/Qwen: `--include-directories`
406
- - Codex: `--add-dir` (per dir)
407
-
408
- - **`--mode analysis`**
409
- - Gemini/Qwen: (default read-only)
410
- - Codex: (default read-only)
411
-
412
- - **`--mode write`**
413
- - Gemini/Qwen: `--approval-mode yolo`
414
- - Codex: `-s danger-full-access`
415
-
416
- ### Command Examples
417
-
418
- #### Task-Type Specific Templates
419
-
420
- **Analysis Task** (Security Audit):
421
- ```bash
422
- ccw cli -p "
423
- PURPOSE: Identify OWASP Top 10 vulnerabilities in authentication module to pass security audit; success = all critical/high issues documented with remediation
424
- TASK: • Scan for injection flaws (SQL, command, LDAP) • Check authentication bypass vectors • Evaluate session management • Assess sensitive data exposure
425
- MODE: analysis
426
- CONTEXT: @src/auth/**/* @src/middleware/auth.ts | Memory: Using bcrypt for passwords, JWT for sessions
427
- EXPECTED: Security report with: severity matrix, file:line references, CVE mappings where applicable, remediation code snippets prioritized by risk
428
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt) | Focus on authentication | Ignore test files
429
- " --tool gemini --mode analysis --cd src/auth
430
- ```
431
-
432
- **Implementation Task** (New Feature):
433
- ```bash
434
- ccw cli -p "
435
- PURPOSE: Implement rate limiting for API endpoints to prevent abuse; must be configurable per-endpoint; backward compatible with existing clients
436
- TASK: • Create rate limiter middleware with sliding window • Implement per-route configuration • Add Redis backend for distributed state • Include bypass for internal services
437
- MODE: write
438
- CONTEXT: @src/middleware/**/* @src/config/**/* | Memory: Using Express.js, Redis already configured, existing middleware pattern in auth.ts
439
- EXPECTED: Production-ready code with: TypeScript types, unit tests, integration test, configuration example, migration guide
440
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/02-implement-feature.txt) | Follow existing middleware patterns | No breaking changes
441
- " --tool codex --mode write
442
- ```
443
-
444
- **Bug Fix Task**:
445
- ```bash
446
- ccw cli -p "
447
- PURPOSE: Fix memory leak in WebSocket connection handler causing server OOM after 24h; root cause must be identified before any fix
448
- TASK: • Trace connection lifecycle from open to close • Identify event listener accumulation • Check cleanup on disconnect • Verify garbage collection eligibility
449
- MODE: analysis
450
- CONTEXT: @src/websocket/**/* @src/services/connection-manager.ts | Memory: Using ws library, ~5000 concurrent connections in production
451
- EXPECTED: Root cause analysis with: memory profile, leak source (file:line), fix recommendation with code, verification steps
452
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/01-diagnose-bug-root-cause.txt) | Focus on resource cleanup
453
- " --tool gemini --mode analysis --cd src
454
- ```
455
-
456
- **Refactoring Task**:
457
- ```bash
458
- ccw cli -p "
459
- PURPOSE: Refactor payment processing to use strategy pattern for multi-gateway support; no functional changes; all existing tests must pass
460
- TASK: • Extract gateway interface from current implementation • Create strategy classes for Stripe, PayPal • Implement factory for gateway selection • Migrate existing code to use strategies
461
- MODE: write
462
- CONTEXT: @src/payments/**/* @src/types/payment.ts | Memory: Currently only Stripe, adding PayPal next sprint, must support future gateways
463
- EXPECTED: Refactored code with: strategy interface, concrete implementations, factory class, updated tests, migration checklist
464
- RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/02-refactor-codebase.txt) | Preserve all existing behavior | Tests must pass
465
- " --tool gemini --mode write
466
- ```
467
- ---
468
-
469
- ## ⚙️ Execution Configuration
470
-
471
- ### Dynamic Timeout Allocation
472
-
473
- **Minimum timeout: 5 minutes (300000ms)** - Never set below this threshold.
474
-
475
- **Timeout Ranges**:
476
- - **Simple** (analysis, search): 5-10min (300000-600000ms)
477
- - **Medium** (refactoring, documentation): 10-20min (600000-1200000ms)
478
- - **Complex** (implementation, migration): 20-60min (1200000-3600000ms)
479
- - **Heavy** (large codebase, multi-file): 60-120min (3600000-7200000ms)
480
-
481
- **Codex Multiplier**: 3x of allocated time (minimum 15min / 900000ms)
482
-
483
- **Auto-detection**: Analyze PURPOSE and TASK fields to determine timeout
484
-
485
- ### Permission Framework
486
-
487
- **Single-Use Authorization**: Each execution requires explicit user instruction. Previous authorization does NOT carry over.
488
-
489
- **Mode Hierarchy**:
490
- - `analysis`: Read-only, safe for auto-execution
491
- - `write`: Create/Modify/Delete files, full operations - requires explicit `--mode write`
492
- - **Exception**: User provides clear instructions like "modify", "create", "implement"
493
-
494
- ---
495
-
496
- ## Best Practices
497
-
498
- ### Workflow Principles
499
-
500
- - **Use CCW unified interface** for all executions
501
- - **Always include template** - Use Task-Template Matrix or universal fallback
502
- - **Be specific** - Clear PURPOSE, TASK, EXPECTED fields
503
- - **Include constraints** - File patterns, scope in RULES
504
- - **Leverage memory context** when building on previous work
505
- - **Discover patterns first** - Use rg/MCP before CLI execution
506
- - **Default to full context** - Use `@**/*` unless specific files needed
507
-
508
- ### Planning Checklist
509
-
510
- - [ ] **Purpose defined** - Clear goal and intent
511
- - [ ] **Mode selected** - `--mode analysis|write`
512
- - [ ] **Context gathered** - File references + memory (default `@**/*`)
513
- - [ ] **Directory navigation** - `--cd` and/or `--includeDirs`
514
- - [ ] **Tool selected** - `--tool gemini|qwen|codex`
515
- - [ ] **Template applied (REQUIRED)** - Use specific or universal fallback template
516
- - [ ] **Constraints specified** - Scope, requirements
1
+ # Intelligent Tools Selection Strategy
2
+
3
+ ## Table of Contents
4
+ 1. [Quick Reference](#quick-reference)
5
+ 2. [Tool Specifications](#tool-specifications)
6
+ 3. [Prompt Template](#prompt-template)
7
+ 4. [CLI Execution](#cli-execution)
8
+ 5. [Configuration](#configuration)
9
+ 6. [Best Practices](#best-practices)
10
+
11
+ ---
12
+
13
+ ## Quick Reference
14
+
15
+ ## Quick Decision Tree
16
+
17
+ ```
18
+ ┌─ Task Analysis/Documentation?
19
+ │ └─→ Use Gemini (Fallback: Codex,Qwen)
20
+ │ └─→ MODE: analysis (read-only)
21
+
22
+ └─ Task Implementation/Bug Fix?
23
+ └─→ Use Codex (Fallback: Gemini,Qwen)
24
+ └─→ MODE: write (file operations)
25
+ ```
26
+
27
+
28
+ ### Universal Prompt Template
29
+
30
+ ```
31
+ PURPOSE: [what] + [why] + [success criteria] + [constraints/scope]
32
+ TASK: • [step 1: specific action] • [step 2: specific action] • [step 3: specific action]
33
+ MODE: [analysis|write]
34
+ CONTEXT: @[file patterns] | Memory: [session/tech/module context]
35
+ EXPECTED: [deliverable format] + [quality criteria] + [structure requirements]
36
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/[mode]-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/[category]/[template].txt) | [domain constraints]
37
+ ```
38
+
39
+ ### Intent Capture Checklist (Before CLI Execution)
40
+
41
+ **⚠️ CRITICAL**: Before executing any CLI command, verify these intent dimensions:
42
+ **Intent Validation Questions**:
43
+ - [ ] Is the objective specific and measurable?
44
+ - [ ] Are success criteria defined?
45
+ - [ ] Is the scope clearly bounded?
46
+ - [ ] Are constraints and limitations stated?
47
+ - [ ] Is the expected output format clear?
48
+ - [ ] Is the action level (read/write) explicit?
49
+
50
+ ## Tool Selection Matrix
51
+
52
+ - **Read/Analyze**
53
+ - Tool: Gemini/Qwen
54
+ - MODE: `analysis`
55
+ - When to Use: Code review, architecture analysis, pattern discovery, exploration
56
+
57
+ - **Write/Implement**
58
+ - Tool: Codex (Fallback: Gemini/Qwen)
59
+ - MODE: `write`
60
+ - When to Use: Feature implementation, bug fixes, test creation, refactoring, documentation generation, file creation
61
+
62
+ ## Essential Command Structure
63
+
64
+ ```bash
65
+ ccw cli -p "<PROMPT>" --tool <gemini|qwen|codex> --mode <analysis|write>
66
+ ```
67
+
68
+ **Note**: `--mode` defaults to `analysis` if not specified. Explicitly specify `--mode write` for file operations.
69
+
70
+ ### Core Principles
71
+
72
+ - **Use tools early and often** - Tools are faster and more thorough
73
+ - **Unified CLI** - Always use `ccw cli -p` for consistent parameter handling
74
+ - **Default mode is analysis** - Omit `--mode` for read-only operations, explicitly use `--mode write` for file modifications
75
+ - **One template required** - ALWAYS reference exactly ONE template in RULES (use universal fallback if no specific match)
76
+ - **Write protection** - Require EXPLICIT `--mode write` for file operations
77
+ - **Use double quotes for shell expansion** - Always wrap prompts in double quotes `"..."` to enable `$(cat ...)` command substitution; NEVER use single quotes or escape characters (`\$`, `\"`, `\'`)
78
+
79
+ ---
80
+
81
+ ## Tool Specifications
82
+
83
+ ### MODE Options
84
+
85
+ - **`analysis`**
86
+ - Permission: Read-only
87
+ - Use For: Code review, architecture analysis, pattern discovery, exploration
88
+ - Specification: Safe for all tools (Gemini/Qwen/Codex)
89
+
90
+ - **`write`**
91
+ - Permission: Create/Modify/Delete
92
+ - Use For: Feature implementation, bug fixes, documentation, code creation, file modifications
93
+ - Specification: Requires explicit `--mode write`
94
+
95
+ ### Mode Protocol References (MANDATORY)
96
+
97
+ **⚠️ REQUIRED**: Every CLI execution MUST include the corresponding mode protocol in RULES:
98
+
99
+ #### Mode Rule= Templates
100
+
101
+ **Purpose**: Mode protocols define permission boundaries and operational constraints for each execution mode.
102
+
103
+ **Protocol Mapping**:
104
+
105
+ - **`analysis`** mode
106
+ - Protocol: `$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md)`
107
+ - Permission: Read-only operations
108
+ - Enforces: No file creation/modification/deletion
109
+
110
+ - **`write`** mode
111
+ - Protocol: `$(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md)`
112
+ - Permission: Create/Modify/Delete files
113
+ - Enforces: Explicit write authorization and full workflow execution capability
114
+
115
+ **RULES Format** (protocol MUST be included):
116
+ ```bash
117
+ # Analysis mode - MUST include analysis-protocol.md
118
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/...) | constraints
119
+
120
+ # Write mode - MUST include write-protocol.md
121
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/...) | constraints
122
+ ```
123
+
124
+ **Validation**: CLI execution without mode protocol reference is INVALID
125
+
126
+ **Why Mode Rules Are Required**:
127
+ - Ensures consistent permission enforcement across all tools (Gemini/Qwen/Codex)
128
+ - Prevents accidental file modifications during analysis tasks
129
+ - Provides explicit authorization trail for write operations
130
+ - Enables safe automation with clear boundaries
131
+
132
+ ### Gemini & Qwen
133
+
134
+ **Via CCW**: `ccw cli -p "<prompt>" --tool gemini --mode analysis` or `--tool qwen --mode analysis`
135
+
136
+ **Characteristics**:
137
+ - Large context window, pattern recognition
138
+ - Best for: Analysis, documentation, code exploration, architecture review
139
+ - Recommended MODE: `analysis` (read-only) for analysis tasks, `write` for file creation
140
+ - Priority: Prefer Gemini; use Qwen as fallback
141
+
142
+
143
+
144
+ **Error Handling**: HTTP 429 may show error but still return results - check if results exist
145
+
146
+ ### Codex
147
+
148
+ **Via CCW**: `ccw cli -p "<prompt>" --tool codex --mode write`
149
+
150
+ **Characteristics**:
151
+ - Autonomous development, mathematical reasoning
152
+ - Best for: Implementation, testing, automation, bug fixes
153
+ - No default MODE - must explicitly specify `--mode analysis` or `--mode write`
154
+
155
+
156
+ ### Session Resume
157
+
158
+ **When to Use**:
159
+ - Multi-round planning (analysis → planning → implementation)
160
+ - Multi-model collaboration (Gemini → Codex on same topic)
161
+ - Topic continuity (building on previous findings)
162
+
163
+ **Usage**:
164
+
165
+ ```bash
166
+ ccw cli -p "Continue analyzing" --tool gemini --mode analysis --resume # Resume last
167
+ ccw cli -p "Fix issues found" --tool codex --mode write --resume <id> # Resume specific
168
+ ccw cli -p "Merge findings" --tool gemini --mode analysis --resume <id1>,<id2> # Merge multiple
169
+ ```
170
+
171
+ - **`--resume`**: Last session
172
+ - **`--resume <id>`**: Specific session
173
+ - **`--resume <id1>,<id2>`**: Merge sessions (comma-separated)
174
+
175
+ **Context Assembly** (automatic):
176
+ ```
177
+ === PREVIOUS CONVERSATION ===
178
+ USER PROMPT: [Previous prompt]
179
+ ASSISTANT RESPONSE: [Previous output]
180
+ === CONTINUATION ===
181
+ [Your new prompt]
182
+ ```
183
+
184
+ **Tool Behavior**: Codex uses native `codex resume`; Gemini/Qwen assembles context as single prompt
185
+
186
+
187
+ ## Prompt Template
188
+
189
+ ### Template Structure
190
+
191
+ Every command MUST include these fields:
192
+
193
+ - **PURPOSE**
194
+ - Purpose: Goal + motivation + success
195
+ - Components: What + Why + Success Criteria + Constraints
196
+ - Bad Example: "Analyze code"
197
+ - Good Example: "Identify security vulnerabilities in auth module to pass compliance audit; success = all OWASP Top 10 addressed; scope = src/auth/** only"
198
+
199
+ - **TASK**
200
+ - Purpose: Actionable steps
201
+ - Components: Specific verbs + targets
202
+ - Bad Example: "• Review code • Find issues"
203
+ - Good Example: "• Scan for SQL injection in query builders Check XSS in template rendering • Verify CSRF token validation"
204
+
205
+ - **MODE**
206
+ - Purpose: Permission level
207
+ - Components: analysis / write / auto
208
+ - Bad Example: (missing)
209
+ - Good Example: "analysis" or "write"
210
+
211
+ - **CONTEXT**
212
+ - Purpose: File scope + history
213
+ - Components: File patterns + Memory
214
+ - Bad Example: "@**/*"
215
+ - Good Example: "@src/auth/**/*.ts @shared/utils/security.ts \| Memory: Previous auth refactoring (WFS-001)"
216
+
217
+ - **EXPECTED**
218
+ - Purpose: Output specification
219
+ - Components: Format + Quality + Structure
220
+ - Bad Example: "Report"
221
+ - Good Example: "Markdown report with: severity levels (Critical/High/Medium/Low), file:line references, remediation code snippets, priority ranking"
222
+
223
+ - **RULES**
224
+ - Purpose: Protocol + template + constraints
225
+ - Components: $(cat protocol) + $(cat template) + domain rules
226
+ - Bad Example: (missing)
227
+ - Good Example: "$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt) \| Focus on authentication \| Ignore test files"
228
+
229
+ ### CONTEXT Configuration
230
+
231
+ **Format**: `CONTEXT: [file patterns] | Memory: [memory context]`
232
+
233
+ #### File Patterns
234
+
235
+ - **`@**/*`**: All files (default)
236
+ - **`@src/**/*.ts`**: TypeScript in src
237
+ - **`@../shared/**/*`**: Sibling directory (requires `--includeDirs`)
238
+ - **`@CLAUDE.md`**: Specific file
239
+
240
+ #### Memory Context
241
+
242
+ Include when building on previous work:
243
+
244
+ ```bash
245
+ # Cross-task reference
246
+ Memory: Building on auth refactoring (commit abc123), implementing refresh tokens
247
+
248
+ # Cross-module integration
249
+ Memory: Integration with auth module, using shared error patterns from @shared/utils/errors.ts
250
+ ```
251
+
252
+ **Memory Sources**:
253
+ - **Related Tasks**: Previous refactoring, extensions, conflict resolution
254
+ - **Tech Stack Patterns**: Framework conventions, security guidelines
255
+ - **Cross-Module References**: Integration points, shared utilities, type dependencies
256
+
257
+ #### Pattern Discovery Workflow
258
+
259
+ For complex requirements, discover files BEFORE CLI execution:
260
+
261
+ ```bash
262
+ # Step 1: Discover files
263
+ rg "export.*Component" --files-with-matches --type ts
264
+
265
+ # Step 2: Build CONTEXT
266
+ CONTEXT: @components/Auth.tsx @types/auth.d.ts | Memory: Previous type refactoring
267
+
268
+ # Step 3: Execute CLI
269
+ ccw cli -p "..." --tool gemini --mode analysis --cd src
270
+ ```
271
+
272
+ ### RULES Configuration
273
+
274
+ **Format**: `RULES: $(cat ~/.claude/workflows/cli-templates/prompts/[category]/[template].txt) | [constraints]`
275
+
276
+ **⚠️ MANDATORY**: Exactly ONE template reference is REQUIRED. Select from Task-Template Matrix or use universal fallback:
277
+ - `universal/00-universal-rigorous-style.txt` - For precision-critical tasks (default fallback)
278
+ - `universal/00-universal-creative-style.txt` - For exploratory tasks
279
+
280
+ **Command Substitution Rules**:
281
+ - Use `$(cat ...)` directly in **double quotes** - command substitution executes in your local shell BEFORE passing to ccw
282
+ - Shell expands `$(cat ...)` into file content automatically - do NOT read template content first
283
+ - NEVER use escape characters (`\$`, `\"`, `\'`) or single quotes - these prevent shell expansion
284
+ - Tilde (`~`) expands correctly in prompt context
285
+
286
+ **Critical**: Use double quotes `"..."` around the entire prompt to enable `$(cat ...)` expansion:
287
+ ```bash
288
+ # ✓ CORRECT - double quotes allow shell expansion
289
+ ccw cli -p "RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ..." --tool gemini
290
+
291
+ # ✗ WRONG - single quotes prevent expansion
292
+ ccw cli -p 'RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ...' --tool gemini
293
+
294
+ # ✗ WRONG - escaped $ prevents expansion
295
+ ccw cli -p "RULES: \$(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) ..." --tool gemini
296
+ ```
297
+
298
+ ### Template System
299
+
300
+ **Base Path**: `~/.claude/workflows/cli-templates/prompts/`
301
+
302
+ **Naming Convention**:
303
+ - `00-*` - Universal fallbacks (when no specific match)
304
+ - `01-*` - Universal, high-frequency
305
+ - `02-*` - Common specialized
306
+ - `03-*` - Domain-specific
307
+
308
+ **Universal Templates**:
309
+
310
+ - **`universal/00-universal-rigorous-style.txt`**: Precision-critical, systematic methodology
311
+ - **`universal/00-universal-creative-style.txt`**: Exploratory, innovative solutions
312
+
313
+ **Task-Template Matrix**:
314
+
315
+ **Analysis**:
316
+ - Execution Tracing: `analysis/01-trace-code-execution.txt`
317
+ - Bug Diagnosis: `analysis/01-diagnose-bug-root-cause.txt`
318
+ - Code Patterns: `analysis/02-analyze-code-patterns.txt`
319
+ - Document Analysis: `analysis/02-analyze-technical-document.txt`
320
+ - Architecture Review: `analysis/02-review-architecture.txt`
321
+ - Code Review: `analysis/02-review-code-quality.txt`
322
+ - Performance: `analysis/03-analyze-performance.txt`
323
+ - Security: `analysis/03-assess-security-risks.txt`
324
+
325
+ **Planning**:
326
+ - Architecture: `planning/01-plan-architecture-design.txt`
327
+ - Task Breakdown: `planning/02-breakdown-task-steps.txt`
328
+ - Component Design: `planning/02-design-component-spec.txt`
329
+ - Migration: `planning/03-plan-migration-strategy.txt`
330
+
331
+ **Development**:
332
+ - Feature: `development/02-implement-feature.txt`
333
+ - Refactoring: `development/02-refactor-codebase.txt`
334
+ - Tests: `development/02-generate-tests.txt`
335
+ - UI Component: `development/02-implement-component-ui.txt`
336
+ - Debugging: `development/03-debug-runtime-issues.txt`
337
+
338
+ ---
339
+
340
+ ## CLI Execution
341
+
342
+ ### Command Options
343
+
344
+ - **`--tool <tool>`**
345
+ - Description: gemini, qwen, codex
346
+ - Default: gemini
347
+
348
+ - **`--mode <mode>`**
349
+ - Description: **REQUIRED**: analysis, write
350
+ - Default: **NONE** (must specify)
351
+
352
+ - **`--model <model>`**
353
+ - Description: Model override
354
+ - Default: auto-select
355
+
356
+ - **`--cd <path>`**
357
+ - Description: Working directory
358
+ - Default: current
359
+
360
+ - **`--includeDirs <dirs>`**
361
+ - Description: Additional directories (comma-separated)
362
+ - Default: none
363
+
364
+ - **`--resume [id]`**
365
+ - Description: Resume previous session
366
+ - Default: -
367
+
368
+ ### Directory Configuration
369
+
370
+ #### Working Directory (`--cd`)
371
+
372
+ When using `--cd`:
373
+ - `@**/*` = Files within working directory tree only
374
+ - CANNOT reference parent/sibling via @ alone
375
+ - Must use `--includeDirs` for external directories
376
+
377
+ #### Include Directories (`--includeDirs`)
378
+
379
+ **TWO-STEP requirement for external files**:
380
+ 1. Add `--includeDirs` parameter
381
+ 2. Reference in CONTEXT with @ patterns
382
+
383
+ ```bash
384
+ # Single directory
385
+ ccw cli -p "CONTEXT: @**/* @../shared/**/*" --tool gemini --mode analysis --cd src/auth --includeDirs ../shared
386
+
387
+ # Multiple directories
388
+ ccw cli -p "..." --tool gemini --mode analysis --cd src/auth --includeDirs ../shared,../types,../utils
389
+ ```
390
+
391
+ **Rule**: If CONTEXT contains `@../dir/**/*`, MUST include `--includeDirs ../dir`
392
+
393
+ **Benefits**: Excludes unrelated directories, reduces token usage
394
+
395
+ ### CCW Parameter Mapping
396
+
397
+ CCW automatically maps to tool-specific syntax:
398
+
399
+ - **`--cd <path>`**
400
+ - Gemini/Qwen: `cd <path> &&`
401
+ - Codex: `-C <path>`
402
+
403
+ - **`--includeDirs <dirs>`**
404
+ - Gemini/Qwen: `--include-directories`
405
+ - Codex: `--add-dir` (per dir)
406
+
407
+ - **`--mode analysis`**
408
+ - Gemini/Qwen: (default read-only)
409
+ - Codex: (default read-only)
410
+
411
+ - **`--mode write`**
412
+ - Gemini/Qwen: `--approval-mode yolo`
413
+ - Codex: `-s danger-full-access`
414
+
415
+ ### Command Examples
416
+
417
+ #### Task-Type Specific Templates
418
+
419
+ **Analysis Task** (Security Audit):
420
+ ```bash
421
+ ccw cli -p "
422
+ PURPOSE: Identify OWASP Top 10 vulnerabilities in authentication module to pass security audit; success = all critical/high issues documented with remediation
423
+ TASK: Scan for injection flaws (SQL, command, LDAP) Check authentication bypass vectors Evaluate session management Assess sensitive data exposure
424
+ MODE: analysis
425
+ CONTEXT: @src/auth/**/* @src/middleware/auth.ts | Memory: Using bcrypt for passwords, JWT for sessions
426
+ EXPECTED: Security report with: severity matrix, file:line references, CVE mappings where applicable, remediation code snippets prioritized by risk
427
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/03-assess-security-risks.txt) | Focus on authentication | Ignore test files
428
+ " --tool gemini --mode analysis --cd src/auth
429
+ ```
430
+
431
+ **Implementation Task** (New Feature):
432
+ ```bash
433
+ ccw cli -p "
434
+ PURPOSE: Implement rate limiting for API endpoints to prevent abuse; must be configurable per-endpoint; backward compatible with existing clients
435
+ TASK: Create rate limiter middleware with sliding window Implement per-route configuration Add Redis backend for distributed state • Include bypass for internal services
436
+ MODE: write
437
+ CONTEXT: @src/middleware/**/* @src/config/**/* | Memory: Using Express.js, Redis already configured, existing middleware pattern in auth.ts
438
+ EXPECTED: Production-ready code with: TypeScript types, unit tests, integration test, configuration example, migration guide
439
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/02-implement-feature.txt) | Follow existing middleware patterns | No breaking changes
440
+ " --tool codex --mode write
441
+ ```
442
+
443
+ **Bug Fix Task**:
444
+ ```bash
445
+ ccw cli -p "
446
+ PURPOSE: Fix memory leak in WebSocket connection handler causing server OOM after 24h; root cause must be identified before any fix
447
+ TASK: Trace connection lifecycle from open to close Identify event listener accumulation Check cleanup on disconnect Verify garbage collection eligibility
448
+ MODE: analysis
449
+ CONTEXT: @src/websocket/**/* @src/services/connection-manager.ts | Memory: Using ws library, ~5000 concurrent connections in production
450
+ EXPECTED: Root cause analysis with: memory profile, leak source (file:line), fix recommendation with code, verification steps
451
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/analysis/01-diagnose-bug-root-cause.txt) | Focus on resource cleanup
452
+ " --tool gemini --mode analysis --cd src
453
+ ```
454
+
455
+ **Refactoring Task**:
456
+ ```bash
457
+ ccw cli -p "
458
+ PURPOSE: Refactor payment processing to use strategy pattern for multi-gateway support; no functional changes; all existing tests must pass
459
+ TASK: Extract gateway interface from current implementation • Create strategy classes for Stripe, PayPal Implement factory for gateway selection • Migrate existing code to use strategies
460
+ MODE: write
461
+ CONTEXT: @src/payments/**/* @src/types/payment.ts | Memory: Currently only Stripe, adding PayPal next sprint, must support future gateways
462
+ EXPECTED: Refactored code with: strategy interface, concrete implementations, factory class, updated tests, migration checklist
463
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/write-protocol.md) $(cat ~/.claude/workflows/cli-templates/prompts/development/02-refactor-codebase.txt) | Preserve all existing behavior | Tests must pass
464
+ " --tool gemini --mode write
465
+ ```
466
+ ---
467
+
468
+ ## ⚙️ Execution Configuration
469
+
470
+ ### Dynamic Timeout Allocation
471
+
472
+ **Minimum timeout: 5 minutes (300000ms)** - Never set below this threshold.
473
+
474
+ **Timeout Ranges**:
475
+ - **Simple** (analysis, search): 5-10min (300000-600000ms)
476
+ - **Medium** (refactoring, documentation): 10-20min (600000-1200000ms)
477
+ - **Complex** (implementation, migration): 20-60min (1200000-3600000ms)
478
+ - **Heavy** (large codebase, multi-file): 60-120min (3600000-7200000ms)
479
+
480
+ **Codex Multiplier**: 3x of allocated time (minimum 15min / 900000ms)
481
+
482
+ **Auto-detection**: Analyze PURPOSE and TASK fields to determine timeout
483
+
484
+ ### Permission Framework
485
+
486
+ **Single-Use Authorization**: Each execution requires explicit user instruction. Previous authorization does NOT carry over.
487
+
488
+ **Mode Hierarchy**:
489
+ - `analysis`: Read-only, safe for auto-execution
490
+ - `write`: Create/Modify/Delete files, full operations - requires explicit `--mode write`
491
+ - **Exception**: User provides clear instructions like "modify", "create", "implement"
492
+
493
+ ---
494
+
495
+ ## Best Practices
496
+
497
+ ### Workflow Principles
498
+
499
+ - **Use CCW unified interface** for all executions
500
+ - **Always include template** - Use Task-Template Matrix or universal fallback
501
+ - **Be specific** - Clear PURPOSE, TASK, EXPECTED fields
502
+ - **Include constraints** - File patterns, scope in RULES
503
+ - **Leverage memory context** when building on previous work
504
+ - **Discover patterns first** - Use rg/MCP before CLI execution
505
+ - **Default to full context** - Use `@**/*` unless specific files needed
506
+
507
+ ### Planning Checklist
508
+
509
+ - [ ] **Purpose defined** - Clear goal and intent
510
+ - [ ] **Mode selected** - `--mode analysis|write`
511
+ - [ ] **Context gathered** - File references + memory (default `@**/*`)
512
+ - [ ] **Directory navigation** - `--cd` and/or `--includeDirs`
513
+ - [ ] **Tool selected** - `--tool gemini|qwen|codex`
514
+ - [ ] **Template applied (REQUIRED)** - Use specific or universal fallback template
515
+ - [ ] **Constraints specified** - Scope, requirements