// packages/plugin-awf/src/constants.ts
// Single Source of Truth for AWF Plugin constants
import { existsSync, readFileSync } from "node:fs";
import { resolve, dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/**
 * Plugin version - Dynamic from package.json (SSoT)
 * No manual update needed — always reads from package.json at runtime
 */
function getPackageVersion() {
    try {
        // Walk up from dist/ or src/ to find package.json
        const candidates = [
            join(__dirname, "..", "package.json"), // from dist/
            join(__dirname, "..", "..", "package.json"), // from src/commands/
        ];
        for (const p of candidates) {
            if (existsSync(p)) {
                const pkg = JSON.parse(readFileSync(p, "utf-8"));
                if (pkg.name === "@nockdev/awf" && pkg.version) {
                    return pkg.version;
                }
            }
        }
    }
    catch {
        // Fallback silently
    }
    return "unknown";
}
export const AWF_VERSION = getPackageVersion();
/**
 * Plugin name
 */
export const AWF_NAME = "@nockdev/awf";
/**
 * Plugin topic for CLI routing
 */
export const AWF_TOPIC = "awf";
/**
 * Plugin description
 */
export const AWF_DESCRIPTION = "DOMYH Awesome Code - AI Development Assistant";
/**
 * HSA server port
 */
export const HSA_PORT = 13100;
/**
 * Update command timeout (30 seconds)
 */
export const EXEC_TIMEOUT = 30000;
/**
 * Maximum skills to display before truncating
 */
export const DISPLAY_SKILL_LIMIT = 10;
/**
 * Agent directory name
 */
export const AGENT_DIR = ".agent";
/**
 * AWF source directory (for development/monorepo)
 * Resolves to domyh-awf sibling directory if exists
 * Checks for protected (.agent/hsa/) or legacy (.agent/mcp/) structure
 */
function findAWFSourceDir() {
    const possiblePaths = [
        resolve(__dirname, "..", "..", "..", "..", "domyh-awf"),
        resolve(__dirname, "..", "..", "..", "domyh-awf"),
        resolve(process.cwd(), "domyh-awf"),
    ];
    for (const p of possiblePaths) {
        // Prefer protected structure (.agent/hsa/)
        if (existsSync(resolve(p, ".agent", "hsa", "mcp", "hsa-server", "package.json"))) {
            return p;
        }
        // Legacy fallback (.agent/mcp/)
        if (existsSync(resolve(p, ".agent", "mcp", "hsa-server", "package.json"))) {
            return p;
        }
    }
    return null;
}
let _awfSourceDir;
/**
 * AWF source directory (lazy-initialized)
 * Only scans filesystem on first access
 */
export function getAWFSourceDir() {
    if (_awfSourceDir === undefined) {
        _awfSourceDir = findAWFSourceDir();
    }
    return _awfSourceDir;
}
