auto-update-daily-20260202
1package paths
2
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7 "time"
8)
9
10// ClaudeDir returns the base Claude directory (~/.claude or CLAUDE_DIR env var)
11func ClaudeDir() string {
12 if dir := os.Getenv("CLAUDE_DIR"); dir != "" {
13 return dir
14 }
15 home, err := os.UserHomeDir()
16 if err != nil {
17 fmt.Fprintf(os.Stderr, "Error getting home directory: %v\n", err)
18 os.Exit(1)
19 }
20 return filepath.Join(home, ".claude")
21}
22
23// HooksDir returns the hooks directory
24func HooksDir() string {
25 return filepath.Join(ClaudeDir(), "hooks")
26}
27
28// SkillsDir returns the skills directory
29func SkillsDir() string {
30 return filepath.Join(ClaudeDir(), "skills")
31}
32
33// AgentsDir returns the agents directory
34func AgentsDir() string {
35 return filepath.Join(ClaudeDir(), "agents")
36}
37
38// HistoryDir returns the history directory
39func HistoryDir() string {
40 return filepath.Join(ClaudeDir(), "history")
41}
42
43// GetHistoryFilePath returns a history file path with year-month organization
44func GetHistoryFilePath(subdir, filename string) string {
45 now := time.Now()
46 yearMonth := now.Format("2006-01")
47 return filepath.Join(HistoryDir(), subdir, yearMonth, filename)
48}
49
50// GetTimestamp returns current timestamp in YYYY-MM-DD-HHMMSS format
51func GetTimestamp() string {
52 return time.Now().Format("2006-01-02-150405")
53}
54
55// GetDate returns current date in YYYY-MM-DD format
56func GetDate() string {
57 return time.Now().Format("2006-01-02")
58}
59
60// GetYearMonth returns current year-month in YYYY-MM format
61func GetYearMonth() string {
62 return time.Now().Format("2006-01")
63}
64
65// ValidateClaudeStructure validates that the Claude directory exists
66func ValidateClaudeStructure() error {
67 claudeDir := ClaudeDir()
68 if _, err := os.Stat(claudeDir); os.IsNotExist(err) {
69 return fmt.Errorf("CLAUDE_DIR does not exist: %s\nExpected ~/.claude or set CLAUDE_DIR environment variable", claudeDir)
70 }
71 return nil
72}
73
74// EnsureHistoryDir creates the history directory structure if needed
75func EnsureHistoryDir(subdir string) error {
76 yearMonth := GetYearMonth()
77 dir := filepath.Join(HistoryDir(), subdir, yearMonth)
78 return os.MkdirAll(dir, 0755)
79}