Skip to main content

#!/usr/bin/env python3 """ Add standardized execution directive to all slash commands.

Ensures every command has explicit execution requirements so AI agents execute commands immediately when invoked, without hesitation or "no action needed" responses. """

import os import re from pathlib import Path

Standard execution directive template

EXECUTION_DIRECTIVE = """## System Prompt

⚠️ EXECUTION DIRECTIVE: When the user invokes this command, you MUST:

  1. IMMEDIATELY execute - no questions, no explanations first
  2. ALWAYS show full output from script/tool execution
  3. ALWAYS provide summary after execution completes

DO NOT:

  • Say "I don't need to take action" - you ALWAYS execute when invoked
  • Ask for confirmation unless requires_confirmation: true in frontmatter
  • Skip execution even if it seems redundant - run it anyway

The user invoking the command IS the confirmation.


"""

def has_execution_directive(content: str) -> bool: """Check if file already has execution directive.""" return "⚠️ EXECUTION DIRECTIVE:" in content or "EXECUTION DIRECTIVE:" in content

def find_system_prompt_location(content: str) -> int: """Find where to insert execution directive (after ## System Prompt header).""" # Look for ## System Prompt header match = re.search(r'^## System Prompt\s*$', content, re.MULTILINE) if match: return match.end()

# If no System Prompt section, look for first ## section after frontmatter
# Skip frontmatter (---...---)
frontmatter_end = content.find('---', 3)
if frontmatter_end == -1:
frontmatter_end = 0

# Find first ## header after frontmatter
match = re.search(r'^##\s+\w+', content[frontmatter_end:], re.MULTILINE)
if match:
# Insert before this header
return frontmatter_end + match.start()

# Fallback: insert after frontmatter
return frontmatter_end + 1

def add_execution_directive(file_path: Path) -> tuple[bool, str]: """ Add execution directive to command file.

Returns:
(modified: bool, status: str)
"""
try:
content = file_path.read_text()

# Skip if already has directive
if has_execution_directive(content):
return False, "already has directive"

# Find insertion point
insert_pos = find_system_prompt_location(content)

# Check if we found a valid location
if insert_pos <= 0:
return False, "no valid insertion point found"

# Insert directive
new_content = (
content[:insert_pos] +
"\n" + EXECUTION_DIRECTIVE +
content[insert_pos:]
)

# Write back
file_path.write_text(new_content)
return True, "directive added"

except Exception as e:
return False, f"error: {e}"

def main(): """Process all command files.""" commands_dir = Path(file).parent.parent / "commands"

if not commands_dir.exists():
print(f"❌ Commands directory not found: {commands_dir}")
return 1

# Get all .md files except COMMAND-GUIDE.md
command_files = [
f for f in commands_dir.glob("*.md")
if f.name != "COMMAND-GUIDE.md"
]

print(f"Found {len(command_files)} command files")
print("=" * 60)

stats = {
"modified": 0,
"skipped": 0,
"errors": 0
}

for file_path in sorted(command_files):
modified, status = add_execution_directive(file_path)

if modified:
stats["modified"] += 1
print(f"✅ {file_path.name:50s} - {status}")
elif "error" in status:
stats["errors"] += 1
print(f"❌ {file_path.name:50s} - {status}")
else:
stats["skipped"] += 1
# Don't print skipped files to reduce noise

print("=" * 60)
print(f"\n📊 Summary:")
print(f" Modified: {stats['modified']}")
print(f" Skipped: {stats['skipped']} (already have directive)")
print(f" Errors: {stats['errors']}")
print(f" Total: {len(command_files)}")

return 0 if stats["errors"] == 0 else 1

if name == "main": exit(main())