| name | go-comment-conventions |
| description | Enforce concise Chinese responsibility and API comments in this Go project. Use when creating, modifying, or reviewing Go packages, files, types, structs, interfaces, fields, tests, constants, functions, or methods so the code remains self-documenting without excessive line-by-line narration. |
Go Comment Conventions
Use these rules for hand-written Go code in this repository. Comments should
state responsibility and semantic meaning, not narrate obvious syntax.
Package and file responsibility
Each package must have one package-level comment, preferably in doc.go:
package llm
Every hand-written .go file must state its responsibility immediately before
the package declaration:
package llm
Do not repeat the full package documentation in every file. A package needs
one package comment; each file needs its own narrower responsibility comment.
For _test.go, describe the test motivation rather than the implementation:
package llm
Types and fields
Every hand-written type declaration needs a concise Chinese comment. This
includes structs, interfaces, named scalar types, aliases, and generic types.
Start the comment with the exact declared name:
type MessageRole string
type ResponseMessage = AssistantMessage
Every struct field needs its own Chinese comment, including unexported fields,
pointer/slice/map fields, and embedded fields. Explain semantic details when
they matter: units, optionality, nil meaning, empty-value meaning, provider
ownership, replay requirements, or billing impact.
type Usage struct {
Input int64
Reasoning *int64
}
Do not use empty or tautological comments such as // Input 输入. A field
comment does not need to document its Go type when its semantic meaning is
already clear.
Interfaces, constants, functions, and methods
Document every interface method because it is part of the behavioral contract:
type Message interface {
Role() MessageRole
Validate() error
}
Document every exported constant, function, and method. Start exported
declaration comments with the exact identifier. Unexported helpers do not need
routine comments unless their behavior is non-obvious or easy to misuse.
const StopReasonToolUse StopReason = "toolUse"
Comments must describe the contract and observable behavior. Do not add methods
or comments merely to imitate an object-oriented style; keep abstractions and
documentation aligned with actual callers.
Generated and third-party code
Do not edit generated or third-party files solely to satisfy this convention.
This exemption covers files such as *.pb.go, *.gen.go, files with a
generator header, vendored code, and checked-in external dependencies. If a
generator is owned by this project, improve its template or generator instead
of hand-editing its output.
Review checklist
When adding or reviewing a Go file, check:
- package responsibility is documented once;
- file responsibility is documented;
- every type and every struct field has a concise Chinese comment;
- every interface method is documented;
- exported constants, functions, and methods are documented;
- tests explain their motivation;
- comments describe semantics rather than obvious assignments;
- generated and third-party files were left untouched.