pumuki-ast-hooks 5.3.19 → 5.3.20
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/docs/VIOLATIONS_RESOLUTION_PLAN.md +38 -34
- package/package.json +7 -1
- package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +18 -0
- package/scripts/hooks-system/application/services/ContextDetectionEngine.js +58 -0
- package/scripts/hooks-system/application/services/DynamicRulesLoader.js +11 -0
- package/scripts/hooks-system/application/services/GitFlowService.js +80 -0
- package/scripts/hooks-system/application/services/GitTreeState.js +4 -0
- package/scripts/hooks-system/application/services/HookSystemScheduler.js +4 -0
- package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +25 -0
- package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +11 -0
- package/scripts/hooks-system/application/services/PlatformAnalysisService.js +19 -0
- package/scripts/hooks-system/application/services/PlatformDetectionService.js +19 -0
- package/scripts/hooks-system/application/services/PlaybookRunner.js +22 -1
- package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +19 -0
- package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +25 -0
- package/scripts/hooks-system/application/services/RealtimeGuardService.js +27 -0
- package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +11 -0
- package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +11 -0
- package/scripts/hooks-system/application/services/commit/FeatureDetector.js +11 -0
- package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +25 -0
- package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +19 -0
- package/scripts/hooks-system/application/services/guard/GuardConfig.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +26 -0
- package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardLockManager.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +25 -0
- package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +11 -0
- package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +11 -0
- package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +18 -0
- package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +18 -0
- package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +18 -0
- package/scripts/hooks-system/application/services/installation/HookInstaller.js +19 -0
- package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +11 -0
- package/scripts/hooks-system/application/services/installation/InstallService.js +25 -1
- package/scripts/hooks-system/application/services/installation/McpConfigurator.js +18 -0
- package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +11 -0
- package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +11 -0
- package/scripts/hooks-system/application/services/logging/AuditLogger.js +4 -0
- package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +11 -0
- package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +33 -0
- package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +27 -0
- package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +26 -0
- package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +18 -0
- package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +25 -0
- package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +28 -0
- package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +26 -0
- package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +4 -0
- package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +25 -0
- package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +26 -0
- package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +26 -0
- package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +11 -0
- package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +18 -0
- package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +11 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +18 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +18 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +11 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +20 -0
- package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +19 -0
- package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +19 -0
- package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +11 -0
- package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +19 -0
- package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +4 -0
- package/scripts/hooks-system/application/services/token/CursorTokenService.js +20 -0
- package/scripts/hooks-system/application/services/token/TokenMetricsService.js +11 -0
- package/scripts/hooks-system/application/services/token/TokenMonitorService.js +19 -0
- package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +12 -0
- package/scripts/hooks-system/config/project.config.json +1 -1
- package/scripts/hooks-system/domain/events/index.js +25 -6
- package/scripts/hooks-system/domain/exceptions/index.js +87 -0
- package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +7 -9
- package/scripts/hooks-system/infrastructure/config/config.js +5 -0
- package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +54 -92
- package/scripts/hooks-system/infrastructure/telemetry/metric-scope.js +98 -0
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
|
|
2
|
+
const {
|
|
3
|
+
createMetricScope: createMetricScope
|
|
4
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
5
|
+
|
|
2
6
|
const fs = require('fs').promises;
|
|
3
7
|
const path = require('path');
|
|
4
8
|
|
|
5
9
|
class PlatformDetectionService {
|
|
6
10
|
constructor() {
|
|
11
|
+
const m_constructor = createMetricScope({
|
|
12
|
+
hook: 'platform_detection_service',
|
|
13
|
+
operation: 'constructor'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
m_constructor.started();
|
|
7
17
|
this.cache = {
|
|
8
18
|
detections: new Map(),
|
|
9
19
|
timestamp: 0,
|
|
@@ -43,6 +53,7 @@ class PlatformDetectionService {
|
|
|
43
53
|
'*.java',
|
|
44
54
|
],
|
|
45
55
|
};
|
|
56
|
+
m_constructor.success();
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
async detectPlatforms(targetPath) {
|
|
@@ -142,6 +153,12 @@ class PlatformDetectionService {
|
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
getAmbiguityScore(filePath) {
|
|
156
|
+
const m_get_ambiguity_score = createMetricScope({
|
|
157
|
+
hook: 'platform_detection_service',
|
|
158
|
+
operation: 'get_ambiguity_score'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
m_get_ambiguity_score.started();
|
|
145
162
|
const platform = this._detectPlatformUncached(filePath);
|
|
146
163
|
const lowerPath = filePath.toLowerCase();
|
|
147
164
|
const ext = path.extname(filePath);
|
|
@@ -156,6 +173,8 @@ class PlatformDetectionService {
|
|
|
156
173
|
if (ext === '.ts' || ext === '.tsx') return 60;
|
|
157
174
|
if (ext === '.js' || ext === '.jsx') return 70;
|
|
158
175
|
|
|
176
|
+
m_get_ambiguity_score.success();
|
|
177
|
+
|
|
159
178
|
return 100;
|
|
160
179
|
}
|
|
161
180
|
|
|
@@ -2,13 +2,27 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { spawnSync } = require('child_process');
|
|
4
4
|
const { DomainError, NotFoundError } = require('../../domain/errors');
|
|
5
|
+
const { NotFoundException } = require('../domain/exceptions');
|
|
6
|
+
|
|
7
|
+
const { recordMetric } = require('../../../infrastructure/telemetry/metrics-logger');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
createMetricScope: createMetricScope
|
|
11
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
5
12
|
|
|
6
13
|
const PLAYBOOKS_PATH = path.join(process.cwd(), 'scripts', 'hooks-system', 'config', 'playbooks.json');
|
|
7
14
|
|
|
8
15
|
class PlaybookRunner {
|
|
9
16
|
constructor(options = {}) {
|
|
17
|
+
const m_constructor = createMetricScope({
|
|
18
|
+
hook: 'playbook_runner',
|
|
19
|
+
operation: 'constructor'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
m_constructor.started();
|
|
10
23
|
this.cwd = options.cwd || process.cwd();
|
|
11
24
|
this.playbooks = JSON.parse(fs.readFileSync(PLAYBOOKS_PATH, 'utf8'));
|
|
25
|
+
m_constructor.success();
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
list() {
|
|
@@ -16,9 +30,15 @@ class PlaybookRunner {
|
|
|
16
30
|
}
|
|
17
31
|
|
|
18
32
|
run(id) {
|
|
33
|
+
const m_run = createMetricScope({
|
|
34
|
+
hook: 'playbook_runner',
|
|
35
|
+
operation: 'run'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
m_run.started();
|
|
19
39
|
const playbook = this.playbooks[id];
|
|
20
40
|
if (!playbook) {
|
|
21
|
-
throw new
|
|
41
|
+
throw new NotFoundException('Playbook', { id });
|
|
22
42
|
}
|
|
23
43
|
|
|
24
44
|
for (const step of playbook.steps) {
|
|
@@ -33,6 +53,7 @@ class PlaybookRunner {
|
|
|
33
53
|
}
|
|
34
54
|
}
|
|
35
55
|
}
|
|
56
|
+
m_run.success();
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
createMetricScope: createMetricScope
|
|
6
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
7
|
+
|
|
4
8
|
const METRICS_FILE = path.join(process.cwd(), '.audit_tmp', 'hook-metrics.jsonl');
|
|
5
9
|
|
|
6
10
|
class PredictiveHookAdvisor {
|
|
7
11
|
constructor({ windowSize = 200 } = {}) {
|
|
12
|
+
const m_constructor = createMetricScope({
|
|
13
|
+
hook: 'predictive_hook_advisor',
|
|
14
|
+
operation: 'constructor'
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
m_constructor.started();
|
|
8
18
|
this.windowSize = windowSize;
|
|
19
|
+
m_constructor.success();
|
|
9
20
|
}
|
|
10
21
|
|
|
11
22
|
loadMetrics() {
|
|
@@ -24,6 +35,12 @@ class PredictiveHookAdvisor {
|
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
getFailureProbabilities() {
|
|
38
|
+
const m_get_failure_probabilities = createMetricScope({
|
|
39
|
+
hook: 'predictive_hook_advisor',
|
|
40
|
+
operation: 'get_failure_probabilities'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
m_get_failure_probabilities.started();
|
|
27
44
|
const metrics = this.loadMetrics();
|
|
28
45
|
const stats = {};
|
|
29
46
|
|
|
@@ -38,6 +55,8 @@ class PredictiveHookAdvisor {
|
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|
|
58
|
+
m_get_failure_probabilities.success();
|
|
59
|
+
|
|
41
60
|
return Object.entries(stats)
|
|
42
61
|
.map(([hook, { total, failures }]) => ({
|
|
43
62
|
hook,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const EvidenceMonitorService = require('./monitoring/EvidenceMonitorService');
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
createMetricScope: createMetricScope
|
|
5
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
6
|
+
|
|
3
7
|
class EvidenceRealtimeGuardPlugin {
|
|
4
8
|
constructor({
|
|
5
9
|
repoRoot = process.cwd(),
|
|
@@ -7,6 +11,12 @@ class EvidenceRealtimeGuardPlugin {
|
|
|
7
11
|
logger = console,
|
|
8
12
|
evidenceMonitor = null
|
|
9
13
|
} = {}) {
|
|
14
|
+
const m_constructor = createMetricScope({
|
|
15
|
+
hook: 'realtime_guard_plugin',
|
|
16
|
+
operation: 'constructor'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
m_constructor.started();
|
|
10
20
|
this.repoRoot = repoRoot;
|
|
11
21
|
this.notificationCenter = notificationCenter;
|
|
12
22
|
this.logger = logger || console;
|
|
@@ -16,18 +26,33 @@ class EvidenceRealtimeGuardPlugin {
|
|
|
16
26
|
logger: this.logger,
|
|
17
27
|
notifier: payload => this.forwardNotification(payload)
|
|
18
28
|
});
|
|
29
|
+
m_constructor.success();
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
start() {
|
|
33
|
+
const m_start = createMetricScope({
|
|
34
|
+
hook: 'realtime_guard_plugin',
|
|
35
|
+
operation: 'start'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
m_start.started();
|
|
22
39
|
if (typeof this.evidenceMonitor.start === 'function') {
|
|
23
40
|
this.evidenceMonitor.start();
|
|
24
41
|
}
|
|
42
|
+
m_start.success();
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
stop() {
|
|
46
|
+
const m_stop = createMetricScope({
|
|
47
|
+
hook: 'realtime_guard_plugin',
|
|
48
|
+
operation: 'stop'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
m_stop.started();
|
|
28
52
|
if (typeof this.evidenceMonitor.stop === 'function') {
|
|
29
53
|
this.evidenceMonitor.stop();
|
|
30
54
|
}
|
|
55
|
+
m_stop.success();
|
|
31
56
|
}
|
|
32
57
|
|
|
33
58
|
forwardNotification(payload) {
|
|
@@ -2,6 +2,12 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { getGitTreeState, isTreeBeyondLimit } = require('./GitTreeState');
|
|
4
4
|
|
|
5
|
+
const { recordMetric } = require('../../../infrastructure/telemetry/metrics-logger');
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
createMetricScope: createMetricScope
|
|
9
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
10
|
+
|
|
5
11
|
class RealtimeGuardService {
|
|
6
12
|
/**
|
|
7
13
|
* @param {Object} dependencies
|
|
@@ -12,6 +18,13 @@ class RealtimeGuardService {
|
|
|
12
18
|
* @param {Object} dependencies.config
|
|
13
19
|
*/
|
|
14
20
|
constructor(dependencies = {}) {
|
|
21
|
+
recordMetric({
|
|
22
|
+
hook: 'realtime_guard_service',
|
|
23
|
+
operation: 'constructor',
|
|
24
|
+
status: 'started',
|
|
25
|
+
hasDependencies: !!dependencies
|
|
26
|
+
});
|
|
27
|
+
|
|
15
28
|
const {
|
|
16
29
|
logger,
|
|
17
30
|
notificationService,
|
|
@@ -62,6 +75,12 @@ class RealtimeGuardService {
|
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
start() {
|
|
78
|
+
const m_start = createMetricScope({
|
|
79
|
+
hook: 'realtime_guard_service',
|
|
80
|
+
operation: 'start'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
m_start.started();
|
|
65
84
|
this.logger.info('Starting RealtimeGuardService...');
|
|
66
85
|
|
|
67
86
|
// Start all monitors
|
|
@@ -78,9 +97,16 @@ class RealtimeGuardService {
|
|
|
78
97
|
this._startGitFlowSync();
|
|
79
98
|
|
|
80
99
|
this.logger.info('[RealtimeGuardService] All services started');
|
|
100
|
+
m_start.success();
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
stop() {
|
|
104
|
+
const m_stop = createMetricScope({
|
|
105
|
+
hook: 'realtime_guard_service',
|
|
106
|
+
operation: 'stop'
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
m_stop.started();
|
|
84
110
|
this.logger.info('Stopping RealtimeGuardService...');
|
|
85
111
|
|
|
86
112
|
this.watchers.forEach(w => w.close());
|
|
@@ -93,6 +119,7 @@ class RealtimeGuardService {
|
|
|
93
119
|
});
|
|
94
120
|
|
|
95
121
|
this.logger.info('[RealtimeGuardService] All services stopped');
|
|
122
|
+
m_stop.success();
|
|
96
123
|
}
|
|
97
124
|
|
|
98
125
|
_startEvidenceMonitoring() {
|
|
@@ -3,12 +3,22 @@ const FileContextGrouper = require('./smart-commit/FileContextGrouper');
|
|
|
3
3
|
const CommitMessageSuggester = require('./smart-commit/CommitMessageSuggester');
|
|
4
4
|
const SmartCommitSummaryBuilder = require('./smart-commit/SmartCommitSummaryBuilder');
|
|
5
5
|
|
|
6
|
+
const {
|
|
7
|
+
createMetricScope: createMetricScope
|
|
8
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
9
|
+
|
|
6
10
|
class SmartDirtyTreeAnalyzer {
|
|
7
11
|
constructor({
|
|
8
12
|
platformDetector = null,
|
|
9
13
|
repoRoot = process.cwd(),
|
|
10
14
|
logger = console
|
|
11
15
|
} = {}) {
|
|
16
|
+
const m_constructor = createMetricScope({
|
|
17
|
+
hook: 'smart_dirty_tree_analyzer',
|
|
18
|
+
operation: 'constructor'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
m_constructor.started();
|
|
12
22
|
this.repoRoot = repoRoot;
|
|
13
23
|
this.logger = logger;
|
|
14
24
|
|
|
@@ -16,6 +26,7 @@ class SmartDirtyTreeAnalyzer {
|
|
|
16
26
|
this.grouper = new FileContextGrouper(this.featureDetector, platformDetector);
|
|
17
27
|
this.suggester = new CommitMessageSuggester(this.featureDetector);
|
|
18
28
|
this.summaryBuilder = new SmartCommitSummaryBuilder();
|
|
29
|
+
m_constructor.success();
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
analyze(files) {
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMetricScope: createMetricScope
|
|
3
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
4
|
+
|
|
1
5
|
class CommitMessageGenerator {
|
|
2
6
|
constructor(logger = console) {
|
|
7
|
+
const m_constructor = createMetricScope({
|
|
8
|
+
hook: 'commit_message_generator',
|
|
9
|
+
operation: 'constructor'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
m_constructor.started();
|
|
3
13
|
this.logger = logger;
|
|
14
|
+
m_constructor.success();
|
|
4
15
|
}
|
|
5
16
|
|
|
6
17
|
/**
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMetricScope: createMetricScope
|
|
3
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
4
|
+
|
|
1
5
|
class FeatureDetector {
|
|
2
6
|
constructor(logger = console) {
|
|
7
|
+
const m_constructor = createMetricScope({
|
|
8
|
+
hook: 'feature_detector',
|
|
9
|
+
operation: 'constructor'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
m_constructor.started();
|
|
3
13
|
this.logger = logger;
|
|
14
|
+
m_constructor.success();
|
|
4
15
|
}
|
|
5
16
|
|
|
6
17
|
/**
|
|
@@ -3,6 +3,10 @@ const path = require('path');
|
|
|
3
3
|
const { spawnSync } = require('child_process');
|
|
4
4
|
const { DomainError } = require('../../../domain/errors');
|
|
5
5
|
|
|
6
|
+
const {
|
|
7
|
+
createMetricScope: createMetricScope
|
|
8
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
9
|
+
|
|
6
10
|
const DEFAULT_PLATFORMS = ['1', '2', '3', '4'];
|
|
7
11
|
|
|
8
12
|
function resolveUpdateEvidenceScript(repoRoot) {
|
|
@@ -33,6 +37,12 @@ class EvidenceContextManager {
|
|
|
33
37
|
timers = { setInterval, clearInterval },
|
|
34
38
|
runCommand = EvidenceContextManager.runUpdateScript
|
|
35
39
|
} = {}) {
|
|
40
|
+
const m_constructor = createMetricScope({
|
|
41
|
+
hook: 'evidence_context_manager',
|
|
42
|
+
operation: 'constructor'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
m_constructor.started();
|
|
36
46
|
this.repoRoot = repoRoot;
|
|
37
47
|
this.updateScript = updateScript;
|
|
38
48
|
this.thresholdSeconds = thresholdSeconds;
|
|
@@ -44,6 +54,7 @@ class EvidenceContextManager {
|
|
|
44
54
|
this.runCommand = runCommand;
|
|
45
55
|
this.timerRef = null;
|
|
46
56
|
this.refreshInProgress = false;
|
|
57
|
+
m_constructor.success();
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
static runUpdateScript(scriptPath, platforms) {
|
|
@@ -61,6 +72,12 @@ class EvidenceContextManager {
|
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
start(reason = 'startup') {
|
|
75
|
+
const m_start = createMetricScope({
|
|
76
|
+
hook: 'evidence_context_manager',
|
|
77
|
+
operation: 'start'
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
m_start.started();
|
|
64
81
|
this.ensureFresh(reason).catch(error => {
|
|
65
82
|
this.log('error', 'EVIDENCE_STARTUP_REFRESH_FAILED', { error: error.message });
|
|
66
83
|
});
|
|
@@ -74,13 +91,21 @@ class EvidenceContextManager {
|
|
|
74
91
|
this.timerRef.unref();
|
|
75
92
|
}
|
|
76
93
|
}
|
|
94
|
+
m_start.success();
|
|
77
95
|
}
|
|
78
96
|
|
|
79
97
|
stop() {
|
|
98
|
+
const m_stop = createMetricScope({
|
|
99
|
+
hook: 'evidence_context_manager',
|
|
100
|
+
operation: 'stop'
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
m_stop.started();
|
|
80
104
|
if (this.timerRef) {
|
|
81
105
|
this.timers.clearInterval(this.timerRef);
|
|
82
106
|
this.timerRef = null;
|
|
83
107
|
}
|
|
108
|
+
m_stop.success();
|
|
84
109
|
}
|
|
85
110
|
|
|
86
111
|
async ensureFresh(reason = 'manual') {
|
|
@@ -11,6 +11,10 @@ const GuardNotificationHandler = require('./GuardNotificationHandler');
|
|
|
11
11
|
const GuardMonitorLoop = require('./GuardMonitorLoop');
|
|
12
12
|
const GuardHealthReminder = require('./GuardHealthReminder');
|
|
13
13
|
|
|
14
|
+
const {
|
|
15
|
+
createMetricScope: createMetricScope
|
|
16
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
17
|
+
|
|
14
18
|
class GuardAutoManagerService {
|
|
15
19
|
constructor({
|
|
16
20
|
repoRoot = process.cwd(),
|
|
@@ -23,6 +27,12 @@ class GuardAutoManagerService {
|
|
|
23
27
|
processRef = process,
|
|
24
28
|
heartbeatMonitor = null
|
|
25
29
|
} = {}) {
|
|
30
|
+
const m_constructor = createMetricScope({
|
|
31
|
+
hook: 'guard_auto_manager_service',
|
|
32
|
+
operation: 'constructor'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
m_constructor.started();
|
|
26
36
|
this.process = processRef;
|
|
27
37
|
|
|
28
38
|
// Configuration & Infrastructure
|
|
@@ -49,6 +59,7 @@ class GuardAutoManagerService {
|
|
|
49
59
|
this.lastHeartbeatState = { healthy: true, reason: 'healthy' };
|
|
50
60
|
this.lastHeartbeatRestart = 0;
|
|
51
61
|
this.shuttingDown = false;
|
|
62
|
+
m_constructor.success();
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
notifyUser(message, level = 'info', metadata = {}) {
|
|
@@ -57,8 +68,15 @@ class GuardAutoManagerService {
|
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
start() {
|
|
71
|
+
const m_start = createMetricScope({
|
|
72
|
+
hook: 'guard_auto_manager_service',
|
|
73
|
+
operation: 'start'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
m_start.started();
|
|
60
77
|
if (!this.lockManager.acquireLock()) {
|
|
61
78
|
this.eventLogger.log('Another guard auto manager instance detected. Exiting.');
|
|
79
|
+
m_start.success();
|
|
62
80
|
return false;
|
|
63
81
|
}
|
|
64
82
|
this.lockManager.writePidFile();
|
|
@@ -68,6 +86,7 @@ class GuardAutoManagerService {
|
|
|
68
86
|
this._startReminder();
|
|
69
87
|
this.monitorLoop.start();
|
|
70
88
|
this.registerProcessHooks();
|
|
89
|
+
m_start.success();
|
|
71
90
|
return true;
|
|
72
91
|
}
|
|
73
92
|
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMetricScope: createMetricScope
|
|
3
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
4
|
+
|
|
1
5
|
class GuardConfig {
|
|
2
6
|
constructor(env = process.env) {
|
|
7
|
+
const m_constructor = createMetricScope({
|
|
8
|
+
hook: 'guard_config',
|
|
9
|
+
operation: 'constructor'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
m_constructor.started();
|
|
3
13
|
this.healthyReminderIntervalMs = Number(env.GUARD_AUTOSTART_HEALTHY_INTERVAL || 0);
|
|
4
14
|
this.heartbeatNotifyCooldownMs = Number(env.GUARD_AUTOSTART_NOTIFY_COOLDOWN || 60000);
|
|
5
15
|
this.healthyReminderCooldownMs = Number(
|
|
@@ -9,6 +19,7 @@ class GuardConfig {
|
|
|
9
19
|
this.monitorIntervalMs = Number(env.GUARD_AUTOSTART_MONITOR_INTERVAL || 5000);
|
|
10
20
|
this.restartCooldownMs = Number(env.GUARD_AUTOSTART_RESTART_COOLDOWN || 2000);
|
|
11
21
|
this.stopSupervisorOnExit = env.GUARD_AUTOSTART_STOP_SUPERVISOR_ON_EXIT !== 'false';
|
|
22
|
+
m_constructor.success();
|
|
12
23
|
}
|
|
13
24
|
}
|
|
14
25
|
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
createMetricScope: createMetricScope
|
|
6
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
7
|
+
|
|
4
8
|
class GuardEventLogger {
|
|
5
9
|
constructor({
|
|
6
10
|
repoRoot = process.cwd(),
|
|
7
11
|
logger = console,
|
|
8
12
|
fsModule = fs
|
|
9
13
|
} = {}) {
|
|
14
|
+
const m_constructor = createMetricScope({
|
|
15
|
+
hook: 'guard_event_logger',
|
|
16
|
+
operation: 'constructor'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
m_constructor.started();
|
|
10
20
|
this.repoRoot = repoRoot;
|
|
11
21
|
this.logger = logger;
|
|
12
22
|
this.fs = fsModule;
|
|
@@ -26,6 +36,7 @@ class GuardEventLogger {
|
|
|
26
36
|
this.logger.debug('GUARD_EVENT_LOGGER_INIT_ERROR', { error: error.message });
|
|
27
37
|
}
|
|
28
38
|
}
|
|
39
|
+
m_constructor.success();
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
log(message, data = {}) {
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMetricScope: createMetricScope
|
|
3
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
4
|
+
|
|
1
5
|
class GuardHealthReminder {
|
|
2
6
|
constructor(timers, notificationHandler, config) {
|
|
7
|
+
const m_constructor = createMetricScope({
|
|
8
|
+
hook: 'guard_health_reminder',
|
|
9
|
+
operation: 'constructor'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
m_constructor.started();
|
|
3
13
|
this.timers = timers;
|
|
4
14
|
this.notificationHandler = notificationHandler;
|
|
5
15
|
this.config = config;
|
|
6
16
|
this.timer = null;
|
|
7
17
|
this.lastReminderAt = 0;
|
|
18
|
+
m_constructor.success();
|
|
8
19
|
}
|
|
9
20
|
|
|
10
21
|
start(checkHealthCallback) {
|
|
22
|
+
const m_start = createMetricScope({
|
|
23
|
+
hook: 'guard_health_reminder',
|
|
24
|
+
operation: 'start'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
m_start.started();
|
|
11
28
|
this.stop();
|
|
12
29
|
|
|
13
30
|
const { healthyReminderIntervalMs } = this.config;
|
|
14
31
|
if (!Number.isFinite(healthyReminderIntervalMs) || healthyReminderIntervalMs <= 0) {
|
|
32
|
+
m_start.success();
|
|
15
33
|
return;
|
|
16
34
|
}
|
|
17
35
|
|
|
@@ -22,13 +40,21 @@ class GuardHealthReminder {
|
|
|
22
40
|
if (this.timer && typeof this.timer.unref === 'function') {
|
|
23
41
|
this.timer.unref();
|
|
24
42
|
}
|
|
43
|
+
m_start.success();
|
|
25
44
|
}
|
|
26
45
|
|
|
27
46
|
stop() {
|
|
47
|
+
const m_stop = createMetricScope({
|
|
48
|
+
hook: 'guard_health_reminder',
|
|
49
|
+
operation: 'stop'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
m_stop.started();
|
|
28
53
|
if (this.timer) {
|
|
29
54
|
this.timers.clearInterval(this.timer);
|
|
30
55
|
this.timer = null;
|
|
31
56
|
}
|
|
57
|
+
m_stop.success();
|
|
32
58
|
}
|
|
33
59
|
|
|
34
60
|
_tick(checkHealthCallback) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
createMetricScope: createMetricScope
|
|
6
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
7
|
+
|
|
4
8
|
class GuardHeartbeatMonitor {
|
|
5
9
|
constructor({
|
|
6
10
|
repoRoot = process.cwd(),
|
|
@@ -8,6 +12,12 @@ class GuardHeartbeatMonitor {
|
|
|
8
12
|
fsModule = fs,
|
|
9
13
|
env = process.env
|
|
10
14
|
} = {}) {
|
|
15
|
+
const m_constructor = createMetricScope({
|
|
16
|
+
hook: 'guard_heartbeat_monitor',
|
|
17
|
+
operation: 'constructor'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
m_constructor.started();
|
|
11
21
|
this.repoRoot = repoRoot;
|
|
12
22
|
this.logger = logger;
|
|
13
23
|
this.fs = fsModule;
|
|
@@ -28,6 +38,7 @@ class GuardHeartbeatMonitor {
|
|
|
28
38
|
.map(entry => entry.trim().toLowerCase())
|
|
29
39
|
.filter(Boolean)
|
|
30
40
|
);
|
|
41
|
+
m_constructor.success();
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
evaluate() {
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
createMetricScope: createMetricScope
|
|
6
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
7
|
+
|
|
4
8
|
class GuardLockManager {
|
|
5
9
|
constructor({
|
|
6
10
|
repoRoot = process.cwd(),
|
|
7
11
|
logger = console,
|
|
8
12
|
fsModule = fs
|
|
9
13
|
} = {}) {
|
|
14
|
+
const m_constructor = createMetricScope({
|
|
15
|
+
hook: 'guard_lock_manager',
|
|
16
|
+
operation: 'constructor'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
m_constructor.started();
|
|
10
20
|
this.repoRoot = repoRoot;
|
|
11
21
|
this.logger = logger;
|
|
12
22
|
this.fs = fsModule;
|
|
@@ -26,6 +36,7 @@ class GuardLockManager {
|
|
|
26
36
|
this.logger.debug('GUARD_LOCK_MANAGER_INIT_DEBUG', { error: error.message });
|
|
27
37
|
}
|
|
28
38
|
}
|
|
39
|
+
m_constructor.success();
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
acquireLock() {
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMetricScope: createMetricScope
|
|
3
|
+
} = require('../../../infrastructure/telemetry/metric-scope');
|
|
4
|
+
|
|
1
5
|
class GuardMonitorLoop {
|
|
2
6
|
constructor(timers, intervalMs, tickCallback, logger) {
|
|
7
|
+
const m_constructor = createMetricScope({
|
|
8
|
+
hook: 'guard_monitor_loop',
|
|
9
|
+
operation: 'constructor'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
m_constructor.started();
|
|
3
13
|
this.timers = timers;
|
|
4
14
|
this.intervalMs = intervalMs;
|
|
5
15
|
this.tickCallback = tickCallback;
|
|
6
16
|
this.logger = logger;
|
|
7
17
|
this.timer = null;
|
|
18
|
+
m_constructor.success();
|
|
8
19
|
}
|
|
9
20
|
|
|
10
21
|
start() {
|
|
22
|
+
const m_start = createMetricScope({
|
|
23
|
+
hook: 'guard_monitor_loop',
|
|
24
|
+
operation: 'start'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
m_start.started();
|
|
11
28
|
this.stop();
|
|
12
29
|
this.timer = this.timers.setInterval(() => {
|
|
13
30
|
try {
|
|
@@ -16,13 +33,21 @@ class GuardMonitorLoop {
|
|
|
16
33
|
this.logger.log(`Monitor error: ${error.message}`);
|
|
17
34
|
}
|
|
18
35
|
}, this.intervalMs);
|
|
36
|
+
m_start.success();
|
|
19
37
|
}
|
|
20
38
|
|
|
21
39
|
stop() {
|
|
40
|
+
const m_stop = createMetricScope({
|
|
41
|
+
hook: 'guard_monitor_loop',
|
|
42
|
+
operation: 'stop'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
m_stop.started();
|
|
22
46
|
if (this.timer) {
|
|
23
47
|
this.timers.clearInterval(this.timer);
|
|
24
48
|
this.timer = null;
|
|
25
49
|
}
|
|
50
|
+
m_stop.success();
|
|
26
51
|
}
|
|
27
52
|
}
|
|
28
53
|
|