"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.execInit = execInit;
const fs_1 = require("fs");
const path_1 = require("path");
const install_js_1 = require("./install.js");
const skill_js_1 = require("./skill.js");
const DEFAULT_CONFIG = `provider: claude
model: sonnet
isolation:
  type: ephemeral
  cleanup: after_success
  exclude:
    - node_modules
    - .git
    - dist
    - build
    - .vsaf/storage
  max_workspaces: 5
`;
async function execInit(projectPath) {
    const vsafDir = (0, path_1.join)(projectPath, '.vsaf');
    if ((0, fs_1.existsSync)(vsafDir)) {
        console.log(`[vsaf] .vsaf/ already initialized at ${projectPath}`);
        return;
    }
    // Create .vsaf/ directory structure
    (0, fs_1.mkdirSync)((0, path_1.join)(vsafDir, 'workflows'), { recursive: true });
    (0, fs_1.mkdirSync)((0, path_1.join)(vsafDir, 'commands'), { recursive: true });
    (0, fs_1.mkdirSync)((0, path_1.join)(vsafDir, 'storage'), { recursive: true });
    (0, fs_1.writeFileSync)((0, path_1.join)(vsafDir, 'config.yaml'), DEFAULT_CONFIG, 'utf-8');
    // Create/merge .mcp.json with vsaf + gitnexus MCP servers
    (0, install_js_1.ensureMcpConfig)(projectPath);
    // Deploy SDLC skills by default (same as `vsaf install sdlc`)
    const skillsDir = (0, path_1.join)(projectPath, '.claude', 'skills');
    const packDir = (0, skill_js_1.resolveSource)('sdlc');
    const packInfo = (0, skill_js_1.resolvePackInfo)('sdlc', projectPath);
    const deploy = (0, install_js_1.deploySkills)(packDir, 'sdlc', packInfo.skillNames, skillsDir, { force: false });
    // Deploy bundled skills (BMAD + mattpocock) without prefix (external dependencies)
    if (packInfo.bundledNames.length > 0) {
        const bundled = (0, install_js_1.deploySkills)(packDir, 'sdlc', packInfo.bundledNames, skillsDir, { force: false, noPrefix: true });
        deploy.deployed.push(...bundled.deployed);
        deploy.skipped.push(...bundled.skipped);
    }
    if (deploy.deployed.length > 0 || deploy.skipped.length > 0) {
        console.log(`\n[vsaf] Skills deployed to ${skillsDir}`);
        for (const name of deploy.deployed)
            console.log(`  ✓ ${name}`);
        for (const name of deploy.skipped)
            console.log(`  ⊘ ${name} (exists, use --force to overwrite)`);
        console.log(`  ${deploy.deployed.length} deployed, ${deploy.skipped.length} skipped\n`);
    }
    console.log(`\n[vsaf] Initialized .vsaf/ at ${projectPath}`);
    console.log('[vsaf] Next: vsaf install sdlc  (install npm dependencies)\n');
}
//# sourceMappingURL=init.js.map