Files
test-opencode/plugin/README.md
2026-01-13 01:16:05 +08:00

59 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OpenCode TypeScript Plugin 测试说明
## 概述
本示例演示 OpenCode Plugin 可以使用 TypeScript 编写,并且可以直接使用 Bun 运行。
## 项目结构
```
plugin/
├── package.json # 项目配置
├── build.ts # Bun 构建脚本
├── src/
│ └── index.ts # TypeScript Plugin 源码
└── dist/ # 构建输出目录(自动生成)
```
## 安装依赖
```bash
cd plugin
bun install
```
## 直接运行(使用 Bun TypeScript 支持)
```bash
bun run src/index.ts
```
## 构建
```bash
bun run build
```
## Plugin 配置
在项目的 `opencode.json` 中添加 plugin 引用:
```json
{
"plugin": [
"./plugin/src/index.ts"
]
}
```
OpenCode 会自动识别 TypeScript 文件并使用 Bun 运行,无需预先编译。
## 功能说明
这个示例 plugin 定义了一个 `greet` 工具,用于打招呼。
TypeScript 优势:
- 类型安全
- 智能提示
- 编译时错误检查
- 更好的代码维护性
## 核心特性
1. **原生 TypeScript 支持**OpenCode 可以直接加载和运行 `.ts` 文件
2. **Bun 运行时**:使用 Bun 的内置 TypeScript 编译器,无需配置 tsc
3. **热重载**:修改源码后自动重新加载
4. **零配置**:只需在 `opencode.json` 中指定 `.ts` 文件路径