claude-code-wakatime 3.0.1 → 3.0.2

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.
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // src/install-hooks.ts
26
+ var import_fs = __toESM(require("fs"));
27
+ var import_path = __toESM(require("path"));
28
+ var import_os = __toESM(require("os"));
29
+ var CLAUDE_SETTINGS = import_path.default.join(import_os.default.homedir(), ".claude", "settings.json");
30
+ var HOOK_EVENTS = ["PreToolUse", "PostToolUse", "SessionEnd", "UserPromptSubmit", "PreCompact", "SubagentStop", "Stop"];
31
+ function loadSettings() {
32
+ if (!import_fs.default.existsSync(CLAUDE_SETTINGS)) {
33
+ return {};
34
+ }
35
+ return JSON.parse(import_fs.default.readFileSync(CLAUDE_SETTINGS, "utf-8"));
36
+ }
37
+ function saveSettings(settings) {
38
+ import_fs.default.mkdirSync(import_path.default.dirname(CLAUDE_SETTINGS), { recursive: true });
39
+ import_fs.default.writeFileSync(CLAUDE_SETTINGS, JSON.stringify(settings, null, 2));
40
+ }
41
+ function installHooks() {
42
+ const settings = loadSettings();
43
+ settings.hooks = settings.hooks || {};
44
+ const hook = {
45
+ matcher: "*",
46
+ hooks: [
47
+ {
48
+ type: "command",
49
+ command: "claude-code-wakatime"
50
+ }
51
+ ]
52
+ };
53
+ let hookAlreadyExists = true;
54
+ for (const event of HOOK_EVENTS) {
55
+ settings.hooks[event] = settings.hooks[event] || [];
56
+ const existingHook = settings.hooks[event].find(
57
+ (existingHook2) => existingHook2.hooks && Array.isArray(existingHook2.hooks) && existingHook2.hooks.some((hookItem) => hookItem.command === "claude-code-wakatime")
58
+ );
59
+ if (!existingHook) {
60
+ settings.hooks[event].push(hook);
61
+ hookAlreadyExists = false;
62
+ }
63
+ }
64
+ if (hookAlreadyExists) {
65
+ console.log(`WakaTime hooks already installed in Claude ${CLAUDE_SETTINGS}`);
66
+ } else {
67
+ saveSettings(settings);
68
+ console.log(`WakaTime hooks installed in Claude ${CLAUDE_SETTINGS}`);
69
+ }
70
+ }
71
+ installHooks();
package/hooks/hooks.json CHANGED
@@ -1,16 +1,5 @@
1
1
  {
2
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
3
  "SessionEnd": [
15
4
  {
16
5
  "matcher": "",
@@ -89,4 +78,4 @@
89
78
  }
90
79
  ]
91
80
  }
92
- }
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-wakatime",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "WakaTime plugin for Claude Code",
5
5
  "bin": {
6
6
  "claude-code-wakatime": "dist/index.js"
@@ -8,7 +8,8 @@
8
8
  "scripts": {
9
9
  "postinstall": "node dist/install-hooks.js",
10
10
  "prebuild": "node scripts/generate-version.js",
11
- "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
11
+ "build:legacy": "esbuild src/install-hooks.ts --bundle --platform=node --outfile=dist/install-hooks.js",
12
+ "build": "npm run build:legacy && esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
12
13
  "watch": "npm run prebuild && tsc --watch",
13
14
  "release:major": "npm run build && npm version major && npm publish && git push && git push --tags",
14
15
  "release:minor": "npm run build && npm version minor && npm publish && git push && git push --tags",
package/src/index.ts CHANGED
@@ -11,8 +11,9 @@ import { Utils } from './utils';
11
11
  import { Logger, LogLevel } from './logger';
12
12
 
13
13
  const STATE_FILE = path.join(os.homedir(), '.wakatime', 'claude-code.json');
14
- const WAKATIME_CLI = path.join(os.homedir(), '.wakatime', 'wakatime-cli');
15
14
  const logger = new Logger();
15
+ const options = new Options();
16
+ const deps = new Dependencies(options, logger);
16
17
 
17
18
  type State = {
18
19
  lastHeartbeatAt?: number;
@@ -191,6 +192,8 @@ function sendHeartbeat(inp: Input | undefined) {
191
192
  const entity = getEntityFile(inp);
192
193
  if (!entity) return;
193
194
 
195
+ const wakatime_cli = deps.getCliLocation();
196
+
194
197
  const args: string[] = [
195
198
  '--entity',
196
199
  entity,
@@ -214,10 +217,10 @@ function sendHeartbeat(inp: Input | undefined) {
214
217
  }
215
218
  }
216
219
 
217
- logger.debug(`Sending heartbeat: ${args}`);
220
+ logger.debug(`Sending heartbeat: ${wakatime_cli} ${args}`);
218
221
 
219
- const options = Utils.buildOptions();
220
- execFile(WAKATIME_CLI, args, options, (error, stdout, stderr) => {
222
+ const execOptions = Utils.buildOptions();
223
+ execFile(wakatime_cli, args, execOptions, (error, stdout, stderr) => {
221
224
  const output = stdout.toString().trim() + stderr.toString().trim();
222
225
  if (output) logger.error(output);
223
226
  if (error) logger.error(error.toString());
@@ -230,10 +233,8 @@ function sendHeartbeat(inp: Input | undefined) {
230
233
  function main() {
231
234
  const inp = parseInput();
232
235
 
233
- const options = new Options();
234
236
  const debug = options.getSetting('settings', 'debug');
235
237
  logger.setLevel(debug === 'true' ? LogLevel.DEBUG : LogLevel.INFO);
236
- const deps = new Dependencies(options, logger);
237
238
 
238
239
  if (inp) {
239
240
  try {
@@ -243,9 +244,7 @@ function main() {
243
244
  }
244
245
  }
245
246
 
246
- if (inp?.hook_event_name === 'SessionStart') {
247
- deps.checkAndInstallCli();
248
- }
247
+ deps.checkAndInstallCli();
249
248
 
250
249
  if (shouldSendHeartbeat(inp)) {
251
250
  sendHeartbeat(inp);
@@ -3,16 +3,7 @@ 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 = [
7
- 'PreToolUse',
8
- 'PostToolUse',
9
- 'SessionStart',
10
- 'SessionEnd',
11
- 'UserPromptSubmit',
12
- 'PreCompact',
13
- 'SubagentStop',
14
- 'Stop',
15
- ];
6
+ const HOOK_EVENTS = ['PreToolUse', 'PostToolUse', 'SessionEnd', 'UserPromptSubmit', 'PreCompact', 'SubagentStop', 'Stop'];
16
7
 
17
8
  function loadSettings(): any {
18
9
  if (!fs.existsSync(CLAUDE_SETTINGS)) {
package/src/logger.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import os from 'os';
4
- import { Utils } from './utils';
5
4
 
6
5
  export enum LogLevel {
7
6
  DEBUG = 0,