pumuki-ast-hooks 5.5.15 → 5.5.16

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 CHANGED
@@ -28,6 +28,37 @@
28
28
  <a href="./docs/CONTRIBUTING.md">Contributing</a>
29
29
  </p>
30
30
 
31
+ ## 📖 Table of Contents
32
+
33
+ - [The Vision: Solving AI Context Loss](#-the-vision-solving-ai-context-loss-in-software-development)
34
+ - [The Fundamental Problem](#the-fundamental-problem)
35
+ - [The Solution: Permanent Context Persistence](#the-solution-permanent-context-persistence)
36
+ - [How It Works: The Complete Flow](#-how-it-works-the-complete-flow)
37
+ - [Phase 1: Context Initialization (`ai_start` Protocol)](#phase-1-context-initialization-ai_start-protocol)
38
+ - [Phase 2: Continuous Context Maintenance](#phase-2-continuous-context-maintenance)
39
+ - [Phase 3: Code Quality Enforcement](#phase-3-code-quality-enforcement)
40
+ - [Phase 4: Evidence Update Before Commits](#phase-4-evidence-update-before-commits)
41
+ - [Tools & Technologies](#️-tools--technologies)
42
+ - [What, How, and When: The Developer's Perspective](#-what-how-and-when-the-developers-perspective)
43
+ - [Complete Architecture and Workflow](#complete-architecture-and-workflow)
44
+ - [What is it?](#what-is-it)
45
+ - [What problems does it solve?](#what-problems-does-it-solve)
46
+ - [Features](#features)
47
+ - [Use Cases](#use-cases)
48
+ - [Installation](#installation)
49
+ - [Quick Start](#quick-start)
50
+ - [📚 Documentation Guide - Step by Step](#-documentation-guide---step-by-step)
51
+ - [Architecture](#architecture)
52
+ - [MCP Servers](#mcp-servers)
53
+ - [API Reference](#api-reference)
54
+ - [Configuration](#configuration)
55
+ - [Best Practices](#best-practices)
56
+ - [FAQ](#faq)
57
+ - [Contributing](#contributing)
58
+ - [License](#license)
59
+
60
+ ---
61
+
31
62
  ### Visual Overview
32
63
 
33
64
  <img src="https://raw.githubusercontent.com/SwiftEnProfundidad/ast-intelligence-hooks/main/docs/images/ast_intelligence_01.png" alt="AST Intelligence System Overview" width="100%" />
@@ -386,66 +417,12 @@ For a detailed architecture, see [ARCHITECTURE.md](ARCHITECTURE.md).
386
417
 
387
418
  ---
388
419
 
389
- ## 📖 Table of Contents
390
-
391
- - [The Vision: Solving AI Context Loss](#-the-vision-solving-ai-context-loss-in-software-development)
392
- - [The Fundamental Problem](#the-fundamental-problem)
393
- - [The Solution: Permanent Context Persistence](#the-solution-permanent-context-persistence)
394
- - [How It Works: The Complete Flow](#-how-it-works-the-complete-flow)
395
- - [Phase 1: Context Initialization (`ai_start` Protocol)](#phase-1-context-initialization-ai_start-protocol)
396
- - [Phase 2: Continuous Context Maintenance](#phase-2-continuous-context-maintenance)
397
- - [Phase 3: Code Quality Enforcement](#phase-3-code-quality-enforcement)
398
- - [Phase 4: Evidence Update Before Commits](#phase-4-evidence-update-before-commits)
399
- - [Tools & Technologies](#️-tools--technologies)
400
- - [What, How, and When: The Developer's Perspective](#-what-how-and-when-the-developers-perspective)
401
- - [Complete Architecture and Workflow](#complete-architecture-and-workflow)
402
- - [What is it?](#what-is-it)
403
- - [What problems does it solve?](#what-problems-does-it-solve)
404
- - [Features](#features)
405
- - [Use Cases](#use-cases)
406
- - [Installation](#installation)
407
- - [Quick Start](#quick-start)
408
- - [📚 Documentation Guide - Step by Step](#-documentation-guide---step-by-step)
409
- - [Architecture](#architecture)
410
- - [MCP Servers](#mcp-servers)
411
- - [API Reference](#api-reference)
412
- - [Configuration](#configuration)
413
- - [Best Practices](#best-practices)
414
- - [FAQ](#faq)
415
- - [Contributing](#contributing)
416
- - [License](#license)
417
-
418
- ---
419
-
420
420
  ## What is it?
421
421
 
422
422
  `ast-intelligence-hooks` is an intelligent static analysis system that automatically validates that your code complies with **Clean Architecture**, **Domain-Driven Design (DDD)**, and **Feature-First Architecture** principles.
423
423
 
424
424
  **But more importantly**, it's a **context persistence system** that ensures AI assistants maintain permanent understanding of your project through the `ai_start` protocol, automatic rule loading, and continuously updated `.AI_EVIDENCE.json`.
425
425
 
426
- ### Key Features
427
-
428
- #### 🧠 Context Persistence (Core Purpose)
429
- - ✅ **`ai_start` Protocol**: Automatically answers the three critical questions for AI context
430
- - ✅ **`.AI_EVIDENCE.json`**: Permanent context file that never goes stale
431
- - ✅ **Automatic rule loading**: All 798+ rules loaded automatically for AI awareness
432
- - ✅ **Context detection**: Real-time understanding of what you're working on
433
-
434
- #### 🔍 Code Validation
435
- - ✅ **798+ validation rules** across all platforms with severity-based quality gates
436
- - ✅ **Multi-platform support**: iOS (Swift/SwiftUI), Android (Kotlin/Jetpack Compose), Backend (TypeScript/NestJS), Frontend (React/Next.js)
437
- - ✅ **Automatic architecture detection**: Identifies multiple patterns per platform (iOS: MVVM, MVVM-C, MVP, VIPER, TCA, Clean Swift, Feature-First + Clean + DDD; Backend: Clean Architecture, DDD, CQRS; Frontend: Feature-First, Component-Based, Atomic Design; Android: MVVM, MVI, MVP, Clean Architecture)
438
- - ✅ **BDD→TDD workflow enforcement**: CRITICAL priority - ensures feature files exist before implementation and tests before code
439
- - ✅ **Pre-commit Git hooks**: Automatic validation blocks commits with CRITICAL/HIGH violations
440
- - ✅ **AST analysis engine**: Deep static code analysis using Abstract Syntax Trees
441
- - ✅ **Clean Architecture enforcement**: Strict SOLID principles validation and dependency rules
442
-
443
- #### 🤖 Automation & Integration
444
- - ✅ **Git Flow automation**: Complete workflow automation via MCP (commit → push → PR → merge)
445
- - ✅ **MCP integration**: Standard Model Context Protocol (MCP) support for any agentic IDE or AI client (Cursor, Claude Desktop, etc.)
446
- - ✅ **Version checking**: Automatic detection of library updates
447
- - ✅ **CI/CD ready**: Seamless integration with GitHub Actions and other CI systems
448
-
449
426
  ---
450
427
 
451
428
  ## What problems does it solve?
@@ -551,8 +528,7 @@ git commit -m "feat: add new feature"
551
528
 
552
529
  ```bash
553
530
  # Analyzes entire codebase
554
- npm run audit
555
-
531
+ bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
556
532
  # Or using CLI
557
533
  ast-hooks analyze
558
534
  ```
@@ -562,7 +538,7 @@ ast-hooks analyze
562
538
  ```yaml
563
539
  # .github/workflows/ci.yml
564
540
  - name: Run AST Analysis
565
- run: npm run audit
541
+ run: bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
566
542
  ```
567
543
 
568
544
  ### 4. Programmatic Usage
@@ -594,7 +570,7 @@ hook-status
594
570
 
595
571
  ---
596
572
 
597
- ## Installation
573
+ ## Quick Start
598
574
 
599
575
  ### Prerequisites
600
576
 
@@ -602,50 +578,10 @@ hook-status
602
578
  - **npm** ≥9.0.0
603
579
  - **Git** (for hooks)
604
580
 
605
- ### Option 1: Installation via npm (Recommended)
606
-
607
- ```bash
608
- npm install --save-dev pumuki-ast-hooks
609
- npm run install-hooks
610
- ```
611
-
612
- ### Option 2: Installation via Git
613
-
614
- ```bash
615
- npm install --save-dev git+https://github.com/carlos/ast-intelligence-hooks.git
616
- npm run install-hooks
617
- ```
618
-
619
- ### Option 3: Manual Installation
620
-
621
- ```bash
622
- git clone https://github.com/carlos/ast-intelligence-hooks.git
623
- cd ast-intelligence-hooks
624
- npm install
625
- npm link
626
- npm run install-hooks
627
- ```
628
-
629
- ### Configure Git Hooks
630
-
631
- ```bash
632
- # Install hooks automatically
633
- npm run install-hooks
634
-
635
- # Or manually
636
- ast-install
637
- ```
638
-
639
- For more details, see [INSTALLATION.md](./docs/INSTALLATION.md).
640
-
641
- ---
642
-
643
- ## Quick Start
644
-
645
581
  ### 1. Install the library
646
582
 
647
583
  ```bash
648
- npm install --save-dev @pumuki/ast-intelligence-hooks
584
+ npm install --save-dev pumuki-ast-hooks
649
585
  ```
650
586
 
651
587
  ### 2. Configure hooks
@@ -666,17 +602,17 @@ The hooks will run automatically and validate your code.
666
602
  ### 4. View full report
667
603
 
668
604
  ```bash
669
- npm run audit
605
+ bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
670
606
  ```
671
607
 
672
608
  ### 5. Check violations
673
609
 
674
610
  ```bash
675
611
  # List all violations
676
- npm run violations:list
612
+ npm run violations
677
613
 
678
614
  # View summary
679
- npm run violations:summary
615
+ bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
680
616
 
681
617
  # Top violations
682
618
  npm run violations:top
@@ -995,14 +931,14 @@ npm run install-hooks
995
931
  ```yaml
996
932
  # .github/workflows/ci.yml
997
933
  - name: AST Analysis
998
- run: npm run audit
934
+ run: bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
999
935
  ```
1000
936
 
1001
937
  ### 3. Review Violations Regularly
1002
938
 
1003
939
  ```bash
1004
940
  # Weekly
1005
- npm run violations:summary
941
+ bash scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh
1006
942
  ```
1007
943
 
1008
944
  ### 4. Configure Appropriate Exclusions
@@ -1100,6 +1036,8 @@ npm run install-hooks # Install hooks
1100
1036
  npm test # Run tests
1101
1037
  npm run lint # Linter
1102
1038
  npm run typecheck # Type checking
1039
+ npm run violations # List violations
1040
+ npm run violations:top # Top violations
1103
1041
  ```
1104
1042
 
1105
1043
  ---
@@ -1125,6 +1063,54 @@ For coding standards, see [CODE_STANDARDS.md](./docs/CODE_STANDARDS.md).
1125
1063
 
1126
1064
  ---
1127
1065
 
1066
+ ## 📝 Recent Changes
1067
+
1068
+ ### Version 5.5.16 (2026-01-04)
1069
+
1070
+ **✨ New Features:**
1071
+ - Restored evidence fields: `protocol_3_questions`, `rules_read`, `current_context`, `platforms`, `session_id`
1072
+ - Added macOS notifications when AI Gate status=BLOCKED
1073
+ - Comprehensive notification types documentation in MCP_SERVERS.md
1074
+ - E2E tests for notification system
1075
+
1076
+ **🔧 Improvements:**
1077
+ - Reorganized README with Table of Contents at the beginning
1078
+ - Consolidated duplicate Features sections
1079
+ - Removed duplicate architectural diagrams
1080
+ - Enhanced documentation structure for better navigation
1081
+
1082
+ **🐛 Bug Fixes:**
1083
+ - Fixed evidence staleness detection in RealtimeGuardService
1084
+ - Improved notification error handling with graceful fallbacks
1085
+
1086
+ ---
1087
+
1088
+ ## ⚠️ Known Issues
1089
+
1090
+ ### Current Limitations
1091
+
1092
+ 1. **macOS Notifications Only**
1093
+ - Notifications currently use osascript (macOS-only)
1094
+ - Other platforms fall back gracefully without errors
1095
+ - Future versions will add cross-platform notification support
1096
+
1097
+ 2. **Evidence Staleness Threshold**
1098
+ - Default threshold is 180 seconds (3 minutes)
1099
+ - May need adjustment for slower systems
1100
+ - Configure via `HOOK_GUARD_EVIDENCE_STALE_THRESHOLD` environment variable
1101
+
1102
+ 3. **Token Monitor Integration**
1103
+ - Token monitor requires explicit environment variable `HOOK_GUARD_EMBEDDED_TOKEN_MONITOR=true`
1104
+ - Not enabled by default to avoid overhead
1105
+
1106
+ ### Workarounds
1107
+
1108
+ - For non-macOS systems: Disable notifications via `HOOK_GUARD_MACOS_NOTIFICATIONS=false`
1109
+ - For slower systems: Increase staleness threshold via environment variable
1110
+ - For token monitoring: Enable explicitly if needed for your workflow
1111
+
1112
+ ---
1113
+
1128
1114
  ## License
1129
1115
 
1130
1116
  This project is licensed under the **MIT License** - see [LICENSE](./LICENSE) for more details.
@@ -1137,8 +1123,8 @@ Developed by **Pumuki Team®**
1137
1123
 
1138
1124
  - **Author**: Juan Carlos Merlos Albarracín (Senior Software Architect - AI-Driven Development)
1139
1125
  - **Contact**: freelancemerlos@gmail.com
1140
- - **Version**: 5.3.9
1141
- - **Repository**: [GitHub](https://github.com/carlos/ast-intelligence-hooks)
1126
+ - **Version**: 5.5.16
1127
+ - **Repository**: [GitHub](https://github.com/SwiftEnProfundidad/ast-intelligence-hooks)
1142
1128
 
1143
1129
  ---
1144
1130
 
@@ -654,6 +654,62 @@ if (aiStart.success && aiStart.evidenceUpdated) {
654
654
 
655
655
  ---
656
656
 
657
+ ## Notification Types
658
+
659
+ The system supports multiple notification channels to keep AI informed of critical events:
660
+
661
+ ### macOS Notifications
662
+
663
+ **Triggered by:** `ai_gate_check()` when violations are detected (status=BLOCKED)
664
+
665
+ **Format:**
666
+ - **Title:** `🚨 AI Gate BLOCKED`
667
+ - **Message:** `{violation_count} violation(s) detected. Fix before proceeding.`
668
+ - **Sound:** Basso (critical alert)
669
+ - **Platform:** macOS only (graceful fallback on other systems)
670
+
671
+ **Example:**
672
+ ```
673
+ Title: 🚨 AI Gate BLOCKED
674
+ Message: 3 violation(s) detected. Fix before proceeding.
675
+ Sound: Basso
676
+ ```
677
+
678
+ ### Evidence Staleness Notifications
679
+
680
+ **Triggered by:** `RealtimeGuardService` when evidence becomes stale
681
+
682
+ **Levels:**
683
+ - **Warning:** Evidence is stale - Auto-refreshing...
684
+ - **Success:** Evidence refreshed successfully
685
+ - **Error:** Failed to refresh evidence
686
+
687
+ ### Token Monitor Notifications
688
+
689
+ **Triggered by:** Token monitor when usage exceeds thresholds
690
+
691
+ **Levels:**
692
+ - **Info:** 🔋 Token monitor started
693
+ - **Warning:** Token usage at 75%+
694
+ - **Critical:** Token usage at 90%+
695
+
696
+ ### Git Flow Notifications
697
+
698
+ **Triggered by:** Git flow auto-sync when branches are synchronized
699
+
700
+ **Format:**
701
+ - **Info:** 🔄 Branches synchronized
702
+ - **Error:** Git flow sync failed
703
+
704
+ ### Notification Configuration
705
+
706
+ **Environment Variables:**
707
+ - `HOOK_GUARD_NOTIFICATIONS_ENABLED` - Enable/disable all notifications (default: true)
708
+ - `HOOK_GUARD_NOTIFICATION_LEVEL` - Minimum level to display (info|warning|error)
709
+ - `HOOK_GUARD_MACOS_NOTIFICATIONS` - Enable macOS notifications (default: true)
710
+
711
+ ---
712
+
657
713
  ## Troubleshooting
658
714
 
659
715
  ### MCP Server Doesn't Start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pumuki-ast-hooks",
3
- "version": "5.5.15",
3
+ "version": "5.5.16",
4
4
  "description": "Enterprise-grade AST Intelligence System with multi-platform support (iOS, Android, Backend, Frontend) and Feature-First + DDD + Clean Architecture enforcement. Includes dynamic violations API for intelligent querying.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -85,6 +85,9 @@
85
85
  "glob": "^10.5.0",
86
86
  "ts-morph": "^21.0.0"
87
87
  },
88
+ "peerDependencies": {
89
+ "ts-morph": ">=21.0.0"
90
+ },
88
91
  "devDependencies": {
89
92
  "@babel/generator": "^7.28.5",
90
93
  "@babel/parser": "^7.28.5",
@@ -123,4 +126,4 @@
123
126
  "./skills": "./skills/skill-rules.json",
124
127
  "./hooks": "./hooks/index.js"
125
128
  }
126
- }
129
+ }
@@ -76,6 +76,43 @@ class InstallService {
76
76
  this.ideIntegration = new IdeIntegrationService(this.targetRoot, this.hookSystemRoot, this.logger);
77
77
  }
78
78
 
79
+ checkCriticalDependencies() {
80
+ const packageJsonPath = path.join(this.targetRoot, 'package.json');
81
+
82
+ if (!fs.existsSync(packageJsonPath)) {
83
+ this.logWarning('package.json not found. Skipping dependency check.');
84
+ return;
85
+ }
86
+
87
+ try {
88
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
89
+ const allDeps = {
90
+ ...packageJson.dependencies,
91
+ ...packageJson.devDependencies
92
+ };
93
+
94
+ const criticalDeps = ['ts-morph'];
95
+ const missingDeps = [];
96
+
97
+ for (const dep of criticalDeps) {
98
+ if (!allDeps[dep]) {
99
+ missingDeps.push(dep);
100
+ }
101
+ }
102
+
103
+ if (missingDeps.length > 0) {
104
+ this.logWarning(`Missing critical dependencies: ${missingDeps.join(', ')}`);
105
+ this.logWarning('AST analysis may fail without these dependencies.');
106
+ this.logWarning(`Install with: npm install --save-dev ${missingDeps.join(' ')}`);
107
+ this.logger.warn('MISSING_CRITICAL_DEPENDENCIES', { missingDeps });
108
+ } else {
109
+ this.logSuccess('All critical dependencies present');
110
+ }
111
+ } catch (error) {
112
+ this.logWarning(`Failed to check dependencies: ${error.message}`);
113
+ }
114
+ }
115
+
79
116
  async run() {
80
117
  this.logger.info('INSTALLATION_STARTED', { targetRoot: this.targetRoot });
81
118
  this.printHeader();
@@ -89,6 +126,9 @@ class InstallService {
89
126
  }
90
127
  this.logSuccess('Git repository detected');
91
128
 
129
+ this.logStep('0.25/8', 'Verifying critical dependencies...');
130
+ this.checkCriticalDependencies();
131
+
92
132
  this.logStep('0.5/8', 'Configuring artifact exclusions...');
93
133
  this.gitService.ensureGitInfoExclude();
94
134
 
@@ -169,6 +169,37 @@ const commands = {
169
169
  process.stdout.write(`${evidencePath}\n`);
170
170
  },
171
171
 
172
+ 'evidence:full-update': () => {
173
+ const auditScript = path.join(HOOKS_ROOT, 'infrastructure/orchestration/intelligent-audit.js');
174
+
175
+ if (!fs.existsSync(auditScript)) {
176
+ console.error('❌ intelligent-audit.js not found');
177
+ process.exit(1);
178
+ }
179
+
180
+ console.log('🔍 Running full AST analysis and updating evidence...');
181
+
182
+ try {
183
+ execSync(`node "${auditScript}"`, {
184
+ stdio: 'inherit',
185
+ env: {
186
+ ...process.env,
187
+ AUTO_EVIDENCE_TRIGGER: process.env.AUTO_EVIDENCE_TRIGGER || 'manual',
188
+ AUTO_EVIDENCE_REASON: process.env.AUTO_EVIDENCE_REASON || 'full_update',
189
+ AUTO_EVIDENCE_SUMMARY: process.env.AUTO_EVIDENCE_SUMMARY || 'Full evidence update with AST analysis'
190
+ }
191
+ });
192
+
193
+ console.log('✅ Evidence updated with full AST analysis');
194
+
195
+ commands['evidence:update']();
196
+
197
+ } catch (error) {
198
+ console.error('❌ Failed to run full evidence update:', error.message);
199
+ process.exit(1);
200
+ }
201
+ },
202
+
172
203
  ast: () => {
173
204
  const filteredArgs = [];
174
205
  let stagingOnlyMode = false;
@@ -2,15 +2,15 @@
2
2
 
3
3
  REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo ".")
4
4
 
5
- AUTO_TRIGGER="${AUTO_EVIDENCE_TRIGGER:-}"
6
- AUTO_REASON="${AUTO_EVIDENCE_REASON:-}"
7
- AUTO_SUMMARY="${AUTO_EVIDENCE_SUMMARY:-}"
5
+ AUTO_TRIGGER="${AUTO_EVIDENCE_TRIGGER:-manual}"
6
+ AUTO_REASON="${AUTO_EVIDENCE_REASON:-user_invoked}"
7
+ AUTO_SUMMARY="${AUTO_EVIDENCE_SUMMARY:-Manual evidence update}"
8
8
 
9
9
  for arg in "$@"; do
10
10
  if [[ "$arg" == "--auto" ]]; then
11
- AUTO_TRIGGER="${AUTO_TRIGGER:-auto}"
12
- AUTO_REASON="${AUTO_REASON:-auto}"
13
- AUTO_SUMMARY="${AUTO_SUMMARY:-auto}"
11
+ AUTO_TRIGGER="auto"
12
+ AUTO_REASON="auto_refresh"
13
+ AUTO_SUMMARY="Automatic evidence refresh"
14
14
  fi
15
15
  done
16
16
 
@@ -25,4 +25,4 @@ if [[ ! -f "$CLI" ]]; then
25
25
  fi
26
26
 
27
27
  AUTO_EVIDENCE_TRIGGER="$AUTO_TRIGGER" AUTO_EVIDENCE_REASON="$AUTO_REASON" AUTO_EVIDENCE_SUMMARY="$AUTO_SUMMARY" \
28
- node "$CLI" evidence:update
28
+ node "$CLI" evidence:full-update
@@ -80,25 +80,61 @@ class EvidenceGuard {
80
80
 
81
81
  async refreshEvidence() {
82
82
  return new Promise((resolve) => {
83
- const child = spawn('bash', [this.updateScript, '--auto'], {
84
- cwd: this.projectRoot,
85
- stdio: 'ignore',
86
- detached: false
87
- });
88
-
89
- child.on('close', (code) => {
90
- if (code === 0) {
91
- console.log(`[EvidenceGuard] Evidence refreshed at ${new Date().toISOString()}`);
92
- } else {
93
- console.error(`[EvidenceGuard] Refresh failed with code ${code}`);
94
- }
95
- resolve();
96
- });
97
-
98
- child.on('error', (error) => {
99
- console.error('[EvidenceGuard] Refresh error:', error.message);
100
- resolve();
101
- });
83
+ const astScript = path.join(
84
+ this.projectRoot,
85
+ 'node_modules/pumuki-ast-hooks/scripts/hooks-system/infrastructure/orchestration/intelligent-audit.js'
86
+ );
87
+
88
+ if (fs.existsSync(astScript)) {
89
+ console.log('[EvidenceGuard] Running full AST analysis...');
90
+ const child = spawn('node', [astScript], {
91
+ cwd: this.projectRoot,
92
+ stdio: 'ignore',
93
+ detached: false,
94
+ env: {
95
+ ...process.env,
96
+ REPO_ROOT: this.projectRoot,
97
+ AUTO_EVIDENCE_TRIGGER: 'auto',
98
+ AUTO_EVIDENCE_REASON: 'evidence_guard_refresh',
99
+ AUTO_EVIDENCE_SUMMARY: 'Automatic refresh by evidence guard'
100
+ }
101
+ });
102
+
103
+ child.on('close', (code) => {
104
+ if (code === 0) {
105
+ console.log(`[EvidenceGuard] Full AST analysis completed at ${new Date().toISOString()}`);
106
+ } else {
107
+ console.error(`[EvidenceGuard] AST analysis failed with code ${code}`);
108
+ }
109
+ resolve();
110
+ });
111
+
112
+ child.on('error', (error) => {
113
+ console.error('[EvidenceGuard] Failed to spawn AST analysis:', error.message);
114
+ resolve();
115
+ });
116
+ } else {
117
+ console.warn('[EvidenceGuard] intelligent-audit.js not found, falling back to update-evidence.sh');
118
+ const child = spawn('bash', [this.updateScript, '--auto'], {
119
+ cwd: this.projectRoot,
120
+ stdio: 'ignore',
121
+ detached: false
122
+ });
123
+
124
+ child.on('close', (code) => {
125
+ if (code === 0) {
126
+ console.log(`[EvidenceGuard] Evidence refreshed (fallback) at ${new Date().toISOString()}`);
127
+ } else {
128
+ console.error(`[EvidenceGuard] Refresh failed with code ${code}`);
129
+ }
130
+ resolve();
131
+ });
132
+
133
+ child.on('error', (error) => {
134
+ console.error('[EvidenceGuard] Refresh error:', error.message);
135
+ resolve();
136
+ });
137
+ }
102
138
  });
103
139
  }
104
140
 
@@ -664,6 +664,22 @@ async function aiGateCheck() {
664
664
 
665
665
  const isBlocked = violations.length > 0;
666
666
 
667
+ if (isBlocked) {
668
+ try {
669
+ const { execSync } = require('child_process');
670
+ const os = require('os');
671
+
672
+ if (os.platform() === 'darwin') {
673
+ const notificationCmd = `osascript -e 'display notification "${violations.length} violation(s) detected. Fix before proceeding." with title "🚨 AI Gate BLOCKED" sound name "Basso"'`;
674
+ execSync(notificationCmd, { stdio: 'ignore' });
675
+ }
676
+ } catch (error) {
677
+ if (process.env.DEBUG) {
678
+ process.stderr.write(`[MCP] Failed to send macOS notification: ${error.message}\n`);
679
+ }
680
+ }
681
+ }
682
+
667
683
  return {
668
684
  status: isBlocked ? 'BLOCKED' : 'ALLOWED',
669
685
  timestamp: new Date().toISOString(),
@@ -1,3 +1,6 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
1
4
  describe('intelligent-audit', () => {
2
5
  it('should export module', () => {
3
6
  const mod = require('../intelligent-audit');
@@ -9,3 +12,153 @@ describe('intelligent-audit', () => {
9
12
  expect(typeof mod.runIntelligentAudit).toBe('function');
10
13
  });
11
14
  });
15
+
16
+ describe('AI_EVIDENCE.json structure validation', () => {
17
+ const createMockEvidence = () => ({
18
+ timestamp: new Date().toISOString(),
19
+ protocol_3_questions: {
20
+ answered: true,
21
+ question_1_file_type: 'Determine the file type and its purpose in the architecture',
22
+ question_2_similar_exists: 'Search for similar files or existing patterns in the codebase',
23
+ question_3_clean_architecture: 'Verify that the code follows Clean Architecture and SOLID principles',
24
+ last_answered: new Date().toISOString()
25
+ },
26
+ rules_read: {
27
+ backend: true,
28
+ frontend: false,
29
+ ios: false,
30
+ android: false,
31
+ gold: true,
32
+ last_checked: new Date().toISOString()
33
+ },
34
+ current_context: {
35
+ working_on: 'AST Intelligence Analysis',
36
+ last_files_edited: [],
37
+ current_branch: 'feature/phase2-restore-evidence-fields',
38
+ base_branch: 'develop',
39
+ timestamp: new Date().toISOString()
40
+ },
41
+ platforms: {
42
+ backend: { detected: true, violations: 465 },
43
+ frontend: { detected: false, violations: 0 },
44
+ ios: { detected: false, violations: 0 },
45
+ android: { detected: false, violations: 0 }
46
+ },
47
+ session_id: 'session-1704361200000-abc123def',
48
+ severity_metrics: {
49
+ last_updated: new Date().toISOString(),
50
+ total_violations: 465,
51
+ by_severity: {
52
+ CRITICAL: 0,
53
+ HIGH: 0,
54
+ MEDIUM: 232,
55
+ LOW: 233
56
+ },
57
+ average_severity_score: 45,
58
+ intelligent_evaluation_rate: 100,
59
+ gate_status: 'PASSED',
60
+ blocked_by: null
61
+ },
62
+ ai_gate: {
63
+ status: 'ALLOWED',
64
+ scope: 'staging',
65
+ last_check: new Date().toISOString(),
66
+ violations: [],
67
+ instruction: '🚨 AI MUST call mcp_ast-intelligence-automation_ai_gate_check BEFORE any action',
68
+ mandatory: true
69
+ }
70
+ });
71
+
72
+ it('should have protocol_3_questions field with all required properties', () => {
73
+ const evidence = createMockEvidence();
74
+ expect(evidence.protocol_3_questions).toBeDefined();
75
+ expect(evidence.protocol_3_questions.answered).toBe(true);
76
+ expect(evidence.protocol_3_questions.question_1_file_type).toBeDefined();
77
+ expect(evidence.protocol_3_questions.question_2_similar_exists).toBeDefined();
78
+ expect(evidence.protocol_3_questions.question_3_clean_architecture).toBeDefined();
79
+ expect(evidence.protocol_3_questions.last_answered).toBeDefined();
80
+ });
81
+
82
+ it('should have rules_read field tracking all platforms', () => {
83
+ const evidence = createMockEvidence();
84
+ expect(evidence.rules_read).toBeDefined();
85
+ expect(evidence.rules_read.backend).toBe(true);
86
+ expect(evidence.rules_read.frontend).toBe(false);
87
+ expect(evidence.rules_read.ios).toBe(false);
88
+ expect(evidence.rules_read.android).toBe(false);
89
+ expect(evidence.rules_read.gold).toBe(true);
90
+ expect(evidence.rules_read.last_checked).toBeDefined();
91
+ });
92
+
93
+ it('should have current_context field with branch and file info', () => {
94
+ const evidence = createMockEvidence();
95
+ expect(evidence.current_context).toBeDefined();
96
+ expect(evidence.current_context.working_on).toBeDefined();
97
+ expect(evidence.current_context.last_files_edited).toBeDefined();
98
+ expect(Array.isArray(evidence.current_context.last_files_edited)).toBe(true);
99
+ expect(evidence.current_context.current_branch).toBeDefined();
100
+ expect(evidence.current_context.base_branch).toBeDefined();
101
+ expect(evidence.current_context.timestamp).toBeDefined();
102
+ });
103
+
104
+ it('should have platforms field with detection and violation counts', () => {
105
+ const evidence = createMockEvidence();
106
+ expect(evidence.platforms).toBeDefined();
107
+ expect(evidence.platforms.backend).toBeDefined();
108
+ expect(evidence.platforms.backend.detected).toBe(true);
109
+ expect(typeof evidence.platforms.backend.violations).toBe('number');
110
+ expect(evidence.platforms.frontend).toBeDefined();
111
+ expect(evidence.platforms.ios).toBeDefined();
112
+ expect(evidence.platforms.android).toBeDefined();
113
+ });
114
+
115
+ it('should have session_id field with unique session identifier', () => {
116
+ const evidence = createMockEvidence();
117
+ expect(evidence.session_id).toBeDefined();
118
+ expect(typeof evidence.session_id).toBe('string');
119
+ expect(evidence.session_id).toMatch(/^session-\d+-[a-z0-9]+$/);
120
+ });
121
+
122
+ it('should have severity_metrics field with complete violation breakdown', () => {
123
+ const evidence = createMockEvidence();
124
+ expect(evidence.severity_metrics).toBeDefined();
125
+ expect(evidence.severity_metrics.total_violations).toBeDefined();
126
+ expect(evidence.severity_metrics.by_severity).toBeDefined();
127
+ expect(evidence.severity_metrics.by_severity.CRITICAL).toBeDefined();
128
+ expect(evidence.severity_metrics.by_severity.HIGH).toBeDefined();
129
+ expect(evidence.severity_metrics.by_severity.MEDIUM).toBeDefined();
130
+ expect(evidence.severity_metrics.by_severity.LOW).toBeDefined();
131
+ expect(evidence.severity_metrics.average_severity_score).toBeDefined();
132
+ expect(evidence.severity_metrics.intelligent_evaluation_rate).toBeDefined();
133
+ expect(evidence.severity_metrics.gate_status).toBeDefined();
134
+ });
135
+
136
+ it('should have ai_gate field with detailed violations array', () => {
137
+ const evidence = createMockEvidence();
138
+ expect(evidence.ai_gate).toBeDefined();
139
+ expect(evidence.ai_gate.status).toBeDefined();
140
+ expect(evidence.ai_gate.scope).toBeDefined();
141
+ expect(evidence.ai_gate.last_check).toBeDefined();
142
+ expect(Array.isArray(evidence.ai_gate.violations)).toBe(true);
143
+ expect(evidence.ai_gate.instruction).toBeDefined();
144
+ expect(evidence.ai_gate.mandatory).toBe(true);
145
+ });
146
+
147
+ it('should validate complete evidence structure with all restored fields', () => {
148
+ const evidence = createMockEvidence();
149
+ const requiredFields = [
150
+ 'protocol_3_questions',
151
+ 'rules_read',
152
+ 'current_context',
153
+ 'platforms',
154
+ 'session_id',
155
+ 'severity_metrics',
156
+ 'ai_gate'
157
+ ];
158
+
159
+ requiredFields.forEach(field => {
160
+ expect(evidence[field]).toBeDefined();
161
+ expect(evidence[field]).not.toBeNull();
162
+ });
163
+ });
164
+ });
@@ -288,6 +288,40 @@ function updateAIEvidence(violations, gateResult, tokenUsage) {
288
288
 
289
289
  evidence.ai_gate = preserveExistingRepoGate ? existingGate : nextGate;
290
290
 
291
+ evidence.protocol_3_questions = {
292
+ answered: true,
293
+ question_1_file_type: 'Determine the file type and its purpose in the architecture',
294
+ question_2_similar_exists: 'Search for similar files or existing patterns in the codebase',
295
+ question_3_clean_architecture: 'Verify that the code follows Clean Architecture and SOLID principles',
296
+ last_answered: formatLocalTimestamp()
297
+ };
298
+
299
+ evidence.rules_read = {
300
+ backend: true,
301
+ frontend: false,
302
+ ios: false,
303
+ android: false,
304
+ gold: true,
305
+ last_checked: formatLocalTimestamp()
306
+ };
307
+
308
+ evidence.current_context = {
309
+ working_on: env.get('AUTO_EVIDENCE_SUMMARY', 'AST Intelligence Analysis'),
310
+ last_files_edited: [],
311
+ current_branch: currentBranch,
312
+ base_branch: baseBranch,
313
+ timestamp: formatLocalTimestamp()
314
+ };
315
+
316
+ evidence.platforms = {
317
+ backend: { detected: true, violations: violations.filter(v => v.category && v.category.includes('backend')).length },
318
+ frontend: { detected: false, violations: 0 },
319
+ ios: { detected: false, violations: 0 },
320
+ android: { detected: false, violations: 0 }
321
+ };
322
+
323
+ evidence.session_id = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
324
+
291
325
  evidence.git_flow = {
292
326
  branch_protection: {
293
327
  main: 'protected',