import { existsSync, unlinkSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
import 'node:os';
import { CCJK_SKILLS_DIR } from './constants.mjs';
import { browserSkill } from './skill.mjs';
import { writeFileAtomic } from './fs-operations.mjs';
import { j as join } from '../shared/ccjk.bQ7Dh1g4.mjs';
import './index2.mjs';
import 'node:process';
import 'node:url';
import 'node:crypto';
import 'node:fs/promises';

const cloudSyncSkill = {
  id: "cloud-sync",
  name: {
    "en": "Cloud Sync",
    "zh-CN": "\u4E91\u540C\u6B65\u7BA1\u7406"
  },
  description: {
    "en": "Cross-device synchronization for configurations, skills, and workflows",
    "zh-CN": "\u8DE8\u8BBE\u5907\u540C\u6B65\u914D\u7F6E\u3001\u6280\u80FD\u548C\u5DE5\u4F5C\u6D41"
  },
  category: "devops",
  triggers: ["/sync", "/cloud", "/backup", "/restore"],
  enabled: true,
  version: "1.0.0",
  author: "CCJK Team",
  tags: ["cloud", "sync", "backup", "restore", "configuration"],
  template: `# Cloud Sync Management

## Overview

Cloud Sync provides seamless cross-device synchronization for your CCJK environment.
Keep your configurations, skills, and workflows in sync across all your development machines.

## Features

### Configuration Sync
- Synchronize CCJK settings across devices
- Preserve API configurations securely
- Sync MCP service configurations

### Skills Sync
- Share custom skills between machines
- Version control for skill updates
- Conflict resolution for concurrent edits

### Workflow Sync
- Sync workflow states and progress
- Share workflow templates
- Collaborative workflow management

### Conflict Resolution
- Intelligent merge for non-conflicting changes
- Manual resolution UI for conflicts
- Version history for rollback

## Commands

### Sync Status
\`\`\`bash
/sync status
\`\`\`
View current synchronization status, pending changes, and last sync time.

### Push Changes
\`\`\`bash
/sync push              # Push all pending changes
/sync push --config     # Push configuration only
/sync push --skills     # Push skills only
/sync push --workflows  # Push workflows only
\`\`\`

### Pull Changes
\`\`\`bash
/sync pull              # Pull all remote changes
/sync pull --force      # Force pull, overwrite local
/sync pull --merge      # Merge with local changes
\`\`\`

### Configure Cloud Storage
\`\`\`bash
/sync config                    # Interactive configuration
/sync config github             # Configure GitHub Gist
/sync config webdav             # Configure WebDAV
/sync config local              # Configure local folder sync
\`\`\`

### Backup Management
\`\`\`bash
/backup create                  # Create full backup
/backup create --name "v1.0"    # Create named backup
/backup list                    # List all backups
/backup restore <id>            # Restore from backup
/backup delete <id>             # Delete a backup
\`\`\`

### Conflict Management
\`\`\`bash
/sync conflicts                 # List all conflicts
/sync resolve <id> --local      # Keep local version
/sync resolve <id> --remote     # Keep remote version
/sync resolve <id> --merge      # Manual merge
\`\`\`

## Supported Cloud Storage

### GitHub Gist (Recommended)
- Free and reliable
- Version history built-in
- Easy to set up with personal access token

\`\`\`bash
/sync config github
# Enter your GitHub personal access token
# Token needs 'gist' scope
\`\`\`

### WebDAV
Compatible with:
- Nutstore (\u575A\u679C\u4E91)
- Nextcloud
- ownCloud
- Any WebDAV server

\`\`\`bash
/sync config webdav
# Enter WebDAV URL, username, and password
\`\`\`

### Local Folder
For manual sync via Dropbox, OneDrive, etc.

\`\`\`bash
/sync config local
# Enter path to sync folder
\`\`\`

## Usage Examples

### First-Time Setup
\`\`\`bash
# 1. Configure cloud storage
/sync config github

# 2. Push initial configuration
/sync push --all

# 3. Verify sync status
/sync status
\`\`\`

### Daily Workflow
\`\`\`bash
# Start of day: pull latest changes
/sync pull

# End of day: push your changes
/sync push
\`\`\`

### Handling Conflicts
\`\`\`bash
# Check for conflicts after pull
/sync conflicts

# Review and resolve each conflict
/sync resolve skill-123 --merge
\`\`\`

### Backup Before Major Changes
\`\`\`bash
# Create backup before risky operations
/backup create --name "before-upgrade"

# If something goes wrong
/backup restore before-upgrade
\`\`\`

## Security

### Sensitive Data Handling
- API keys are encrypted before sync
- OAuth tokens are never synced (re-authenticate on each device)
- Local encryption key derived from device-specific identifier

### Access Control
- GitHub: Uses personal access token with minimal scope
- WebDAV: Supports app-specific passwords
- All connections use HTTPS/TLS

## Best Practices

1. **Regular Syncing**: Sync at least daily to avoid large conflicts
2. **Named Backups**: Create named backups before major changes
3. **Review Conflicts**: Don't auto-resolve conflicts without review
4. **Secure Tokens**: Use app-specific passwords when available
5. **Test Restore**: Periodically test backup restoration

## Troubleshooting

### Sync Failed
\`\`\`bash
# Check connection
/sync status --verbose

# Force re-authentication
/sync config github --reauth
\`\`\`

### Conflicts Won't Resolve
\`\`\`bash
# Reset sync state
/sync reset

# Re-initialize from remote
/sync pull --force
\`\`\`

### Backup Corrupted
\`\`\`bash
# List all backups with integrity check
/backup list --verify

# Delete corrupted backup
/backup delete <corrupted-id>
\`\`\`
`
};

const marketplaceSkill = {
  id: "mcp-marketplace",
  name: {
    "en": "MCP Marketplace",
    "zh-CN": "MCP \u63D2\u4EF6\u5E02\u573A"
  },
  description: {
    "en": "Discover, install and manage MCP plugins",
    "zh-CN": "\u53D1\u73B0\u3001\u5B89\u88C5\u548C\u7BA1\u7406 MCP \u63D2\u4EF6"
  },
  category: "dev",
  triggers: ["/market", "/mcp", "/plugins", "/install"],
  enabled: true,
  version: "1.0.0",
  author: "CCJK Team",
  tags: ["mcp", "marketplace", "plugins", "extensions", "install"],
  template: `# MCP Marketplace Skill

## Overview

The MCP Marketplace provides a centralized hub for discovering, installing, and managing
Model Context Protocol (MCP) plugins. It integrates seamlessly with Claude Code and CCJK
to enhance your AI-assisted development workflow.

## Features

- **Browse Marketplace**: Discover trending and recommended plugins
- **Search Plugins**: Search by name, category, or tags
- **Install Management**: One-click install, update, and uninstall
- **Security Scanning**: Automatic security checks before installation
- **Dependency Resolution**: Automatic handling of plugin dependencies

## Commands

### Search Plugins
\`\`\`bash
# Search by keyword
ccjk market search <query>

# Search with filters
ccjk market search <query> --category ai-tools
ccjk market search <query> --tag productivity
\`\`\`

### Browse Marketplace
\`\`\`bash
# View trending plugins
ccjk market trending

# Browse by category
ccjk market browse --category dev-tools
ccjk market browse --category ai-tools
ccjk market browse --category data-processing
\`\`\`

### Install Plugins
\`\`\`bash
# Install a plugin
ccjk market install <plugin-id>

# Install specific version
ccjk market install <plugin-id>@1.2.0

# Install with dependencies
ccjk market install <plugin-id> --with-deps

# Force reinstall
ccjk market install <plugin-id> --force
\`\`\`

### Update Plugins
\`\`\`bash
# Update all plugins
ccjk market update

# Update specific plugin
ccjk market update <plugin-id>

# Check for updates
ccjk market check-updates
\`\`\`

### Manage Installed Plugins
\`\`\`bash
# List installed plugins
ccjk market list

# Show plugin details
ccjk market info <plugin-id>

# Uninstall plugin
ccjk market uninstall <plugin-id>

# Enable/disable plugin
ccjk market enable <plugin-id>
ccjk market disable <plugin-id>
\`\`\`

## Categories

### AI Tools
AI-enhanced functionality for code generation, analysis, and optimization.
- Code completion enhancers
- AI-powered refactoring
- Intelligent code review

### Development Tools
Tools to assist with coding and development workflows.
- Language servers
- Linters and formatters
- Build tool integrations

### Productivity Tools
Enhance your development efficiency.
- Task automation
- Snippet managers
- Documentation generators

### Data Processing
Data transformation and analysis tools.
- Data converters
- Schema validators
- API integrators

### Integrations
Third-party service integrations.
- Cloud service connectors
- Database integrations
- CI/CD tool bridges

## Security

All plugins undergo security scanning before installation:

### Security Checks
- **Permission Analysis**: Detects dangerous permission requests
- **Vulnerability Scanning**: Checks against known CVE databases
- **Code Pattern Analysis**: Identifies suspicious code patterns
- **Dependency Audit**: Scans dependencies for vulnerabilities

### Security Levels
- \`verified\` - Officially verified by CCJK team
- \`community\` - Community-reviewed plugin
- \`unverified\` - New or unreviewed plugin

### Skip Security (Not Recommended)
\`\`\`bash
ccjk market install <plugin-id> --skip-verification
\`\`\`

## Configuration

### Plugin Settings
\`\`\`bash
# Configure plugin
ccjk market config <plugin-id> --set key=value

# View plugin config
ccjk market config <plugin-id> --list

# Reset plugin config
ccjk market config <plugin-id> --reset
\`\`\`

### Global Settings
\`\`\`bash
# Set default registry
ccjk market registry set <url>

# Enable auto-updates
ccjk market settings --auto-update true

# Set security level
ccjk market settings --security-level strict
\`\`\`

## Plugin Development

### Create a Plugin
\`\`\`bash
ccjk market create <plugin-name>
\`\`\`

### Publish to Marketplace
\`\`\`bash
ccjk market publish
\`\`\`

### Plugin Manifest Example
\`\`\`json
{
  "packageId": "my-plugin",
  "name": "My Plugin",
  "version": "1.0.0",
  "description": "A useful MCP plugin",
  "author": "Your Name",
  "license": "MIT",
  "keywords": ["mcp", "plugin"],
  "mcpServer": {
    "command": "node",
    "args": ["dist/server.js"]
  }
}
\`\`\`

## Troubleshooting

### Installation Issues
\`\`\`bash
# Clear cache and retry
ccjk market cache clear
ccjk market install <plugin-id>

# Verbose installation
ccjk market install <plugin-id> --verbose
\`\`\`

### Dependency Conflicts
\`\`\`bash
# Check dependencies
ccjk market deps <plugin-id>

# Force resolve conflicts
ccjk market install <plugin-id> --force-deps
\`\`\`

### Rollback
\`\`\`bash
# Rollback to previous version
ccjk market rollback <plugin-id>

# Rollback to specific version
ccjk market rollback <plugin-id>@1.0.0
\`\`\`

## Best Practices

1. **Review Before Install**: Always check plugin ratings and reviews
2. **Keep Updated**: Regularly update plugins for security patches
3. **Minimal Plugins**: Only install plugins you actively use
4. **Backup Config**: Export your plugin configuration before major changes
5. **Report Issues**: Help improve the ecosystem by reporting bugs

## Integration with Claude Code

The marketplace integrates directly with Claude Code's MCP system:

\`\`\`bash
# Installed plugins are automatically available in Claude Code
claude --mcp-list  # Shows marketplace-installed plugins

# Plugins can be used in conversations
# Example: Using a database plugin
"Connect to my PostgreSQL database and show tables"
\`\`\`
`
};

const workflowSkill = {
  id: "workflow-automation",
  name: {
    "en": "Workflow Automation",
    "zh-CN": "\u5DE5\u4F5C\u6D41\u81EA\u52A8\u5316"
  },
  description: {
    "en": "Subagent-driven development workflow with two-stage review",
    "zh-CN": "Subagent \u9A71\u52A8\u7684\u4E24\u9636\u6BB5\u5BA1\u67E5\u5F00\u53D1\u5DE5\u4F5C\u6D41"
  },
  category: "dev",
  triggers: ["/workflow", "/wf", "/flow"],
  enabled: true,
  version: "1.0.0",
  author: "CCJK",
  tags: ["workflow", "subagent", "review", "automation", "ci"],
  template: `# Workflow Automation Skill

## Overview

This skill provides Subagent-driven development workflows with automatic two-stage review.
Inspired by Anthropic's Superpowers architecture for autonomous agent collaboration.

## Core Concepts

### Two-Stage Review
1. **Draft Stage**: Subagents work on tasks in parallel
2. **Review Stage**: Automated quality checks and validation
3. **Finalize Stage**: Merge approved changes

### Workflow States
- \`idle\` \u2192 \`planning\` \u2192 \`executing\` \u2192 \`reviewing\` \u2192 \`finalizing\` \u2192 \`completed\`

## Quick Start

### Create a Workflow
\`\`\`bash
ccjk workflow create "Implement user authentication"
\`\`\`

### Start Workflow Execution
\`\`\`bash
ccjk workflow start <workflow-id>
\`\`\`

### Check Workflow Status
\`\`\`bash
ccjk workflow status <workflow-id>
ccjk workflow list
\`\`\`

## Task Management

### Add Tasks to Workflow
\`\`\`bash
ccjk workflow task add <workflow-id> "Create login component"
ccjk workflow task add <workflow-id> "Add authentication API" --depends-on task-1
\`\`\`

### Task Priorities
\`\`\`bash
ccjk workflow task add <workflow-id> "Fix security bug" --priority critical
ccjk workflow task add <workflow-id> "Add tests" --priority high
\`\`\`

### View Task Dependencies
\`\`\`bash
ccjk workflow tasks <workflow-id> --graph
\`\`\`

## Subagent Scheduling

### Automatic Scheduling
The scheduler automatically:
- Assigns tasks to available subagents
- Respects task dependencies
- Balances workload across agents
- Handles failures with retry logic

### Manual Assignment
\`\`\`bash
ccjk workflow assign <task-id> <subagent-id>
\`\`\`

### View Subagent Status
\`\`\`bash
ccjk workflow agents
ccjk workflow agent <agent-id> --tasks
\`\`\`

## Review System

### Automatic Review
When tasks complete, the system automatically:
1. Runs requirement verification
2. Performs code quality checks
3. Validates test coverage
4. Checks for security issues

### Review Results
\`\`\`bash
ccjk workflow review <workflow-id>
ccjk workflow review <task-id> --detailed
\`\`\`

### Manual Review Override
\`\`\`bash
ccjk workflow approve <task-id>
ccjk workflow reject <task-id> --reason "Missing tests"
\`\`\`

## Quality Checks

### Built-in Checks
- **Naming Conventions**: camelCase, PascalCase validation
- **Code Structure**: Function length, nesting depth
- **Error Handling**: Try-catch coverage
- **Documentation**: JSDoc/TSDoc presence
- **Style**: Consistent formatting

### Custom Checks
\`\`\`bash
ccjk workflow check add "No console.log" --pattern "console\\.log"
ccjk workflow check add "Max file size" --max-lines 500
\`\`\`

## Workflow Templates

### Feature Development
\`\`\`bash
ccjk workflow create --template feature "Add dark mode"
\`\`\`

### Bug Fix
\`\`\`bash
ccjk workflow create --template bugfix "Fix login timeout"
\`\`\`

### Refactoring
\`\`\`bash
ccjk workflow create --template refactor "Migrate to TypeScript"
\`\`\`

## Events and Hooks

### Available Events
- \`workflow:created\`
- \`workflow:started\`
- \`task:assigned\`
- \`task:completed\`
- \`review:passed\`
- \`review:failed\`
- \`workflow:completed\`

### Add Hooks
\`\`\`bash
ccjk workflow hook add task:completed "npm test"
ccjk workflow hook add review:passed "npm run lint"
\`\`\`

## Best Practices

### 1. Break Down Large Tasks
Split complex features into smaller, independent tasks that can run in parallel.

### 2. Define Clear Dependencies
Use \`--depends-on\` to ensure tasks run in the correct order.

### 3. Set Appropriate Priorities
- \`critical\`: Security fixes, blocking issues
- \`high\`: Important features, bugs
- \`medium\`: Regular development
- \`low\`: Nice-to-have improvements

### 4. Review Before Merge
Always check review results before finalizing:
\`\`\`bash
ccjk workflow review <workflow-id> --summary
\`\`\`

### 5. Use Templates
Create custom templates for recurring workflow patterns.

## Integration with Git

### Automatic Branch Management
\`\`\`bash
ccjk workflow create "Feature X" --branch feature/x
\`\`\`

### Worktree Support
Each subagent can work in isolated git worktrees:
\`\`\`bash
ccjk workflow start <id> --worktree
\`\`\`

## Troubleshooting

### Stuck Workflow
\`\`\`bash
ccjk workflow diagnose <workflow-id>
ccjk workflow retry <task-id>
\`\`\`

### Cancel Workflow
\`\`\`bash
ccjk workflow cancel <workflow-id>
ccjk workflow cancel <workflow-id> --force
\`\`\`

### View Logs
\`\`\`bash
ccjk workflow logs <workflow-id>
ccjk workflow logs <task-id> --tail 100
\`\`\`
`
};

const BUILTIN_SKILLS = [
  cloudSyncSkill,
  browserSkill,
  marketplaceSkill,
  workflowSkill
];
let registry = null;
function ensureSkillsDir() {
  if (!existsSync(CCJK_SKILLS_DIR)) {
    mkdirSync(CCJK_SKILLS_DIR, { recursive: true });
  }
}
function getRegistry() {
  if (!registry) {
    registry = loadRegistry();
  }
  return registry;
}
function loadRegistry() {
  ensureSkillsDir();
  const skills = /* @__PURE__ */ new Map();
  const categories = /* @__PURE__ */ new Map();
  for (const skill of BUILTIN_SKILLS) {
    skills.set(skill.id, skill);
    const categorySkills = categories.get(skill.category) || [];
    categorySkills.push(skill.id);
    categories.set(skill.category, categorySkills);
  }
  const files = readdirSync(CCJK_SKILLS_DIR).filter((f) => f.endsWith(".json"));
  for (const file of files) {
    try {
      const content = readFileSync(join(CCJK_SKILLS_DIR, file), "utf-8");
      const skill = JSON.parse(content);
      skills.set(skill.id, skill);
      const categorySkills = categories.get(skill.category) || [];
      categorySkills.push(skill.id);
      categories.set(skill.category, categorySkills);
    } catch {
    }
  }
  return {
    skills,
    categories,
    lastUpdated: /* @__PURE__ */ new Date()
  };
}
function refreshRegistry() {
  registry = loadRegistry();
}
function getAllSkills() {
  return Array.from(getRegistry().skills.values());
}
function getSkill(id) {
  return getRegistry().skills.get(id);
}
function searchSkills(options) {
  let skills = getAllSkills();
  if (options.category) {
    skills = skills.filter((s) => s.category === options.category);
  }
  if (options.enabled !== void 0) {
    skills = skills.filter((s) => s.enabled === options.enabled);
  }
  if (options.tags && options.tags.length > 0) {
    skills = skills.filter(
      (s) => s.tags && options.tags.some((tag) => s.tags.includes(tag))
    );
  }
  if (options.query) {
    const query = options.query.toLowerCase();
    skills = skills.filter((s) => {
      const nameEn = typeof s.name === "string" ? s.name : s.name?.en || "";
      const nameZh = typeof s.name === "string" ? s.name : s.name?.["zh-CN"] || "";
      return s.id.toLowerCase().includes(query) || nameEn.toLowerCase().includes(query) || nameZh.toLowerCase().includes(query) || s.triggers.some((t) => t.toLowerCase().includes(query));
    });
  }
  if (options.limit) {
    skills = skills.slice(0, options.limit);
  }
  return skills;
}
function addSkill(skill) {
  ensureSkillsDir();
  try {
    const filePath = join(CCJK_SKILLS_DIR, `${skill.id}.json`);
    writeFileAtomic(filePath, JSON.stringify(skill, null, 2));
    refreshRegistry();
    return {
      skillId: skill.id,
      success: true,
      path: filePath
    };
  } catch (error) {
    return {
      skillId: skill.id,
      success: false,
      error: error instanceof Error ? error.message : "Unknown error"
    };
  }
}
function removeSkill(id) {
  const filePath = join(CCJK_SKILLS_DIR, `${id}.json`);
  if (existsSync(filePath)) {
    unlinkSync(filePath);
    refreshRegistry();
    return true;
  }
  return false;
}
function setSkillEnabled(id, enabled) {
  const skill = getSkill(id);
  if (!skill)
    return false;
  skill.enabled = enabled;
  addSkill(skill);
  return true;
}
const BATCH_TEMPLATES = {
  typescript: {
    category: "dev",
    skills: [
      {
        id: "ts-debug",
        name: { "en": "TypeScript Debug", "zh-CN": "TypeScript \u8C03\u8BD5" },
        description: { "en": "Debug TypeScript code", "zh-CN": "\u8C03\u8BD5 TypeScript \u4EE3\u7801" },
        triggers: ["/ts-debug", "/tsd"],
        templateFile: "ts-debug.md",
        tags: ["typescript", "debug"]
      },
      {
        id: "ts-refactor",
        name: { "en": "TypeScript Refactor", "zh-CN": "TypeScript \u91CD\u6784" },
        description: { "en": "Refactor TypeScript code", "zh-CN": "\u91CD\u6784 TypeScript \u4EE3\u7801" },
        triggers: ["/ts-refactor", "/tsr"],
        templateFile: "ts-refactor.md",
        tags: ["typescript", "refactor"]
      },
      {
        id: "ts-test",
        name: { "en": "TypeScript Test", "zh-CN": "TypeScript \u6D4B\u8BD5" },
        description: { "en": "Generate TypeScript tests", "zh-CN": "\u751F\u6210 TypeScript \u6D4B\u8BD5" },
        triggers: ["/ts-test", "/tst"],
        templateFile: "ts-test.md",
        tags: ["typescript", "testing"]
      },
      {
        id: "ts-type-check",
        name: { "en": "TypeScript Type Check", "zh-CN": "TypeScript \u7C7B\u578B\u68C0\u67E5" },
        description: { "en": "Fix TypeScript type errors", "zh-CN": "\u4FEE\u590D TypeScript \u7C7B\u578B\u9519\u8BEF" },
        triggers: ["/ts-type", "/tstc"],
        templateFile: "ts-type-check.md",
        tags: ["typescript", "types"]
      },
      {
        id: "ts-migrate",
        name: { "en": "TypeScript Migration", "zh-CN": "TypeScript \u8FC1\u79FB" },
        description: { "en": "Migrate JS to TypeScript", "zh-CN": "\u4ECE JS \u8FC1\u79FB\u5230 TypeScript" },
        triggers: ["/ts-migrate", "/tsm"],
        templateFile: "ts-migrate.md",
        tags: ["typescript", "migration"]
      }
    ]
  },
  python: {
    category: "dev",
    skills: [
      {
        id: "py-debug",
        name: { "en": "Python Debug", "zh-CN": "Python \u8C03\u8BD5" },
        description: { "en": "Debug Python code", "zh-CN": "\u8C03\u8BD5 Python \u4EE3\u7801" },
        triggers: ["/py-debug", "/pyd"],
        templateFile: "py-debug.md",
        tags: ["python", "debug"]
      },
      {
        id: "py-refactor",
        name: { "en": "Python Refactor", "zh-CN": "Python \u91CD\u6784" },
        description: { "en": "Refactor Python code", "zh-CN": "\u91CD\u6784 Python \u4EE3\u7801" },
        triggers: ["/py-refactor", "/pyr"],
        templateFile: "py-refactor.md",
        tags: ["python", "refactor"]
      },
      {
        id: "py-test",
        name: { "en": "Python Test", "zh-CN": "Python \u6D4B\u8BD5" },
        description: { "en": "Generate Python tests", "zh-CN": "\u751F\u6210 Python \u6D4B\u8BD5" },
        triggers: ["/py-test", "/pyt"],
        templateFile: "py-test.md",
        tags: ["python", "testing"]
      }
    ]
  },
  seo: {
    category: "seo",
    skills: [
      {
        id: "seo-meta",
        name: { "en": "SEO Meta Optimization", "zh-CN": "SEO \u5143\u6570\u636E\u4F18\u5316" },
        description: { "en": "Optimize meta tags for SEO", "zh-CN": "\u4F18\u5316 SEO \u5143\u6807\u7B7E" },
        triggers: ["/seo-meta", "/meta"],
        templateFile: "seo-meta.md",
        tags: ["seo", "meta"]
      },
      {
        id: "seo-sitemap",
        name: { "en": "Sitemap Generator", "zh-CN": "\u7AD9\u70B9\u5730\u56FE\u751F\u6210" },
        description: { "en": "Generate XML sitemap", "zh-CN": "\u751F\u6210 XML \u7AD9\u70B9\u5730\u56FE" },
        triggers: ["/sitemap", "/seo-sitemap"],
        templateFile: "seo-sitemap.md",
        tags: ["seo", "sitemap"]
      },
      {
        id: "seo-schema",
        name: { "en": "Schema Markup", "zh-CN": "\u7ED3\u6784\u5316\u6570\u636E\u6807\u8BB0" },
        description: { "en": "Add structured data markup", "zh-CN": "\u6DFB\u52A0\u7ED3\u6784\u5316\u6570\u636E\u6807\u8BB0" },
        triggers: ["/schema", "/seo-schema"],
        templateFile: "seo-schema.md",
        tags: ["seo", "schema"]
      },
      {
        id: "seo-cwv",
        name: { "en": "Core Web Vitals", "zh-CN": "\u6838\u5FC3\u7F51\u9875\u6307\u6807" },
        description: { "en": "Optimize Core Web Vitals", "zh-CN": "\u4F18\u5316\u6838\u5FC3\u7F51\u9875\u6307\u6807" },
        triggers: ["/cwv", "/seo-cwv"],
        templateFile: "seo-cwv.md",
        tags: ["seo", "performance"]
      }
    ]
  },
  devops: {
    category: "devops",
    skills: [
      {
        id: "devops-docker",
        name: { "en": "Docker Setup", "zh-CN": "Docker \u914D\u7F6E" },
        description: { "en": "Set up Docker configuration", "zh-CN": "\u914D\u7F6E Docker" },
        triggers: ["/docker", "/devops-docker"],
        templateFile: "devops-docker.md",
        tags: ["devops", "docker"]
      },
      {
        id: "devops-ci",
        name: { "en": "CI Pipeline", "zh-CN": "CI \u6D41\u6C34\u7EBF" },
        description: { "en": "Set up CI pipeline", "zh-CN": "\u914D\u7F6E CI \u6D41\u6C34\u7EBF" },
        triggers: ["/ci", "/devops-ci"],
        templateFile: "devops-ci.md",
        tags: ["devops", "ci"]
      },
      {
        id: "devops-deploy",
        name: { "en": "Deploy Script", "zh-CN": "\u90E8\u7F72\u811A\u672C" },
        description: { "en": "Create deployment script", "zh-CN": "\u521B\u5EFA\u90E8\u7F72\u811A\u672C" },
        triggers: ["/deploy", "/devops-deploy"],
        templateFile: "devops-deploy.md",
        tags: ["devops", "deploy"]
      },
      {
        id: "devops-monitor",
        name: { "en": "Monitoring Setup", "zh-CN": "\u76D1\u63A7\u914D\u7F6E" },
        description: { "en": "Set up monitoring", "zh-CN": "\u914D\u7F6E\u76D1\u63A7" },
        triggers: ["/monitor", "/devops-monitor"],
        templateFile: "devops-monitor.md",
        tags: ["devops", "monitoring"]
      }
    ]
  }
};
function createBatchSkills(options) {
  const results = [];
  const extractStr = (val, fallback) => {
    if (!val)
      return fallback;
    if (typeof val === "string")
      return val;
    return val.en || val["zh-CN"] || Object.values(val)[0] || fallback;
  };
  if (options.lang) {
    const template = BATCH_TEMPLATES[options.lang];
    if (template) {
      for (const skillDef of template.skills) {
        const nameStr = extractStr(skillDef.name, skillDef.id);
        const descStr = extractStr(skillDef.description, "");
        const skill = {
          ...skillDef,
          category: template.category,
          enabled: true,
          version: "1.0.0",
          template: `# ${nameStr}

${descStr}

This is a placeholder template.`
        };
        results.push(addSkill(skill));
      }
    }
  }
  if (options.seo) {
    const template = BATCH_TEMPLATES.seo;
    for (const skillDef of template.skills) {
      const nameStr = extractStr(skillDef.name, skillDef.id);
      const descStr = extractStr(skillDef.description, "");
      const skill = {
        ...skillDef,
        category: template.category,
        enabled: true,
        version: "1.0.0",
        template: `# ${nameStr}

${descStr}

This is a placeholder template.`
      };
      results.push(addSkill(skill));
    }
  }
  if (options.devops) {
    const template = BATCH_TEMPLATES.devops;
    for (const skillDef of template.skills) {
      const nameStr = extractStr(skillDef.name, skillDef.id);
      const descStr = extractStr(skillDef.description, "");
      const skill = {
        ...skillDef,
        category: template.category,
        enabled: true,
        version: "1.0.0",
        template: `# ${nameStr}

${descStr}

This is a placeholder template.`
      };
      results.push(addSkill(skill));
    }
  }
  return results;
}
function getBatchCategories() {
  return Object.keys(BATCH_TEMPLATES);
}

export { addSkill, createBatchSkills, ensureSkillsDir, getAllSkills, getBatchCategories, getRegistry, getSkill, refreshRegistry, removeSkill, searchSkills, setSkillEnabled };
