pumuki-ast-hooks 5.6.6 → 5.6.8

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.
@@ -29,11 +29,13 @@
29
29
  ### Step 0: Git Repository Check ⚠️
30
30
 
31
31
  **What happens:**
32
+
32
33
  - The installer checks if you're in a Git repository (automatically at Step 0)
33
34
  - Verifies that `.git` directory exists
34
35
  - Tests that `git rev-parse --show-toplevel` works correctly
35
36
 
36
37
  **Why it matters:**
38
+
37
39
  - **Required for**: Git hooks, Git Flow automation, commit-time analysis
38
40
  - **Without Git**: The library cannot function properly
39
41
 
@@ -41,6 +43,7 @@
41
43
  The installer now automatically detects if Git is missing and shows a clear warning before proceeding. This prevents incomplete installations.
42
44
 
43
45
  **If Git is missing:**
46
+
44
47
  ```
45
48
  ❌ CRITICAL: Git repository not found!
46
49
  This library REQUIRES a Git repository to function properly.
@@ -53,6 +56,7 @@ The installer now automatically detects if Git is missing and shows a clear warn
53
56
  ```
54
57
 
55
58
  **Action required:**
59
+
56
60
  ```bash
57
61
  git init
58
62
  git add .
@@ -64,6 +68,7 @@ git commit -m "Initial commit"
64
68
  ### Step 1: Platform Detection
65
69
 
66
70
  **What happens:**
71
+
67
72
  - Scans project files for platform indicators
68
73
  - Detects iOS (`.swift`, `.xcodeproj`, `Podfile`)
69
74
  - Detects Android (`.kt`, `.gradle.kts`, `AndroidManifest.xml`)
@@ -71,11 +76,13 @@ git commit -m "Initial commit"
71
76
  - Detects Frontend (`next.config.js`, `app/**/page.tsx`)
72
77
 
73
78
  **Output:**
79
+
74
80
  ```
75
81
  ✓ Detected: backend, frontend
76
82
  ```
77
83
 
78
84
  **Impact:**
85
+
79
86
  - Only relevant rules are loaded for detected platforms
80
87
  - Platform-specific analysis is enabled
81
88
 
@@ -84,11 +91,13 @@ git commit -m "Initial commit"
84
91
  ### Step 2: ESLint Configuration
85
92
 
86
93
  **What happens:**
94
+
87
95
  - Installs ESLint configs for detected platforms
88
96
  - Creates `.eslintrc.js` files with appropriate rules
89
97
  - Configures TypeScript/JavaScript linting
90
98
 
91
99
  **Files created:**
100
+
92
101
  - `.eslintrc.js` (project root)
93
102
  - Platform-specific configs in `scripts/hooks-system/`
94
103
 
@@ -97,10 +106,12 @@ git commit -m "Initial commit"
97
106
  ### Step 3: Directory Structure
98
107
 
99
108
  **What happens:**
109
+
100
110
  - Creates `scripts/hooks-system/` directory structure
101
111
  - Sets up folders for: `domain/`, `application/`, `infrastructure/`, `presentation/`
102
112
 
103
113
  **Structure created:**
114
+
104
115
  ```
105
116
  scripts/hooks-system/
106
117
  ├── domain/
@@ -117,11 +128,13 @@ scripts/hooks-system/
117
128
  ### Step 4: Copy System Files
118
129
 
119
130
  **What happens:**
131
+
120
132
  - Copies all AST analysis engines from the library
121
133
  - Installs MCP server scripts
122
134
  - Copies rule definitions and validators
123
135
 
124
136
  **Files copied:**
137
+
125
138
  - `infrastructure/ast/ast-intelligence.js` - Main analysis engine
126
139
  - `infrastructure/mcp/ast-intelligence-automation.js` - MCP server
127
140
  - Platform-specific analyzers (iOS, Android, Backend, Frontend)
@@ -131,11 +144,13 @@ scripts/hooks-system/
131
144
  ### Step 5: Project Configuration
132
145
 
133
146
  **What happens:**
147
+
134
148
  - Creates `.ast-intelligence.config.js` in project root
135
149
  - Configures platform settings
136
150
  - Sets up ignore patterns
137
151
 
138
152
  **Configuration file:**
