import { pluginManager } from "./plugin-interface.js";
import { logger } from "../core/monitoring/logger.js";
import { existsSync, readFileSync } from "fs";
import { join } from "path";
async function loadPlugins() {
  const configPath = join(process.cwd(), ".stackmemory", "plugins.json");
  let enabledPlugins = [];
  if (existsSync(configPath)) {
    try {
      const config = JSON.parse(readFileSync(configPath, "utf-8"));
      enabledPlugins = config.enabled || [];
    } catch (error) {
      logger.warn("Failed to load plugin configuration", error);
    }
  } else {
    enabledPlugins = [];
    if (process.env["ENABLE_LINEAR_PLUGIN"] === "true") {
      enabledPlugins.push("linear");
    }
  }
  for (const pluginName of enabledPlugins) {
    try {
      await loadPlugin(pluginName);
    } catch (error) {
      logger.warn(`Failed to load plugin ${pluginName}`, error);
    }
  }
  const loadedPlugins = pluginManager.getAllPlugins();
  if (loadedPlugins.length > 0) {
    logger.info(
      `Loaded ${loadedPlugins.length} plugins: ${loadedPlugins.map((p) => p.name).join(", ")}`
    );
  }
}
async function loadPlugin(name) {
  switch (name) {
    case "linear": {
      const { LinearPlugin } = await import("./linear/index.js");
      const plugin = new LinearPlugin();
      await pluginManager.register(plugin);
      break;
    }
    // Future plugins can be added here
    // case 'github': {
    //   const { GitHubPlugin } = await import('./github/index.js');
    //   await pluginManager.register(new GitHubPlugin());
    //   break;
    // }
    default:
      logger.warn(`Unknown plugin: ${name}`);
  }
}
export {
  loadPlugins,
  pluginManager
};
//# sourceMappingURL=loader.js.map
