PROMPT GUIDELINES FOR COMMANDS
CONTEXT
Core Function
- Goal: Encapsulate workflows → Simple
/command invocation
- Scope: Reusable templates, multi-step processes, ecosystem integration
Dependencies
- Bash (shell), YAML (frontmatter), Markdown
Threat Model
- Input → Sanitize(shell_escapes) → Validate(Safe) → Execute
- Command injection via arguments → Strip dangerous chars
- Destructive_Op → Require User_Confirm
Validation Layers (Apply in Order)
- Input: Type check, schema validate, sanitize
- Context: Verify permissions, check dependencies
- Execution: Confirm intent, check for destructiveness
- Output: Verify format, redact secrets
See Security & Validation section below for detailed implementation
SYNTAX & STRUCTURE
Basic Command Template
---
description: >-
[One-line purpose]
Scope: [areas covered]
agent: [Optional: @agent/name]
---
## USER INPUT
**Default**: [Default behavior when no arguments provided]
**Input**: $ARGUMENTS
1. Step_1: Action
2. Step_2: Verify(Result)
3. Step_3: Error_Handle → Fallback
User Input Section (MANDATORY)
All commands MUST include a User Input section:
- Default: Document behavior when no arguments provided
- Input: MUST contain
$ARGUMENTS placeholder for command parser substitution
- Do NOT reference $ARGUMENTS inline in execution steps
- To refer to user-provided data: Use natural language phrases like "the user input" or "provided context" in execution steps
- Example: "Incorporate provided context if available" (correct)
INLINE COMMAND EXECUTION
- Syntax:
!command`` for shell output in command context
- Usage: Embed context from git, environment, file operations
- Preference: Use inline execution where feasible (save tokens, direct calls)
- When to use:
- Static data retrieval (dates, branches, file existence)
- Environment variable checks
- Git status/info
- Simple conditionals returning strings
- Non-destructive commands
Error Handling (MANDATORY)
- Handle inline: All error handling within command itself
- Simple:
command 2>/dev/null || fallback (preferred, no command -v needed)
- Conditional:
command -v tool && tool command (only when pre-check needed)
- Operators:
|| for fallbacks, && for chains
- Defaults:
${VAR:-default} for missing variables
- Suppress:
2>/dev/null to hide errors
- PROHIBITED:
2>&1 redirect causes parser errors (use 2>/dev/null)
- Safe alternative for capturing both streams: Wrap in
sh -c and use 2>&1 inside: !sh -c 'command 2>&1'`
Examples
- Environment:
IS_WORK=!echo ${IS_WORK:-0}`
- Date/time:
TODAY=!date +%Y-%m-%d`
- Git status:
STATUS=!git status --porcelain || echo "clean"`
- Branch name:
BRANCH=!command -v git && git rev-parse --abbrev-ref HEAD || echo "not-in-git"`
- File checks:
EXIST=!test -f .env && echo "exists" || echo "not found"`
- Command results:
PRS=!gh pr list --state merged --json title | jq '.[] | .title' 2>/dev/null || echo "none"`
COMPLEX COMMANDS
Complex Command Wrapper
- Issue: Commands with pipes (
|), subshells (), complex conditionals, multiple redirections (2>/dev/null) may fail during interpolation
- Solution: Wrap complex commands in
sh -c '...' to ensure proper shell parsing
- ⚠️ SECURITY WARNING: NEVER include user input inside
sh -c '...' unless fully sanitised. sh -c re-enables shell parsing and command injection risks
- When to use:
- Pipes:
command1 | command2
- Subshells:
(command1 && command2) || command3
- Multiple redirections:
command 2>&1 | command
- Complex conditionals with nested operations
Complex Command Examples
# Simple command (no sh -c needed)
BRANCH=!`git rev-parse --abbrev-ref HEAD`
# Complex command with pipe and redirection (sh -c required)
RESULT=!`sh -c 'git diff --staged | grep -Ei "password|secret|key|token|api_key" 2>/dev/null || echo "safe"'`
# Complex command with subshell (sh -c required)
DEFAULT=!`sh -c 'git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed "s|^origin/||" || { git rev-parse --verify main >/dev/null 2>/dev/null && echo main; } || echo master'`
# Multiple pipes and operators (sh -c required)
DATA=!`sh -c 'cat file.json | jq -r ".items[].value" 2>/dev/null | head -5 || echo "none"'`
SECURITY & VALIDATION (MANDATORY)
- Prohibition: Hardcoded credentials == FORBIDDEN
- Input Sanitization: $ARGUMENTS → Strip dangerous chars → Validate schema
- Strip characters:
; | & $ ( ) < > backticks, newlines
- Validate against whitelist: POSIX character class
[:alnum:], [:punct:] (safe subset)
- Use safe quoting:
printf '%q' or ${VAR@Q} for shell-safe escaping
- Example:
SAFE_INPUT=$(printf '%q' "$ARGUMENTS")
- Destructive Ops:
rm, sudo, git push -f, chmod → Require User_Confirm
- Validation Pipeline:
- Parse $ARGUMENTS
- Sanitize (remove shell escapes)
- Validate schema/type
- Confirm if destructive
- Execute safely
- Error Handling: Never expose secrets in error messages
CRITICAL VARIABLE USAGE RULES
$ARGUMENTS Variable
- Purpose: Capture user input when command is invoked
- MUST Appear ONLY: In the User Input section (
**Input**: $ARGUMENTS)
- Forbidden Patterns:
- NEVER use $ARGUMENTS in ANY phase (Phase 1, 2, 3, or 4)
- NEVER assign intermediate values to $ARGUMENTS
- NEVER reference $ARGUMENTS in execution steps
- NEVER use $ARGUMENTS for conditions or validation
Referencing User Input
- To refer to user-provided data: Use natural language phrases like "the user input" or "provided context" in execution steps
- Example: "Incorporate provided context if available" (correct)
- Example: "Incorporate provided context if available" (correct)
- Example: "Use the date from user input" (correct)
- Example:
IF $ARGUMENTS.ambiguous != FALSE (WRONG - uses $ARGUMENTS)
Bash Variable Usage (TODAY, PRS, etc.)
- These ARE NOT $ARGUMENTS
- These capture command outputs for later processing
- Example:
TODAY=date +%Y-%m-%d, PRS=gh pr list ... (correct - these are command outputs)
Violation Check
- User Input section: MUST contain
**Input**: $ARGUMENTS
- All phases: MUST NOT contain $ARGUMENTS anywhere
- Execution steps: MUST reference user input naturally, not via $ARGUMENTS
COMMAND TEMPLATE
---
description: >-
[One-line purpose]
Scope: [areas covered]
---
# COMMAND_NAME
## EXECUTION PROTOCOL
### Phase 1: Clarification [MANDATORY]
- **Rule**: Multiple logic chains supported. Each on new line.
- **Logic**:
- Check overall context ambiguity
- Validate arguments provided
- Validate command dependencies
- Validate permissions
IF arguments ambiguous THEN
- List required arguments
- Wait(User_Input)
END
IF dependencies missing THEN
- List required tools/commands
- Wait(User_Input)
END
IF all validations pass
- Proceed to Phase 2
END
### Phase 2: Planning [MANDATORY]
- **Rule**: Multiple logic chains supported. Each on new line.
- **Logic**:
- Analyze command requirements
- Identify execution steps
- Map dependencies
- Assess impacts
IF impact > Low THEN
- Propose plan (Steps + Bash Commands + Impacts)
- Wait(User_Confirm)
ELSE
- Execute plan directly
END
### Phase 3: Execution [MANDATORY]
- **Rule**: Multiple logic chains supported. Each on new line.
- **Logic**:
- For each step
- Execute bash command
- Validate result
IF result fails THEN
- Identify failure point
- Apply error handling
- Retry with fallback
END
### Phase 4: Validation [MANDATORY]
- **Rule**: Multiple logic chains supported. Each on new line.
- **Logic**:
- Run final checklist
- Verify command executed successfully
- Verify output matches expected format
- Verify no side effects
IF checklist fails THEN
- Identify failed checks
- Apply corrections
- Re-run checklist
END
IF checklist passes
- Complete command execution
END
## USER INPUT [MANDATORY]
**Default**: [Default behaviour. Remove if not set]
**Input**: $ARGUMENTS
## EXECUTION STEPS [MANDATORY]
### Execution Pattern
Execute bash commands step by step
IF step fails THEN
- Identify failure point
- Apply error handling
- Retry with fallback
- Abort if cannot recover
END
### Conditional Execution
IF environment variable set THEN
- Use variable value
- Apply environment-specific logic
ELSE
- Use default value
- Apply default logic
END
### Multi-Step Execution
Execute step 1
- Validate result
- IF result invalid THEN
- Apply fix
- Re-validate
- END
Execute step 2
- Validate result
- IF result invalid THEN
- Apply fix
- Re-validate
- END
Continue until all steps complete
### Error Handling
IF command fails THEN
- Check exit code
- Display meaningful error
- Suggest resolution
- Exit with error code
END
## THREAT MODEL [OPTIONAL]
### Input Validation
Input → Sanitize() → Validate(Safe) → Execute
IF input contains shell metacharacters THEN
- Sanitize input
- Validate schema
- Reject if validation fails
END
IF path traversal detected THEN
- Reject absolute paths
- Validate against whitelist
- Error if path invalid
END
### Destructive Operations
IF destructive operation requested THEN
- Require User_Confirm
- Display operation details
- Display impact assessment
- Wait(User_Confirm)
END
IF operation is rm OR sudo OR chmod 777 THEN
- Require User_Confirm
- Display warning message
- Wait(User_Confirm)
END
## DEPENDENCIES [OPTIONAL]
### External Tools
- tool1: [version/purpose]
- tool2: [version/purpose]
### Skills
- skill(skill-id): [purpose]
### Dependency Validation
IF tool required THEN
- Check tool availability
- Validate tool version
- Error if tool not installed
END
IF skill required THEN
- Load skill(skill-id)
- Verify skill availability
- Error if skill not found
END
IF dependency missing THEN
- Error(Dependency not available)
- List missing dependency
- Abort command execution
END
## GLOSSARY [RECOMMENDED when abbreviations exist]
**TERM1**: [Definition]
**TERM2**: [Definition]
1---2name: prompt-guidelines-commands3description: Command creation guidelines for encapsulating workflows into simple command invocations. Provides command syntax, error handling patterns, security validation, and complex command handling. Includes examples for environment variables, git operations, and command chaining. Scope: command creation, command structure, error handling, security. Excludes: skill creation, agent creation (handled by component-specific skills). Triggers: command, create command, add command, new command.4---5
6# PROMPT GUIDELINES FOR COMMANDS
7
8## CONTEXT
9
10### Core Function
11- **Goal**: Encapsulate workflows → Simple `/command` invocation
12- **Scope**: Reusable templates, multi-step processes, ecosystem integration
13
14### Dependencies
15- Bash (shell), YAML (frontmatter), Markdown
16
17### Threat Model
18- Input → Sanitize(shell_escapes) → Validate(Safe) → Execute
19- Command injection via arguments → Strip dangerous chars
20- Destructive_Op → Require User_Confirm
21
22### Validation Layers (Apply in Order)
231. Input: Type check, schema validate, sanitize
242. Context: Verify permissions, check dependencies
253. Execution: Confirm intent, check for destructiveness
264. Output: Verify format, redact secrets
27
28*See Security & Validation section below for detailed implementation*
29
30## SYNTAX & STRUCTURE
31
32### Basic Command Template
33```markdown
34---
35description: >-
36 [One-line purpose]
37 Scope: [areas covered]
38 agent: [Optional: @agent/name]
39---
40
41## USER INPUT
42
43**Default**: [Default behavior when no arguments provided]
44
45**Input**: $ARGUMENTS
46
471. Step_1: Action
482. Step_2: Verify(Result)
493. Step_3: Error_Handle → Fallback
50```
51
52### User Input Section (MANDATORY)
53All commands MUST include a User Input section:
54- **Default**: Document behavior when no arguments provided
55- **Input**: MUST contain `$ARGUMENTS` placeholder for command parser substitution
56- Do NOT reference $ARGUMENTS inline in execution steps
57- **To refer to user-provided data**: Use natural language phrases like "the user input" or "provided context" in execution steps
58- **Example**: "Incorporate provided context if available" (correct)
59
60## INLINE COMMAND EXECUTION
61- **Syntax**: `!`command`` for shell output in command context
62- **Usage**: Embed context from git, environment, file operations
63- **Preference**: Use inline execution where feasible (save tokens, direct calls)
64- **When to use**:
65 - Static data retrieval (dates, branches, file existence)
66 - Environment variable checks
67 - Git status/info
68 - Simple conditionals returning strings
69 - Non-destructive commands
70
71### Error Handling (MANDATORY)
72- **Handle inline**: All error handling within command itself
73- **Simple**: `command 2>/dev/null || fallback` (preferred, no `command -v` needed)
74- **Conditional**: `command -v tool && tool command` (only when pre-check needed)
75- **Operators**: `||` for fallbacks, `&&` for chains
76- **Defaults**: `${VAR:-default}` for missing variables
77- **Suppress**: `2>/dev/null` to hide errors
78- **PROHIBITED**: `2>&1` redirect causes parser errors (use `2>/dev/null`)
79- **Safe alternative for capturing both streams**: Wrap in `sh -c` and use `2>&1` inside: `!`sh -c 'command 2>&1'`
80
81### Examples
82- Environment: `IS_WORK=!`echo ${IS_WORK:-0}`
83- Date/time: `TODAY=!`date +%Y-%m-%d`
84- Git status: `STATUS=!`git status --porcelain || echo "clean"`
85- Branch name: `BRANCH=!`command -v git && git rev-parse --abbrev-ref HEAD || echo "not-in-git"`
86- File checks: `EXIST=!`test -f .env && echo "exists" || echo "not found"`
87- Command results: `PRS=!`gh pr list --state merged --json title | jq '.[] | .title' 2>/dev/null || echo "none"`
88
89## COMPLEX COMMANDS
90
91### Complex Command Wrapper
92- **Issue**: Commands with pipes (`|`), subshells `()`, complex conditionals, multiple redirections (`2>/dev/null`) may fail during interpolation
93- **Solution**: Wrap complex commands in `sh -c '...'` to ensure proper shell parsing
94- **⚠️ SECURITY WARNING**: NEVER include user input inside `sh -c '...'` unless fully sanitised. `sh -c` re-enables shell parsing and command injection risks
95- **When to use**:
96 - Pipes: `command1 | command2`
97 - Subshells: `(command1 && command2) || command3`
98 - Multiple redirections: `command 2>&1 | command`
99 - Complex conditionals with nested operations
100
101### Complex Command Examples
102```markdown
103# Simple command (no sh -c needed)
104BRANCH=!`git rev-parse --abbrev-ref HEAD`
105
106# Complex command with pipe and redirection (sh -c required)
107RESULT=!`sh -c 'git diff --staged | grep -Ei "password|secret|key|token|api_key" 2>/dev/null || echo "safe"'`
108
109# Complex command with subshell (sh -c required)
110DEFAULT=!`sh -c 'git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed "s|^origin/||" || { git rev-parse --verify main >/dev/null 2>/dev/null && echo main; } || echo master'`
111
112# Multiple pipes and operators (sh -c required)
113DATA=!`sh -c 'cat file.json | jq -r ".items[].value" 2>/dev/null | head -5 || echo "none"'`
114```
115
116## SECURITY & VALIDATION (MANDATORY)
117- **Prohibition**: Hardcoded credentials == FORBIDDEN
118- **Input Sanitization**: $ARGUMENTS → Strip dangerous chars → Validate schema
119 - **Strip characters**: `; | & $ ( ) < >` backticks, newlines
120 - **Validate against whitelist**: POSIX character class `[:alnum:]`, `[:punct:]` (safe subset)
121 - **Use safe quoting**: `printf '%q'` or `${VAR@Q}` for shell-safe escaping
122 - **Example**: `SAFE_INPUT=$(printf '%q' "$ARGUMENTS")`
123- **Destructive Ops**: `rm`, `sudo`, `git push -f`, `chmod` → Require `User_Confirm`
124- **Validation Pipeline**:
125 1. Parse $ARGUMENTS
126 2. Sanitize (remove shell escapes)
127 3. Validate schema/type
128 4. Confirm if destructive
129 5. Execute safely
130- **Error Handling**: Never expose secrets in error messages
131
132## CRITICAL VARIABLE USAGE RULES
133
134### $ARGUMENTS Variable
135- **Purpose**: Capture user input when command is invoked
136- **MUST Appear ONLY**: In the User Input section (`**Input**: $ARGUMENTS`)
137- **Forbidden Patterns**:
138 - NEVER use $ARGUMENTS in ANY phase (Phase 1, 2, 3, or 4)
139 - NEVER assign intermediate values to $ARGUMENTS
140 - NEVER reference $ARGUMENTS in execution steps
141 - NEVER use $ARGUMENTS for conditions or validation
142
143### Referencing User Input
144- **To refer to user-provided data**: Use natural language phrases like "the user input" or "provided context" in execution steps
145- **Example**: "Incorporate provided context if available" (correct)
146- Example: "Incorporate provided context if available" (correct)
147- Example: "Use the date from user input" (correct)
148- Example: `IF $ARGUMENTS.ambiguous != FALSE` (WRONG - uses $ARGUMENTS)
149
150### Bash Variable Usage (TODAY, PRS, etc.)
151- These ARE NOT $ARGUMENTS
152- These capture command outputs for later processing
153- Example: `TODAY=date +%Y-%m-%d`, `PRS=gh pr list ...` (correct - these are command outputs)
154
155### Violation Check
156- User Input section: MUST contain `**Input**: $ARGUMENTS`
157- All phases: MUST NOT contain $ARGUMENTS anywhere
158- Execution steps: MUST reference user input naturally, not via $ARGUMENTS
159
160## COMMAND TEMPLATE
161
162```markdown
163---
164description: >-
165 [One-line purpose]
166 Scope: [areas covered]
167---
168
169# COMMAND_NAME
170
171## EXECUTION PROTOCOL
172
173### Phase 1: Clarification [MANDATORY]
174- **Rule**: Multiple logic chains supported. Each on new line.
175- **Logic**:
176 - Check overall context ambiguity
177 - Validate arguments provided
178 - Validate command dependencies
179 - Validate permissions
180
181IF arguments ambiguous THEN
182 - List required arguments
183 - Wait(User_Input)
184END
185
186IF dependencies missing THEN
187 - List required tools/commands
188 - Wait(User_Input)
189END
190
191IF all validations pass
192 - Proceed to Phase 2
193END
194
195### Phase 2: Planning [MANDATORY]
196- **Rule**: Multiple logic chains supported. Each on new line.
197- **Logic**:
198 - Analyze command requirements
199 - Identify execution steps
200 - Map dependencies
201 - Assess impacts
202
203IF impact > Low THEN
204 - Propose plan (Steps + Bash Commands + Impacts)
205 - Wait(User_Confirm)
206ELSE
207 - Execute plan directly
208END
209
210### Phase 3: Execution [MANDATORY]
211- **Rule**: Multiple logic chains supported. Each on new line.
212- **Logic**:
213 - For each step
214 - Execute bash command
215 - Validate result
216
217 IF result fails THEN
218 - Identify failure point
219 - Apply error handling
220 - Retry with fallback
221 END
222
223### Phase 4: Validation [MANDATORY]
224- **Rule**: Multiple logic chains supported. Each on new line.
225- **Logic**:
226 - Run final checklist
227 - Verify command executed successfully
228 - Verify output matches expected format
229 - Verify no side effects
230
231IF checklist fails THEN
232 - Identify failed checks
233 - Apply corrections
234 - Re-run checklist
235END
236
237IF checklist passes
238 - Complete command execution
239END
240
241## USER INPUT [MANDATORY]
242
243**Default**: [Default behaviour. Remove if not set]
244**Input**: $ARGUMENTS
245
246## EXECUTION STEPS [MANDATORY]
247
248### Execution Pattern
249Execute bash commands step by step
250
251IF step fails THEN
252 - Identify failure point
253 - Apply error handling
254 - Retry with fallback
255 - Abort if cannot recover
256END
257
258### Conditional Execution
259
260IF environment variable set THEN
261 - Use variable value
262 - Apply environment-specific logic
263ELSE
264 - Use default value
265 - Apply default logic
266END
267
268### Multi-Step Execution
269
270Execute step 1
271 - Validate result
272 - IF result invalid THEN
273 - Apply fix
274 - Re-validate
275 - END
276
277Execute step 2
278 - Validate result
279 - IF result invalid THEN
280 - Apply fix
281 - Re-validate
282 - END
283
284Continue until all steps complete
285
286### Error Handling
287
288IF command fails THEN
289 - Check exit code
290 - Display meaningful error
291 - Suggest resolution
292 - Exit with error code
293END
294
295## THREAT MODEL [OPTIONAL]
296
297### Input Validation
298Input → Sanitize() → Validate(Safe) → Execute
299
300IF input contains shell metacharacters THEN
301 - Sanitize input
302 - Validate schema
303 - Reject if validation fails
304END
305
306IF path traversal detected THEN
307 - Reject absolute paths
308 - Validate against whitelist
309 - Error if path invalid
310END
311
312### Destructive Operations
313
314IF destructive operation requested THEN
315 - Require User_Confirm
316 - Display operation details
317 - Display impact assessment
318 - Wait(User_Confirm)
319END
320
321IF operation is rm OR sudo OR chmod 777 THEN
322 - Require User_Confirm
323 - Display warning message
324 - Wait(User_Confirm)
325END
326
327## DEPENDENCIES [OPTIONAL]
328
329### External Tools
330- tool1: [version/purpose]
331- tool2: [version/purpose]
332
333### Skills
334- skill(skill-id): [purpose]
335
336### Dependency Validation
337
338IF tool required THEN
339 - Check tool availability
340 - Validate tool version
341 - Error if tool not installed
342END
343
344IF skill required THEN
345 - Load skill(skill-id)
346 - Verify skill availability
347 - Error if skill not found
348END
349
350IF dependency missing THEN
351 - Error(Dependency not available)
352 - List missing dependency
353 - Abort command execution
354END
355
356## GLOSSARY [RECOMMENDED when abbreviations exist]
357
358**TERM1**: [Definition]
359**TERM2**: [Definition]
360```