Skip to main content

scripts-add-action-policies

#!/usr/bin/env python3 """

title: "Classification of commands by behavior type" component_type: script version: "1.0.0" audience: contributor status: stable summary: "Add Action Policy sections to command files in batches. Efficiently processes multiple comman..." keywords: ['action', 'add', 'analysis', 'generation', 'git'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "add-action-policies.py" language: python executable: true usage: "python3 scripts/add-action-policies.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false

Add Action Policy sections to command files in batches. Efficiently processes multiple commands with appropriate policy templates. """

import argparse import os import sys from pathlib import Path

Classification of commands by behavior type

PROACTIVE_COMMANDS = { 'implement', 'prototype', 'action', 'component-scaffold', 'rust-scaffold', 'typescript-scaffold', 'python-scaffold', 'test-generate', 'tdd-cycle', 'refactor-clean', 'new-project', 'setup-submodule', 'batch-setup-submodules', 'create-plan', 'create-plan', 'create-plan', 'create-worktree', 'generate-project-plan', 'commit', 'commit', 'git-sync', 'describe-pr', 'describe-pr', 'pr-enhance', 'context-save', 'context-restore', 'create-handoff', 'resume-handoff', 'c4-methodology-skill', 'doc-generate', 'feature-development', 'founder-mode', 'implement-plan', 'oneshot-plan', 'oneshot', 'production-cleanup', 'ralph-impl', 'ralph-plan', 'slo-implement', 'recursive-workflow', 'linear', 'motion' }

CONSERVATIVE_COMMANDS = { 'analyze', 'research', 'strategy', 'deliberation', 'code-explain', 'complexity-gauge', 'tech-debt', 'ai-review', 'full-review', 'local-review', 'security-sast', 'security-deps', 'security-hardening', 'analyze-hooks', 'monitor-setup', 'config-validate', 'verify-submodule', 'a11y', 'agent-dispatcher', 'COMMAND-GUIDE', 'suggest-agent', 'db-performance-analyzer', 'debug', 'documentation-librarian', 'error-analysis', 'error-trace', 'incident-response', 'intent-classification-skill', 'multi-agent-research', 'optimize', 'project_explain', 'prompt-enhancement', 'research-codebase', 'research-codebase', 'research-codebase', 'ralph-research', 'smart-debug', 'smart-research', 'submodule-status', 'validate-plan', 'web-search-hooks', 'workflow_resume', 'hello', 'README', 'db-migrations', 'document', 'generate-curriculum-content', 'generate-project-plan-hooks', 'evaluate-ui', 'ui' }

def get_proactive_policy(): return """

Action Policy

<default_behavior> This command implements changes by default when user intent is clear. Proceeds with:

  • Code generation/modification
  • File creation/updates
  • Configuration changes
  • Git operations (if applicable)

Provides concise progress updates during execution. </default_behavior>

After execution, verify: - Files created/modified as intended - Code compiles/tests pass (if applicable) - Git changes committed (if applicable) - Next recommended step provided """

def get_conservative_policy(): return """

Action Policy

<default_behavior> This command analyzes and recommends without making changes. Provides:

  • Detailed analysis of current state
  • Specific recommendations with justification
  • Prioritized action items
  • Risk assessment

User decides which recommendations to implement. </default_behavior>

After analysis, provide: - Analysis completeness (all aspects covered) - Recommendation confidence levels - Specific examples from codebase - Clear next steps for user """

def has_action_policy(filepath): """Check if file already has Action Policy section.""" with open(filepath, 'r', encoding='utf-8') as f: content = f.read() return '## Action Policy' in content

def add_action_policy(filepath, command_name): """Add appropriate Action Policy to command file.""" if has_action_policy(filepath): print(f" ✓ {command_name} - already has Action Policy") return False

# Determine policy type
if command_name in PROACTIVE_COMMANDS:
policy = get_proactive_policy()
policy_type = "PROACTIVE"
elif command_name in CONSERVATIVE_COMMANDS:
policy = get_conservative_policy()
policy_type = "CONSERVATIVE"
else:
print(f" ⚠ {command_name} - not classified, using CONSERVATIVE by default")
policy = get_conservative_policy()
policy_type = "CONSERVATIVE (default)"

# Read current content
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

# Append policy before the last newline
content = content.rstrip() + policy + '\n'

# Write updated content
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)

print(f" ✓ {command_name} - added {policy_type} policy")
return True

def process_batch(commands_dir, batch_name, command_files): """Process a batch of command files.""" print(f"\n{'='*60}") print(f"Processing {batch_name}") print(f"{'='*60}")

updated = 0
skipped = 0

for cmd_file in command_files:
filepath = commands_dir / cmd_file
if not filepath.exists():
print(f" ⚠ {cmd_file} - FILE NOT FOUND")
continue

command_name = cmd_file.replace('.md', '')
if add_action_policy(filepath, command_name):
updated += 1
else:
skipped += 1

print(f"\n{batch_name} Summary: {updated} updated, {skipped} skipped")
return updated, skipped

def parse_args(): """Parse command line arguments""" parser = argparse.ArgumentParser( description='Add Action Policy sections to CODITECT command files.', formatter_class=argparse.RawDescriptionHelpFormatter, epilog=''' Examples: %(prog)s # Process all batches (12-16) %(prog)s --dry-run # Show what would be changed without modifying files %(prog)s --batch 12 # Process only batch 12 %(prog)s --list-commands # List command classifications

Policy Types: PROACTIVE - Commands that implement changes by default CONSERVATIVE - Commands that analyze/recommend without making changes

Commands are classified into batches 12-16 for incremental processing. ''' ) parser.add_argument('--dry-run', action='store_true', help='Show what would be changed without modifying files') parser.add_argument('--batch', type=int, choices=[12, 13, 14, 15, 16], help='Process only a specific batch') parser.add_argument('--list-commands', action='store_true', help='List all command classifications') parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output') return parser.parse_args()

def main(): args = parse_args()

# Handle --list-commands
if args.list_commands:
print("PROACTIVE Commands (implement changes):")
for cmd in sorted(PROACTIVE_COMMANDS):
print(f" - {cmd}")
print(f"\nCONSERVATIVE Commands (analyze/recommend):")
for cmd in sorted(CONSERVATIVE_COMMANDS):
print(f" - {cmd}")
return

# Get commands directory
script_dir = Path(__file__).parent
repo_root = script_dir.parent
commands_dir = repo_root / 'commands'

if not commands_dir.exists():
print(f"Error: Commands directory not found at {commands_dir}")
sys.exit(1)

# Define batches (remaining commands after Batch 11)
batches = {
'Batch 12': [
'create-handoff.md', 'create-plan.md', 'create-plan.md',
'create-worktree.md', 'db-migrations.md', 'db-performance-analyzer.md',
'debug.md', 'deliberation.md', 'describe-pr.md', 'doc-generate.md',
'document.md', 'documentation-librarian.md', 'error-analysis.md',
'error-trace.md'
],
'Batch 13': [
'feature-development.md', 'founder-mode.md',
'full-review.md', 'generate-curriculum-content.md', 'generate-project-plan.md',
'generate-project-plan-hooks.md', 'git-sync.md', 'hello.md', 'implement.md',
'implement-plan.md', 'incident-response.md', 'intent-classification-skill.md',
'linear.md', 'local-review.md'
],
'Batch 14': [
'monitor-setup.md', 'motion.md', 'multi-agent-research.md', 'new-project.md',
'oneshot.md', 'oneshot-plan.md', 'optimize.md', 'pr-enhance.md',
'production-cleanup.md', 'project_explain.md', 'prompt-enhancement.md',
'prototype.md', 'python-scaffold.md', 'ralph-impl.md', 'ralph-plan.md'
],
'Batch 15': [
'ralph-research.md', 'README.md', 'recursive-workflow.md', 'refactor-clean.md',
'research.md', 'research-codebase.md', 'research-codebase.md',
'research-codebase.md', 'resume-handoff.md', 'rust-scaffold.md',
'security-deps.md', 'security-hardening.md', 'security-sast.md',
'setup-submodule.md', 'slo-implement.md'
],
'Batch 16': [
'smart-debug.md', 'smart-research.md', 'strategy.md', 'submodule-status.md',
'suggest-agent.md', 'tdd-cycle.md', 'tech-debt.md', 'test-generate.md',
'typescript-scaffold.md', 'ui.md', 'validate-plan.md',
'verify-submodule.md', 'web-search-hooks.md', 'workflow_resume.md'
]
}

total_updated = 0
total_skipped = 0

# Process each batch
for batch_name, command_files in batches.items():
updated, skipped = process_batch(commands_dir, batch_name, command_files)
total_updated += updated
total_skipped += skipped

# Final summary
print(f"\n{'='*60}")
print(f"FINAL SUMMARY")
print(f"{'='*60}")
print(f"Total commands updated: {total_updated}")
print(f"Total commands skipped: {total_skipped}")
print(f"Total processed: {total_updated + total_skipped}")
print()

if name == 'main': main()