Skip to content

Commit a19b73e

Browse files
committed
docs: standardize Go docstrings with Parameters/Returns/Fields sections
Go documentation fixes: - Add Fields blocks to structs (addFlags, EntryParams, IndexEntry, TaskBlock, fixResult, ContextUpdate, Session, Message) - Add Parameters/Returns to functions (ParseDecisionHeaders, GenerateIndex, UpdateIndex, UpdateLearningsIndex, UncheckedTaskPattern, GetIndentLevel, RemoveBlocksFromLines, SetContextDir, ContextDir) - Preserve taxonomy groupings in Session struct Fields block - Remove redundant inline comments where Fields block exists - Add Flags/Returns to watch.Cmd() Agent guidance: - Add Go Documentation Standard section to AGENT_PLAYBOOK.md - Add learning: documentation audits require verification against standards - Update template AGENT_PLAYBOOK.md for new projects Signed-off-by: Jose Alekhinne <alekhinejose@gmail.com>
1 parent 3fad0cf commit a19b73e

18 files changed

Lines changed: 398 additions & 79 deletions

File tree

.context/AGENT_PLAYBOOK.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,73 @@ Never assume: If you don't see it in files, you don't know it.
359359
- Don't invent history - check sessions/ for actual discussions
360360
- If uncertain, say "I don't see this documented"
361361
- Trust files over intuition
362+
363+
## Go Documentation Standard
364+
365+
When writing Go code, follow this docstring format consistently.
366+
367+
### Functions
368+
369+
```go
370+
// FunctionName does X.
371+
//
372+
// Extended description if needed.
373+
//
374+
// Parameters:
375+
// - param1: Description of first parameter
376+
// - param2: Description of second parameter
377+
//
378+
// Returns:
379+
// - ReturnType: Description of return value
380+
// - error: When this error occurs
381+
func FunctionName(param1 Type1, param2 Type2) (ReturnType, error) {
382+
```
383+
384+
### Structs
385+
386+
```go
387+
// StructName represents X.
388+
//
389+
// Extended description if needed.
390+
//
391+
// Fields:
392+
// - Field1: Description of field
393+
// - Field2: Description of field
394+
type StructName struct {
395+
Field1 Type1
396+
Field2 Type2
397+
}
398+
```
399+
400+
### Struct Fields with Taxonomy
401+
402+
For complex structs, group related fields:
403+
404+
```go
405+
// Session represents a conversation session.
406+
//
407+
// Fields:
408+
//
409+
// Identity:
410+
// - ID: Unique session identifier
411+
// - Slug: URL-friendly identifier
412+
//
413+
// Timing:
414+
// - StartTime: When the session started
415+
// - EndTime: When the session ended
416+
type Session struct {
417+
ID string
418+
Slug string
419+
420+
StartTime time.Time
421+
EndTime time.Time
422+
}
423+
```
424+
425+
### Reference Examples
426+
427+
Before writing new code, check these well-documented files:
428+
- `internal/cli/status/types.go` — struct documentation
429+
- `internal/claude/types.go` — structs with Fields sections
430+
- `internal/drift/detector.go` — functions with Parameters/Returns
431+
- `internal/context/loader.go` — complete function documentation

.context/LEARNINGS.md

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
11
# Learnings
22

