claude-git-hooks 2.30.2 → 2.33.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/CHANGELOG.md +80 -9
- package/CLAUDE.md +139 -87
- package/README.md +117 -93
- package/lib/commands/close-release.js +7 -7
- package/lib/commands/create-pr.js +47 -21
- package/lib/commands/diff-batch-info.js +0 -9
- package/lib/commands/telemetry-cmd.js +0 -15
- package/lib/config.js +0 -1
- package/lib/hooks/pre-commit.js +43 -0
- package/lib/hooks/prepare-commit-msg.js +15 -0
- package/lib/utils/analysis-engine.js +10 -0
- package/lib/utils/authorization.js +6 -7
- package/lib/utils/github-api.js +92 -60
- package/lib/utils/github-client.js +5 -105
- package/lib/utils/judge.js +12 -5
- package/lib/utils/label-resolver.js +232 -0
- package/lib/utils/metrics.js +185 -0
- package/lib/utils/pr-statistics.js +15 -0
- package/lib/utils/remote-config.js +102 -0
- package/lib/utils/reviewer-selector.js +154 -0
- package/lib/utils/telemetry.js +12 -39
- package/package.json +1 -1
package/lib/utils/telemetry.js
CHANGED
|
@@ -24,7 +24,7 @@ import fs from 'fs/promises';
|
|
|
24
24
|
import fsSync from 'fs';
|
|
25
25
|
import path from 'path';
|
|
26
26
|
import logger from './logger.js';
|
|
27
|
-
import
|
|
27
|
+
import { recordMetric, rotateMetrics as rotateMetricsData, clearMetrics as clearMetricsData } from './metrics.js';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Telemetry event structure
|
|
@@ -82,15 +82,6 @@ const getCurrentLogFile = () => {
|
|
|
82
82
|
return path.join(getTelemetryDir(), `telemetry-${date}.jsonl`);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
/**
|
|
86
|
-
* Check if telemetry is enabled
|
|
87
|
-
* Why: Enabled by default, users must explicitly disable
|
|
88
|
-
*
|
|
89
|
-
* @returns {boolean} True if telemetry is enabled (default: true)
|
|
90
|
-
*/
|
|
91
|
-
const isTelemetryEnabled = () =>
|
|
92
|
-
// Enabled by default - only disabled if explicitly set to false
|
|
93
|
-
config.system?.telemetry !== false;
|
|
94
85
|
/**
|
|
95
86
|
* Ensure telemetry directory exists
|
|
96
87
|
* Why: Create on first use
|
|
@@ -134,11 +125,6 @@ const appendEvent = async (event) => {
|
|
|
134
125
|
* @param {Object} metadata - Event metadata (success, retryAttempt, totalRetries)
|
|
135
126
|
*/
|
|
136
127
|
export const recordEvent = async (eventType, eventData = {}, metadata = {}) => {
|
|
137
|
-
// Check opt-in
|
|
138
|
-
if (!isTelemetryEnabled()) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
128
|
try {
|
|
143
129
|
// Ensure directory exists
|
|
144
130
|
await ensureTelemetryDir();
|
|
@@ -156,6 +142,11 @@ export const recordEvent = async (eventType, eventData = {}, metadata = {}) => {
|
|
|
156
142
|
|
|
157
143
|
// Append to log
|
|
158
144
|
await appendEvent(event);
|
|
145
|
+
|
|
146
|
+
// Dual-write to unified metrics
|
|
147
|
+
recordMetric(eventType, { ...eventData, _meta: metadata }).catch((err) => {
|
|
148
|
+
logger.debug('telemetry - recordEvent', 'Metrics write failed', err);
|
|
149
|
+
});
|
|
159
150
|
} catch (error) {
|
|
160
151
|
// Don't fail on telemetry errors
|
|
161
152
|
logger.debug('telemetry - recordEvent', 'Failed to record event', error);
|
|
@@ -289,14 +280,6 @@ const readTelemetryEvents = async (maxDays = 7) => {
|
|
|
289
280
|
* @returns {Promise<Object>} Statistics object
|
|
290
281
|
*/
|
|
291
282
|
export const getStatistics = async (maxDays = 7) => {
|
|
292
|
-
if (!isTelemetryEnabled()) {
|
|
293
|
-
return {
|
|
294
|
-
enabled: false,
|
|
295
|
-
message:
|
|
296
|
-
'Telemetry is disabled. To enable (default), remove or set "system.telemetry: true" in .claude/config.json'
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
283
|
try {
|
|
301
284
|
const events = await readTelemetryEvents(maxDays);
|
|
302
285
|
|
|
@@ -415,10 +398,6 @@ export const getStatistics = async (maxDays = 7) => {
|
|
|
415
398
|
* @param {number} maxDays - Keep files newer than this many days (default: 30)
|
|
416
399
|
*/
|
|
417
400
|
export const rotateTelemetry = async (maxDays = 30) => {
|
|
418
|
-
if (!isTelemetryEnabled()) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
401
|
try {
|
|
423
402
|
const dir = getTelemetryDir();
|
|
424
403
|
const files = await fs.readdir(dir);
|
|
@@ -450,6 +429,9 @@ export const rotateTelemetry = async (maxDays = 30) => {
|
|
|
450
429
|
} catch (error) {
|
|
451
430
|
logger.debug('telemetry - rotateTelemetry', 'Failed to rotate telemetry', error);
|
|
452
431
|
}
|
|
432
|
+
|
|
433
|
+
// Also rotate unified metrics (90-day retention)
|
|
434
|
+
await rotateMetricsData().catch(() => {});
|
|
453
435
|
};
|
|
454
436
|
|
|
455
437
|
/**
|
|
@@ -479,6 +461,9 @@ export const clearTelemetry = async () => {
|
|
|
479
461
|
} catch (error) {
|
|
480
462
|
logger.error('telemetry - clearTelemetry', 'Failed to clear telemetry', error);
|
|
481
463
|
}
|
|
464
|
+
|
|
465
|
+
// Also clear unified metrics
|
|
466
|
+
await clearMetricsData().catch(() => {});
|
|
482
467
|
};
|
|
483
468
|
|
|
484
469
|
/**
|
|
@@ -492,18 +477,6 @@ export const displayStatistics = async () => {
|
|
|
492
477
|
console.log('║ TELEMETRY STATISTICS ║');
|
|
493
478
|
console.log('╚════════════════════════════════════════════════════════════════════╝\n');
|
|
494
479
|
|
|
495
|
-
if (!stats.enabled) {
|
|
496
|
-
console.log(stats.message);
|
|
497
|
-
console.log('\nTelemetry is disabled in your configuration.');
|
|
498
|
-
console.log('To re-enable (default), remove or set to true in .claude/config.json:');
|
|
499
|
-
console.log('{');
|
|
500
|
-
console.log(' "system": {');
|
|
501
|
-
console.log(' "telemetry": true');
|
|
502
|
-
console.log(' }');
|
|
503
|
-
console.log('}\n');
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
480
|
if (stats.error) {
|
|
508
481
|
console.log(`Error: ${stats.error}`);
|
|
509
482
|
console.log(`Details: ${stats.details}\n`);
|