@@ -20,6 +20,7 @@ A local code analysis tool that parses codebases via Tree-sitter into a knowledg
2020| ` search <query> ` | FTS keyword search (includes @annotations ) | ` ccg search "authentication" ` |
2121| ` search --semantic <q> ` | Vector similarity search | ` ccg search --semantic "payment flow" ` |
2222| ` query <cypher> ` | Execute Cypher query on AGE graph | ` ccg query "MATCH (n:Function) RETURN n" ` |
23+ | ` annotate [file\|dir] ` | AI-generate annotations for code | ` ccg annotate internal/analysis/ ` |
2324
2425## Execution
2526
@@ -41,11 +42,74 @@ Show available commands:
4142
4243```
4344Available ccg commands:
44- ccg build [dir] — Build code knowledge graph
45- ccg update [dir] — Incremental update
46- ccg status — Graph statistics
47- ccg search <query> — Full-text search (annotations included)
48- ccg query <cypher> — Execute Cypher query (requires AGE)
45+ ccg build [dir] — Build code knowledge graph
46+ ccg update [dir] — Incremental update
47+ ccg status — Graph statistics
48+ ccg search <query> — Full-text search (annotations included)
49+ ccg query <cypher> — Execute Cypher query (requires AGE)
50+ ccg annotate [file|dir] — AI-generate @annotations for code
51+ ```
52+
53+ ## Annotate Command
54+
55+ ` ccg annotate ` is NOT a CLI binary command — it is an AI-driven workflow executed by Claude.
56+
57+ When the user runs ` ccg annotate [file|dir] ` , Claude should:
58+
59+ ### Step 1: Read target files
60+ - If a file path is given, read that file
61+ - If a directory is given, find all source files (` .go ` , ` .py ` , ` .ts ` , ` .java ` , etc.)
62+ - Skip test files, vendor, node_modules
63+
64+ ### Step 2: Analyze each function/class/file
65+ For each declaration, read the code and determine:
66+ - ** What it does** (→ summary line above declaration)
67+ - ** Why it exists** (→ ` @intent ` )
68+ - ** Business rules it enforces** (→ ` @domainRule ` )
69+ - ** Side effects** (→ ` @sideEffect ` : DB writes, API calls, file I/O, notifications)
70+ - ** What state it changes** (→ ` @mutates ` : fields, tables, caches)
71+ - ** Prerequisites** (→ ` @requires ` : auth, valid input, active state)
72+ - ** Guarantees** (→ ` @ensures ` : return conditions, post-state)
73+ - ** File/package purpose** (→ ` @index ` on package declaration)
74+
75+ ### Step 3: Write annotations
76+ - Add annotations as comments directly above the declaration
77+ - Use the language's comment syntax (` // ` for Go, ` # ` for Python, etc.)
78+ - Do NOT overwrite existing annotations — only add missing ones
79+ - Do NOT add trivial annotations (e.g., ` @intent returns the name ` for ` getName() ` )
80+
81+ ### Step 4: Rebuild
82+ After annotating, run ` ccg build . ` to re-index with new annotations.
83+
84+ ### Annotation Quality Rules
85+ - ` @intent ` should describe WHY, not WHAT (not "creates user" but "register new account for onboarding flow")
86+ - ` @domainRule ` should be specific business logic, not generic validation
87+ - ` @sideEffect ` only for actual side effects (DB, network, file, notification)
88+ - ` @index ` should summarize the module's responsibility in one line
89+ - Skip getters/setters/trivial functions — annotate functions with business meaning
90+ - Write annotations in the same language as existing code comments (Korean if Korean, English if English)
91+
92+ ### Example output
93+
94+ ``` go
95+ // @index User authentication and session management service.
96+ package auth
97+
98+ // AuthenticateUser validates credentials and creates a session.
99+ // Called from login API handler.
100+ //
101+ // @param username user login ID
102+ // @param password plaintext password (hashed internally)
103+ // @return JWT token on success
104+ // @intent verify user identity before granting system access
105+ // @domainRule lock account after 5 consecutive failed attempts
106+ // @domainRule locked accounts auto-unlock after 30 minutes
107+ // @sideEffect writes login attempt to audit_log table
108+ // @sideEffect sends security alert email on 3rd failed attempt
109+ // @mutates user.FailedAttempts, user.LockedUntil, user.LastLoginAt
110+ // @requires user.IsActive == true
111+ // @ensures err == nil implies valid JWT with 24h expiry
112+ func AuthenticateUser (username , password string ) (string , error ) {
49113` ` `
50114
51115## Smart Behaviors
0 commit comments