#!/usr/bin/env node
import {
  BaseCommand,
  EXIT_CODES
} from "../../chunk-SRFNNOLC.js";
import {
  LOCAL_DEFAULTS,
  resolveAuthor
} from "../../chunk-ZECXM7LP.js";
import "../../chunk-T4EXUIBY.js";
import {
  directoryExists,
  writeFile
} from "../../chunk-473YHDYQ.js";
import {
  CLI_BIN_NAME,
  LOCAL_SKILLS_PATH,
  SCHEMA_PATHS,
  STANDARD_FILES,
  yamlSchemaComment
} from "../../chunk-FVN5PFFY.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/commands/new/skill.ts
init_esm_shims();
import { Args, Flags } from "@oclif/core";
import path from "path";
var KEBAB_CASE_PATTERN = /^[a-z][a-z0-9-]*$/;
function validateSkillName(name) {
  if (!name || name.trim() === "") {
    return "Skill name is required";
  }
  if (!KEBAB_CASE_PATTERN.test(name)) {
    return "Skill name must be kebab-case (lowercase letters, numbers, and hyphens, starting with a letter)";
  }
  return null;
}
function toTitleCase(kebabCase) {
  return kebabCase.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
}
function generateSkillMd(name, author) {
  const titleName = toTitleCase(name);
  const skillId = `${name} (${author})`;
  return `---
name: ${skillId}
description: Brief description of this skill
---

# ${titleName}

> **Quick Guide:** Add a brief summary of what this skill teaches.

---

<critical_requirements>

## CRITICAL: Before Using This Skill

**(Add critical requirements here)**

</critical_requirements>

---

**When to use:**

- Add use cases here

**Key patterns covered:**

- Add patterns here

---

<patterns>

## Core Patterns

### Pattern 1: Example Pattern

Add your patterns here.

</patterns>

---

<critical_reminders>

## CRITICAL REMINDERS

**(Repeat critical requirements here)**

</critical_reminders>
`;
}
function generateMetadataYaml(name, author, category) {
  const titleName = toTitleCase(name);
  return `${yamlSchemaComment(SCHEMA_PATHS.metadata)}
category: ${category}
categoryExclusive: false
author: "${author}"
cliName: ${titleName}
cliDescription: Brief description
usageGuidance: Use when <guidance>.
tags:
  - local
  - custom
`;
}
var NewSkill = class _NewSkill extends BaseCommand {
  static summary = "Create a new local skill with proper structure";
  static description = "Create a new local skill scaffold with SKILL.md and metadata.yaml files";
  static args = {
    name: Args.string({
      description: "Name of the skill to create (kebab-case)",
      required: true
    })
  };
  static flags = {
    ...BaseCommand.baseFlags,
    author: Flags.string({
      char: "a",
      description: "Author identifier (e.g., @myhandle)",
      required: false
    }),
    category: Flags.string({
      char: "c",
      description: "Skill category",
      default: LOCAL_DEFAULTS.CATEGORY
    }),
    force: Flags.boolean({
      char: "f",
      description: "Overwrite existing skill directory",
      default: false
    })
  };
  async run() {
    const { args, flags } = await this.parse(_NewSkill);
    const projectDir = process.cwd();
    this.log("");
    this.log("Create New Skill");
    this.log("");
    const validationError = validateSkillName(args.name);
    if (validationError) {
      this.error(validationError, { exit: EXIT_CODES.INVALID_ARGS });
    }
    let author = flags.author;
    if (!author) {
      author = await resolveAuthor(projectDir) || LOCAL_DEFAULTS.AUTHOR;
    }
    const category = flags.category;
    const skillDir = path.join(projectDir, LOCAL_SKILLS_PATH, args.name);
    if (await directoryExists(skillDir)) {
      if (!flags.force) {
        this.error(`Skill directory already exists: ${skillDir}
Use --force to overwrite.`, {
          exit: EXIT_CODES.ERROR
        });
      }
      this.warn(`Overwriting existing skill at ${skillDir}`);
    }
    this.log(`Skill name: ${args.name}`);
    this.log(`Author: ${author}`);
    this.log(`Category: ${category}`);
    this.log(`Directory: ${skillDir}`);
    this.log("");
    if (flags["dry-run"]) {
      this.log("[DRY RUN] Would create skill files");
      return;
    }
    this.log("Creating skill files...");
    try {
      const skillMdContent = generateSkillMd(args.name, author);
      const metadataContent = generateMetadataYaml(args.name, author, category);
      const skillMdPath = path.join(skillDir, STANDARD_FILES.SKILL_MD);
      const metadataPath = path.join(skillDir, STANDARD_FILES.METADATA_YAML);
      await writeFile(skillMdPath, skillMdContent);
      await writeFile(metadataPath, metadataContent);
      this.log("");
      this.logSuccess(`Created ${STANDARD_FILES.SKILL_MD} at ${skillMdPath}`);
      this.logSuccess(`Created ${STANDARD_FILES.METADATA_YAML} at ${metadataPath}`);
      this.log("");
      this.log(
        `Skill created successfully! Run '${CLI_BIN_NAME} compile' to include it in your agents.`
      );
      this.log("");
    } catch (error) {
      this.handleError(error);
    }
  }
};
export {
  NewSkill as default,
  generateMetadataYaml,
  generateSkillMd,
  toTitleCase,
  validateSkillName
};
//# sourceMappingURL=skill.js.map