Skip to content

插件参考手册

插件 API

基础插件结构

javascript
module.exports = {
  name: 'my-plugin',
  version: '1.0.0',
  description: 'Plugin description',

  // 初始化
  async init(context) {
    // Setup code
  },

  // 工具定义
  tools: {
    'tool-name': {
      description: 'Tool description',
      schema: {
        type: 'object',
        properties: {
          param: { type: 'string' }
        }
      },
      async execute(params) {
        // Tool logic
        return result;
      }
    }
  },

  // 钩子
  hooks: {
    'pre-command': async (context) => {
      // Hook logic
    }
  }
};

插件开发

Context API

javascript
// 访问配置
context.config

// 文件系统操作
await context.fs.read(path)
await context.fs.write(path, content)

// 执行命令
await context.exec('npm test')

// 日志
context.log.info('Message')
context.log.error('Error')

小结

在本章中,我们学习了:

  • ✅ 插件 API 结构
  • ✅ 插件开发基础
  • ✅ Context API 使用