Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d9efea7ab | |||
| 9068ced11e |
81
AGENTS.md
81
AGENTS.md
@@ -14,28 +14,66 @@
|
||||
|
||||
### 代码与文档
|
||||
- **代码注释**:默认中文,遵循项目规范
|
||||
- **独立文档文件**(.md、.txt):默认英文
|
||||
- **项目文档**(README、API 文档等):默认英文
|
||||
- **配置文档**(AGENTS.md、自定义规则等):可使用中文
|
||||
- **工具输出**:可保持原语言,但解释用中文
|
||||
|
||||
---
|
||||
|
||||
## 2. 回复规范
|
||||
## 2. 回复规范(Token 优化核心)
|
||||
|
||||
### 内容限制
|
||||
- **禁止展示超过 100 行的内容**
|
||||
- **文件操作**:只说明操作类型、文件路径、改动目的,**不展示具体内容**
|
||||
- **命令输出**:直接展示,不重复总结(除非出错或用户要求)
|
||||
### 🚫 严格禁止(减少 Output Token)
|
||||
|
||||
### 回复风格
|
||||
- 任务完成后简短总结(不超过 5 条要点)
|
||||
- 禁止详细报告、表格、装饰性符号、重复描述
|
||||
- 例外:用户明确要求或错误诊断
|
||||
#### 禁止展示内容
|
||||
- ❌ 超过 100 行的文件内容
|
||||
- ❌ 代码块展示(用文件路径代替,如 `src/utils.ts:42`)
|
||||
- ❌ 工具输出重复总结(bash/read 结果已可见)
|
||||
- ❌ 装饰性 emoji、表格、边框符号
|
||||
|
||||
### 示例
|
||||
✅ **正确**:已创建 LICENSE 文件,使用 MIT License。
|
||||
❌ **错误**:[展示完整的 License 文本内容]
|
||||
#### 禁止冗余表达
|
||||
- ❌ "让我先..."、"现在我将..."、"接下来..."(直接执行)
|
||||
- ❌ 预告即将使用的工具(直接调用)
|
||||
- ❌ 详细报告式总结
|
||||
- ❌ 重复描述已完成的操作
|
||||
|
||||
#### 禁止思考过程展示
|
||||
- ❌ "我认为应该..."、"让我分析一下..."
|
||||
- ❌ 多轮内部推理过程
|
||||
- ✅ 直接给出结论和操作
|
||||
|
||||
### ✅ 推荐做法
|
||||
|
||||
#### 文件操作
|
||||
- 只说:操作类型 + 文件路径 + 目的
|
||||
- 例:`已修改 src/config.ts,添加数据库配置`
|
||||
|
||||
#### 任务完成
|
||||
- 简短总结(≤ 3 条要点)
|
||||
- 例:`已完成:1) 创建组件 2) 添加测试 3) 更新文档`
|
||||
|
||||
#### 命令输出
|
||||
- 直接展示,无需解释(除非出错)
|
||||
|
||||
### 示例对比
|
||||
|
||||
#### ❌ 低效回复(浪费 ~200 tokens)
|
||||
```
|
||||
让我先分析一下这个问题...
|
||||
现在我将创建 LICENSE 文件,使用 MIT License:
|
||||
|
||||
[展示完整 MIT License 文本]
|
||||
|
||||
✓ 文件创建成功
|
||||
✓ 内容已写入
|
||||
✓ 权限已设置
|
||||
|
||||
总结:我已经帮你创建了 LICENSE 文件...
|
||||
```
|
||||
|
||||
#### ✅ 高效回复(仅 ~15 tokens)
|
||||
```
|
||||
已创建 LICENSE 文件,使用 MIT License。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Git 操作限制
|
||||
|
||||
@@ -57,7 +95,6 @@
|
||||
- **完成任务 ≠ 自动推送**
|
||||
- 需要 Git 操作时,**询问用户**或**提示用户使用命令**
|
||||
|
||||
---
|
||||
|
||||
## 4. 批量修改策略
|
||||
|
||||
@@ -74,15 +111,19 @@
|
||||
- 已有测试覆盖
|
||||
- 用户明确要求
|
||||
|
||||
---
|
||||
|
||||
## 5. 代码质量
|
||||
|
||||
### 原则
|
||||
- 确保程序能够运行,需要用户手动运行的除外
|
||||
- 确保代码能够正常运行(除非程序需要用户提供运行时参数或手动执行)
|
||||
- 类型检查零错误
|
||||
- 尝试修复所有 Linter 警告
|
||||
- 允许存在 warning,但不允许存在 error
|
||||
- 尽力修复 Linter 警告(允许存在合理的 warning)
|
||||
- 不允许存在 error
|
||||
|
||||
### 安全
|
||||
- 不提交敏感信息(.env、密钥)
|
||||
|
||||
|
||||
## 6. skill 和 command
|
||||
|
||||
- 默认在oc 的全局配置目录下创建 skill 和 command
|
||||
|
||||
@@ -73,13 +73,8 @@ opencode/
|
||||
│ ├── mqtts-quick-reference.md # 快速参考
|
||||
│ └── USAGE_EXAMPLES.md # 使用示例
|
||||
│
|
||||
├── plugin/ # 插件扩展系统
|
||||
│ └── notification.ts # 通知插件(邮件、Slack、钉钉等)
|
||||
│
|
||||
├── README.md # 项目说明文档(当前文件)
|
||||
├── AGENTS.md # 全局开发规范和指南
|
||||
├── opencode.json # 项目配置文件
|
||||
├── package.json # Node.js 依赖配置
|
||||
└── .gitignore # Git 忽略文件配置
|
||||
```
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {},
|
||||
"permission": "allow",
|
||||
"plugin": ["@mohak34/opencode-notifier@latest"],
|
||||
"provider": {
|
||||
"opencode": {
|
||||
"models": {
|
||||
@@ -10,19 +13,15 @@
|
||||
"budgetTokens": 16000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"claude-sonnet-4-5": {
|
||||
"zhipuai-coding-plan": {
|
||||
"options": {
|
||||
"thinking": {
|
||||
"type": "enabled",
|
||||
"budgetTokens": 16000
|
||||
}
|
||||
}
|
||||
}
|
||||
"apiKey": "0f76aea86295476dbfa98724013b0fe8.o2EaJVqcl4Cf7WLP"
|
||||
}
|
||||
}
|
||||
},
|
||||
"mcp": {
|
||||
},
|
||||
"permission": "allow"
|
||||
"model": "zhipuai-coding-plan/glm-4.7",
|
||||
"small_model": "zhipuai-coding-plan/glm-4.7"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user