1+ ---
2+ description: Command execution guidelines for isolation-focused Memory Bank
3+ globs: command-execution.mdc
4+ alwaysApply: false
5+ ---
6+
7+ # COMMAND EXECUTION SYSTEM
8+
9+ > **TL;DR:** This system provides guidelines for efficient command execution, balancing clarity and token optimization through appropriate command chaining, with proper documentation of commands and results.
10+
11+ ## 🔍 COMMAND EFFICIENCY WORKFLOW
12+
13+ ```mermaid
14+ graph TD
15+ Start["Command<br>Planning"] --> Analyze["Analyze Command<br>Requirements"]
16+ Analyze --> Balance["Balance Clarity<br>vs. Efficiency"]
17+ Balance --> Complexity{"Command<br>Complexity?"}
18+
19+ Complexity -->|"Simple"| Single["Execute<br>Single Command"]
20+ Complexity -->|"Moderate"| Chain["Use Efficient<br>Command Chaining"]
21+ Complexity -->|"Complex"| Group["Group Into<br>Logical Steps"]
22+
23+ Single & Chain & Group --> Verify["Verify<br>Results"]
24+ Verify --> Document["Document<br>Command & Result"]
25+ Document --> Next["Next<br>Command"]
26+ ```
27+
28+ ## 📋 COMMAND CHAINING GUIDELINES
29+
30+ ```mermaid
31+ graph TD
32+ Command["Command<br>Execution"] --> ChainApprop{"Is Chaining<br>Appropriate?"}
33+
34+ ChainApprop -->|"Yes"| ChainTypes["Chain<br>Types"]
35+ ChainApprop -->|"No"| SingleCmd["Use Single<br>Commands"]
36+
37+ ChainTypes --> Sequential["Sequential Operations<br>cmd1 && cmd2"]
38+ ChainTypes --> Conditional["Conditional Operations<br>cmd1 || cmd2"]
39+ ChainTypes --> Piping["Piping<br>cmd1 | cmd2"]
40+ ChainTypes --> Grouping["Command Grouping<br>(cmd1; cmd2)"]
41+
42+ Sequential & Conditional & Piping & Grouping --> Doc["Document<br>Commands & Results"]
43+ ```
44+
45+ ## 🚦 DIRECTORY VERIFICATION WORKFLOW
46+
47+ ```mermaid
48+ graph TD
49+ Command["Command<br>Execution"] --> DirCheck["Check Current<br>Directory"]
50+ DirCheck --> ProjectRoot{"In Project<br>Root?"}
51+
52+ ProjectRoot -->|"Yes"| Execute["Execute<br>Command"]
53+ ProjectRoot -->|"No"| Locate["Locate<br>Project Root"]
54+
55+ Locate --> Found{"Project Root<br>Found?"}
56+ Found -->|"Yes"| Navigate["Navigate to<br>Project Root"]
57+ Found -->|"No"| Error["Error: Cannot<br>Find Project Root"]
58+
59+ Navigate --> Execute
60+ Execute --> Verify["Verify<br>Results"]
61+ ```
62+
63+ ## 📋 DIRECTORY VERIFICATION CHECKLIST
64+
65+ Before executing any npm or build command:
66+
67+ | Step | Windows (PowerShell) | Unix/Linux/Mac | Purpose |
68+ |------|----------------------|----------------|---------|
69+ | **Check package.json** | `Test-Path package.json` | `ls package.json` | Verify current directory is project root |
70+ | **Check for parent directory** | `Test-Path "*/package.json"` | `find . -maxdepth 2 -name package.json` | Find potential project directories |
71+ | **Navigate to project root** | `cd [project-dir]` | `cd [project-dir]` | Move to correct directory before executing commands |
72+
73+ ## 📋 REACT-SPECIFIC COMMAND GUIDELINES
74+
75+ For React applications, follow these strict guidelines:
76+
77+ | Command | Correct Usage | Incorrect Usage | Notes |
78+ |---------|---------------|----------------|-------|
79+ | **npm start** | `cd [project-root] && npm start` | `npm start` (from parent dir) | Must execute from directory with package.json |
80+ | **npm run build** | `cd [project-root] && npm run build` | `cd [parent-dir] && npm run build` | Must execute from directory with package.json |
81+ | **npm install** | `cd [project-root] && npm install [pkg]` | `npm install [pkg]` (wrong dir) | Dependencies installed to nearest package.json |
82+ | **npm create** | `npm create vite@latest my-app -- --template react` | Manually configuring webpack | Use standard tools for project creation |
83+
84+ ## 🔄 COMMAND CHAINING PATTERNS
85+
86+ Effective command chaining patterns include:
87+
88+ | Pattern | Format | Examples | Use Case |
89+ |---------|--------|----------|----------|
90+ | **Sequential** | `cmd1 && cmd2` | `mkdir dir && cd dir` | Commands that should run in sequence, second only if first succeeds |
91+ | **Conditional** | `cmd1 || cmd2` | `test -f file.txt || touch file.txt` | Fallback commands, second only if first fails |
92+ | **Piping** | `cmd1 \| cmd2` | `grep "pattern" file.txt \| wc -l` | Pass output of first command as input to second |
93+ | **Background** | `cmd &` | `npm start &` | Run command in background |
94+ | **Grouping** | `(cmd1; cmd2)` | `(echo "Start"; npm test; echo "End")` | Group commands to run as a unit |
95+
96+ ## 📋 COMMAND DOCUMENTATION TEMPLATE
97+
98+ ```
99+ ## Command Execution: [Purpose]
100+
101+ ### Command
102+ ```
103+ [actual command or chain]
104+ ```
105+
106+ ### Result
107+ ```
108+ [command output]
109+ ```
110+
111+ ### Effect
112+ [Brief description of what changed in the system]
113+
114+ ### Next Steps
115+ [What needs to be done next]
116+ ```
117+
118+ ## 🔍 PLATFORM-SPECIFIC CONSIDERATIONS
119+
120+ ```mermaid
121+ graph TD
122+ Platform["Platform<br>Detection"] --> Windows["Windows<br>Commands"]
123+ Platform --> Unix["Unix/Linux/Mac<br>Commands"]
124+
125+ Windows --> WinAdapt["Windows Command<br>Adaptations"]
126+ Unix --> UnixAdapt["Unix Command<br>Adaptations"]
127+
128+ WinAdapt --> WinChain["Windows Chaining:<br>Commands separated by &"]
129+ UnixAdapt --> UnixChain["Unix Chaining:<br>Commands separated by ;"]
130+
131+ WinChain & UnixChain --> Execute["Execute<br>Platform-Specific<br>Commands"]
132+ ```
133+
134+ ## 📋 COMMAND EFFICIENCY EXAMPLES
135+
136+ Examples of efficient command usage:
137+
138+ | Inefficient | Efficient | Explanation |
139+ |-------------|-----------|-------------|
140+ | `mkdir dir`<br>`cd dir`<br>`npm init -y` | `mkdir dir && cd dir && npm init -y` | Combines related sequential operations |
141+ | `ls`<br>`grep "\.js$"` | `ls \| grep "\.js$"` | Pipes output of first command to second |
142+ | `test -f file.txt`<br>`if not exists, touch file.txt` | `test -f file.txt \|\| touch file.txt` | Creates file only if it doesn't exist |
143+ | `mkdir dir1`<br>`mkdir dir2`<br>`mkdir dir3` | `mkdir dir1 dir2 dir3` | Uses command's built-in multiple argument capability |
144+ | `npm install pkg1`<br>`npm install pkg2` | `npm install pkg1 pkg2` | Installs multiple packages in one command |
145+
146+ ## 📋 REACT PROJECT INITIALIZATION STANDARDS
147+
148+ Always use these standard approaches for React project creation:
149+
150+ | Approach | Command | Benefits | Avoids |
151+ |----------|---------|----------|--------|
152+ | **Create React App** | `npx create-react-app my-app` | Preconfigured webpack & babel | Manual configuration errors |
153+ | **Create React App w/TypeScript** | `npx create-react-app my-app --template typescript` | Type safety + preconfigured | Inconsistent module systems |
154+ | **Vite** | `npm create vite@latest my-app -- --template react` | Faster build times | Complex webpack setups |
155+ | **Next.js** | `npx create-next-app@latest my-app` | SSR support | Module system conflicts |
156+
157+ ## ⚠️ ERROR HANDLING WORKFLOW
158+
159+ ```mermaid
160+ sequenceDiagram
161+ participant User
162+ participant AI
163+ participant System
164+
165+ AI->>System: Execute Command
166+ System->>AI: Return Result
167+
168+ alt Success
169+ AI->>AI: Verify Expected Result
170+ AI->>User: Report Success
171+ else Error
172+ AI->>AI: Analyze Error Message
173+ AI->>AI: Identify Likely Cause
174+ AI->>User: Explain Error & Cause
175+ AI->>User: Suggest Corrective Action
176+ User->>AI: Approve Correction
177+ AI->>System: Execute Corrected Command
178+ end
179+ ```
180+
181+ ## 📋 COMMAND RESULT VERIFICATION
182+
183+ After command execution, verify:
184+
185+ ```mermaid
186+ graph TD
187+ Execute["Execute<br>Command"] --> Check{"Check<br>Result"}
188+
189+ Check -->|"Success"| Verify["Verify Expected<br>Outcome"]
190+ Check -->|"Error"| Analyze["Analyze<br>Error"]
191+
192+ Verify -->|"Expected"| Document["Document<br>Success"]
193+ Verify -->|"Unexpected"| Investigate["Investigate<br>Unexpected Result"]
194+
195+ Analyze --> Diagnose["Diagnose<br>Error Cause"]
196+ Diagnose --> Correct["Propose<br>Correction"]
197+
198+ Document & Investigate & Correct --> Next["Next Step<br>in Process"]
199+ ```
200+
201+ ## 📝 COMMAND EXECUTION CHECKLIST
202+
203+ ```
204+ ✓ COMMAND EXECUTION CHECKLIST
205+ - Command purpose clearly identified? [YES/NO]
206+ - Appropriate balance of clarity vs. efficiency? [YES/NO]
207+ - Platform-specific considerations addressed? [YES/NO]
208+ - Command documented with results? [YES/NO]
209+ - Outcome verified against expectations? [YES/NO]
210+ - Errors properly handled (if any)? [YES/NO/NA]
211+ - For npm/build commands: Executed from project root? [YES/NO/NA]
212+ - For React projects: Using standard tooling? [YES/NO/NA]
213+
214+ → If all YES: Command execution complete
215+ → If any NO: Address missing elements
216+ ```
217+
218+ ## 🚨 COMMAND EXECUTION WARNINGS
219+
220+ Avoid these common command issues:
221+
222+ ```mermaid
223+ graph TD
224+ Warning["Command<br>Warnings"] --> W1["Excessive<br>Verbosity"]
225+ Warning --> W2["Insufficient<br>Error Handling"]
226+ Warning --> W3["Unnecessary<br>Complexity"]
227+ Warning --> W4["Destructive<br>Operations Without<br>Confirmation"]
228+ Warning --> W5["Wrong Directory<br>Execution"]
229+
230+ W1 --> S1["Use flags to reduce<br>unnecessary output"]
231+ W2 --> S2["Include error handling<br>in command chains"]
232+ W3 --> S3["Prefer built-in<br>command capabilities"]
233+ W4 --> S4["Show confirmation<br>before destructive actions"]
234+ W5 --> S5["Verify directory before<br>npm/build commands"]
235+ ```
0 commit comments