/**
 * commands/author-skill.mjs — `apt-tools author-skill <name>` (C4).
 *
 * Scaffolds a new Aperant skill test-first:
 *   - packages/framework/skills/apt-{name}/SKILL.md (stub)
 *   - packages/framework/src/__tests__/apt-{name}-skill-structure.test.ts (generated)
 *
 * One-shot, non-interactive. Refuses to overwrite — authors who want to
 * restart delete the scaffolded files by hand.
 *
 * Usage:
 *
 *   apt-tools author-skill <name> [--description <text>] [--dry-run] [--framework-root <path>]
 *
 * --framework-root defaults to the shipping packages/framework/ directory
 * resolved from the command's own __dirname (same pattern as template.mjs).
 * Tests pass an explicit --framework-root pointing at a tmpdir so the real
 * skills/ tree is never touched.
 */
import { dirname, resolve as resolvePath } from 'node:path';
import { fileURLToPath } from 'node:url';
import { scaffoldSkill } from '../skill-author/scaffold.mjs';
import { parseFlags } from '../util/args.mjs';
import { err, ok } from '../util/result.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// commands/author-skill.mjs → ../../../ = packages/framework/. Same resolution
// pattern as commands/template.mjs:13-18 so the dispatch is consistent.
const DEFAULT_FRAMEWORK_ROOT = resolvePath(__dirname, '..', '..', '..');
export function cmdAuthorSkill(name, extraArgs) {
    if (!name || name.startsWith('--')) {
        return err('Usage: apt-tools author-skill <name> [--description <text>] [--dry-run] [--framework-root <path>]');
    }
    const flags = parseFlags(extraArgs ?? []);
    const descriptionFlag = flags.get('description');
    const description = typeof descriptionFlag === 'string' && descriptionFlag.length > 0
        ? descriptionFlag
        : 'TODO: describe the skill';
    const dryRun = flags.get('dry-run') === true || flags.get('dry-run') === 'true';
    const frameworkRootFlag = flags.get('framework-root');
    const frameworkRoot = typeof frameworkRootFlag === 'string' && frameworkRootFlag.length > 0
        ? resolvePath(frameworkRootFlag)
        : DEFAULT_FRAMEWORK_ROOT;
    let result;
    try {
        result = scaffoldSkill({ name, description, frameworkRoot, dryRun });
    }
    catch (e) {
        const msg = e instanceof Error ? e.message : String(e);
        return err(msg);
    }
    return ok({
        status: 'ok',
        command: 'author-skill',
        skill_path: result.skillPath,
        test_path: result.testPath,
        dry_run: result.dryRun,
        framework_root: frameworkRoot,
        next_steps: [
            `Fill in the TODO stubs in ${result.skillPath}`,
            `Run the structural test: pnpm --filter @aperant/framework test --run ${result.testPath}`,
            'Extend the generated test with skill-specific assertions as the body fleshes out',
        ],
    });
}
//# sourceMappingURL=author-skill.mjs.map