refactor: 更新配置并删除通知插件

This commit is contained in:
2026-01-15 09:36:05 +08:00
parent 9068ced11e
commit 5d9efea7ab
3 changed files with 10 additions and 88 deletions

View File

@@ -73,13 +73,8 @@ opencode/
│ ├── mqtts-quick-reference.md # 快速参考 │ ├── mqtts-quick-reference.md # 快速参考
│ └── USAGE_EXAMPLES.md # 使用示例 │ └── USAGE_EXAMPLES.md # 使用示例
├── plugin/ # 插件扩展系统
│ └── notification.ts # 通知插件邮件、Slack、钉钉等
├── README.md # 项目说明文档(当前文件) ├── README.md # 项目说明文档(当前文件)
├── AGENTS.md # 全局开发规范和指南 ├── AGENTS.md # 全局开发规范和指南
├── opencode.json # 项目配置文件 ├── opencode.json # 项目配置文件
├── package.json # Node.js 依赖配置
└── .gitignore # Git 忽略文件配置 └── .gitignore # Git 忽略文件配置
``` ```

View File

@@ -1,5 +1,8 @@
{ {
"$schema": "https://opencode.ai/config.json", "$schema": "https://opencode.ai/config.json",
"mcp": {},
"permission": "allow",
"plugin": ["@mohak34/opencode-notifier@latest"],
"provider": { "provider": {
"opencode": { "opencode": {
"models": { "models": {
@@ -10,19 +13,15 @@
"budgetTokens": 16000 "budgetTokens": 16000
} }
} }
}
}
}, },
"claude-sonnet-4-5": { "zhipuai-coding-plan": {
"options": { "options": {
"thinking": { "apiKey": "0f76aea86295476dbfa98724013b0fe8.o2EaJVqcl4Cf7WLP"
"type": "enabled",
"budgetTokens": 16000
}
}
}
} }
} }
}, },
"mcp": { "model": "zhipuai-coding-plan/glm-4.7",
}, "small_model": "zhipuai-coding-plan/glm-4.7"
"permission": "allow"
} }

View File

@@ -1,72 +0,0 @@
import type { Plugin } from "@opencode-ai/plugin"
/**
* 通知 Plugin
* 在会话完成或发生错误时发送系统通知
*/
export const NotificationPlugin: Plugin = async ({ project, client, $ }) => {
// 检测操作系统
const platform = process.platform
/**
* 发送系统通知
* @param title 通知标题
* @param message 通知内容
* @param isError 是否为错误通知
*/
const sendNotification = async (title: string, message: string, isError: boolean = false) => {
try {
if (platform === "darwin") {
// macOS - 使用 osascript
const sound = isError ? ' sound name "Basso"' : ''
await $`osascript -e 'display notification "${message}" with title "${title}"${sound}'`
} else if (platform === "linux") {
// Linux - 使用 notify-send
const urgency = isError ? "-u critical" : ""
await $`notify-send "${title}" "${message}" ${urgency}`
} else if (platform === "win32") {
// Windows - 使用 PowerShell
const script = `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('${message}', '${title}')`
await $`powershell -Command "& {${script}}"`
}
// 记录日志
await client.app.log({
service: "notification",
level: "info",
message: `已发送通知: ${title} - ${message}`,
})
} catch (error) {
// 如果通知发送失败,记录错误但不中断流程
await client.app.log({
service: "notification",
level: "error",
message: `发送通知失败: ${error}`,
})
}
}
return {
event: async ({ event }) => {
const projectName = project?.name || "OpenCode"
// 会话完成时发送通知
if (event.type === "session.idle") {
await sendNotification(
projectName,
"会话已完成!",
false
)
}
// 会话错误时发送通知
if (event.type === "session.error") {
await sendNotification(
projectName,
"会话发生错误!",
true
)
}
},
}
}