claude-code-wakatime 2.2.0 → 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 +41693 -182
- package/hooks/hooks.json +92 -0
- package/package.json +12 -13
- package/src/dependencies.ts +2 -2
- package/src/index.ts +6 -8
- 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/hooks/hooks.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"SessionEnd": [
|
|
15
|
+
{
|
|
16
|
+
"matcher": "",
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"PreToolUse": [
|
|
26
|
+
{
|
|
27
|
+
"matcher": "",
|
|
28
|
+
"hooks": [
|
|
29
|
+
{
|
|
30
|
+
"type": "command",
|
|
31
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"PostToolUse": [
|
|
37
|
+
{
|
|
38
|
+
"matcher": "",
|
|
39
|
+
"hooks": [
|
|
40
|
+
{
|
|
41
|
+
"type": "command",
|
|
42
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"UserPromptSubmit": [
|
|
48
|
+
{
|
|
49
|
+
"matcher": "",
|
|
50
|
+
"hooks": [
|
|
51
|
+
{
|
|
52
|
+
"type": "command",
|
|
53
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"PreCompact": [
|
|
59
|
+
{
|
|
60
|
+
"matcher": "",
|
|
61
|
+
"hooks": [
|
|
62
|
+
{
|
|
63
|
+
"type": "command",
|
|
64
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"SubagentStop": [
|
|
70
|
+
{
|
|
71
|
+
"matcher": "",
|
|
72
|
+
"hooks": [
|
|
73
|
+
{
|
|
74
|
+
"type": "command",
|
|
75
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"Stop": [
|
|
81
|
+
{
|
|
82
|
+
"matcher": "",
|
|
83
|
+
"hooks": [
|
|
84
|
+
{
|
|
85
|
+
"type": "command",
|
|
86
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-wakatime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "WakaTime plugin for Claude Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"claude-code-wakatime": "dist/index.js"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"postinstall": "node dist/install-hooks.js",
|
|
10
10
|
"prebuild": "node scripts/generate-version.js",
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
|
|
12
12
|
"watch": "npm run prebuild && tsc --watch",
|
|
13
13
|
"release:major": "npm version major && npm publish && git push && git push --tags",
|
|
14
14
|
"release:minor": "npm version minor && npm publish && git push && git push --tags",
|
|
@@ -24,28 +24,27 @@
|
|
|
24
24
|
"time-tracking",
|
|
25
25
|
"ai"
|
|
26
26
|
],
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"adm-zip": "0.5.16",
|
|
29
|
-
"request": "2.88.2",
|
|
30
|
-
"semver": "^7.7.2",
|
|
31
|
-
"which": "^5.0.0"
|
|
32
|
-
},
|
|
33
27
|
"devDependencies": {
|
|
28
|
+
"@types/adm-zip": "^0.5.7",
|
|
29
|
+
"@types/azdata": "^1.46.6",
|
|
34
30
|
"@types/eslint": "^8.44.7",
|
|
35
31
|
"@types/node": "^20.9.2",
|
|
36
32
|
"@types/pidusage": "^2.0.5",
|
|
37
33
|
"@types/prettier": "^2.7.3",
|
|
38
|
-
"@types/adm-zip": "^0.5.7",
|
|
39
|
-
"@types/azdata": "^1.46.6",
|
|
40
34
|
"@types/request": "^2.48.12",
|
|
41
35
|
"@types/semver": "^7.7.0",
|
|
36
|
+
"@types/which": "^3.0.4",
|
|
42
37
|
"@typescript-eslint/eslint-plugin": "6.11.0",
|
|
43
38
|
"@typescript-eslint/parser": "6.11.0",
|
|
44
|
-
"
|
|
45
|
-
"eslint": "^8.54.0",
|
|
39
|
+
"adm-zip": "0.5.16",
|
|
46
40
|
"azdata": "^1.0.0",
|
|
41
|
+
"esbuild": "^0.25.12",
|
|
42
|
+
"eslint": "^8.54.0",
|
|
47
43
|
"prettier": "^3.1.0",
|
|
48
|
-
"
|
|
44
|
+
"request": "2.88.2",
|
|
45
|
+
"semver": "^7.7.2",
|
|
46
|
+
"typescript": "^5.2.2",
|
|
47
|
+
"which": "^5.0.0"
|
|
49
48
|
},
|
|
50
49
|
"author": "WakaTime",
|
|
51
50
|
"license": "BSD-3-Clause",
|
package/src/dependencies.ts
CHANGED
|
@@ -153,7 +153,7 @@ export class Dependencies {
|
|
|
153
153
|
url: this.githubReleasesUrl,
|
|
154
154
|
json: true,
|
|
155
155
|
headers: {
|
|
156
|
-
'User-Agent': 'github.com/wakatime/
|
|
156
|
+
'User-Agent': 'github.com/wakatime/claude-code-wakatime',
|
|
157
157
|
},
|
|
158
158
|
};
|
|
159
159
|
this.logger.debug(`Fetching latest wakatime-cli version from GitHub API: ${options.url}`);
|
|
@@ -378,7 +378,7 @@ export class Dependencies {
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
private reportMissingPlatformSupport(osname: string, architecture: string): void {
|
|
381
|
-
const url = `https://api.wakatime.com/api/v1/cli-missing?osname=${osname}&architecture=${architecture}&plugin=
|
|
381
|
+
const url = `https://api.wakatime.com/api/v1/cli-missing?osname=${osname}&architecture=${architecture}&plugin=claude-code`;
|
|
382
382
|
const proxy = this.options.getSetting('settings', 'proxy');
|
|
383
383
|
const noSSLVerify = this.options.getSetting('settings', 'no_ssl_verify');
|
|
384
384
|
let options: request.CoreOptions & { url: string } = { url: url };
|
package/src/index.ts
CHANGED
|
@@ -214,15 +214,13 @@ function sendHeartbeat(inp: Input | undefined) {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
logger.debug(`Sending heartbeat: ${args}`);
|
|
218
|
+
|
|
217
219
|
const options = Utils.buildOptions();
|
|
218
|
-
execFile(WAKATIME_CLI, args, options, (error,
|
|
219
|
-
const output =
|
|
220
|
-
if (output)
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
if (!(error != null)) {
|
|
224
|
-
logger.debug(`Sending heartbeat: ${args}`);
|
|
225
|
-
}
|
|
220
|
+
execFile(WAKATIME_CLI, args, options, (error, stdout, stderr) => {
|
|
221
|
+
const output = stdout.toString().trim() + stderr.toString().trim();
|
|
222
|
+
if (output) logger.error(output);
|
|
223
|
+
if (error) logger.error(error.toString());
|
|
226
224
|
});
|
|
227
225
|
} catch (err: any) {
|
|
228
226
|
logger.errorException(err);
|
package/src/install-hooks.ts
CHANGED
|
@@ -3,7 +3,16 @@ import path from 'path';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
|
|
5
5
|
const CLAUDE_SETTINGS = path.join(os.homedir(), '.claude', 'settings.json');
|
|
6
|
-
const HOOK_EVENTS = [
|
|
6
|
+
const HOOK_EVENTS = [
|
|
7
|
+
'PreToolUse',
|
|
8
|
+
'PostToolUse',
|
|
9
|
+
'SessionStart',
|
|
10
|
+
'SessionEnd',
|
|
11
|
+
'UserPromptSubmit',
|
|
12
|
+
'PreCompact',
|
|
13
|
+
'SubagentStop',
|
|
14
|
+
'Stop',
|
|
15
|
+
];
|
|
7
16
|
|
|
8
17
|
function loadSettings(): any {
|
|
9
18
|
if (!fs.existsSync(CLAUDE_SETTINGS)) {
|
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();
|