33
<!-- INDEX:START -->
4-
| Date | Learning |
5-
|------------|------------------------------------------------------|
6-
| 2026-01-28 | Required flags now enforced for learnings |
7-
| 2026-01-28 | Claude Code Hooks Receive JSON via Stdin |
8-
| 2026-01-28 | Changelogs vs Blogs serve different audiences |
9-
| 2026-01-28 | IDE is already the UI |
4+
| Date | Learning |
5+
|------|--------|
6+
| 2026-01-29 | Documentation audits require verification against actual standards |
7+
| 2026-01-28 | Required flags now enforced for learnings |
8+
| 2026-01-28 | Claude Code Hooks Receive JSON via Stdin |
9+
| 2026-01-28 | Changelogs vs Blogs serve different audiences |
10+
| 2026-01-28 | IDE is already the UI |
1011
| 2026-01-28 | Subtasks complete does not mean parent task complete |
11-
| 2026-01-28 | AI session JSONL formats are not standardized |
12-
| 2026-01-27 | Always Complete Decision Record Sections |
13-
| 2026-01-27 | Slash Commands Require Matching Permissions |
14-
| 2026-01-26 | Go json.Marshal Escapes Shell Characters |
15-
| 2026-01-26 | Claude Code Hook Key Names |
16-
| 2026-01-25 | defer os.Chdir Fails errcheck Linter |
17-
| 2026-01-25 | golangci-lint Go Version Mismatch in CI |
18-
| 2026-01-25 | CI Tests Need CTX_SKIP_PATH_CHECK |
19-
| 2026-01-25 | AGENTS.md Is Not Auto-Loaded |
20-
| 2026-01-25 | Hook Regex Can Overfit |
21-
| 2026-01-25 | Autonomous Mode Creates Technical Debt |
22-
| 2026-01-23 | ctx agent vs Manual File Reading Trade-offs |
23-
| 2026-01-23 | Claude Code Skills Format |
24-
| 2026-01-23 | Infer Intent on "Do You Remember?" Questions |
25-
| 2026-01-23 | Always Use ctx from PATH |
26-
| 2026-01-21 | Exit Criteria Must Include Verification |
27-
| 2026-01-21 | Orchestrator vs Agent Tasks Must Be Separate |
28-
| 2026-01-21 | One Templates Directory, Not Two |
29-
| 2026-01-21 | Hooks Should Use PATH, Not Hardcoded Paths |
30-
| 2026-01-20 | ctx and Ralph Loop Are Separate Systems |
31-
| 2026-01-20 | .context/ Is NOT a Claude Code Primitive |
32-
| 2026-01-20 | SessionEnd Hook Catches Ctrl+C |
33-
| 2026-01-20 | Session Filename Must Include Time |
34-
| 2026-01-20 | Two Tiers of Persistence |
35-
| 2026-01-20 | Auto-Load Works, Auto-Save Was Missing |
36-
| 2026-01-20 | Always Backup Before Modifying User Files |
37-
| 2026-01-19 | CGO Must Be Disabled for ARM64 Linux |
12+
| 2026-01-28 | AI session JSONL formats are not standardized |
13+
| 2026-01-27 | Always Complete Decision Record Sections |
14+
| 2026-01-27 | Slash Commands Require Matching Permissions |
15+
| 2026-01-26 | Go json.Marshal Escapes Shell Characters |
16+
| 2026-01-26 | Claude Code Hook Key Names |
17+
| 2026-01-25 | defer os.Chdir Fails errcheck Linter |
18+
| 2026-01-25 | golangci-lint Go Version Mismatch in CI |
19+
| 2026-01-25 | CI Tests Need CTX_SKIP_PATH_CHECK |
20+
| 2026-01-25 | AGENTS.md Is Not Auto-Loaded |
21+
| 2026-01-25 | Hook Regex Can Overfit |
22+
| 2026-01-25 | Autonomous Mode Creates Technical Debt |
23+
| 2026-01-23 | ctx agent vs Manual File Reading Trade-offs |
24+
| 2026-01-23 | Claude Code Skills Format |
25+
| 2026-01-23 | Infer Intent on "Do You Remember?" Questions |
26+
| 2026-01-23 | Always Use ctx from PATH |
27+
| 2026-01-21 | Exit Criteria Must Include Verification |
28+
| 2026-01-21 | Orchestrator vs Agent Tasks Must Be Separate |
29+
| 2026-01-21 | One Templates Directory, Not Two |
30+
| 2026-01-21 | Hooks Should Use PATH, Not Hardcoded Paths |
31+
| 2026-01-20 | ctx and Ralph Loop Are Separate Systems |
32+
| 2026-01-20 | .context/ Is NOT a Claude Code Primitive |
33+
| 2026-01-20 | SessionEnd Hook Catches Ctrl+C |
34+
| 2026-01-20 | Session Filename Must Include Time |
35+
| 2026-01-20 | Two Tiers of Persistence |
36+
| 2026-01-20 | Auto-Load Works, Auto-Save Was Missing |
37+
| 2026-01-20 | Always Backup Before Modifying User Files |
38+
| 2026-01-19 | CGO Must Be Disabled for ARM64 Linux |
3839
<!-- INDEX:END -->
3940

4041
---
4142

43+
## [2026-01-29-164322] Documentation audits require verification against actual standards
44+
45+
**Context**: Agent claimed 'no Go docstring issues found' but manual inspection revealed many functions missing Parameters/Returns sections. The agent only checked if comments existed, not if they followed the standard format.
46+
47+
**Lesson**: When auditing documentation, compare against a known-good example first. Pattern-match for the COMPLETE standard (e.g., '// Parameters:' AND '// Returns:' sections), not just presence of any comment.
48+
49+
**Application**: Before declaring 'no issues', manually verify at least 5 random samples match the documented standard. Use grep patterns that detect missing sections, not just missing comments.
50+
51+
---
52+
4253
## [2026-01-28-191951] Required flags now enforced for learnings
4354

4455
**Context**: Implemented ctx add learning flags to match decision's ADR (Architectural Decision Record) pattern

internal/cli/add/add.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ Examples:
127127
}
128128

