claude-code-wakatime 2.1.0 → 2.1.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.
- package/README.md +2 -0
- package/dist/index.js +16 -6
- package/dist/logger.js +2 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +16 -6
- package/src/logger.ts +2 -2
package/README.md
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
2. Add your [api key](https://wakatime.com/settings/api-key) to `~/.wakatime.cfg`:
|
|
10
10
|
|
|
11
|
+
```
|
|
11
12
|
[settings]
|
|
12
13
|
api_key = waka_123
|
|
14
|
+
```
|
|
13
15
|
|
|
14
16
|
4. Use Claude Code and your AI coding activity will be displayed on your [WakaTime dashboard](https://wakatime.com)
|
|
15
17
|
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const utils_1 = require("./utils");
|
|
|
15
15
|
const logger_1 = require("./logger");
|
|
16
16
|
const STATE_FILE = path_1.default.join(os_1.default.homedir(), '.wakatime', 'claude-code.json');
|
|
17
17
|
const WAKATIME_CLI = path_1.default.join(os_1.default.homedir(), '.wakatime', 'wakatime-cli');
|
|
18
|
+
const logger = new logger_1.Logger();
|
|
18
19
|
function shouldSendHeartbeat(inp) {
|
|
19
20
|
if (inp?.hook_event_name === 'Stop') {
|
|
20
21
|
return true;
|
|
@@ -90,7 +91,7 @@ function updateState() {
|
|
|
90
91
|
fs_1.default.mkdirSync(path_1.default.dirname(STATE_FILE), { recursive: true });
|
|
91
92
|
fs_1.default.writeFileSync(STATE_FILE, JSON.stringify({ lastHeartbeatAt: utils_1.Utils.timestamp() }, null, 2));
|
|
92
93
|
}
|
|
93
|
-
function sendHeartbeat(inp
|
|
94
|
+
function sendHeartbeat(inp) {
|
|
94
95
|
const projectFolder = inp?.cwd;
|
|
95
96
|
try {
|
|
96
97
|
const args = [
|
|
@@ -109,12 +110,21 @@ function sendHeartbeat(inp, logger) {
|
|
|
109
110
|
}
|
|
110
111
|
if (inp?.transcript_path) {
|
|
111
112
|
const lineChanges = calculateLineChanges(inp.transcript_path);
|
|
112
|
-
if (lineChanges
|
|
113
|
+
if (lineChanges) {
|
|
113
114
|
args.push('--ai-line-changes');
|
|
114
115
|
args.push(lineChanges.toString());
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
+
const options = utils_1.Utils.buildOptions();
|
|
119
|
+
(0, child_process_1.execFile)(WAKATIME_CLI, args, options, (error, _stdout, stderr) => {
|
|
120
|
+
const output = _stdout.toString().trim() + stderr.toString().trim();
|
|
121
|
+
if (output) {
|
|
122
|
+
logger.error(output);
|
|
123
|
+
}
|
|
124
|
+
if (!(error != null)) {
|
|
125
|
+
logger.debug(`Sending heartbeat: ${args}`);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
118
128
|
}
|
|
119
129
|
catch (err) {
|
|
120
130
|
logger.errorException(err);
|
|
@@ -124,7 +134,7 @@ function main() {
|
|
|
124
134
|
const inp = parseInput();
|
|
125
135
|
const options = new options_1.Options();
|
|
126
136
|
const debug = options.getSetting('settings', 'debug');
|
|
127
|
-
|
|
137
|
+
logger.setLevel(debug === 'true' ? logger_1.LogLevel.DEBUG : logger_1.LogLevel.INFO);
|
|
128
138
|
const deps = new dependencies_1.Dependencies(options, logger);
|
|
129
139
|
if (inp) {
|
|
130
140
|
try {
|
|
@@ -134,11 +144,11 @@ function main() {
|
|
|
134
144
|
// ignore
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
|
-
if (inp?.hook_event_name === 'SessionStart') {
|
|
147
|
+
if (inp?.hook_event_name === 'SessionStart demo') {
|
|
138
148
|
deps.checkAndInstallCli();
|
|
139
149
|
}
|
|
140
150
|
if (shouldSendHeartbeat(inp)) {
|
|
141
|
-
sendHeartbeat(inp
|
|
151
|
+
sendHeartbeat(inp);
|
|
142
152
|
updateState();
|
|
143
153
|
}
|
|
144
154
|
}
|
package/dist/logger.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.Logger = exports.LogLevel = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
10
|
var LogLevel;
|
|
12
11
|
(function (LogLevel) {
|
|
13
12
|
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
@@ -19,7 +18,7 @@ const LOG_FILE = path_1.default.join(os_1.default.homedir(), '.wakatime', 'claud
|
|
|
19
18
|
class Logger {
|
|
20
19
|
constructor(level) {
|
|
21
20
|
this.level = LogLevel.INFO;
|
|
22
|
-
if (level)
|
|
21
|
+
if (level !== undefined)
|
|
23
22
|
this.setLevel(level);
|
|
24
23
|
}
|
|
25
24
|
getLevel() {
|
|
@@ -30,7 +29,7 @@ class Logger {
|
|
|
30
29
|
}
|
|
31
30
|
log(level, msg) {
|
|
32
31
|
if (level >= this.level) {
|
|
33
|
-
msg = `[${
|
|
32
|
+
msg = `[${new Date().toISOString()}][${LogLevel[level]}] ${msg}\n`;
|
|
34
33
|
fs_1.default.mkdirSync(path_1.default.dirname(LOG_FILE), { recursive: true });
|
|
35
34
|
fs_1.default.appendFileSync(LOG_FILE, msg);
|
|
36
35
|
}
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import os from 'os';
|
|
6
|
-
import {
|
|
6
|
+
import { execFile } from 'child_process';
|
|
7
7
|
import { Options } from './options';
|
|
8
8
|
import { VERSION } from './version';
|
|
9
9
|
import { Dependencies } from './dependencies';
|
|
@@ -12,6 +12,7 @@ import { Logger, LogLevel } from './logger';
|
|
|
12
12
|
|
|
13
13
|
const STATE_FILE = path.join(os.homedir(), '.wakatime', 'claude-code.json');
|
|
14
14
|
const WAKATIME_CLI = path.join(os.homedir(), '.wakatime', 'wakatime-cli');
|
|
15
|
+
const logger = new Logger();
|
|
15
16
|
|
|
16
17
|
type State = {
|
|
17
18
|
lastHeartbeatAt?: number;
|
|
@@ -104,7 +105,7 @@ function updateState() {
|
|
|
104
105
|
fs.writeFileSync(STATE_FILE, JSON.stringify({ lastHeartbeatAt: Utils.timestamp() } as State, null, 2));
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
function sendHeartbeat(inp: Input | undefined
|
|
108
|
+
function sendHeartbeat(inp: Input | undefined) {
|
|
108
109
|
const projectFolder = inp?.cwd;
|
|
109
110
|
try {
|
|
110
111
|
const args: string[] = [
|
|
@@ -124,13 +125,22 @@ function sendHeartbeat(inp: Input | undefined, logger: Logger) {
|
|
|
124
125
|
|
|
125
126
|
if (inp?.transcript_path) {
|
|
126
127
|
const lineChanges = calculateLineChanges(inp.transcript_path);
|
|
127
|
-
if (lineChanges
|
|
128
|
+
if (lineChanges) {
|
|
128
129
|
args.push('--ai-line-changes');
|
|
129
130
|
args.push(lineChanges.toString());
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
const options = Utils.buildOptions();
|
|
135
|
+
execFile(WAKATIME_CLI, args, options, (error, _stdout, stderr) => {
|
|
136
|
+
const output = _stdout.toString().trim() + stderr.toString().trim();
|
|
137
|
+
if (output) {
|
|
138
|
+
logger.error(output);
|
|
139
|
+
}
|
|
140
|
+
if (!(error != null)) {
|
|
141
|
+
logger.debug(`Sending heartbeat: ${args}`);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
134
144
|
} catch (err: any) {
|
|
135
145
|
logger.errorException(err);
|
|
136
146
|
}
|
|
@@ -141,7 +151,7 @@ function main() {
|
|
|
141
151
|
|
|
142
152
|
const options = new Options();
|
|
143
153
|
const debug = options.getSetting('settings', 'debug');
|
|
144
|
-
|
|
154
|
+
logger.setLevel(debug === 'true' ? LogLevel.DEBUG : LogLevel.INFO);
|
|
145
155
|
const deps = new Dependencies(options, logger);
|
|
146
156
|
|
|
147
157
|
if (inp) {
|
|
@@ -157,7 +167,7 @@ function main() {
|
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
if (shouldSendHeartbeat(inp)) {
|
|
160
|
-
sendHeartbeat(inp
|
|
170
|
+
sendHeartbeat(inp);
|
|
161
171
|
updateState();
|
|
162
172
|
}
|
|
163
173
|
}
|
package/src/logger.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class Logger {
|
|
|
16
16
|
private level: LogLevel = LogLevel.INFO;
|
|
17
17
|
|
|
18
18
|
constructor(level?: LogLevel) {
|
|
19
|
-
if (level) this.setLevel(level);
|
|
19
|
+
if (level !== undefined) this.setLevel(level);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
public getLevel(): LogLevel {
|
|
@@ -29,7 +29,7 @@ export class Logger {
|
|
|
29
29
|
|
|
30
30
|
public log(level: LogLevel, msg: string): void {
|
|
31
31
|
if (level >= this.level) {
|
|
32
|
-
msg = `[${
|
|
32
|
+
msg = `[${new Date().toISOString()}][${LogLevel[level]}] ${msg}\n`;
|
|
33
33
|
fs.mkdirSync(path.dirname(LOG_FILE), { recursive: true });
|
|
34
34
|
fs.appendFileSync(LOG_FILE, msg);
|
|
35
35
|
}
|