When and how auto-generated comments are created and maintained.
Comments can be generated at several points in the development workflow:
- During LLM code generation
- As a post-processing command
- Via IDE integration
- In CI/CD pipelines
When Claude or another LLM generates Covenant code, comments are generated simultaneously.
Prompt Instruction:
When generating Covenant code, include inline comments that:
- Explain what each section does
- Describe non-obvious steps
- Note the purpose of each function
Use this format:
// [section explanation]
[section content]
// [step explanation]
step id="..." kind="..."
Configuration:
In the code generation spec, set comment verbosity:
{
"generation": {
"commentVerbosity": "standard",
"includeStepComments": true,
"includeSectionComments": true
}
}Annotate existing code:
# Annotate a single file
covenant annotate src/auth.cov
# Annotate with specific verbosity
covenant annotate --verbosity=detailed src/auth.cov
# Annotate all files
covenant annotate --all
# Update stale comments only
covenant annotate --update src/
# Force regeneration
covenant annotate --force src/auth.cov
# Strip auto-generated comments
covenant strip-comments src/auth.covCode Actions:
- "Explain this snippet" - Add detailed comments
- "Simplify comments" - Reduce to minimal
- "Update comments" - Refresh stale comments
Hover Tooltips:
- Show explanation on hover (without modifying file)
- Option to insert as comment
Language Server Protocol:
{
"command": "covenant.annotate",
"arguments": {
"snippetId": "auth.login",
"verbosity": "standard"
}
}Auto-annotate before commit:
.covenant/hooks/pre-commit:
#!/bin/bash
# Auto-annotate staged .cov files
staged_cov_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cov$')
if [ -n "$staged_cov_files" ]; then
covenant annotate --update $staged_cov_files
git add $staged_cov_files
fiEnable hook:
covenant hooks install pre-commitGitHub Action:
name: Documentation
on: [push]
jobs:
annotate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: covenant-lang/setup@v1
- name: Check comment coverage
run: covenant annotate --check --coverage=80%
- name: Generate documentation
run: covenant docs generate- User requests: "Create a user login function"
- LLM generates code with comments
- User reviews and commits
// [LLM generates this]
// AUTO-GENERATED
// Authenticates user with email and password
snippet id="auth.login" kind="fn"
// ... code with inline comments ...
end
- Developer runs:
covenant annotate src/legacy.cov - Generator analyzes AST
- Comments inserted based on analysis
- Developer reviews diff and commits
- Developer modifies function
- Pre-commit hook detects change (hash mismatch)
- Hook runs:
covenant annotate --update <file> - Stale comments regenerated
- Commit proceeds with updated comments
- Developer decides comments are cluttering code
- Runs:
covenant strip-comments --level=step src/auth.cov - Step-level comments removed, section comments preserved
- Manual comments (
[MANUAL]) preserved
Each auto-generated comment block includes a hash:
// AUTO-GENERATED (hash: abc123)
// Function: Authenticates user
On update:
- Compute current snippet hash
- Compare with stored hash
- If different, mark as stale
In IDE, stale comments could be:
- Grayed out
- Marked with warning icon
- Shown with "Update available" hint
Comments marked [MANUAL] are never modified:
// [MANUAL] IMPORTANT: Rate limit this endpoint!
// [AUTO] Authenticates user with email and password
snippet id="auth.login" kind="fn"
Plain // comments (no marker) are:
- Preserved by
--update - Removed by
--force - Preserved by
strip-comments
Encourage markers for clarity:
// [MANUAL] Business rule: Max 5 attempts per hour
// [AUTO] Validates login attempt count
step id="s1" kind="query"
When comments are auto-generated, suggest commit message:
docs: Auto-generate comments for auth module
- Added comments to auth.login
- Added comments to auth.validate_token
- Updated stale comments in auth.refresh
Generated by: covenant annotate v1.0
Show comment changes separately:
snippet id="auth.login" kind="fn"
+ // EFFECTS: Database access for user lookup
effects
effect database
end.covenant/config.json:
{
"comments": {
"autoGenerate": true,
"verbosity": "standard",
"preCommitHook": true,
"ciCheck": true,
"minCoverage": 80
}
}~/.covenant/config.json:
{
"comments": {
"defaultVerbosity": "minimal",
"preferredMarkerStyle": "simple"
}
}At top of file:
// @covenant-comments verbosity=detailed
// @covenant-comments skip-steps=s1,s2
snippet id="complex.function" kind="fn"
Track comment coverage:
covenant annotate --coverage-report
Comment Coverage Report
=======================
Total snippets: 42
With comments: 38 (90%)
Stale comments: 3 (7%)
Missing: 4 (10%)
Missing comments:
- src/utils.cov: utils.helper_fn
- src/db.cov: db.raw_query
- src/db.cov: db.batch_insert
- src/http.cov: http.middlewareIf comment generation fails:
- Log error with context
- Leave code unchanged
- Report in CLI output
- Continue with other files
If file has syntax errors:
- Report parse error
- Skip comment generation for that file
- Suggest fixing errors first
If LLM enhancement times out:
- Fall back to template-based comments
- Log timeout warning
- Mark as "template-only" in metadata