claude-code-wakatime 2.1.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +25 -0
- package/.claude-plugin/plugin.json +17 -0
- package/README.md +58 -11
- package/dist/index.js +41704 -119
- package/hooks/hooks.json +92 -0
- package/package.json +12 -13
- package/src/dependencies.ts +2 -2
- package/src/index.ts +91 -10
- package/src/install-hooks.ts +10 -1
- package/dist/dependencies.js +0 -416
- package/dist/install-hooks.js +0 -53
- package/dist/logger.js +0 -74
- package/dist/options.js +0 -214
- package/dist/utils.js +0 -129
- package/dist/version.js +0 -5
package/dist/dependencies.js
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Dependencies = void 0;
|
|
40
|
-
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
41
|
-
const child_process = __importStar(require("child_process"));
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
43
|
-
const os = __importStar(require("os"));
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const request = __importStar(require("request"));
|
|
46
|
-
const semver = __importStar(require("semver"));
|
|
47
|
-
const which = __importStar(require("which"));
|
|
48
|
-
const utils_1 = require("./utils");
|
|
49
|
-
var osName;
|
|
50
|
-
(function (osName) {
|
|
51
|
-
osName["darwin"] = "darwin";
|
|
52
|
-
osName["windows"] = "windows";
|
|
53
|
-
osName["linux"] = "linux";
|
|
54
|
-
})(osName || (osName = {}));
|
|
55
|
-
class Dependencies {
|
|
56
|
-
constructor(options, logger) {
|
|
57
|
-
this.cliLocation = undefined;
|
|
58
|
-
this.cliLocationGlobal = undefined;
|
|
59
|
-
this.cliInstalled = false;
|
|
60
|
-
this.githubDownloadUrl = 'https://github.com/wakatime/wakatime-cli/releases/latest/download';
|
|
61
|
-
this.githubReleasesUrl = 'https://api.github.com/repos/wakatime/wakatime-cli/releases/latest';
|
|
62
|
-
this.legacyOperatingSystems = {
|
|
63
|
-
[osName.darwin]: [{ kernelLessThan: '17.0.0', tag: 'v1.39.1-alpha.1' }],
|
|
64
|
-
};
|
|
65
|
-
this.options = options;
|
|
66
|
-
this.logger = logger;
|
|
67
|
-
this.resourcesLocation = options.resourcesLocation;
|
|
68
|
-
}
|
|
69
|
-
getCliLocation() {
|
|
70
|
-
if (this.cliLocation)
|
|
71
|
-
return this.cliLocation;
|
|
72
|
-
this.cliLocation = this.getCliLocationGlobal();
|
|
73
|
-
if (this.cliLocation)
|
|
74
|
-
return this.cliLocation;
|
|
75
|
-
const osname = this.osName();
|
|
76
|
-
const arch = this.architecture();
|
|
77
|
-
const ext = utils_1.Utils.isWindows() ? '.exe' : '';
|
|
78
|
-
const binary = `wakatime-cli-${osname}-${arch}${ext}`;
|
|
79
|
-
this.cliLocation = path.join(this.resourcesLocation, binary);
|
|
80
|
-
return this.cliLocation;
|
|
81
|
-
}
|
|
82
|
-
getCliLocationGlobal() {
|
|
83
|
-
if (this.cliLocationGlobal)
|
|
84
|
-
return this.cliLocationGlobal;
|
|
85
|
-
const binaryName = `wakatime-cli${utils_1.Utils.isWindows() ? '.exe' : ''}`;
|
|
86
|
-
const path = which.sync(binaryName, { nothrow: true });
|
|
87
|
-
if (path) {
|
|
88
|
-
this.cliLocationGlobal = path;
|
|
89
|
-
this.logger.debug(`Using global wakatime-cli location: ${path}`);
|
|
90
|
-
}
|
|
91
|
-
return this.cliLocationGlobal;
|
|
92
|
-
}
|
|
93
|
-
isCliInstalled() {
|
|
94
|
-
if (this.cliInstalled)
|
|
95
|
-
return true;
|
|
96
|
-
this.cliInstalled = fs.existsSync(this.getCliLocation());
|
|
97
|
-
return this.cliInstalled;
|
|
98
|
-
}
|
|
99
|
-
checkAndInstallCli(callback) {
|
|
100
|
-
if (!this.isCliInstalled()) {
|
|
101
|
-
this.installCli(callback ?? (() => { }));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.isCliLatest((isLatest) => {
|
|
105
|
-
if (!isLatest) {
|
|
106
|
-
this.installCli(callback ?? (() => { }));
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
callback?.();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
isCliLatest(callback) {
|
|
115
|
-
if (this.getCliLocationGlobal()) {
|
|
116
|
-
callback(true);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
let args = ['--version'];
|
|
120
|
-
const options = utils_1.Utils.buildOptions();
|
|
121
|
-
try {
|
|
122
|
-
child_process.execFile(this.getCliLocation(), args, options, (error, _stdout, stderr) => {
|
|
123
|
-
if (!(error != null)) {
|
|
124
|
-
let currentVersion = _stdout.toString().trim() + stderr.toString().trim();
|
|
125
|
-
this.logger.debug(`Current wakatime-cli version is ${currentVersion}`);
|
|
126
|
-
if (currentVersion === '<local-build>') {
|
|
127
|
-
callback(true);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const tag = this.legacyReleaseTag();
|
|
131
|
-
if (tag && currentVersion !== tag) {
|
|
132
|
-
callback(false);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const accessed = this.options.getSetting('internal', 'cli_version_last_accessed', true);
|
|
136
|
-
const now = Math.round(Date.now() / 1000);
|
|
137
|
-
const lastAccessed = parseInt(accessed ?? '0');
|
|
138
|
-
const fourHours = 4 * 3600;
|
|
139
|
-
if (lastAccessed && lastAccessed + fourHours > now) {
|
|
140
|
-
this.logger.debug(`Skip checking for wakatime-cli updates because recently checked ${now - lastAccessed} seconds ago.`);
|
|
141
|
-
callback(true);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.logger.debug('Checking for updates to wakatime-cli...');
|
|
145
|
-
this.getLatestCliVersion((latestVersion) => {
|
|
146
|
-
if (currentVersion === latestVersion) {
|
|
147
|
-
this.logger.debug('wakatime-cli is up to date');
|
|
148
|
-
callback(true);
|
|
149
|
-
}
|
|
150
|
-
else if (latestVersion) {
|
|
151
|
-
this.logger.debug(`Found an updated wakatime-cli ${latestVersion}`);
|
|
152
|
-
callback(false);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.logger.debug('Unable to find latest wakatime-cli version');
|
|
156
|
-
callback(false);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
callback(false);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
callback(false);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
getLatestCliVersion(callback) {
|
|
170
|
-
const proxy = this.options.getSetting('settings', 'proxy');
|
|
171
|
-
const noSSLVerify = this.options.getSetting('settings', 'no_ssl_verify');
|
|
172
|
-
let options = {
|
|
173
|
-
url: this.githubReleasesUrl,
|
|
174
|
-
json: true,
|
|
175
|
-
headers: {
|
|
176
|
-
'User-Agent': 'github.com/wakatime/vscode-wakatime',
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
this.logger.debug(`Fetching latest wakatime-cli version from GitHub API: ${options.url}`);
|
|
180
|
-
if (proxy) {
|
|
181
|
-
this.logger.debug(`Using Proxy: ${proxy}`);
|
|
182
|
-
options['proxy'] = proxy;
|
|
183
|
-
}
|
|
184
|
-
if (noSSLVerify === 'true')
|
|
185
|
-
options['strictSSL'] = false;
|
|
186
|
-
try {
|
|
187
|
-
request.get(options, (error, response, json) => {
|
|
188
|
-
if (!error && response && response.statusCode == 200) {
|
|
189
|
-
this.logger.debug(`GitHub API Response ${response.statusCode}`);
|
|
190
|
-
const latestCliVersion = json['tag_name'];
|
|
191
|
-
this.logger.debug(`Latest wakatime-cli version from GitHub: ${latestCliVersion}`);
|
|
192
|
-
this.options.setSetting('internal', 'cli_version_last_accessed', String(Math.round(Date.now() / 1000)), true);
|
|
193
|
-
callback(latestCliVersion);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
if (response) {
|
|
197
|
-
this.logger.warn(`GitHub API Response ${response.statusCode}: ${error}`);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
this.logger.warn(`GitHub API Response Error: ${error}`);
|
|
201
|
-
}
|
|
202
|
-
callback('');
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
this.logger.warnException(e);
|
|
208
|
-
callback('');
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
installCli(callback) {
|
|
212
|
-
this.logger.debug(`Downloading wakatime-cli from GitHub...`);
|
|
213
|
-
const url = this.cliDownloadUrl();
|
|
214
|
-
let zipFile = path.join(this.resourcesLocation, 'wakatime-cli' + this.randStr() + '.zip');
|
|
215
|
-
this.downloadFile(url, zipFile, () => {
|
|
216
|
-
this.extractCli(zipFile, callback);
|
|
217
|
-
}, callback);
|
|
218
|
-
}
|
|
219
|
-
isSymlink(file) {
|
|
220
|
-
try {
|
|
221
|
-
return fs.lstatSync(file).isSymbolicLink();
|
|
222
|
-
}
|
|
223
|
-
catch (_) { }
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
extractCli(zipFile, callback) {
|
|
227
|
-
this.logger.debug(`Extracting wakatime-cli into "${this.resourcesLocation}"...`);
|
|
228
|
-
this.backupCli();
|
|
229
|
-
this.unzip(zipFile, this.resourcesLocation, (unzipped) => {
|
|
230
|
-
if (!unzipped) {
|
|
231
|
-
this.restoreCli();
|
|
232
|
-
}
|
|
233
|
-
else if (!utils_1.Utils.isWindows()) {
|
|
234
|
-
this.removeCli();
|
|
235
|
-
const cli = this.getCliLocation();
|
|
236
|
-
try {
|
|
237
|
-
this.logger.debug('Chmod 755 wakatime-cli...');
|
|
238
|
-
fs.chmodSync(cli, 0o755);
|
|
239
|
-
}
|
|
240
|
-
catch (e) {
|
|
241
|
-
this.logger.warnException(e);
|
|
242
|
-
}
|
|
243
|
-
const ext = utils_1.Utils.isWindows() ? '.exe' : '';
|
|
244
|
-
const link = path.join(this.resourcesLocation, `wakatime-cli${ext}`);
|
|
245
|
-
if (!this.isSymlink(link)) {
|
|
246
|
-
try {
|
|
247
|
-
this.logger.debug(`Create symlink from wakatime-cli to ${cli}`);
|
|
248
|
-
fs.symlinkSync(cli, link);
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
this.logger.warnException(e);
|
|
252
|
-
try {
|
|
253
|
-
fs.copyFileSync(cli, link);
|
|
254
|
-
fs.chmodSync(link, 0o755);
|
|
255
|
-
}
|
|
256
|
-
catch (e2) {
|
|
257
|
-
this.logger.warnException(e2);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
callback();
|
|
263
|
-
});
|
|
264
|
-
this.logger.debug('Finished extracting wakatime-cli.');
|
|
265
|
-
}
|
|
266
|
-
backupCli() {
|
|
267
|
-
if (fs.existsSync(this.getCliLocation())) {
|
|
268
|
-
fs.renameSync(this.getCliLocation(), `${this.getCliLocation()}.backup`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
restoreCli() {
|
|
272
|
-
const backup = `${this.getCliLocation()}.backup`;
|
|
273
|
-
if (fs.existsSync(backup)) {
|
|
274
|
-
fs.renameSync(backup, this.getCliLocation());
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
removeCli() {
|
|
278
|
-
const backup = `${this.getCliLocation()}.backup`;
|
|
279
|
-
if (fs.existsSync(backup)) {
|
|
280
|
-
fs.unlinkSync(backup);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
downloadFile(url, outputFile, callback, error) {
|
|
284
|
-
const proxy = this.options.getSetting('settings', 'proxy');
|
|
285
|
-
const noSSLVerify = this.options.getSetting('settings', 'no_ssl_verify');
|
|
286
|
-
let options = { url: url };
|
|
287
|
-
if (proxy) {
|
|
288
|
-
this.logger.debug(`Using Proxy: ${proxy}`);
|
|
289
|
-
options['proxy'] = proxy;
|
|
290
|
-
}
|
|
291
|
-
if (noSSLVerify === 'true')
|
|
292
|
-
options['strictSSL'] = false;
|
|
293
|
-
try {
|
|
294
|
-
let r = request.get(options);
|
|
295
|
-
r.on('error', (e) => {
|
|
296
|
-
this.logger.warn(`Failed to download ${url}`);
|
|
297
|
-
this.logger.warn(e.toString());
|
|
298
|
-
error();
|
|
299
|
-
});
|
|
300
|
-
let out = fs.createWriteStream(outputFile);
|
|
301
|
-
r.pipe(out);
|
|
302
|
-
r.on('end', () => {
|
|
303
|
-
out.on('finish', () => {
|
|
304
|
-
callback();
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
catch (e) {
|
|
309
|
-
this.logger.warnException(e);
|
|
310
|
-
callback();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
unzip(file, outputDir, callback) {
|
|
314
|
-
if (fs.existsSync(file)) {
|
|
315
|
-
try {
|
|
316
|
-
let zip = new adm_zip_1.default(file);
|
|
317
|
-
zip.extractAllTo(outputDir, true);
|
|
318
|
-
fs.unlinkSync(file);
|
|
319
|
-
callback(true);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
catch (e) {
|
|
323
|
-
this.logger.warnException(e);
|
|
324
|
-
}
|
|
325
|
-
try {
|
|
326
|
-
fs.unlinkSync(file);
|
|
327
|
-
}
|
|
328
|
-
catch (e2) {
|
|
329
|
-
this.logger.warnException(e2);
|
|
330
|
-
}
|
|
331
|
-
callback(false);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
legacyReleaseTag() {
|
|
335
|
-
const osname = this.osName();
|
|
336
|
-
const legacyOS = this.legacyOperatingSystems[osname];
|
|
337
|
-
if (!legacyOS)
|
|
338
|
-
return;
|
|
339
|
-
const version = legacyOS.find((spec) => {
|
|
340
|
-
try {
|
|
341
|
-
return semver.lt(os.release(), spec.kernelLessThan);
|
|
342
|
-
}
|
|
343
|
-
catch (e) {
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
return version?.tag;
|
|
348
|
-
}
|
|
349
|
-
architecture() {
|
|
350
|
-
const arch = os.arch();
|
|
351
|
-
if (arch.indexOf('32') > -1)
|
|
352
|
-
return '386';
|
|
353
|
-
if (arch.indexOf('x64') > -1)
|
|
354
|
-
return 'amd64';
|
|
355
|
-
return arch;
|
|
356
|
-
}
|
|
357
|
-
osName() {
|
|
358
|
-
let osname = os.platform();
|
|
359
|
-
if (osname == 'win32')
|
|
360
|
-
osname = 'windows';
|
|
361
|
-
return osname;
|
|
362
|
-
}
|
|
363
|
-
cliDownloadUrl() {
|
|
364
|
-
const osname = this.osName();
|
|
365
|
-
const arch = this.architecture();
|
|
366
|
-
// Use legacy wakatime-cli release to support older operating systems
|
|
367
|
-
const tag = this.legacyReleaseTag();
|
|
368
|
-
if (tag) {
|
|
369
|
-
return `https://github.com/wakatime/wakatime-cli/releases/download/${tag}/wakatime-cli-${osname}-${arch}.zip`;
|
|
370
|
-
}
|
|
371
|
-
const validCombinations = [
|
|
372
|
-
'android-amd64',
|
|
373
|
-
'android-arm64',
|
|
374
|
-
'darwin-amd64',
|
|
375
|
-
'darwin-arm64',
|
|
376
|
-
'freebsd-386',
|
|
377
|
-
'freebsd-amd64',
|
|
378
|
-
'freebsd-arm',
|
|
379
|
-
'linux-386',
|
|
380
|
-
'linux-amd64',
|
|
381
|
-
'linux-arm',
|
|
382
|
-
'linux-arm64',
|
|
383
|
-
'netbsd-386',
|
|
384
|
-
'netbsd-amd64',
|
|
385
|
-
'netbsd-arm',
|
|
386
|
-
'openbsd-386',
|
|
387
|
-
'openbsd-amd64',
|
|
388
|
-
'openbsd-arm',
|
|
389
|
-
'openbsd-arm64',
|
|
390
|
-
'windows-386',
|
|
391
|
-
'windows-amd64',
|
|
392
|
-
'windows-arm64',
|
|
393
|
-
];
|
|
394
|
-
if (!validCombinations.includes(`${osname}-${arch}`))
|
|
395
|
-
this.reportMissingPlatformSupport(osname, arch);
|
|
396
|
-
return `${this.githubDownloadUrl}/wakatime-cli-${osname}-${arch}.zip`;
|
|
397
|
-
}
|
|
398
|
-
reportMissingPlatformSupport(osname, architecture) {
|
|
399
|
-
const url = `https://api.wakatime.com/api/v1/cli-missing?osname=${osname}&architecture=${architecture}&plugin=vscode`;
|
|
400
|
-
const proxy = this.options.getSetting('settings', 'proxy');
|
|
401
|
-
const noSSLVerify = this.options.getSetting('settings', 'no_ssl_verify');
|
|
402
|
-
let options = { url: url };
|
|
403
|
-
if (proxy)
|
|
404
|
-
options['proxy'] = proxy;
|
|
405
|
-
if (noSSLVerify === 'true')
|
|
406
|
-
options['strictSSL'] = false;
|
|
407
|
-
try {
|
|
408
|
-
request.get(options);
|
|
409
|
-
}
|
|
410
|
-
catch (e) { }
|
|
411
|
-
}
|
|
412
|
-
randStr() {
|
|
413
|
-
return (Math.random() + 1).toString(36).substring(7);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
exports.Dependencies = Dependencies;
|
package/dist/install-hooks.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const os_1 = __importDefault(require("os"));
|
|
9
|
-
const CLAUDE_SETTINGS = path_1.default.join(os_1.default.homedir(), '.claude', 'settings.json');
|
|
10
|
-
const HOOK_EVENTS = ['PreToolUse', 'PostToolUse', 'UserPromptSubmit', 'SessionStart', 'Stop'];
|
|
11
|
-
function loadSettings() {
|
|
12
|
-
if (!fs_1.default.existsSync(CLAUDE_SETTINGS)) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
return JSON.parse(fs_1.default.readFileSync(CLAUDE_SETTINGS, 'utf-8'));
|
|
16
|
-
}
|
|
17
|
-
function saveSettings(settings) {
|
|
18
|
-
fs_1.default.mkdirSync(path_1.default.dirname(CLAUDE_SETTINGS), { recursive: true });
|
|
19
|
-
fs_1.default.writeFileSync(CLAUDE_SETTINGS, JSON.stringify(settings, null, 2));
|
|
20
|
-
}
|
|
21
|
-
function installHooks() {
|
|
22
|
-
const settings = loadSettings();
|
|
23
|
-
settings.hooks = settings.hooks || {};
|
|
24
|
-
const hook = {
|
|
25
|
-
matcher: '*',
|
|
26
|
-
hooks: [
|
|
27
|
-
{
|
|
28
|
-
type: 'command',
|
|
29
|
-
command: 'claude-code-wakatime',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
};
|
|
33
|
-
let hookAlreadyExists = true;
|
|
34
|
-
for (const event of HOOK_EVENTS) {
|
|
35
|
-
settings.hooks[event] = settings.hooks[event] || [];
|
|
36
|
-
// Check if a hook with the same command already exists
|
|
37
|
-
const existingHook = settings.hooks[event].find((existingHook) => existingHook.hooks &&
|
|
38
|
-
Array.isArray(existingHook.hooks) &&
|
|
39
|
-
existingHook.hooks.some((hookItem) => hookItem.command === 'claude-code-wakatime'));
|
|
40
|
-
if (!existingHook) {
|
|
41
|
-
settings.hooks[event].push(hook);
|
|
42
|
-
hookAlreadyExists = false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (hookAlreadyExists) {
|
|
46
|
-
console.log(`WakaTime hooks already installed in Claude ${CLAUDE_SETTINGS}`);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
saveSettings(settings);
|
|
50
|
-
console.log(`WakaTime hooks installed in Claude ${CLAUDE_SETTINGS}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
installHooks();
|
package/dist/logger.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Logger = exports.LogLevel = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const os_1 = __importDefault(require("os"));
|
|
10
|
-
var LogLevel;
|
|
11
|
-
(function (LogLevel) {
|
|
12
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
13
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
14
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
15
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
16
|
-
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
17
|
-
const LOG_FILE = path_1.default.join(os_1.default.homedir(), '.wakatime', 'claude-code.log');
|
|
18
|
-
class Logger {
|
|
19
|
-
constructor(level) {
|
|
20
|
-
this.level = LogLevel.INFO;
|
|
21
|
-
if (level !== undefined)
|
|
22
|
-
this.setLevel(level);
|
|
23
|
-
}
|
|
24
|
-
getLevel() {
|
|
25
|
-
return this.level;
|
|
26
|
-
}
|
|
27
|
-
setLevel(level) {
|
|
28
|
-
this.level = level;
|
|
29
|
-
}
|
|
30
|
-
log(level, msg) {
|
|
31
|
-
if (level >= this.level) {
|
|
32
|
-
msg = `[${new Date().toISOString()}][${LogLevel[level]}] ${msg}\n`;
|
|
33
|
-
fs_1.default.mkdirSync(path_1.default.dirname(LOG_FILE), { recursive: true });
|
|
34
|
-
fs_1.default.appendFileSync(LOG_FILE, msg);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
debug(msg) {
|
|
38
|
-
this.log(LogLevel.DEBUG, msg);
|
|
39
|
-
}
|
|
40
|
-
debugException(msg) {
|
|
41
|
-
if (msg.message !== undefined) {
|
|
42
|
-
this.log(LogLevel.DEBUG, msg.message);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.log(LogLevel.DEBUG, msg.toString());
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
info(msg) {
|
|
49
|
-
this.log(LogLevel.INFO, msg);
|
|
50
|
-
}
|
|
51
|
-
warn(msg) {
|
|
52
|
-
this.log(LogLevel.WARN, msg);
|
|
53
|
-
}
|
|
54
|
-
warnException(msg) {
|
|
55
|
-
if (msg.message !== undefined) {
|
|
56
|
-
this.log(LogLevel.WARN, msg.message);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.log(LogLevel.WARN, msg.toString());
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
error(msg) {
|
|
63
|
-
this.log(LogLevel.ERROR, msg);
|
|
64
|
-
}
|
|
65
|
-
errorException(msg) {
|
|
66
|
-
if (msg.message !== undefined) {
|
|
67
|
-
this.log(LogLevel.ERROR, msg.message);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this.log(LogLevel.ERROR, msg.toString());
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.Logger = Logger;
|