بنقرة واحدة
go-coding-standards
Use when writing or reviewing Go code — explains harness9 project coding conventions and patterns
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Use when writing or reviewing Go code — explains harness9 project coding conventions and patterns
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Feature auto-development — clarify requirements, generate spec, dispatch dev sub-agent to implement and merge into current branch
Use when the user invokes /commit or asks to commit changes, after a code review has been completed and the changes are confirmed ready to stage and commit to git.
Use when the user invokes /cr, requests a code review, or before committing to verify correctness, security, and quality of new or modified code in the working tree.
Use when the user invokes /pr or asks to push changes and open a pull request, after commits are ready to be pushed to a remote branch and merged into the main branch.
发布 harness9 CLI 新版本。接受可选的 version 参数;若未提供,则自动将当前最新 tag 的 patch 号加 1。执行:切换到 master、拉取最新代码、创建 tag、推送 tag 触发 GoReleaser,并基于两个 tag 之间的提交生成详细、结构化的 Release Note 覆盖 GitHub Release 默认说明。
Use when asked about harness9 architecture, module design, or how components interact — explains the system design
| name | go-coding-standards |
| description | Use when writing or reviewing Go code — explains harness9 project coding conventions and patterns |
| trigger | write, review, refactor, add, implement |
| 类别 | 规范 | 示例 |
|---|---|---|
| 包名 | 小写、单单词、无下划线 | engine、provider、schema |
| 导出类型/函数 | PascalCase | AgentEngine、NewRegistry |
| 未导出类型/函数 | camelCase | mainLoop、runLoop |
| 接口名 | 以 -er 后缀为惯例 | Provider、Registry、BaseTool |
| 常量 | PascalCase(导出)或 camelCase(未导出),不使用全大写 | RoleSystem、maxLogOutputLen |
| 配置选项函数 | With 前缀 | WithMaxTurns、WithToolTimeout |
error 返回值,禁止 _ 忽略fmt.Errorf("context: %w", err) 包装错误,保留错误链// ✅ 正确
result, err := doSomething()
if err != nil {
return fmt.Errorf("do something: %w", err)
}
// ❌ 错误
result, _ := doSomething()
命名规范:New + 类型名
func NewReadFileTool(workDir string) *ReadFileTool {
return &ReadFileTool{workDir: filepath.Clean(workDir)}
}
接口定义在使用者侧,而非实现者侧。
// ✅ 正确:Registry 接口定义在 tools 包(使用者侧)
// internal/tools/registry.go
type Registry interface {
Register(tool BaseTool) error
GetAvailableTools() []schema.ToolDefinition
Execute(ctx context.Context, call schema.ToolCall) schema.ToolResult
}
// ❌ 错误:不要在实现所在的包中定义接口
并发工具执行使用预分配切片 + 索引写入,确保结果顺序:
// Go 1.22+ 中 for range 每次迭代已自动创建新绑定,无需手动传参捕获。
// 本项目使用 Go 1.25,以下写法是正确的:
results := make([]schema.ToolResult, len(toolCalls))
var wg sync.WaitGroup
for i, tc := range toolCalls {
wg.Add(1)
go func() {
defer wg.Done()
toolCtx, cancel := context.WithTimeout(ctx, e.toolTimeout)
defer cancel()
results[i] = e.registry.Execute(toolCtx, tc)
}()
}
wg.Wait()
internal/tools/ 下创建 xxx.go,实现 BaseTool 接口safePath() 校验所有文件路径参数internal/tools/xxx_test.go 中添加表驱动测试cmd/harness9/main.go 中注册工具type MyTool struct {
workDir string
}
func (t *MyTool) Name() string { return "my_tool" }
func (t *MyTool) Definition() schema.ToolDefinition { /* JSON Schema */ }
func (t *MyTool) Execute(ctx context.Context, args json.RawMessage) (string, error) { /* ... */ }
testing 包,不引入第三方断言库go test ./...func TestXxx(t *testing.T) {
cases := []struct {
name string
input string
want string
}{
{"normal", "foo", "bar"},
{"empty", "", ""},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := Xxx(tc.input)
if got != tc.want {
t.Errorf("got %q, want %q", got, tc.want)
}
})
}
}
提交前必须通过:
gofmt -l . # 无输出表示格式正确
go vet ./... # 无 warning
go test ./... # 全部通过