skills/crafting-opencode-rules/SKILL.md
创建或修改 OpenCode 规则文件时使用。帮助从对话历史中提取模式、分析项目约定(AGENTS.md、linter、package.json),并生成格式正确的规则。触发条件:用户想创建规则、固化重复指令、跨会话持久化指导、或为特定文件/主题定制 Agent 行为。
npx skillsauth add sampx/agent-tools crafting-rulesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
规则是注入到系统提示中的 Markdown 文件,用于引导 Agent 行为。
基本结构:
---
globs:
- '**/*.ts'
keywords:
- 'vitest'
---
# 规则标题
- 规则内容:具体、可执行的指令。
| 字段 | 类型 | 用途 |
|------|------|------|
| globs | string[] | 上下文中任一文件匹配时触发 |
| keywords | string[] | 用户最新提示匹配关键词时触发 |
| alwaysApply | boolean | 始终应用 |
匹配规则:
globs 和 keywords 同时存在时,任一匹配即触发(OR 逻辑)globs AND keywords;需要此行为请拆分为多条规则| 场景 | 推荐方式 |
|------|----------|
| 针对特定文件/目录的代码规则 | globs |
| 针对某个主题(可能不涉及文件) | keywords |
| 两种情况都应触发 | globs + keywords |
| 全局标准(语气、结构、安全、提交规范) | 无条件 |
重要约束: 关键词匹配是大小写不敏感的词边界前缀匹配。例如 test 会匹配 tests 和 testing。
~/.config/opencode/rules/ - 个人偏好,跨项目生效.opencode/rules/ - 项目/团队约定,仓库级行为应该创建规则的信号:
分析问题:
创建流程:
匹配机制: 关键词使用大小写不敏感的词边界前缀匹配。短/泛化关键词容易过度匹配。
| 类别 | 示例 |
|------|------|
| 泛化名词 | code, file, project, repo, bug, issue, change |
| 常见动词 | add, update, remove, fix, make, create, implement |
| 过宽主题 | testing, performance, security, deployment, database, api |
| 单词缩写 | ci, cd, db, ui, ux |
| 类别 | 示例 |
|------|------|
| 工具/框架名 | vitest, jest, pytest, playwright, cypress, eslint, prettier, typescript, terraform, kubernetes |
| 复合短语 | unit test, integration test, snapshot test, lint rule, error boundary, api endpoint, rest api |
| 高意图动词 | refactor, rollback, migrate, deprecate |
考虑 denylist 关键词时的替代方案:
关键词自检:
---
globs:
- '**/*.ts'
- '**/*.tsx'
---
# TypeScript
- 优先用 `type` 而非 `interface`(除非需要声明合并)
- 避免 `any`;使用 `unknown` 并收窄类型
---
keywords:
- 'unit test'
- 'integration test'
- 'vitest'
- 'jest'
---
# Unit Tests
- 遵循 Arrange-Act-Assert 模式
- 测试命名:`it('should <expected> when <condition>')`
# Code Style
- 优先早返回而非深层嵌套
- 将魔法数字提取为命名常量
---
globs:
- '**/deploy/**'
- '**/*.tf'
keywords:
- 'terraform'
- 'kubernetes'
- 'production'
- 'rollback'
---
# Deployment
- 禁止硬编码密钥;使用环境变量或密钥管理器
- 任何生产变更计划必须包含回滚步骤
tools
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.
development
Workspace-level Git worktree management — create, list, remove, and prune isolated development environments. Use this skill whenever the user needs to create a worktree, set up an isolated workspace, work on multiple features in parallel, list existing worktrees, check what worktrees exist, remove or delete a worktree, clean up stale worktrees, or manage git working trees in any way. Triggers include "create worktree", "new worktree", "list worktrees", "show worktrees", "remove worktree", "delete worktree", "clean up worktree", "prune worktree", "isolated environment", "parallel development", "worktree for <project>", or any request involving git worktree operations.
development
Issue/Plan-driven development workflow. Tasks must be backed by a GitHub Issue or Plan. Trigger: issue references like #14, creating issues, creating plans, implementing plans, executing plans, checking plans, verifying plans, Plan lifecycle transitions (approve/complete/verify/archive), decomposing PRDs into Issues. Skip: spec-driven workflows, research/discussion/explanation only, small ad-hoc changes that don't need an Issue or Plan.
testing
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.