import os from "node:os";
import path from "node:path";
import { existsSync } from "node:fs";
import { pathExists, readJson } from "../utils/fs.js";
import { readYamlFile } from "../utils/yaml.js";
export const TOOL_NAMES = ["codex", "claude", "copilot"];
export const SPECIALIST_RESULT_FIELDS = [
    "role",
    "status",
    "summary",
    "agreements",
    "conflicts",
    "validations",
    "risks",
    "touched_files",
    "next_steps"
];
export const PROJECT_TYPES = ["python", "node", "docs", "data-platform", "generic"];
export const TASK_TYPES = [
    "planning",
    "implementation",
    "inline",
    "review",
    "testing",
    "docs",
    "bugfix",
    "refactor",
    "migration",
    "release-readiness"
];
export const EXECUTION_MODES = ["assisted", "guarded", "inline"];
export const CHANGE_SIZES = ["small", "medium", "large"];
export const FILE_AREAS = ["application", "config", "context", "data", "docs", "infra", "tests", "unknown"];
export async function loadCanonicalConfig(repoRoot) {
    const configDir = path.join(repoRoot, "configs");
    return {
        repoRoot,
        global: await readYamlFile(path.join(configDir, "global.yaml")),
        routing: await readYamlFile(path.join(configDir, "routing.yaml")),
        models: await readYamlFile(path.join(configDir, "models.yaml")),
        guardrails: await readYamlFile(path.join(configDir, "guardrails.yaml")),
        mcpServers: await readJson(path.join(configDir, "mcp.servers.json")),
        specialists: await readYamlFile(path.join(configDir, "specialists.yaml")),
        policies: await readYamlFile(path.join(configDir, "policies.yaml"))
    };
}
export function getGlobalHomeRoot() {
    if (process.env.KIWI_CONTROL_HOME) {
        return process.env.KIWI_CONTROL_HOME;
    }
    if (process.env.SHREY_JUNIOR_HOME) {
        return process.env.SHREY_JUNIOR_HOME;
    }
    const kiwiControlHome = path.join(os.homedir(), ".kiwi-control");
    const legacyHome = path.join(os.homedir(), ".shrey-junior");
    if (existsSync(kiwiControlHome) || !existsSync(legacyHome)) {
        return kiwiControlHome;
    }
    return legacyHome;
}
export function getGlobalHomePaths(root = getGlobalHomeRoot()) {
    return {
        root,
        configs: path.join(root, "configs"),
        prompts: path.join(root, "prompts"),
        specialists: path.join(root, "specialists"),
        policies: path.join(root, "policies"),
        mcp: path.join(root, "mcp"),
        defaults: path.join(root, "defaults"),
        adapters: path.join(root, "adapters"),
        bin: path.join(root, "bin")
    };
}
export async function loadGlobalBootstrapDefaults(root = getGlobalHomeRoot()) {
    const filePath = path.join(root, "defaults", "bootstrap.yaml");
    if (!(await pathExists(filePath))) {
        return null;
    }
    return readYamlFile(filePath);
}
