-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.js
More file actions
113 lines (96 loc) · 2.79 KB
/
paths.js
File metadata and controls
113 lines (96 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Shared paths module for GitGud
* Uses ~/.gitgud/ for persistent cross-platform data storage
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
// Plugin root (for reading default config)
const PLUGIN_ROOT = process.env.CLAUDE_PLUGIN_ROOT || path.dirname(__dirname);
// User data directory: ~/.gitgud/
const USER_DATA_DIR = path.join(os.homedir(), '.gitgud');
// Ensure user data directory exists
if (!fs.existsSync(USER_DATA_DIR)) {
fs.mkdirSync(USER_DATA_DIR, { recursive: true });
}
// Config file in user directory (persists across plugin updates)
const CONFIG_FILE = path.join(USER_DATA_DIR, 'config.json');
// State files
const COUNTER_FILE = path.join(USER_DATA_DIR, 'request_counter');
const PENDING_TASK_FILE = path.join(USER_DATA_DIR, 'pending_task');
const SKIPS_FILE = path.join(USER_DATA_DIR, 'daily_skips');
const LAST_SKIP_DATE_FILE = path.join(USER_DATA_DIR, 'last_skip_date');
const STREAK_FILE = path.join(USER_DATA_DIR, 'streak_data');
const ACHIEVEMENTS_FILE = path.join(USER_DATA_DIR, 'achievements.json');
const STATS_FILE = path.join(USER_DATA_DIR, 'stats.json');
const HISTORY_FILE = path.join(USER_DATA_DIR, 'task_history.jsonl');
// Default configuration
const DEFAULT_CONFIG = {
frequency: 10,
daily_skips: 3,
difficulty: 'adaptive',
enabled: true
};
// Helper functions
function readFile(filePath, defaultValue) {
try {
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath, 'utf8').trim();
}
} catch (e) {}
return defaultValue;
}
function readJsonFile(filePath, defaultValue) {
try {
if (fs.existsSync(filePath)) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
} catch (e) {}
return defaultValue;
}
function writeFile(filePath, content) {
fs.writeFileSync(filePath, String(content));
}
function writeJsonFile(filePath, data) {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
}
function appendFile(filePath, content) {
fs.appendFileSync(filePath, content + '\n');
}
function readConfig() {
return { ...DEFAULT_CONFIG, ...readJsonFile(CONFIG_FILE, {}) };
}
function writeConfig(config) {
writeJsonFile(CONFIG_FILE, config);
}
function getToday() {
return new Date().toISOString().split('T')[0];
}
function getYesterday() {
const d = new Date();
d.setDate(d.getDate() - 1);
return d.toISOString().split('T')[0];
}
module.exports = {
PLUGIN_ROOT,
USER_DATA_DIR,
CONFIG_FILE,
COUNTER_FILE,
PENDING_TASK_FILE,
SKIPS_FILE,
LAST_SKIP_DATE_FILE,
STREAK_FILE,
ACHIEVEMENTS_FILE,
STATS_FILE,
HISTORY_FILE,
DEFAULT_CONFIG,
readFile,
readJsonFile,
writeFile,
writeJsonFile,
appendFile,
readConfig,
writeConfig,
getToday,
getYesterday
};