Skip to content

Commit 9d7e664

Browse files
committed
docs: add CLI output convention and broaden audit scope
- Document cmd.Printf/cmd.Println convention in CONVENTIONS.md - Add code pattern drift checking to audit-docs skill - Add pre-flight checklist for CLI code in AGENT_PLAYBOOK.md - Add task for AST-based linter test - Fix package doc comment (initialize, not initcmd) Signed-off-by: Jose Alekhinne <alekhinejose@gmail.com>
1 parent a19b73e commit 9d7e664

6 files changed

Lines changed: 92 additions & 8 deletions

File tree

.claude/commands/audit-docs.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ Review prose docs for internal consistency.
5757
- Outdated references to removed features
5858
- Tone inconsistencies
5959
60+
### 4. Code Pattern Drift
61+
62+
Check that code follows established conventions in CONVENTIONS.md.
63+
64+
**Check for:**
65+
- CLI output methods: `fmt.Print*` instead of `cmd.Print*` in CLI code
66+
- Other patterns documented in CONVENTIONS.md
67+
68+
**Method:**
69+
1. Read CONVENTIONS.md to understand established patterns
70+
2. Grep for violations (e.g., `fmt.Print` in `internal/cli/**/*.go`)
71+
3. Flag files that violate conventions
72+
73+
**Files to scan:** `internal/cli/**/*.go` for CLI patterns
74+
6075
## Output Format
6176
6277
Produce a structured report:
@@ -68,6 +83,7 @@ Produce a structured report:
6883
- X Go docstring issues found
6984
- Y CLI/docs mismatches found
7085
- Z narrative inconsistencies flagged
86+
- W code pattern violations found
7187

7288
## Go Docstring Issues
7389

@@ -92,14 +108,22 @@ Produce a structured report:
92108

93109
### Outdated References
94110
- `docs/integrations.md:45` — References removed `--minimal` flag
111+
112+
## Code Pattern Violations
113+
114+
### CLI Output Methods
115+
- `internal/cli/task/run.go:127` — Uses `fmt.Printf` instead of `cmd.Printf`
116+
- `internal/cli/watch/run.go:45` — Uses `fmt.Println` instead of `cmd.Println`
95117
```
96118
97119
## Execution
98120
99-
1. **Scan Go files** for docstring patterns
100-
2. **Parse docs/*.md** for CLI references
101-
3. **Run ctx --help** variants to get actual CLI surface
102-
4. **Compare and report**
121+
1. **Read CONVENTIONS.md** to understand established patterns
122+
2. **Scan Go files** for docstring patterns
123+
3. **Parse docs/*.md** for CLI references
124+
4. **Run ctx --help** variants to get actual CLI surface
125+
5. **Check code patterns** against conventions (e.g., CLI output methods)
126+
6. **Compare and report**
103127
104128
Do NOT auto-fix anything. This audit produces a report for human review.
105129

.context/AGENT_PLAYBOOK.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,24 @@ Never assume: If you don't see it in files, you don't know it.
360360
- If uncertain, say "I don't see this documented"
361361
- Trust files over intuition
362362

363+
## Pre-Flight Checklist: CLI Code
364+
365+
Before writing or modifying CLI code (`internal/cli/**/*.go`):
366+
367+
1. **Read CONVENTIONS.md** — Load established patterns into context
368+
2. **Check similar commands** — How do existing commands in the same package handle output?
369+
3. **Use cmd methods for output**`cmd.Printf`, `cmd.Println`, not `fmt.Printf`, `fmt.Println`
370+
4. **Follow docstring format** — See Go Documentation Standard below
371+
372+
**Quick pattern check:**
373+
```bash
374+
# See how other commands do output
375+
grep -n "cmd.Printf\|cmd.Println" internal/cli/status/*.go
376+
377+
# Spot violations in your changes
378+
grep -n "fmt.Printf\|fmt.Println" internal/cli/yourpackage/*.go
379+
```
380+
363381
## Go Documentation Standard
364382

365383
When writing Go code, follow this docstring format consistently.

.context/CONVENTIONS.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@
44

55
## Patterns
66

7+
### CLI Output Methods
8+
9+
In CLI command code (`internal/cli/**/*.go`), always use Cobra's command methods
10+
for output instead of raw `fmt` functions:
11+
12+
```go
13+
// ✓ Correct - uses cmd methods
14+
cmd.Printf("%s Done\n", green(""))
15+
cmd.Println("Status:")
16+
fmt.Fprintln(cmd.OutOrStdout(), "Output here")
17+
18+
// ✗ Wrong - bypasses Cobra's output handling
19+
fmt.Printf("%s Done\n", green(""))
20+
fmt.Println("Status:")
21+
```
22+
23+
**Why this matters:**
24+
- Cobra's `cmd.OutOrStdout()` respects output redirection in tests
25+
- Makes CLI commands testable without capturing os.Stdout
26+
- Consistent pattern across all commands
27+
28+
**Exceptions:**
29+
- Helper functions that don't have access to `*cobra.Command` may use `fmt`
30+
- But prefer passing `io.Writer` or the command down to helpers
31+
732
## Testing
833

934
## Documentation

.context/TASKS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
## Backlog
5050

51+
- [ ] Write AST-based test that warns if CLI functions use fmt.Print* instead of cmd.Print* #added:2026-01-29-171351
52+
5153
- [ ] feat: ctx journal - LLM-powered session analysis and synthesis
5254

5355
Parent command for working with exported sessions (.context/journal/):

internal/cli/initialize/doc.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
// \ Copyright 2026-present Context contributors.
55
// SPDX-License-Identifier: Apache-2.0
66

7-
// Package initcmd implements the "ctx init" command for initializing a
7+
// Package initialize implements the "ctx init" command for initializing a
88
// .context/ directory with template files.
99
//
1010
// The init command creates the foundation for persistent AI context by
1111
// generating template files for constitution rules, tasks, decisions,
1212
// learnings, conventions, and architecture documentation. It also sets
1313
// up Claude Code integration with hooks and slash commands.
1414
//
15-
// Note: This package is named "initcmd" because "init" is a reserved
16-
// keyword in Go for package initialization functions.
17-
//
1815
// # File Organization
1916
//
2017
// - init.go: Command definition and flag registration

internal/templates/AGENT_PLAYBOOK.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,24 @@ the codebase. Periodic consolidation prevents this from compounding.
284284

285285
When in doubt, ask: "Would a new contributor understand where this belongs?"
286286

287+
## Pre-Flight Checklist: CLI Code
288+
289+
Before writing or modifying CLI code (`internal/cli/**/*.go`):
290+
291+
1. **Read CONVENTIONS.md** — Load established patterns into context
292+
2. **Check similar commands** — How do existing commands in the same package handle output?
293+
3. **Use cmd methods for output**`cmd.Printf`, `cmd.Println`, not `fmt.Printf`, `fmt.Println`
294+
4. **Follow docstring format** — See Go Documentation Standard below
295+
296+
**Quick pattern check:**
297+
```bash
298+
# See how other commands do output
299+
grep -n "cmd.Printf\|cmd.Println" internal/cli/status/*.go
300+
301+
# Spot violations in your changes
302+
grep -n "fmt.Printf\|fmt.Println" internal/cli/yourpackage/*.go
303+
```
304+
287305
## Go Documentation Standard
288306

289307
When writing Go code, follow this docstring format consistently.

0 commit comments

Comments
 (0)