129129
// addFlags holds all flags for the add command.
130+
//
131+
// Fields:
132+
// - priority: Priority level for tasks (high, medium, low)
133+
// - section: Target section in TASKS.md
134+
// - fromFile: Read content from file instead of argument
135+
// - context: Context field for decisions/learnings
136+
// - rationale: Rationale field for decisions
137+
// - consequences: Consequences field for decisions
138+
// - lesson: Lesson field for learnings
139+
// - application: Application field for learnings
130140
type addFlags struct {
131141
priority string
132142
section string

internal/cli/add/index.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ const (
1818
)
1919

2020
// IndexEntry represents a parsed entry header from a context file.
21+
//
22+
// Fields:
23+
// - Timestamp: Full timestamp (YYYY-MM-DD-HHMMSS)
24+
// - Date: Date only (YYYY-MM-DD)
25+
// - Title: Entry title
2126
type IndexEntry struct {
22-
Timestamp string // Full timestamp: YYYY-MM-DD-HHMMSS
23-
Date string // Date only: YYYY-MM-DD
24-
Title string // Entry title
27+
Timestamp string
28+
Date string
29+
Title string
2530
}
2631

2732
// DecisionEntry is an alias for backward compatibility.
@@ -61,6 +66,12 @@ func ParseEntryHeaders(content string) []IndexEntry {
6166
}
6267

6368
// ParseDecisionHeaders is an alias for ParseEntryHeaders for backward compatibility.
69+
//
70+
// Parameters:
71+
// - content: The full content of a context file
72+
//
73+
// Returns:
74+
// - []DecisionEntry: Slice of parsed entries (may be empty)
6475
func ParseDecisionHeaders(content string) []DecisionEntry {
6576
return ParseEntryHeaders(content)
6677
}
@@ -103,6 +114,12 @@ func GenerateIndexTable(entries []IndexEntry, columnHeader string) string {
103114
}
104115

105116
// GenerateIndex creates a markdown table for decisions (backward compatibility).
117+
//
118+
// Parameters:
119+
// - entries: Slice of decision entries to include
120+
//
121+
// Returns:
122+
// - string: Markdown table or empty string if no entries
106123
func GenerateIndex(entries []DecisionEntry) string {
107124
return GenerateIndexTable(entries, "Decision")
108125
}
@@ -182,11 +199,23 @@ func updateFileIndex(content, fileHeader, columnHeader string) string {
182199
}
183200

184201
// UpdateIndex regenerates the decision index in DECISIONS.md content.
202+
//
203+
// Parameters:
204+
// - content: The full content of DECISIONS.md
205+
//
206+
// Returns:
207+
// - string: Updated content with regenerated index
185208
func UpdateIndex(content string) string {
186209
return updateFileIndex(content, "# Decisions", "Decision")
187210
}
188211

189212
// UpdateLearningsIndex regenerates the learning index in LEARNINGS.md content.
213+
//
214+
// Parameters:
215+
// - content: The full content of LEARNINGS.md
216+
//
217+
// Returns:
218+
// - string: Updated content with regenerated index
190219
func UpdateLearningsIndex(content string) string {
191220
return updateFileIndex(content, "# Learnings", "Learning")
192221
}

internal/cli/add/run.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,36 @@ import (
2020
)
2121

2222
// EntryParams contains all parameters needed to add an entry to a context file.
23+
//
24+
// Fields:
25+
// - Type: Entry type (decision, learning, task, convention)
26+
// - Content: Title or main content
27+
// - Section: Target section (for tasks)
28+
// - Priority: Priority level (for tasks)
29+
// - Context: Context field (for decisions/learnings)
30+
// - Rationale: Rationale (for decisions)
31+
// - Consequences: Consequences (for decisions)
32+
// - Lesson: Lesson (for learnings)
33+
// - Application: Application (for learnings)
2334
type EntryParams struct {
24-
Type string // decision, learning, task, convention
25-
Content string // Title or main content
26-
Section string // Target section (for tasks)
27-
Priority string // Priority level (for tasks)
28-
Context string // Context field (for decisions/learnings)
29-
Rationale string // Rationale (for decisions)
30-
Consequences string // Consequences (for decisions)
31-
Lesson string // Lesson (for learnings)
32-
Application string // Application (for learnings)
35+
Type string
36+
Content string
37+
Section string
38+
Priority string
39+
Context string
40+
Rationale string
41+
Consequences string
42+
Lesson string
43+
Application string
3344
}
3445

3546
// ValidateEntry checks that required fields are present for the given entry type.
3647
//
37-
// Returns an error with details about missing fields, or nil if valid.
48+
// Parameters:
49+
// - params: Entry parameters to validate
50+
//
51+
// Returns:
52+
// - error: Non-nil with details about missing fields, nil if valid
3853
func ValidateEntry(params EntryParams) error {
3954
fType := strings.ToLower(params.Type)
4055

0 commit comments

Comments
 (0)