#!/usr/bin/env node
// Add more ECC prompt templates for pi
"use strict";
var fs = require('fs');
var path = require('path');

var PROMPTS_DIR = path.resolve(process.env.HOME, '.pi/agent/prompts');

var MORE_TEMPLATES = {
  'ecc-refactor-clean': {
    description: 'ECC Refactor Clean - 清理无效代码、简化冗余逻辑',
    'argument-hint': '[目标目录/文件]',
    body: '# Refactor & Clean\n\nIdentify and remove dead code, simplify complex logic, and improve code quality.\n\n## Process\n1. **Scan** - Find unused exports, dead code paths, redundant abstractions\n2. **Analyze** - Verify removal won\'t break anything\n3. **Clean** - Remove dead code, simplify logic\n4. **Verify** - Tests still pass, build still succeeds\n\nTarget: $@'
  },
  'ecc-quality-gate': {
    description: 'ECC Quality Gate - 质量门禁：测试/构建/类型/安全检查',
    'argument-hint': '[路径]',
    body: '# Quality Gate\n\nRun comprehensive quality checks before merging.\n\n## Gates\n1. **Test** - All tests pass (80%+ coverage)\n2. **Build** - Build succeeds\n3. **Type** - Type checking passes\n4. **Lint** - Linting clean\n5. **Security** - No vulnerabilities\n6. **Review** - Code reviewed\n\nPath: $@'
  },
  'ecc-go-review': {
    description: 'ECC Go Review - Go 代码审查 (并发、内存安全、惯用写法)',
    'argument-hint': '[Go 文件/包路径]',
    body: '# Go Code Review\n\nReview Go code for correctness, concurrency safety, and idiomatic Go.\n\n## Focus Areas\n1. **Concurrency** - Goroutine leaks, race conditions, channel patterns\n2. **Error Handling** - Errors checked, properly wrapped\n3. **Performance** - Allocation patterns, interface boxing\n4. **Idiomatic Go** - naming, formatting, conventions\n5. **Testing** - Table-driven tests, coverage\n\nPackage: $@'
  },
  'ecc-python-review': {
    description: 'ECC Python Review - Python 代码审查 (PEP 8、类型提示、安全)',
    'argument-hint': '[Python 文件/包路径]',
    body: '# Python Code Review\n\nReview Python code for PEP 8 compliance, type safety, and security.\n\n## Focus Areas\n1. **PEP 8** - Style, naming, imports ordering\n2. **Type Hints** - Proper typing, Optional vs None\n3. **Performance** - List comprehensions, generators, avoid anti-patterns\n4. **Security** - Injection, eval, unsafe deserialization\n5. **Testing** - pytest patterns, fixtures, mocks\n\nModule: $@'
  }
};

console.log('Adding more ECC prompt templates...\n');
var added = 0;
Object.keys(MORE_TEMPLATES).forEach(function(name) {
  var config = MORE_TEMPLATES[name];
  var filePath = path.join(PROMPTS_DIR, name + '.md');
  
  if (fs.existsSync(filePath)) {
    console.log('  [SKIP] ' + name + ' - already exists');
    return;
  }
  
  var fm = '---\ndescription: ' + config.description + '\n';
  if (config['argument-hint']) {
    fm += 'argument-hint: ' + config['argument-hint'] + '\n';
  }
  fm += '---\n\n';
  
  var content = fm + config.body + '\n';
  fs.writeFileSync(filePath, content, 'utf8');
  console.log('  [OK] ' + name);
  added++;
});

console.log('\nAdded ' + added + ' prompt templates');
console.log('Total prompt templates: ' + fs.readdirSync(PROMPTS_DIR).filter(function(f) { return f.startsWith('ecc-') && f.endsWith('.md'); }).length);
