pumuki-ast-hooks 5.3.20 → 5.3.22

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.
Files changed (95) hide show
  1. package/docs/RELEASE_NOTES.md +35 -0
  2. package/docs/VIOLATIONS_RESOLUTION_PLAN.md +60 -59
  3. package/package.json +3 -3
  4. package/scripts/hooks-system/.AI_TOKEN_STATUS.txt +1 -1
  5. package/scripts/hooks-system/.audit-reports/notifications.log +935 -0
  6. package/scripts/hooks-system/.audit-reports/token-monitor.log +2809 -0
  7. package/scripts/hooks-system/application/CompositionRoot.js +38 -22
  8. package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +0 -18
  9. package/scripts/hooks-system/application/services/ContextDetectionEngine.js +0 -58
  10. package/scripts/hooks-system/application/services/DynamicRulesLoader.js +2 -12
  11. package/scripts/hooks-system/application/services/GitFlowService.js +0 -80
  12. package/scripts/hooks-system/application/services/GitTreeState.js +2 -5
  13. package/scripts/hooks-system/application/services/HookSystemScheduler.js +0 -4
  14. package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +0 -25
  15. package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +0 -11
  16. package/scripts/hooks-system/application/services/PlatformAnalysisService.js +0 -19
  17. package/scripts/hooks-system/application/services/PlatformDetectionService.js +0 -19
  18. package/scripts/hooks-system/application/services/PlaybookRunner.js +1 -22
  19. package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +0 -19
  20. package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +0 -25
  21. package/scripts/hooks-system/application/services/RealtimeGuardService.js +71 -41
  22. package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +0 -11
  23. package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +0 -11
  24. package/scripts/hooks-system/application/services/commit/FeatureDetector.js +0 -11
  25. package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +0 -25
  26. package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +31 -21
  27. package/scripts/hooks-system/application/services/guard/GuardConfig.js +15 -18
  28. package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +0 -11
  29. package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +0 -26
  30. package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +6 -20
  31. package/scripts/hooks-system/application/services/guard/GuardLockManager.js +0 -11
  32. package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +0 -25
  33. package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +0 -11
  34. package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +23 -11
  35. package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +0 -11
  36. package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +0 -18
  37. package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +0 -18
  38. package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +1 -19
  39. package/scripts/hooks-system/application/services/installation/HookInstaller.js +62 -24
  40. package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +0 -11
  41. package/scripts/hooks-system/application/services/installation/InstallService.js +1 -25
  42. package/scripts/hooks-system/application/services/installation/McpConfigurator.js +2 -19
  43. package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +0 -11
  44. package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +0 -11
  45. package/scripts/hooks-system/application/services/logging/AuditLogger.js +0 -8
  46. package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +13 -15
  47. package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +0 -33
  48. package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +0 -27
  49. package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +0 -26
  50. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +0 -18
  51. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +4 -28
  52. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +0 -28
  53. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +0 -26
  54. package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +0 -4
  55. package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +0 -25
  56. package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +0 -26
  57. package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +0 -26
  58. package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +0 -11
  59. package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +0 -18
  60. package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +0 -11
  61. package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +0 -18
  62. package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +0 -18
  63. package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +0 -11
  64. package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +0 -20
  65. package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +0 -19
  66. package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +0 -19
  67. package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +0 -11
  68. package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +0 -19
  69. package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +0 -4
  70. package/scripts/hooks-system/application/services/token/CursorTokenService.js +0 -20
  71. package/scripts/hooks-system/application/services/token/TokenMetricsService.js +2 -12
  72. package/scripts/hooks-system/application/services/token/TokenMonitorService.js +0 -19
  73. package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +0 -12
  74. package/scripts/hooks-system/bin/cli.js +15 -1
  75. package/scripts/hooks-system/bin/guard-env.sh +18 -38
  76. package/scripts/hooks-system/bin/guard-supervisor.js +5 -515
  77. package/scripts/hooks-system/bin/session-loader.sh +3 -262
  78. package/scripts/hooks-system/bin/start-guards.sh +21 -184
  79. package/scripts/hooks-system/bin/update-evidence.sh +10 -1161
  80. package/scripts/hooks-system/config/project.config.json +1 -1
  81. package/scripts/hooks-system/domain/events/index.js +31 -24
  82. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidAnalysisOrchestrator.js +3 -2
  83. package/scripts/hooks-system/infrastructure/ast/ast-core.js +12 -20
  84. package/scripts/hooks-system/infrastructure/ast/ast-intelligence.js +8 -18
  85. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendPatternDetector.js +2 -1
  86. package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +18 -14
  87. package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend.js +196 -196
  88. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSASTIntelligentAnalyzer.js +3 -2
  89. package/scripts/hooks-system/infrastructure/hooks/skill-activation-prompt.js +3 -2
  90. package/scripts/hooks-system/infrastructure/logging/UnifiedLoggerFactory.js +5 -4
  91. package/scripts/hooks-system/infrastructure/mcp/ast-intelligence-automation.js +88 -0
  92. package/scripts/hooks-system/infrastructure/orchestration/intelligent-audit.js +17 -16
  93. package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +92 -54
  94. package/scripts/hooks-system/infrastructure/telemetry/metrics-server.js +3 -2
  95. package/scripts/hooks-system/infrastructure/validators/enforce-english-literals.js +6 -8
