pumuki-ast-hooks 5.3.20 → 5.3.21

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 +58 -58
  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,20 +1,9 @@
1
1
  const path = require('path');
2
2
 
3
- const {
4
- createMetricScope: createMetricScope
5
- } = require('../../../infrastructure/telemetry/metric-scope');
6
-
7
3
  class FileContextGrouper {
8
4
  constructor(featureDetector, platformDetector = null) {
9
- const m_constructor = createMetricScope({
10
- hook: 'file_context_grouper',
11
- operation: 'constructor'
12
- });
13
-
14
- m_constructor.started();
15
5
  this.featureDetector = featureDetector;
16
6
  this.platformDetector = platformDetector;
17
- m_constructor.success();
18
7
  }
19
8
 
20
9
  group(files) {
@@ -100,18 +89,10 @@ class FileContextGrouper {
100
89
  }
101
90
 
102
91
  getContextDirectory(file) {
103
- const m_get_context_directory = createMetricScope({
104
- hook: 'file_context_grouper',
105
- operation: 'get_context_directory'
106
- });
107
-
108
- m_get_context_directory.started();
109
92
  const parts = file.split(path.sep);
110
93
  if (parts.length <= 2) {
111
- m_get_context_directory.success();
112
94
  return parts[0] || 'root';
113
95
  }
114
- m_get_context_directory.success();
115
96
  return parts.slice(0, 2).join(path.sep);
116
97
  }
117
98
 
@@ -1,7 +1,3 @@
1
- const {
2
- createMetricScope: createMetricScope
3
- } = require('../../../infrastructure/telemetry/metric-scope');
4
-
5
1
  class SmartCommitSummaryBuilder {
6
2
  build(suggestions, orphans) {
7
3
  const lines = [];
@@ -1,9 +1,5 @@
1
1
  const CursorTokenRepository = require('../../../infrastructure/repositories/CursorTokenRepository');
2
2
 
3
- const {
4
- createMetricScope: createMetricScope
5
- } = require('../../../infrastructure/telemetry/metric-scope');
6
-
7
3
  class CursorTokenService {
8
4
  constructor({
9
5
  cursorTokenRepository = null,
@@ -14,12 +10,6 @@ class CursorTokenService {
14
10
  fetchImpl,
15
11
  logger = console
16
12
  } = {}) {
17
- const m_constructor = createMetricScope({
18
- hook: 'cursor_token_service',
19
- operation: 'constructor'
20
- });
21
-
22
- m_constructor.started();
23
13
  this.logger = logger;
24
14
  this.repository = cursorTokenRepository || new CursorTokenRepository({
25
15
  repoRoot,
@@ -29,34 +19,24 @@ class CursorTokenService {
29
19
  fetchImpl,
30
20
  logger
31
21
  });
32
- m_constructor.success();
33
22
  }
34
23
 
35
24
  async getCurrentUsage() {
36
- const m_get_current_usage = createMetricScope({
37
- hook: 'cursor_token_service',
38
- operation: 'get_current_usage'
39
- });
40
-
41
- m_get_current_usage.started();
42
25
  // Strategy: First try API (most accurate), then File (fallback/offline)
43
26
 
44
27
  const apiUsage = await this.repository.getUsageFromApi();
45
28
  if (apiUsage) {
46
29
  this.logger.debug?.('CURSOR_SERVICE_USING_API', { usage: apiUsage });
47
- m_get_current_usage.success();
48
30
  return apiUsage;
49
31
  }
50
32
 
51
33
  const fileUsage = await this.repository.getUsageFromFile();
52
34
  if (fileUsage) {
53
35
  this.logger.debug?.('CURSOR_SERVICE_USING_FILE', { usage: fileUsage });
54
- m_get_current_usage.success();
55
36
  return fileUsage;
56
37
  }
57
38
 
58
39
  this.logger.warn?.('CURSOR_SERVICE_NO_DATA_AVAILABLE');
59
- m_get_current_usage.success();
60
40
  return null;
61
41
  }
62
42
  }
@@ -1,22 +1,11 @@
1
1
  const { execSync } = require('child_process');
2
2
 
3
- const {
4
- createMetricScope: createMetricScope
5
- } = require('../../../infrastructure/telemetry/metric-scope');
6
-
7
3
  class TokenMetricsService {
8
4
  constructor(cursorTokenService, thresholds, logger) {
9
- const m_constructor = createMetricScope({
10
- hook: 'token_metrics_service',
11
- operation: 'constructor'
12
- });
13
-
14
- m_constructor.started();
15
5
  this.cursorTokenService = cursorTokenService;
16
6
  this.thresholds = thresholds;
17
7
  this.logger = logger;
18
8
  this.repoRoot = process.cwd();
19
- m_constructor.success();
20
9
  }
21
10
 
22
11
  async collectMetrics(fallbackEstimator) {
@@ -65,7 +54,8 @@ class TokenMetricsService {
65
54
  if (untrusted) {
66
55
  level = 'ok';
67
56
  }
68
- const forceLevel = (process.env.TOKEN_MONITOR_FORCE_LEVEL || '').toLowerCase();
57
+ const env = require('../../config/env');
58
+ const forceLevel = (env.get('TOKEN_MONITOR_FORCE_LEVEL', '') || '').toLowerCase();
69
59
  if (forceLevel === 'warning' || forceLevel === 'critical' || forceLevel === 'ok') {
70
60
  level = forceLevel;
71
61
  }
@@ -2,10 +2,6 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execSync } = require('child_process');
4
4
 
5
- const {
6
- createMetricScope: createMetricScope
7
- } = require('../../../infrastructure/telemetry/metric-scope');
8
-
9
5
  const fsPromises = fs.promises;
10
6
  const CursorTokenService = require('./CursorTokenService');
11
7
  const NotificationCenterService = require('../notification/NotificationCenterService');
@@ -25,12 +21,6 @@ class TokenMonitorService {
25
21
  fallbackEstimator = null,
26
22
  cursorTokenService = null
27
23
  } = {}) {
28
- const m_constructor = createMetricScope({
29
- hook: 'token_monitor_service',
30
- operation: 'constructor'
31
- });
32
-
33
- m_constructor.started();
34
24
  this.repoRoot = repoRoot;
35
25
  this.dataFile = dataFile || path.join(this.repoRoot, '.audit_tmp', 'token-usage.jsonl');
36
26
  this.stateFile = stateFile || path.join(this.repoRoot, '.AI_TOKEN_STATUS.txt');
@@ -57,16 +47,9 @@ class TokenMonitorService {
57
47
 
58
48
  this.metricsService = new TokenMetricsService(this.cursorTokenService, this.thresholds, this.logger);
59
49
  this.statusReporter = new TokenStatusReporter(this.stateFile);
60
- m_constructor.success();
61
50
  }
62
51
 
63
52
  async run() {
64
- const m_run = createMetricScope({
65
- hook: 'token_monitor_service',
66
- operation: 'run'
67
- });
68
-
69
- m_run.started();
70
53
  // Collect metrics
71
54
  const metrics = await this.metricsService.collectMetrics(this.fallbackEstimator);
72
55
 
@@ -76,8 +59,6 @@ class TokenMonitorService {
76
59
  // Notify
77
60
  await this.emitNotification(metrics);
78
61
 
79
- m_run.success();
80
-
81
62
  return metrics;
82
63
  }
83
64
 
@@ -1,21 +1,9 @@
1
1
  const fs = require('fs');
2
-
3
- const {
4
- createMetricScope: createMetricScope
5
- } = require('../../../infrastructure/telemetry/metric-scope');
6
-
7
2
  const fsPromises = fs.promises;
8
3
 
9
4
  class TokenStatusReporter {
10
5
  constructor(stateFile) {
11
- const m_constructor = createMetricScope({
12
- hook: 'token_status_reporter',
13
- operation: 'constructor'
14
- });
15
-
16
- m_constructor.started();
17
6
  this.stateFile = stateFile;
18
- m_constructor.success();
19
7
  }
20
8
 
21
9
  async writeStatusFile(metrics) {
@@ -121,7 +121,21 @@ const commands = {
121
121
  },
122
122
 
123
123
  ast: () => {
124
- execSync(`node ${path.join(HOOKS_ROOT, 'infrastructure/ast/ast-intelligence.js')}`, { stdio: 'inherit' });
124
+ const env = { ...process.env };
125
+ const filteredArgs = [];
126
+
127
+ for (const arg of args) {
128
+ if (arg === '--staged') {
129
+ env.STAGING_ONLY_MODE = '1';
130
+ } else {
131
+ filteredArgs.push(arg);
132
+ }
133
+ }
134
+
135
+ execSync(
136
+ `node ${path.join(HOOKS_ROOT, 'infrastructure/ast/ast-intelligence.js')} ${filteredArgs.join(' ')}`,
137
+ { stdio: 'inherit', env }
138
+ );
125
139
  },
126
140
 
127
141
  install: () => {
@@ -1,40 +1,20 @@
1
1
  #!/bin/bash
2
- # ═══════════════════════════════════════════════════════════════
3
- # Guard Environment Defaults
4
- # ═══════════════════════════════════════════════════════════════
2
+ # Script Wrapper
3
+ # Redirects to the centralized implementation in scripts/hooks-system
4
+ REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo ".")
5
+ IMPL="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/scripts/hooks-system/bin/guard-env.sh"
6
+ if [[ -f "$IMPL" ]]; then
7
+ # shellcheck disable=SC1090
8
+ source "$IMPL"
9
+ return 0 2>/dev/null || exit 0
10
+ fi
5
11
 
6
- export HOOK_GUARD_EVIDENCE_STALE_THRESHOLD=${HOOK_GUARD_EVIDENCE_STALE_THRESHOLD:-180000}
7
- export HOOK_GUARD_EVIDENCE_POLL_INTERVAL=${HOOK_GUARD_EVIDENCE_POLL_INTERVAL:-30000}
8
- export HOOK_GUARD_EVIDENCE_REMINDER_INTERVAL=${HOOK_GUARD_EVIDENCE_REMINDER_INTERVAL:-120000}
9
- export HOOK_GUARD_INACTIVITY_GRACE_MS=${HOOK_GUARD_INACTIVITY_GRACE_MS:-60000}
10
- export HOOK_GUARD_AUTO_REFRESH=${HOOK_GUARD_AUTO_REFRESH:-true}
11
- export HOOK_GUARD_AI_START=${HOOK_GUARD_AI_START:-true}
12
- export HOOK_GUARD_AI_START_COOLDOWN=${HOOK_GUARD_AI_START_COOLDOWN:-60000}
13
- export HOOK_GUARD_EMBEDDED_TOKEN_MONITOR=${HOOK_GUARD_EMBEDDED_TOKEN_MONITOR:-false}
14
- export HOOK_GUARD_AUTORELOAD_DEBOUNCE=${HOOK_GUARD_AUTORELOAD_DEBOUNCE:-1500}
15
- export HOOK_GUARD_AUTORELOAD_FORCE=${HOOK_GUARD_AUTORELOAD_FORCE:-5000}
16
- export HOOK_GUARD_DIRTY_TREE_LIMIT=${HOOK_GUARD_DIRTY_TREE_LIMIT:-24}
17
- export HOOK_GUARD_DIRTY_TREE_WARNING=${HOOK_GUARD_DIRTY_TREE_WARNING:-12}
18
- export HOOK_GUARD_DIRTY_TREE_INTERVAL=${HOOK_GUARD_DIRTY_TREE_INTERVAL:-60000}
19
- export HOOK_GUARD_DIRTY_TREE_REMINDER=${HOOK_GUARD_DIRTY_TREE_REMINDER:-300000}
20
- export TOKEN_MONITOR_INTERVAL=${TOKEN_MONITOR_INTERVAL:-180}
21
- export TOKEN_MONITOR_REMINDER_SECONDS=${TOKEN_MONITOR_REMINDER_SECONDS:-180}
22
- export TOKEN_MONITOR_MIN_DELTA=${TOKEN_MONITOR_MIN_DELTA:-25000}
23
- export HOOK_GUARD_GITFLOW_AUTOSYNC=${HOOK_GUARD_GITFLOW_AUTOSYNC:-true}
24
- export HOOK_GUARD_GITFLOW_AUTOSYNC_INTERVAL=${HOOK_GUARD_GITFLOW_AUTOSYNC_INTERVAL:-300000}
25
- export HOOK_GUARD_GITFLOW_AUTOSYNC_COOLDOWN=${HOOK_GUARD_GITFLOW_AUTOSYNC_COOLDOWN:-900000}
26
- export HOOK_GUARD_GITFLOW_AUTOCLEAN=${HOOK_GUARD_GITFLOW_AUTOCLEAN:-true}
27
- export HOOK_GUARD_GITFLOW_MAIN_BRANCH=${HOOK_GUARD_GITFLOW_MAIN_BRANCH:-main}
28
- export HOOK_GUARD_GITFLOW_DEVELOP_BRANCH=${HOOK_GUARD_GITFLOW_DEVELOP_BRANCH:-develop}
29
- export HOOK_GUARD_GITFLOW_REQUIRE_CLEAN=${HOOK_GUARD_GITFLOW_REQUIRE_CLEAN:-true}
30
- export GUARD_AUTOSTART_HEALTHY_INTERVAL=${GUARD_AUTOSTART_HEALTHY_INTERVAL:-0}
31
- export GUARD_AUTOSTART_HEALTHY_COOLDOWN=${GUARD_AUTOSTART_HEALTHY_COOLDOWN:-900000}
32
- export HOOK_GUARD_HEARTBEAT_PATH="${HOOK_GUARD_HEARTBEAT_PATH:-.audit_tmp/guard-heartbeat.json}"
33
- export HOOK_GUARD_HEARTBEAT_INTERVAL=${HOOK_GUARD_HEARTBEAT_INTERVAL:-15000}
34
- export HOOK_GUARD_HEARTBEAT_MAX_AGE=${HOOK_GUARD_HEARTBEAT_MAX_AGE:-45000}
35
- export HOOK_GUARD_HEARTBEAT_CHECK_INTERVAL=${HOOK_GUARD_HEARTBEAT_CHECK_INTERVAL:-15000}
36
- export HOOK_GUARD_HEARTBEAT_NOTIFY_COOLDOWN=${HOOK_GUARD_HEARTBEAT_NOTIFY_COOLDOWN:-180000}
37
- export HOOK_GUARD_GITFLOW_MONITOR=${HOOK_GUARD_GITFLOW_MONITOR:-true}
38
- export HOOK_GUARD_GITFLOW_MONITOR_INTERVAL=${HOOK_GUARD_GITFLOW_MONITOR_INTERVAL:-300000}
39
- export HOOK_GUARD_GITFLOW_BRANCH_COOLDOWN=${HOOK_GUARD_GITFLOW_BRANCH_COOLDOWN:-900000}
40
- export HOOK_GUARD_DEV_DOCS_AUTO_REFRESH=${HOOK_GUARD_DEV_DOCS_AUTO_REFRESH:-true}
12
+ IMPL="$REPO_ROOT/node_modules/pumuki-ast-hooks/scripts/hooks-system/bin/guard-env.sh"
13
+ if [[ -f "$IMPL" ]]; then
14
+ # shellcheck disable=SC1090
15
+ source "$IMPL"
16
+ return 0 2>/dev/null || exit 0
17
+ fi
18
+
19
+ echo "guard-env.sh implementation not found. Please reinstall dependencies." >&2
20
+ return 1 2>/dev/null || exit 1