153
+
139
154
  ```javascript
140
155
  module.exports = {
141
156
  platforms: ['backend', 'frontend'],
@@ -149,11 +164,13 @@ module.exports = {
149
164
  ### Step 6: IDE Configuration and MCP Servers
150
165
 
151
166
  **What happens:**
167
+
152
168
  - Creates `.cursor/` directory (or `.windsurf/`, `.vscode/`, etc. for other agentic IDEs)
153
169
  - Creates `.cursor/mcp.json` with MCP server configuration
154
170
  - Creates `.cursor/settings.json` with IDE-specific settings
155
171
 
156
172
  **Note on Rules:** The library automatically searches for agentic IDE rules (`.mdc` files) in:
173
+
157
174
  - Project-level: `.cursor/rules/`, `.windsurf/rules/`, `.vscode/rules/` (highest priority)
158
175
  - Global locations: `~/.cursor/rules/`, `~/Library/Application Support/Cursor/User/rules/`
159
176
  - Other IDE project caches
@@ -161,6 +178,7 @@ module.exports = {
161
178
  Rules are used by `ai-start` when generating `.AI_EVIDENCE.json` to provide context to AI assistants. See [Usage Guide - Adding Your Own IDE Rules](../docs/USAGE.md#adding-your-own-ide-rules-mdc-files) for details.
162
179
 
163
180
  **MCP Configuration (`.cursor/mcp.json`):**
181
+
164
182
  ```json