@@ -1,25 +1,22 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
1
+ const envHelper = require('../../../config/env');
4
2
 
5
3
  class GuardConfig {
6
- constructor(env = process.env) {
7
- const m_constructor = createMetricScope({
8
- hook: 'guard_config',
9
- operation: 'constructor'
10
- });
4
+ constructor(env = envHelper) {
5
+ const getNumber = (name, def) =>
6
+ typeof env.getNumber === 'function' ? env.getNumber(name, def) : Number(env[name] || def);
7
+ const getBool = (name, def) =>
8
+ typeof env.getBool === 'function' ? env.getBool(name, def) : (env[name] !== 'false');
11
9
 
12
- m_constructor.started();
13
- this.healthyReminderIntervalMs = Number(env.GUARD_AUTOSTART_HEALTHY_INTERVAL || 0);
14
- this.heartbeatNotifyCooldownMs = Number(env.GUARD_AUTOSTART_NOTIFY_COOLDOWN || 60000);
15
- this.healthyReminderCooldownMs = Number(
16
- env.GUARD_AUTOSTART_HEALTHY_COOLDOWN || (this.healthyReminderIntervalMs > 0 ? this.healthyReminderIntervalMs : 0)
10
+ this.healthyReminderIntervalMs = getNumber('GUARD_AUTOSTART_HEALTHY_INTERVAL', 0);
11
+ this.heartbeatNotifyCooldownMs = getNumber('GUARD_AUTOSTART_NOTIFY_COOLDOWN', 60000);
12
+ this.healthyReminderCooldownMs = getNumber(
13
+ 'GUARD_AUTOSTART_HEALTHY_COOLDOWN',
14
+ this.healthyReminderIntervalMs > 0 ? this.healthyReminderIntervalMs : 0
17
15
  );
18
- this.heartbeatRestartCooldownMs = Number(env.GUARD_AUTOSTART_HEARTBEAT_COOLDOWN || 60000);
19
- this.monitorIntervalMs = Number(env.GUARD_AUTOSTART_MONITOR_INTERVAL || 5000);
20
- this.restartCooldownMs = Number(env.GUARD_AUTOSTART_RESTART_COOLDOWN || 2000);
21
- this.stopSupervisorOnExit = env.GUARD_AUTOSTART_STOP_SUPERVISOR_ON_EXIT !== 'false';
22
- m_constructor.success();
16
+ this.heartbeatRestartCooldownMs = getNumber('GUARD_AUTOSTART_HEARTBEAT_COOLDOWN', 60000);
17
+ this.monitorIntervalMs = getNumber('GUARD_AUTOSTART_MONITOR_INTERVAL', 5000);
18
+ this.restartCooldownMs = getNumber('GUARD_AUTOSTART_RESTART_COOLDOWN', 2000);
19
+ this.stopSupervisorOnExit = getBool('GUARD_AUTOSTART_STOP_SUPERVISOR_ON_EXIT', true);
23
20
  }
24
21
  }
25
22
 
@@ -1,22 +1,12 @@
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
-
8
4
  class GuardEventLogger {
9
5
  constructor({
10
6
  repoRoot = process.cwd(),
11
7
  logger = console,
12
8
  fsModule = fs
13
9
  } = {}) {
14
- const m_constructor = createMetricScope({
15
- hook: 'guard_event_logger',
16
- operation: 'constructor'
17
- });
18
-
19
- m_constructor.started();
20
10
  this.repoRoot = repoRoot;
21
11
  this.logger = logger;
22
12
  this.fs = fsModule;
@@ -36,7 +26,6 @@ class GuardEventLogger {
36
26
  this.logger.debug('GUARD_EVENT_LOGGER_INIT_ERROR', { error: error.message });
37
27
  }
38
28
  }
39
- m_constructor.success();
40
29
  }
41
30
 
42
31
  log(message, data = {}) {
@@ -1,35 +1,17 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
4
-
5
1
  class GuardHealthReminder {
6
2
  constructor(timers, notificationHandler, config) {
7
- const m_constructor = createMetricScope({
8
- hook: 'guard_health_reminder',
9
- operation: 'constructor'
10
- });
11
-
12
- m_constructor.started();
13
3
  this.timers = timers;
14
4
  this.notificationHandler = notificationHandler;
15
5
  this.config = config;
16
6
  this.timer = null;
17
7
  this.lastReminderAt = 0;
18
- m_constructor.success();
19
8
  }
20
9
 
21
10
  start(checkHealthCallback) {
22
- const m_start = createMetricScope({
23
- hook: 'guard_health_reminder',
24
- operation: 'start'
25
- });
26
-
27
- m_start.started();
28
11
  this.stop();
29
12
 
30
13
  const { healthyReminderIntervalMs } = this.config;
31
14
  if (!Number.isFinite(healthyReminderIntervalMs) || healthyReminderIntervalMs <= 0) {
32
- m_start.success();
33
15
  return;
34
16
  }
35
17
 
@@ -40,21 +22,13 @@ class GuardHealthReminder {
40
22
  if (this.timer && typeof this.timer.unref === 'function') {
41
23
  this.timer.unref();
42
24
  }
43
- m_start.success();
44
25
  }
45
26
 
46
27
  stop() {
47
- const m_stop = createMetricScope({
48
- hook: 'guard_health_reminder',
49
- operation: 'stop'
50
- });
51
-
52
- m_stop.started();
53
28
  if (this.timer) {
54
29
  this.timers.clearInterval(this.timer);
55
30
  this.timer = null;
56
31
  }
57
- m_stop.success();
58
32
  }
59
33
 
60
34
  _tick(checkHealthCallback) {
@@ -1,44 +1,30 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
-
4
- const {
5
- createMetricScope: createMetricScope
6
- } = require('../../../infrastructure/telemetry/metric-scope');
3
+ const env = require('../../../config/env');
7
4
 
8
5
  class GuardHeartbeatMonitor {
9
6
  constructor({
10
7
  repoRoot = process.cwd(),
11
8
  logger = console,
12
- fsModule = fs,
13
- env = process.env
9
+ fsModule = fs
14
10
  } = {}) {
15
- const m_constructor = createMetricScope({
16
- hook: 'guard_heartbeat_monitor',
17
- operation: 'constructor'
18
- });
19
-
20
- m_constructor.started();
21
11
  this.repoRoot = repoRoot;
22
12
  this.logger = logger;
23
13
  this.fs = fsModule;
24
- this.env = env;
25
-
26
- const heartbeatRelative = env.HOOK_GUARD_HEARTBEAT_PATH || path.join('.audit_tmp', 'guard-heartbeat.json');
14
+ const heartbeatRelative = env.get('HOOK_GUARD_HEARTBEAT_PATH', path.join('.audit_tmp', 'guard-heartbeat.json'));
27
15
  this.heartbeatPath = path.isAbsolute(heartbeatRelative)
28
16
  ? heartbeatRelative
29
17
  : path.join(this.repoRoot, heartbeatRelative);
30
18
 
31
- this.heartbeatMaxAgeMs = Number(
32
- env.GUARD_AUTOSTART_HEARTBEAT_MAX_AGE || env.HOOK_GUARD_HEARTBEAT_MAX_AGE || 60000
33
- );
19
+ this.heartbeatMaxAgeMs = env.getNumber('GUARD_AUTOSTART_HEARTBEAT_MAX_AGE',
20
+ env.getNumber('HOOK_GUARD_HEARTBEAT_MAX_AGE', 60000));
34
21
 
35
22
  this.heartbeatRestartReasons = new Set(
36
- (env.GUARD_AUTOSTART_HEARTBEAT_RESTART || 'missing,stale,invalid,degraded')
23
+ (env.get('GUARD_AUTOSTART_HEARTBEAT_RESTART', 'missing,stale,invalid,degraded'))
37
24
  .split(',')
38
25
  .map(entry => entry.trim().toLowerCase())
39
26
  .filter(Boolean)
40
27
  );
41
- m_constructor.success();
42
28
  }
43
29
 
44
30
  evaluate() {
@@ -1,22 +1,12 @@
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
-
8
4
  class GuardLockManager {
9
5
  constructor({
10
6
  repoRoot = process.cwd(),
11
7
  logger = console,
12
8
  fsModule = fs
13
9
  } = {}) {
14
- const m_constructor = createMetricScope({
15
- hook: 'guard_lock_manager',
16
- operation: 'constructor'
17
- });
18
-
19
- m_constructor.started();
20
10
  this.repoRoot = repoRoot;
21
11
  this.logger = logger;
22
12
  this.fs = fsModule;
@@ -36,7 +26,6 @@ class GuardLockManager {
36
26
  this.logger.debug('GUARD_LOCK_MANAGER_INIT_DEBUG', { error: error.message });
37
27
  }
38
28
  }
39
- m_constructor.success();
40
29
  }
41
30
 
42
31
  acquireLock() {
@@ -1,30 +1,13 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
4
-
5
1
  class GuardMonitorLoop {
6
2
  constructor(timers, intervalMs, tickCallback, logger) {
7
- const m_constructor = createMetricScope({
8
- hook: 'guard_monitor_loop',
9
- operation: 'constructor'
10
- });
11
-
12
- m_constructor.started();
13
3
  this.timers = timers;
14
4
  this.intervalMs = intervalMs;
15
5
  this.tickCallback = tickCallback;
16
6
  this.logger = logger;
17
7
  this.timer = null;
18
- m_constructor.success();
19
8
  }
20
9
 
21
10
  start() {
22
- const m_start = createMetricScope({
23
- hook: 'guard_monitor_loop',
24
- operation: 'start'
25
- });
26
-
27
- m_start.started();
28
11
  this.stop();
29
12
  this.timer = this.timers.setInterval(() => {
30
13
  try {
@@ -33,21 +16,13 @@ class GuardMonitorLoop {
33
16
  this.logger.log(`Monitor error: ${error.message}`);
34
17
  }
35
18
  }, this.intervalMs);
36
- m_start.success();
37
19
  }
38
20
 
39
21
  stop() {
40
- const m_stop = createMetricScope({
41
- hook: 'guard_monitor_loop',
42
- operation: 'stop'
43
- });
44
-
45
- m_stop.started();
46
22
  if (this.timer) {
47
23
  this.timers.clearInterval(this.timer);
48
24
  this.timer = null;
49
25
  }
50
- m_stop.success();
51
26
  }
52
27
  }
53
28
 
@@ -1,20 +1,9 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
4
-
5
1
  class GuardNotificationHandler {
6
2
  constructor(notificationCenter, eventLogger, config) {
7
- const m_constructor = createMetricScope({
8
- hook: 'guard_notification_handler',
9
- operation: 'constructor'
10
- });
11
-
12
- m_constructor.started();
13
3
  this.notificationCenter = notificationCenter;
14
4
  this.eventLogger = eventLogger;
15
5
  this.config = config;
16
6
  this.lastNotificationState = { reason: null, at: 0 };
17
- m_constructor.success();
18
7
  }
19
8
 
20
9
  notify(message, level = 'info', options = {}) {
@@ -1,10 +1,6 @@
1
1
  const path = require('path');
2
2
  const { spawnSync } = require('child_process');
3
3
 
4
- const {
5
- createMetricScope: createMetricScope
6
- } = require('../../../infrastructure/telemetry/metric-scope');
7
-
8
4
  class GuardProcessManager {
9
5
  constructor({
10
6
  repoRoot = process.cwd(),
@@ -12,12 +8,6 @@ class GuardProcessManager {
12
8
  fsModule = require('fs'),
13
9
  childProcess = { spawnSync }
14
10
  } = {}) {
15
- const m_constructor = createMetricScope({
16
- hook: 'guard_process_manager',
17
- operation: 'constructor'
18
- });
19
-
20
- m_constructor.started();
21
11
  this.repoRoot = repoRoot;
22
12
  this.logger = logger;
23
13
  this.fs = fsModule;
@@ -25,7 +15,7 @@ class GuardProcessManager {
25
15
 
26
16
  this.supervisorPidFile = path.join(this.repoRoot, '.guard-supervisor.pid');
27
17
  this.startScript = path.join(this.repoRoot, 'bin', 'start-guards.sh');
28
- m_constructor.success();
18
+ this.busy = false;
29
19
  }
30
20
 
31
21
  isSupervisorRunning() {
@@ -69,6 +59,15 @@ class GuardProcessManager {
69
59
  }
70
60
 
71
61
  startSupervisor() {
62
+ if (this.busy) {
63
+ return {
64
+ success: false,
65
+ error: new Error('bulkhead_busy'),
66
+ stdout: '',
67
+ stderr: 'bulkhead_busy'
68
+ };
69
+ }
70
+ this.busy = true;
72
71
  try {
73
72
  const result = this.childProcess.spawnSync(this.startScript, ['start'], {
74
73
  cwd: this.repoRoot,
@@ -91,10 +90,21 @@ class GuardProcessManager {
91
90
  stdout: '',
92
91
  stderr: error.message
93
92
  };
93
+ } finally {
94
+ this.busy = false;
94
95
  }
95
96
  }
96
97
 
97
98
  stopSupervisor() {
99
+ if (this.busy) {
100
+ return {
101
+ success: false,
102
+ error: new Error('bulkhead_busy'),
103
+ stdout: '',
104
+ stderr: 'bulkhead_busy'
105
+ };
106
+ }
107
+ this.busy = true;
98
108
  try {
99
109
  const result = this.childProcess.spawnSync(this.startScript, ['stop'], {
100
110
  cwd: this.repoRoot,
@@ -117,6 +127,8 @@ class GuardProcessManager {
117
127
  stdout: '',
118
128
  stderr: error.message
119
129
  };
130
+ } finally {
131
+ this.busy = false;
120
132
  }
121
133
  }
122
134
  }
@@ -1,7 +1,3 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
4
-
5
1
  class GuardRecoveryService {
6
2
  constructor({
7
3
  repoRoot,
@@ -10,19 +6,12 @@ class GuardRecoveryService {
10
6
  notificationHandler,
11
7
  restartCooldownMs = 2000
12
8
  }) {
13
- const m_constructor = createMetricScope({
14
- hook: 'guard_recovery_service',
15
- operation: 'constructor'
16
- });
17
-
18
- m_constructor.started();
19
9
  this.repoRoot = repoRoot;
20
10
  this.logger = logger;
21
11
  this.startScript = startScript;
22
12
  this.notificationHandler = notificationHandler;
23
13
  this.restartCooldownMs = restartCooldownMs;
24
14
  this.lastEnsure = 0;
25
- m_constructor.success();
26
15
  }
27
16
 
28
17
  ensureSupervisor(reason, eventLogger) {
@@ -1,10 +1,6 @@
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
-
8
4
  const COLORS = {
9
5
  reset: '\x1b[0m',
10
6
  green: '\x1b[32m',
@@ -14,24 +10,11 @@ const COLORS = {
14
10
 
15
11
  class ConfigurationGeneratorService {
16
12
  constructor(targetRoot, hookSystemRoot) {
17
- const m_constructor = createMetricScope({
18
- hook: 'configuration_generator_service',
19
- operation: 'constructor'
20
- });
21
-
22
- m_constructor.started();
23
13
  this.targetRoot = targetRoot || process.cwd();
24
14
  this.hookSystemRoot = hookSystemRoot;
25
- m_constructor.success();
26
15
  }
27
16
 
28
17
  createProjectConfig(platforms) {
29
- const m_create_project_config = createMetricScope({
30
- hook: 'configuration_generator_service',
31
- operation: 'create_project_config'
32
- });
33
-
34
- m_create_project_config.started();
35
18
  const config = {
36
19
  version: '3.1.0',
37
20
  project: {
@@ -90,7 +73,6 @@ class ConfigurationGeneratorService {
90
73
 
91
74
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
92
75
  this.logSuccess('Configuration created');
93
- m_create_project_config.success();
94
76
  }
95
77
 
96
78
  installESLintConfigs() {
@@ -1,10 +1,6 @@
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
-
8
4
  const COLORS = {
9
5
  reset: '\x1b[0m',
10
6
  green: '\x1b[32m',
@@ -13,25 +9,12 @@ const COLORS = {
13
9
 
14
10
  class FileSystemInstallerService {
15
11
  constructor(targetRoot, hookSystemRoot, logger = null) {
16
- const m_constructor = createMetricScope({
17
- hook: 'file_system_installer_service',
18
- operation: 'constructor'
19
- });
20
-
21
- m_constructor.started();
22
12
  this.targetRoot = targetRoot || process.cwd();
23
13
  this.hookSystemRoot = hookSystemRoot;
24
14
  this.logger = logger;
25
- m_constructor.success();
26
15
  }
27
16
 
28
17
  createDirectoryStructure() {
29
- const m_create_directory_structure = createMetricScope({
30
- hook: 'file_system_installer_service',
31
- operation: 'create_directory_structure'
32
- });
33
-
34
- m_create_directory_structure.started();
35
18
  const dirs = [
36
19
  'scripts/hooks-system',
37
20
  'scripts/hooks-system/docs',
@@ -46,7 +29,6 @@ class FileSystemInstallerService {
46
29
  }
47
30
  });
48
31
  this.logSuccess('Directory structure created');
49
- m_create_directory_structure.success();
50
32
  }
51
33
 
52
34
  copySystemFiles() {
@@ -2,10 +2,6 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execSync, spawnSync } = require('child_process');
4
4
 
5
- const {
6
- createMetricScope: createMetricScope
7
- } = require('../../../infrastructure/telemetry/metric-scope');
8
-
9
5
  const COLORS = {
10
6
  reset: '\x1b[0m',
11
7
  blue: '\x1b[34m',
@@ -17,15 +13,8 @@ const COLORS = {
17
13
 
18
14
  class GitEnvironmentService {
19
15
  constructor(targetRoot, version = 'unknown') {
20
- const m_constructor = createMetricScope({
21
- hook: 'git_environment_service',
22
- operation: 'constructor'
23
- });
24
-
25
- m_constructor.started();
26
16
  this.targetRoot = targetRoot || process.cwd();
27
17
  this.version = version;
28
- m_constructor.success();
29
18
  }
30
19
 
31
20
  checkGitRepository() {
@@ -99,13 +88,6 @@ class GitEnvironmentService {
99
88
  }
100
89
 
101
90
  getPreCommitHookContent() {
102
- const m_get_pre_commit_hook_content = createMetricScope({
103
- hook: 'git_environment_service',
104
- operation: 'get_pre_commit_hook_content'
105
- });
106
-
107
- m_get_pre_commit_hook_content.started();
108
- m_get_pre_commit_hook_content.success();
109
91
  return `#!/bin/bash
110
92
  # AST Intelligence Hooks - Pre-commit
111
93
  # Auto-generated by pumuki-ast-hooks v${this.version}
@@ -128,7 +110,7 @@ fi
128
110
 
129
111
  # Try node_modules/.bin first (works with npm install)
130
112
  if [ -f "node_modules/.bin/ast-hooks" ]; then
131
- OUTPUT=$(node_modules/.bin/ast-hooks ast 2>&1)
113
+ OUTPUT=$(node_modules/.bin/ast-hooks ast --staged 2>&1)
132
114
  EXIT_CODE=$?
133
115
  echo "$OUTPUT"
134
116
  if [ $EXIT_CODE -ne 0 ]; then
@@ -1,18 +1,8 @@
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
-
8
4
  class HookInstaller {
9
5
  constructor(targetRoot, hookSystemRoot, logger = null) {
10
- const m_constructor = createMetricScope({
11
- hook: 'hook_installer',
12
- operation: 'constructor'
13
- });
14
-
15
- m_constructor.started();
16
6
  this.targetRoot = targetRoot;
17
7
  this.hookSystemRoot = hookSystemRoot;
18
8
  this.logger = logger;
@@ -22,7 +12,50 @@ class HookInstaller {
22
12
  yellow: '\x1b[33m',
23
13
  cyan: '\x1b[36m'
24
14
  };
25
- m_constructor.success();
15
+ }
16
+
17
+ getPackageRoot() {
18
+ let dir = this.hookSystemRoot;
19
+ for (let i = 0; i < 8; i++) {
20
+ const pkgJson = path.join(dir, 'package.json');
21
+ try {
22
+ if (fs.existsSync(pkgJson) && fs.statSync(pkgJson).isFile()) {
23
+ return dir;
24
+ }
25
+ } catch (error) {
26
+ const msg = error && error.message ? error.message : String(error);
27
+ this.logger?.debug?.('HOOK_INSTALLER_PACKAGE_ROOT_PROBE_ERROR', {
28
+ pkgJson,
29
+ error: msg
30
+ });
31
+ }
32
+
33
+ const parent = path.dirname(dir);
34
+ if (parent === dir) {
35
+ break;
36
+ }
37
+ dir = parent;
38
+ }
39
+
40
+ return path.resolve(this.hookSystemRoot, '..', '..', '..');
41
+ }
42
+
43
+ resolveFirstExistingDir(candidates) {
44
+ for (const candidate of candidates) {
45
+ if (!candidate) continue;
46
+ try {
47
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
48
+ return candidate;
49
+ }
50
+ } catch (error) {
51
+ const msg = error && error.message ? error.message : String(error);
52
+ this.logger?.debug?.('HOOK_INSTALLER_DIR_PROBE_ERROR', {
53
+ candidate,
54
+ error: msg
55
+ });
56
+ }
57
+ }
58
+ return null;
26
59
  }
27
60
 
28
61
  install(platforms) {
@@ -42,12 +75,20 @@ class HookInstaller {
42
75
  }
43
76
 
44
77
  installSkills(claudeSkillsDir, platforms) {
45
- const librarySkillsDir = path.join(this.hookSystemRoot, 'skills');
78
+ const packageRoot = this.getPackageRoot();
79
+ const librarySkillsDir = this.resolveFirstExistingDir([
80
+ path.join(this.hookSystemRoot, 'skills'),
81
+ path.join(packageRoot, 'skills')
82
+ ]);
46
83
 
47
- if (!fs.existsSync(librarySkillsDir)) {
84
+ if (!librarySkillsDir) {
48
85
  return;
49
86
  }
50
87
 
88
+ if (!fs.existsSync(claudeSkillsDir)) {
89
+ fs.mkdirSync(claudeSkillsDir, { recursive: true });
90
+ }
91
+
51
92
  const relevantSkills = this.getRelevantSkills(platforms);
52
93
 
53
94
  relevantSkills.forEach(skillName => {
@@ -69,9 +110,13 @@ class HookInstaller {
69
110
  }
70
111
 
71
112
  installHooks(claudeHooksDir) {
72
- const libraryHooksDir = path.join(this.hookSystemRoot, 'hooks');
113
+ const packageRoot = this.getPackageRoot();
114
+ const libraryHooksDir = this.resolveFirstExistingDir([
115
+ path.join(this.hookSystemRoot, 'hooks'),
116
+ path.join(packageRoot, 'hooks')
117
+ ]);
73
118
 
74
- if (!fs.existsSync(libraryHooksDir)) {
119
+ if (!libraryHooksDir) {
75
120
  return;
76
121
  }
77
122
 
@@ -111,7 +156,8 @@ class HookInstaller {
111
156
  }
112
157
 
113
158
  copyIDERules() {
114
- const sourceRulesDir = path.join(this.hookSystemRoot, '.cursor', 'rules');
159
+ const packageRoot = this.getPackageRoot();
160
+ const sourceRulesDir = path.join(packageRoot, '.cursor', 'rules');
115
161
 
116
162
  if (!fs.existsSync(sourceRulesDir)) {
117
163
  return;
@@ -139,12 +185,6 @@ class HookInstaller {
139
185
  }
140
186
 
141
187
  getRelevantSkills(platforms) {
142
- const m_get_relevant_skills = createMetricScope({
143
- hook: 'hook_installer',
144
- operation: 'get_relevant_skills'
145
- });
146
-
147
- m_get_relevant_skills.started();
148
188
  const allSkills = ['backend-guidelines', 'frontend-guidelines', 'ios-guidelines', 'android-guidelines'];
149
189
  const relevantSkills = [];
150
190
 
@@ -153,8 +193,6 @@ class HookInstaller {
153
193
  if (platforms.includes('ios')) relevantSkills.push('ios-guidelines');
154
194
  if (platforms.includes('android')) relevantSkills.push('android-guidelines');
155
195
 
156
- m_get_relevant_skills.success();
157
-
158
196
  return relevantSkills.length > 0 ? relevantSkills : allSkills;
159
197
  }
160
198