@sin/plugin-sdk
Plugin SDK for SIN Code CLI — TypeScript-based OpenCode fork with plugins
Installation
bash
npm install @sin/plugin-sdkQuick Start
Create a Plugin
typescript
import { definePlugin, createTool, createHook } from '@sin/plugin-sdk';
export default definePlugin({
name: '@sin/my-plugin',
version: '1.0.0',
type: 'tool',
description: 'My awesome plugin',
async activate(ctx) {
// Register a tool
ctx.tools.register(createTool({
name: 'hello',
description: 'Say hello',
parameters: {
name: { type: 'string', required: true }
},
execute: async ({ name }) => ({
content: `Hello, ${name}!`
})
}));
// Register a hook
ctx.events.on('session:start', async (data) => {
ctx.logger.info('Session started!');
});
}
});Plugin Manifest
Create sin-plugin.json:
json
{
"name": "@sin/my-plugin",
"version": "1.0.0",
"type": "tool",
"main": "dist/index.js",
"sinPlugin": {
"minVersion": "1.0.0",
"capabilities": ["tool"],
"config": {
"apiKey": {
"type": "string",
"required": true,
"description": "API Key for the service"
}
}
}
}Testing
typescript
import { testPlugin, mockContext } from '@sin/plugin-sdk/test';
describe('My Plugin', () => {
it('should activate successfully', async () => {
const result = await testPlugin(myPlugin, {
config: { apiKey: 'test-key' }
});
expect(result.success).toBe(true);
});
});API Reference
Plugin Types
tool— New tools for the agenthook— Event-based automationagent— Specialized agent configurationscommand— New slash commandsauth— Model authentication providerstheme— Visual themesmemory— Persistent memory systemsmcp— Model Context Protocol servers
Core APIs
definePlugin()— Create a plugincreateTool()— Create a toolcreateHook()— Create a hookcreateCommand()— Create a commanddefineAuthProvider()— Create an auth provider
Context APIs
ctx.config— Plugin configurationctx.session— Current session infoctx.tools— Tool registryctx.events— Event busctx.logger— Logging interfacectx.sin— SIN Core API (memory, a2a, permissions)
Examples
See the examples directory for complete plugin implementations.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
Apache 2.0