// OpenCode插件API兼容入口点 // 基于第一性原理分析,创建符合OpenCode插件系统期望的接口 // 安全初始化 - 防止OpenCode启动失败 try { // 检查是否在OpenCode环境中运行 const hasOpenCodeAPI = typeof globalThis !== "undefined" && (globalThis as any).OpenCode !== undefined; if (!hasOpenCodeAPI) { console.warn( `[sisyphus-debatewiki] OpenCode API not available - running in standalone mode`, ); } } catch (error) { console.error(`[sisyphus-debatewiki] Initialization warning:`, error); // 不抛出异常 - 让OpenCode继续启动 } // 定义插件信息 export const PLUGIN_INFO = { name: "sisyphus-debatewiki", version: "1.0.2", description: "Multi-agent forum debate, wiki collaboration, and knowledge synthesis system based on Sisyphus orchestration pattern", features: [ "Multi-agent forum debates", "Consensus algorithms (voting, deliberation, weighted)", "Wiki collaboration system", "Grounded theory research engine", "Ten different debate flow types" ] }; // OpenCode插件API兼容的初始化函数 // 这是OpenCode期望的函数调用模式 export default function initialize(api: any) { console.log(`[sisyphus-debatewiki] Initializing plugin via OpenCode API: ${PLUGIN_INFO.version}`); // 注册插件功能到OpenCode系统 try { // 注册命令 if (api && api.commands) { api.commands.register({ name: "start-debate", description: "Start a multi-agent debate session", handler: async (args: any) => { console.log("[sisyphus-debatewiki] Starting debate via sisyphus_task"); // 委托给专门的论坛智能体 return { status: "delegated_to_forum_agent", message: "Debate start request delegated to specialized forum agent via sisyphus orchestration", args }; } }); api.commands.register({ name: "calculate-consensus", description: "Calculate consensus among agents", handler: async (args: any) => { console.log("[sisyphus-debatewiki] Calculating consensus via sisyphus_task"); // 委托给专门的共识智能体 return { status: "delegated_to_consensus_agent", message: "Consensus calculation delegated to specialized consensus agent via sisyphus orchestration", args }; } }); api.commands.register({ name: "create-wiki-page", description: "Create a wiki page collaboratively", handler: async (args: any) => { console.log("[sisyphus-debatewiki] Creating wiki page via sisyphus_task"); // 委托给专门的维基智能体 return { status: "delegated_to_wiki_agent", message: "Wiki page creation delegated to specialized wiki agent via sisyphus orchestration", args }; } }); api.commands.register({ name: "perform-grounded-theory", description: "Perform grounded theory analysis", handler: async (args: any) => { console.log("[sisyphus-debatewiki] Performing grounded theory analysis via sisyphus_task"); // 委托给专门的扎根理论智能体 return { status: "delegated_to_gt_agent", message: "Grounded theory analysis delegated to specialized GT agent via sisyphus orchestration", args }; } }); } // 返回插件实例 return { name: PLUGIN_INFO.name, version: PLUGIN_INFO.version, description: PLUGIN_INFO.description, initialized: true, capabilities: PLUGIN_INFO.features, // 保持与Sisyphus编排模式的兼容性 sisyphus_delegate: (task: any) => { console.log(`[sisyphus-debatewiki] Delegating task to specialized agent: ${task.agent}`); // 这里会通过sisyphus_task委托给专门的智能体 return { status: "delegated", task: task, message: `Task delegated to ${task.agent} agent` }; } }; } catch (error: any) { console.error(`[sisyphus-debatewiki] Error during plugin initialization:`, error.message); // 返回最小功能集,确保OpenCode可以继续启动 return { name: PLUGIN_INFO.name, version: PLUGIN_INFO.version, description: PLUGIN_INFO.description, initialized: false, error: error.message }; } }