165
183
  {
166
184
  "mcpServers": {
@@ -180,7 +198,15 @@ Rules are used by `ai-start` when generating `.AI_EVIDENCE.json` to provide cont
180
198
  }
181
199
  ```
182
200
 
201
+ **Token economy (contract):**
202
+
203
+ - The MCP tools expose a cost-aware guidance rule to agents.
204
+ - `ai_gate_check` returns it under `mandatory_rules.framework_rules`.
205
+ - `pre_flight_check` returns it under `framework_rules`.
206
+ - Agents should batch checks, avoid redundant scans, reuse cached context where safe, and ask the user for missing info to reduce token cost.
207
+
183
208
  **What this enables:**
209
+
184
210
  - Cursor AI can read project state (evidence status, gitflow state, context)
185
211
  - Cursor AI can execute tools (gate checks, gitflow automation, validation)
186
212
 
@@ -189,11 +215,13 @@ Rules are used by `ai-start` when generating `.AI_EVIDENCE.json` to provide cont
189
215
  ### Step 7: Git Hooks Installation
190
216
 
191
217
  **What happens:**
218
+
192
219
  - Creates `.git/hooks/pre-commit` script
193
220
  - Makes it executable (`chmod +x`)
194
221
  - Hook analyzes staged files before commit
195
222
 
196
223
  **Pre-commit hook script:**
224
+
197
225
  ```bash
198
226
  #!/bin/bash
199
227
  # AST Intelligence Hooks - Pre-commit
@@ -249,10 +277,12 @@ Check your `package.json` for these scripts:
249
277
  **Status:** Always ready, executes automatically
250
278
 
251
279
  **When it runs:**
280
+
252
281
  - Every time you execute `git commit`
253
282
  - Only analyzes staged files (`.ts`, `.tsx`, `.js`, `.jsx`, `.swift`, `.kt`)
254
283
 
255
284
  **What it does:**
285
+
256
286
  1. Checks for bypass flag (`GIT_BYPASS_HOOK=1`)
257
287
  2. Changes to project root directory
258
288
  3. Filters staged files by extension
@@ -263,6 +293,7 @@ Check your `package.json` for these scripts:
263
293
  8. If no violations → allows commit to proceed
264
294
 
265
295
  **Example output (blocked):**
296
+
266
297
  ```
267
298
  🚨 CRITICAL: backend.service.singleton_pattern
268
299
  File: src/users/users.service.ts:12
@@ -273,12 +304,14 @@ Check your `package.json` for these scripts:
273
304
  ```
274
305
 
275
306
  **Example output (allowed):**
307
+
276
308
  ```
277
309
  ✅ No violations detected
278
310
  [commit proceeds normally]
279
311
  ```
280
312
 
281
313
  **Important:**
314
+
282
315
  - Only CRITICAL and HIGH violations block commits
283
316
  - MEDIUM and LOW violations are reported but don't block
284
317
  - You can bypass temporarily with `GIT_BYPASS_HOOK=1 git commit`
@@ -294,17 +327,20 @@ Check your `package.json` for these scripts:
294
327
  #### 📚 Resources (Cursor can READ these)
295
328
 
296
329
  **`evidence://status`**
330
+
297
331
  - Status of `.AI_EVIDENCE.json` file
298
332
  - Returns: `fresh`, `stale`, `missing`, or `error`
299
333
  - Age in seconds, timestamp, current branch
300
334
  - Cursor uses this to know if project context is up-to-date
301
335
 
302
336
  **`gitflow://state`**
337
+
303
338
  - Current Git Flow workflow state
304
339
  - Returns: branch name, last commit, PR URL, status
305
340
  - Cursor uses this to understand Git state
306
341
 
307
342
  **`context://active`**
343
+
308
344
  - Automatically detected project context
309
345
  - Returns: platforms detected, files changed, confidence level
310
346
  - Cursor uses this to understand what you're working on
@@ -312,31 +348,37 @@ Check your `package.json` for these scripts:
312
348
  #### 🛠️ Tools (Cursor can EXECUTE these)
313
349
 
314
350
  **`check_evidence_status`**
351
+
315
352
  - Checks if `.AI_EVIDENCE.json` is stale
316
353
  - Cursor calls this to verify evidence freshness
317
354
 
318
355
  **`ai_gate_check` ⚠️ MANDATORY**
356
+
319
357
  - **Must be called at START of EVERY AI response**
320
358
  - Checks if there are blocking violations
321
359
  - Returns: `ALLOWED` or `BLOCKED`
322
360
  - If `BLOCKED`: AI should NOT proceed with task
323
361
 
324
362
  **`auto_complete_gitflow`**
363
+
325
364
  - Automates complete Git Flow cycle
326
365
  - Commit → Push → Create PR → Merge (optional)
327
366
  - Cursor can call this when you ask for Git Flow automation
328
367
 
329
368
  **`sync_branches`**
369
+
330
370
  - Synchronizes `develop` and `main` branches
331
371
  - Fetches, pulls, updates local branches
332
372
  - Cursor can call this to ensure branches are in sync
333
373
 
334
374
  **`validate_and_fix`**
375
+
335
376
  - Validates common problems
336
377
  - Fixes automatically when possible
337
378
  - Cursor can call this to check/fix issues
338
379
 
339
380
  **`auto_execute_ai_start`**
381
+
340
382
  - Analyzes context and executes `ai-start` if needed
341
383
  - Detects if code files were modified (≥30% confidence)
342
384
  - Updates `.AI_EVIDENCE.json` automatically
@@ -349,6 +391,7 @@ Check your `package.json` for these scripts:
349
391
  **Status:** Executed on-demand (by hooks or manual commands)
350
392
 
351
393
  **What it does:**
394
+
352
395
  - Parses code files into Abstract Syntax Trees (AST)
353
396
  - Applies rule checkers for each platform
354
397
  - Detects violations of:
@@ -359,6 +402,7 @@ Check your `package.json` for these scripts:
359
402
  - Generates detailed violation reports
360
403
 
361
404
  **Rule categories:**
405
+
362
406
  - **Architecture violations**: Dependency direction, layer violations
363
407
  - **SOLID violations**: Singleton, God classes, tight coupling
364
408
  - **Platform-specific**: iOS patterns, Android patterns, NestJS patterns, React patterns
@@ -370,6 +414,7 @@ Check your `package.json` for these scripts:
370
414
  The library automatically detects architecture patterns for **all platforms** (iOS, Android, Backend, Frontend) without any configuration needed.
371
415
 
372
416
  **iOS - Detected Patterns:**
417
+
373
418
  - Feature-First + Clean + DDD
374
419
  - MVVM-C (MVVM + Coordinator)
375
420
  - MVVM
@@ -379,6 +424,7 @@ The library automatically detects architecture patterns for **all platforms** (i
379
424
  - Clean Swift
380
425
 
381
426
  **Android - Detected Patterns:**
427
+
382
428
  - Feature-First + Clean + DDD
383
429
  - MVVM (Model-View-ViewModel)
384
430
  - MVI (Model-View-Intent)
@@ -386,6 +432,7 @@ The library automatically detects architecture patterns for **all platforms** (i
386
432
  - Clean Architecture (Domain-Data-Presentation)
387
433
 
388
434
  **Backend - Detected Patterns:**
435
+
389
436
  - Feature-First + Clean + DDD
390
437
  - Clean Architecture (Hexagonal/Ports & Adapters)
391
438
  - Onion Architecture
@@ -393,12 +440,14 @@ The library automatically detects architecture patterns for **all platforms** (i
393
440
  - CQRS (Command Query Responsibility Segregation)
394
441
 
395
442
  **Frontend - Detected Patterns:**
443
+
396
444
  - Feature-First + Clean + DDD
397
445
  - Component-Based Architecture
398
446
  - Atomic Design Pattern
399
447
  - State Management patterns (Zustand, Redux, Context)
400
448
 
401
449
  **Automatic Detection:**
450
+
402
451
  - The library analyzes your project structure, imports, and code patterns
403
452
  - No configuration file needed - detection happens automatically
404
453
  - Works with any architecture pattern you use
@@ -532,6 +581,7 @@ Run audit again to verify fixes
532
581
  **Scenario:** You create a service with Singleton pattern
533
582
 
534
583
  **Code:**
584
+
535
585
  ```typescript
536
586
  class UserService {
537
587
  private static instance: UserService;
@@ -546,6 +596,7 @@ class UserService {
546
596
  ```
547
597
 
548
598
  **When you commit:**
599
+
549
600
  ```
550
601
  $ git commit -m "feat: add user service"
551
602
 
@@ -558,6 +609,7 @@ $ git commit -m "feat: add user service"
558
609
  ```
559
610
 
560
611
  **Fix:**
612
+
561
613
  ```typescript
562
614
  @Injectable()
563
615
  export class UserService {
@@ -566,6 +618,7 @@ export class UserService {
566
618
  ```
567
619
 
568
620
  **Commit again:**
621
+
569
622
  ```
570
623
  $ git commit -m "feat: add user service"
571
624
 
@@ -581,6 +634,7 @@ $ git commit -m "feat: add user service"
581
634
  **Scenario:** You modify code, evidence is 5 minutes old
582
635
 
583
636
  **Cursor AI workflow:**
637
+
584
638
  1. You ask: "Add authentication to this endpoint"
585
639
  2. Cursor calls `ai_gate_check` → `ALLOWED`
586
640
  3. Cursor reads `evidence://status` → `stale` (age: 350s)
@@ -599,13 +653,14 @@ $ git commit -m "feat: add user service"
599
653
  **You ask Cursor:** "Commit, push and create PR"
600
654
 
601
655
  **Cursor workflow:**
656
+
602
657
  1. Cursor calls `auto_complete_gitflow` with your message
603
658
  2. MCP verifies you're on feature branch ✅
604
659
  3. MCP commits changes (if any) ✅
605
660
  4. MCP pushes to origin ✅
606
661
  5. MCP creates PR to `develop` ✅
607
662
  6. MCP returns PR URL
608
- 7. Cursor shows you: "✅ PR created: https://github.com/user/repo/pull/42"
663
+ 7. Cursor shows you: "✅ PR created: <https://github.com/user/repo/pull/42>"
609
664
 
610
665
  ---
611
666
 
@@ -616,6 +671,7 @@ $ git commit -m "feat: add user service"
616
671
  **Cause:** You're not in a Git repository
617
672
 
618
673
  **Solution:**
674
+
619
675
  ```bash
620
676
  git init
621
677
  git add .
@@ -623,6 +679,7 @@ git commit -m "Initial commit"
623
679
  ```
624
680
 
625
681
  Then re-run the installer:
682
+
626
683
  ```bash
627
684
  npm run install-hooks
628
685
  ```
@@ -632,6 +689,7 @@ npm run install-hooks
632
689
  ### Problem: Commit blocked but I need to commit now
633
690
 
634
691
  **Temporary bypass:**
692
+
635
693
  ```bash
636
694
  GIT_BYPASS_HOOK=1 git commit -m "emergency fix"
637
695
  ```
@@ -643,11 +701,13 @@ GIT_BYPASS_HOOK=1 git commit -m "emergency fix"
643
701
  ### Problem: MCP server not showing in Cursor
644
702
 
645
703
  **Check 1:** Verify `.cursor/mcp.json` exists
704
+
646
705
  ```bash
647
706
  cat .cursor/mcp.json
648
707
  ```
649
708
 
650
709
  **Check 2:** Verify Node path is correct
710
+
651
711
  ```bash
652
712
  which node
653
713
  # Update .cursor/mcp.json with correct path
@@ -656,6 +716,7 @@ which node
656
716
  **Check 3:** Restart Cursor completely
657
717
 
658
718
  **Check 4:** Check Cursor logs
719
+
659
720
  - View → Output → MCP
660
721
 
661
722
  ---
@@ -663,17 +724,20 @@ which node
663
724
  ### Problem: Hook not running
664
725
 
665
726
  **Check 1:** Verify hook exists and is executable
727
+
666
728
  ```bash
667
729
  ls -la .git/hooks/pre-commit
668
730
  # Should show: -rwxr-xr-x
669
731
  ```
670
732
 
671
733
  **Check 2:** Make executable if needed
734
+
672
735
  ```bash
673
736
  chmod +x .git/hooks/pre-commit
674
737
  ```
675
738
 
676
739
  **Check 3:** Test hook manually
740
+
677
741
  ```bash
678
742
  .git/hooks/pre-commit
679
743
  ```
@@ -683,16 +747,19 @@ chmod +x .git/hooks/pre-commit
683
747
  ### Problem: Evidence always stale
684
748
 
685
749
  **Check 1:** Verify `.AI_EVIDENCE.json` exists
750
+
686
751
  ```bash
687
752
  ls -la .AI_EVIDENCE.json
688
753
  ```
689
754
 
690
755
  **Check 2:** Update evidence manually
756
+
691
757
  ```bash
692
758
  npm run ai-start develop
693
759
  ```
694
760
 
695
761
  **Check 3:** Check file permissions
762
+
696
763
  ```bash
697
764
  chmod 644 .AI_EVIDENCE.json
698
765
  ```
@@ -713,4 +780,3 @@ Now that you understand how it works:
713
780
  **Last updated**: 2025-01-13
714
781
  **Version**: 5.3.1
715
782
  **Author**: Juan Carlos Merlos Albarracín (Senior Software Architect - AI-Driven Development) <freelancemerlos@gmail.com>
716
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pumuki-ast-hooks",
3
- "version": "5.6.6",
3
+ "version": "5.6.8",
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": {
@@ -134,4 +134,4 @@
134
134
  "./skills": "./skills/skill-rules.json",
135
135
  "./hooks": "./hooks/index.js"
136
136
  }
137
- }
137
+ }
@@ -1,3 +1,4 @@
1
1
  {"timestamp":"2026-01-11T00:41:26.979Z","level":"info","component":"AutoRecovery","event":"NotificationCenterService shutdown","data":{"totalEnqueued":0,"totalSent":0,"totalDeduplicated":0,"totalCooldownSkipped":0,"totalFailed":0,"totalRetries":0,"queueSize":0,"deduplication":{"size":0},"cooldowns":{"activeCooldowns":0}},"context":{}}
2
2
  {"timestamp":"2026-01-11T00:47:24.400Z","level":"info","component":"AutoRecovery","event":"NotificationCenterService shutdown","data":{"totalEnqueued":0,"totalSent":0,"totalDeduplicated":0,"totalCooldownSkipped":0,"totalFailed":0,"totalRetries":0,"queueSize":0,"deduplication":{"size":0},"cooldowns":{"activeCooldowns":0}},"context":{}}
3
3
  {"timestamp":"2026-01-11T00:48:07.599Z","level":"info","component":"AutoRecovery","event":"NotificationCenterService shutdown","data":{"totalEnqueued":0,"totalSent":0,"totalDeduplicated":0,"totalCooldownSkipped":0,"totalFailed":0,"totalRetries":0,"queueSize":0,"deduplication":{"size":0},"cooldowns":{"activeCooldowns":0}},"context":{}}
4
+ {"timestamp":"2026-01-11T14:18:31.035Z","level":"info","component":"AutoRecovery","event":"NotificationCenterService shutdown","data":{"totalEnqueued":0,"totalSent":0,"totalDeduplicated":0,"totalCooldownSkipped":0,"totalFailed":0,"totalRetries":0,"queueSize":0,"deduplication":{"size":0},"cooldowns":{"activeCooldowns":0}},"context":{}}
@@ -10,3 +10,7 @@
10
10
  {"timestamp":"2026-01-11T00:48:08.399Z","level":"info","component":"InstallWizard","event":"INSTALL_WIZARD_CONFIG_EXISTS","data":{"configPath":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/.hook-system/config.json"},"context":{}}
11
11
  {"timestamp":"2026-01-11T00:48:08.400Z","level":"error","component":"InstallWizard","event":"INSTALL_WIZARD_SYMLINK_FAILED","data":{"error":"EEXIST: file already exists, symlink '/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/scripts/hooks-system/bin/guard-supervisor.js' -> '/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/.git/hooks/guard-supervisor'"},"context":{}}
12
12
  {"timestamp":"2026-01-11T00:48:08.400Z","level":"info","component":"InstallWizard","event":"INSTALL_WIZARD_COMPLETED","data":{},"context":{}}
13
+ {"timestamp":"2026-01-11T14:18:31.365Z","level":"info","component":"InstallWizard","event":"INSTALL_WIZARD_START","data":{"repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"},"context":{}}
14
+ {"timestamp":"2026-01-11T14:18:31.376Z","level":"info","component":"InstallWizard","event":"INSTALL_WIZARD_CONFIG_EXISTS","data":{"configPath":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/.hook-system/config.json"},"context":{}}
15
+ {"timestamp":"2026-01-11T14:18:31.376Z","level":"error","component":"InstallWizard","event":"INSTALL_WIZARD_SYMLINK_FAILED","data":{"error":"EEXIST: file already exists, symlink '/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/scripts/hooks-system/bin/guard-supervisor.js' -> '/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system/.git/hooks/guard-supervisor'"},"context":{}}
16
+ {"timestamp":"2026-01-11T14:18:31.376Z","level":"info","component":"InstallWizard","event":"INSTALL_WIZARD_COMPLETED","data":{},"context":{}}
@@ -302,3 +302,27 @@
302
302
  {"timestamp":1768092487598,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
303
303
  {"timestamp":1768092487599,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
304
304
  {"timestamp":1768092487599,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
305
+ {"timestamp":1768141111032,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
306
+ {"timestamp":1768141111033,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
307
+ {"timestamp":1768141111033,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
308
+ {"timestamp":1768141111033,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
309
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
310
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
311
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
312
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
313
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
314
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
315
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
316
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
317
+ {"timestamp":1768141111034,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
318
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
319
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
320
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
321
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
322
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
323
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
324
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
325
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"constructor","status":"started","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
326
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"started"}
327
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"ensure_dir","status":"success"}
328
+ {"timestamp":1768141111035,"hook":"audit_logger","operation":"constructor","status":"success","repoRoot":"/Users/juancarlosmerlosalbarracin/Developer/Projects/ast-intelligence-hooks/scripts/hooks-system"}
@@ -8,4 +8,137 @@ describe('cli', () => {
8
8
  it('should be valid JavaScript', () => {
9
9
  expect(() => require.resolve('../cli.js')).not.toThrow();
10
10
  });
11
+
12
+ it('should expose proposeHumanIntent and infer goal from recent commits', () => {
13
+ const childProcess = require('child_process');
14
+
15
+ const originalExecSync = childProcess.execSync;
16
+ childProcess.execSync = (cmd) => {
17
+ const command = String(cmd);
18
+ if (command.includes('git log') && command.includes('--pretty=%s')) {
19
+ return 'fix: token economy docs, assets and MCP outputs\nRelease: 2026-01-11\n';
20
+ }
21
+ return '';
22
+ };
23
+
24
+ const { proposeHumanIntent } = require('../cli.js');
25
+ expect(typeof proposeHumanIntent).toBe('function');
26
+
27
+ const proposed = proposeHumanIntent({
28
+ evidence: { ai_gate: { status: 'ALLOWED' }, platforms: {} },
29
+ branch: 'develop',
30
+ stagedFiles: []
31
+ });
32
+ expect(proposed && typeof proposed.primary_goal).toBe('string');
33
+ expect(proposed.primary_goal.toLowerCase()).toContain('token economy');
34
+
35
+ childProcess.execSync = originalExecSync;
36
+ });
37
+
38
+ it('wrap-up should auto-save human_intent by default', () => {
39
+ const fs = require('fs');
40
+ const childProcess = require('child_process');
41
+
42
+ const originalConsoleLog = console.log;
43
+ const logSpy = jest.fn();
44
+ console.log = logSpy;
45
+
46
+ const originalArgv = process.argv;
47
+ const originalExecSync = childProcess.execSync;
48
+
49
+ const existsSyncSpy = jest.spyOn(fs, 'existsSync').mockImplementation(() => true);
50
+ const readFileSyncSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => JSON.stringify({ ai_gate: { status: 'ALLOWED' }, platforms: {} }));
51
+ const writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { });
52
+
53
+ childProcess.execSync = (cmd) => {
54
+ const command = String(cmd);
55
+ if (command.includes('git rev-parse --show-toplevel')) {
56
+ return '/tmp/repo\n';
57
+ }
58
+ if (command.includes('git branch --show-current')) {
59
+ return 'main\n';
60
+ }
61
+ if (command.includes('git diff --cached --name-only')) {
62
+ return '\n';
63
+ }
64
+ if (command.includes('git log') && command.includes('--pretty=%s')) {
65
+ return 'fix: token economy docs, assets and MCP outputs\n';
66
+ }
67
+ if (command.includes('node') && command.includes('intelligent-audit.js')) {
68
+ return '';
69
+ }
70
+ return '';
71
+ };
72
+
73
+ process.argv = ['node', 'cli.js', 'wrap-up'];
74
+ jest.resetModules();
75
+ const { commands } = require('../cli.js');
76
+ commands['wrap-up']();
77
+
78
+ expect(logSpy.mock.calls.map(c => String(c[0] || '')).join('\n')).toContain('auto-saved');
79
+ expect(writeFileSyncSpy).toHaveBeenCalled();
80
+ const written = writeFileSyncSpy.mock.calls.map(c => String(c[1] || '')).join('\n');
81
+ expect(written).toContain('"human_intent"');
82
+ expect(written.toLowerCase()).toContain('token economy');
83
+
84
+ console.log = originalConsoleLog;
85
+ process.argv = originalArgv;
86
+ childProcess.execSync = originalExecSync;
87
+ existsSyncSpy.mockRestore();
88
+ readFileSyncSpy.mockRestore();
89
+ writeFileSyncSpy.mockRestore();
90
+ });
91
+
92
+ it('wrap-up should not save when --no-save is provided', () => {
93
+ const fs = require('fs');
94
+ const childProcess = require('child_process');
95
+
96
+ const originalConsoleLog = console.log;
97
+ const logSpy = jest.fn();
98
+ console.log = logSpy;
99
+
100
+ const originalArgv = process.argv;
101
+ const originalExecSync = childProcess.execSync;
102
+
103
+ const existsSyncSpy = jest.spyOn(fs, 'existsSync').mockImplementation(() => true);
104
+ const readFileSyncSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => JSON.stringify({ ai_gate: { status: 'ALLOWED' }, platforms: {} }));
105
+ const writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { });
106
+
107
+ childProcess.execSync = (cmd) => {
108
+ const command = String(cmd);
109
+ if (command.includes('git rev-parse --show-toplevel')) {
110
+ return '/tmp/repo\n';
111
+ }
112
+ if (command.includes('git branch --show-current')) {
113
+ return 'main\n';
114
+ }
115
+ if (command.includes('git diff --cached --name-only')) {
116
+ return '\n';
117
+ }
118
+ if (command.includes('git log') && command.includes('--pretty=%s')) {
119
+ return 'fix: token economy docs, assets and MCP outputs\n';
120
+ }
121
+ if (command.includes('node') && command.includes('intelligent-audit.js')) {
122
+ return '';
123
+ }
124
+ return '';
125
+ };
126
+
127
+ process.argv = ['node', 'cli.js', 'wrap-up', '--no-save'];
128
+ jest.resetModules();
129
+ const { commands } = require('../cli.js');
130
+ commands['wrap-up']();
131
+
132
+ expect(logSpy.mock.calls.map(c => String(c[0] || '')).join('\n')).toContain('proposal only');
133
+ expect(writeFileSyncSpy).toHaveBeenCalled();
134
+ const written = writeFileSyncSpy.mock.calls.map(c => String(c[1] || '')).join('\n');
135
+ expect(written).not.toContain('"human_intent"');
136
+
137
+ console.log = originalConsoleLog;
138
+ process.argv = originalArgv;
139
+ childProcess.execSync = originalExecSync;
140
+ existsSyncSpy.mockRestore();
141
+ readFileSyncSpy.mockRestore();
142
+ writeFileSyncSpy.mockRestore();
143
+ });
11
144
  });