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,264 +1,5 @@
1
1
  #!/bin/bash
2
- # ═══════════════════════════════════════════════════════════════
3
- # AI Session Loader (VS Code Startup)
4
- # ═══════════════════════════════════════════════════════════════
5
- # Automatically loads session context when VS Code opens workspace
6
- # Triggered by: .vscode/tasks.json (runOn: folderOpen)
7
- # ═══════════════════════════════════════════════════════════════
8
-
9
- set -euo pipefail
10
-
11
- # Colors
12
- RED='\033[0;31m'
13
- GREEN='\033[0;32m'
14
- YELLOW='\033[1;33m'
15
- BLUE='\033[0;34m'
16
- CYAN='\033[0;36m'
17
- MAGENTA='\033[0;35m'
18
- NC='\033[0m'
19
-
20
- # Paths
2
+ # Script Wrapper
3
+ # Redirects to the centralized implementation in scripts/hooks-system
21
4
  REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo ".")
22
- SESSION_FILE="$REPO_ROOT/.AI_SESSION_START.md"
23
- TOKEN_STATUS="$REPO_ROOT/.AI_TOKEN_STATUS.txt"
24
- VIOLATIONS_REPORT="$REPO_ROOT/.violations-by-priority.md"
25
-
26
- # Clear screen
27
- clear
28
-
29
- # Banner
30
- echo -e "${BLUE}╔══════════════════════════════════════════════════════════╗${NC}"
31
- echo -e "${BLUE}║ ║${NC}"
32
- echo -e "${BLUE}║ 🤖 AI SESSION LOADER ║${NC}"
33
- echo -e "${BLUE}║ Workspace Opened - Loading Context... ║${NC}"
34
- echo -e "${BLUE}║ ║${NC}"
35
- echo -e "${BLUE}╚══════════════════════════════════════════════════════════╝${NC}"
36
- echo ""
37
-
38
- # Show current branch
39
- CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
40
- echo -e "${CYAN}📍 Current Branch: ${MAGENTA}$CURRENT_BRANCH${NC}"
41
- echo ""
42
-
43
- # Show last 3 commits
44
- echo -e "${CYAN}📝 Recent Commits:${NC}"
45
- git log --oneline -3 2>/dev/null | sed 's/^/ /' || echo " No commits yet"
46
- echo ""
47
-
48
- # Show session context
49
- if [[ -f "$SESSION_FILE" ]]; then
50
- echo -e "${CYAN}📖 Session Context:${NC}"
51
-
52
- # Prefer current session from .AI_EVIDENCE.json (auto-updated by ai-start)
53
- LOCAL_EVIDENCE_FILE="$REPO_ROOT/.AI_EVIDENCE.json"
54
- if [[ -f "$LOCAL_EVIDENCE_FILE" ]]; then
55
- CURRENT_SESSION_ID=$(jq -r '.session_id // empty' "$LOCAL_EVIDENCE_FILE" 2>/dev/null || echo "")
56
- CURRENT_ACTION=$(jq -r '.action // empty' "$LOCAL_EVIDENCE_FILE" 2>/dev/null || echo "")
57
- if [[ -n "$CURRENT_SESSION_ID" ]]; then
58
- if [[ -n "$CURRENT_ACTION" && "$CURRENT_ACTION" != "null" ]]; then
59
- echo " **Sesión actual (evidence):** $CURRENT_SESSION_ID - $CURRENT_ACTION"
60
- else
61
- echo " **Sesión actual (evidence):** $CURRENT_SESSION_ID"
62
- fi
63
- fi
64
- fi
65
-
66
- # Also show static plan context from .AI_SESSION_START.md (without duplicating Sesión actual)
67
- head -20 "$SESSION_FILE" | grep -E "Branch activo|Fase del plan|Progreso total|Violations.*restantes" | sed 's/^/ /' || true
68
- echo ""
69
- fi
70
-
71
- # Show token status
72
- if [[ -f "$TOKEN_STATUS" ]]; then
73
- echo -e "${CYAN}🔋 Token Status:${NC}"
74
- grep -E "Status:|Used:|Remaining:" "$TOKEN_STATUS" | sed 's/^/ /' || true
75
- echo ""
76
- fi
77
-
78
- # Show top violations
79
- if [[ -f "$VIOLATIONS_REPORT" ]]; then
80
- echo -e "${CYAN}🎯 Top Violations:${NC}"
81
- grep -A 4 "## 📊 Summary" "$VIOLATIONS_REPORT" | tail -5 | sed 's/^/ /' 2>/dev/null || echo " No violations report"
82
- echo ""
83
- fi
84
-
85
- # Check .AI_EVIDENCE.json freshness
86
- EVIDENCE_FILE="$REPO_ROOT/.AI_EVIDENCE.json"
87
- EVIDENCE_AGE=0
88
- if [[ -f "$EVIDENCE_FILE" ]]; then
89
- EVIDENCE_TS=$(jq -r '.timestamp' "$EVIDENCE_FILE" 2>/dev/null || echo "")
90
- if [[ -n "$EVIDENCE_TS" ]] && [[ "$EVIDENCE_TS" != "null" ]]; then
91
- # Parse ISO 8601 timestamp with timezone offset (e.g., 2025-12-14T08:04:44+01:00)
92
- # macOS date command doesn't handle +01:00 format well, so we convert to UTC first
93
- if [[ "$EVIDENCE_TS" =~ ^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2})([+-][0-9]{2}):([0-9]{2})$ ]]; then
94
- # Format with timezone offset: convert to epoch using Python or node
95
- EVIDENCE_EPOCH=$(python3 -c "from datetime import datetime; print(int(datetime.fromisoformat('$EVIDENCE_TS').timestamp()))" 2>/dev/null || \
96
- node -e "console.log(Math.floor(new Date('$EVIDENCE_TS').getTime() / 1000))" 2>/dev/null || \
97
- echo "0")
98
- elif [[ "$EVIDENCE_TS" =~ ^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2})Z?$ ]]; then
99
- # Format without timezone (assume local time)
100
- CLEAN_TS=$(echo "$EVIDENCE_TS" | sed 's/Z$//' | sed 's/\.[0-9]*$//')
101
- EVIDENCE_EPOCH=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$CLEAN_TS" +%s 2>/dev/null || echo "0")
102
- else
103
- EVIDENCE_EPOCH=0
104
- fi
105
-
106
- NOW_EPOCH=$(date +%s)
107
- EVIDENCE_AGE=$((NOW_EPOCH - EVIDENCE_EPOCH))
108
-
109
- # Sanity check: if age is negative or unreasonably large (> 1 year), assume parsing failed
110
- if [[ $EVIDENCE_AGE -lt 0 ]] || [[ $EVIDENCE_AGE -gt 31536000 ]]; then
111
- EVIDENCE_AGE=0
112
- AGE_FORMATTED="unknown"
113
- fi
114
-
115
- # Format age in human-readable format
116
- if [[ $EVIDENCE_AGE -lt 60 ]]; then
117
- AGE_FORMATTED="${EVIDENCE_AGE}s"
118
- elif [[ $EVIDENCE_AGE -lt 3600 ]]; then
119
- AGE_MIN=$((EVIDENCE_AGE / 60))
120
- AGE_SEC=$((EVIDENCE_AGE % 60))
121
- AGE_FORMATTED="${AGE_MIN}m ${AGE_SEC}s"
122
- elif [[ $EVIDENCE_AGE -lt 86400 ]]; then
123
- AGE_HOUR=$((EVIDENCE_AGE / 3600))
124
- AGE_MIN=$(( (EVIDENCE_AGE % 3600) / 60 ))
125
- AGE_FORMATTED="${AGE_HOUR}h ${AGE_MIN}m"
126
- else
127
- AGE_DAYS=$((EVIDENCE_AGE / 86400))
128
- AGE_HOUR=$(( (EVIDENCE_AGE % 86400) / 3600 ))
129
- AGE_FORMATTED="${AGE_DAYS}d ${AGE_HOUR}h"
130
- fi
131
-
132
- if [[ $EVIDENCE_AGE -gt 180 ]]; then
133
- echo -e "${YELLOW}⚠️ Evidence is stale (${AGE_FORMATTED} old, max 3min)${NC}"
134
- echo -e "${CYAN}🔄 Auto-updating evidence...${NC}"
135
-
136
- # Auto-update evidence if stale
137
- UPDATE_EVIDENCE_SCRIPT="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/update-evidence.sh"
138
- if [[ ! -f "$UPDATE_EVIDENCE_SCRIPT" ]]; then
139
- # Try scripts/hooks-system path as fallback
140
- UPDATE_EVIDENCE_SCRIPT="$REPO_ROOT/scripts/hooks-system/bin/update-evidence.sh"
141
- fi
142
-
143
- # Try node_modules path if script not found in scripts/
144
- if [[ ! -x "$UPDATE_EVIDENCE_SCRIPT" ]]; then
145
- UPDATE_EVIDENCE_SCRIPT="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/update-evidence.sh"
146
- fi
147
-
148
- if [[ -x "$UPDATE_EVIDENCE_SCRIPT" ]]; then
149
- # Detect platforms from project structure
150
- PLATFORMS=""
151
- [[ -d "$REPO_ROOT/apps/backend" ]] && PLATFORMS="${PLATFORMS}backend,"
152
- [[ -d "$REPO_ROOT/apps/frontend" ]] && PLATFORMS="${PLATFORMS}frontend,"
153
- [[ -d "$REPO_ROOT/apps/mobile/ios" ]] && PLATFORMS="${PLATFORMS}ios,"
154
- [[ -d "$REPO_ROOT/apps/mobile/android" ]] && PLATFORMS="${PLATFORMS}android,"
155
- PLATFORMS="${PLATFORMS%,}" # Remove trailing comma
156
-
157
- if [[ -n "$PLATFORMS" ]]; then
158
- if "$UPDATE_EVIDENCE_SCRIPT" --auto --platforms "$PLATFORMS" >/dev/null 2>&1; then
159
- echo -e "${GREEN}✅ Evidence updated${NC}"
160
- # Send macOS notification
161
- osascript -e "display notification \"Evidence auto-updated at $(date '+%Y-%m-%d %H:%M:%S') (was ${AGE_FORMATTED} old)\" with title \"🔄 Evidence Refreshed\" sound name \"Glass\"" 2>/dev/null || true
162
- else
163
- echo -e "${YELLOW}⚠️ Evidence update failed${NC}"
164
- fi
165
- else
166
- echo -e "${YELLOW}⚠️ Could not auto-detect platforms, run manually:${NC}"
167
- echo -e "${YELLOW} $UPDATE_EVIDENCE_SCRIPT --auto --platforms <platforms>${NC}"
168
- fi
169
- else
170
- echo -e "${YELLOW}⚠️ Update script not found, run manually:${NC}"
171
- echo -e "${YELLOW} ./scripts/hooks-system/bin/update-evidence.sh --auto --platforms <platforms>${NC}"
172
- fi
173
- echo ""
174
- else
175
- echo -e "${GREEN}✅ Evidence fresh (${AGE_FORMATTED} old)${NC}"
176
- echo ""
177
- fi
178
- fi
179
- fi
180
-
181
- # Execute AI Gate Check automatically
182
- echo -e "${CYAN}🚦 Running AI Gate Check...${NC}"
183
- UPDATE_EVIDENCE_SCRIPT="$REPO_ROOT/scripts/hooks-system/bin/update-evidence.sh"
184
- if [[ ! -x "$UPDATE_EVIDENCE_SCRIPT" ]]; then
185
- # Try node_modules path
186
- UPDATE_EVIDENCE_SCRIPT="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/update-evidence.sh"
187
- fi
188
- if [[ -x "$UPDATE_EVIDENCE_SCRIPT" ]]; then
189
- # Update evidence and run audit to get ai_gate (don't use --refresh-only, we need audit)
190
- if "$UPDATE_EVIDENCE_SCRIPT" --auto >/dev/null 2>&1; then
191
- # Read gate status from evidence
192
- if [[ -f "$EVIDENCE_FILE" ]]; then
193
- GATE_STATUS=$(jq -r '.ai_gate.status // "UNKNOWN"' "$EVIDENCE_FILE" 2>/dev/null || echo "UNKNOWN")
194
- CRITICAL_COUNT=$(jq -r '[.ai_gate.violations[]? | select(.severity == "CRITICAL")] | length' "$EVIDENCE_FILE" 2>/dev/null || echo "0")
195
- HIGH_COUNT=$(jq -r '[.ai_gate.violations[]? | select(.severity == "HIGH")] | length' "$EVIDENCE_FILE" 2>/dev/null || echo "0")
196
-
197
- if [[ "$GATE_STATUS" == "BLOCKED" ]]; then
198
- TOTAL_BLOCKING=$((CRITICAL_COUNT + HIGH_COUNT))
199
- if [[ $TOTAL_BLOCKING -gt 0 ]]; then
200
- echo -e "${RED} 🚫 BLOCKED: ${TOTAL_BLOCKING} blocking violations (${CRITICAL_COUNT} CRITICAL, ${HIGH_COUNT} HIGH)${NC}"
201
- osascript -e "display notification \"${TOTAL_BLOCKING} blocking violations detected\" with title \"🚫 AI Gate Blocked\" sound name \"Basso\"" 2>/dev/null || true
202
- else
203
- echo -e "${GREEN} ✅ Gate passed${NC}"
204
- fi
205
- else
206
- echo -e "${GREEN} ✅ Gate passed${NC}"
207
- fi
208
- fi
209
- else
210
- echo -e "${YELLOW} ⚠️ Gate check failed${NC}"
211
- fi
212
- else
213
- echo -e "${YELLOW} ⚠️ Update script not found${NC}"
214
- fi
215
- echo ""
216
-
217
- # Start realtime guards (watch-hooks + token monitor)
218
- GUARDS_SCRIPT="$REPO_ROOT/scripts/hooks-system/bin/start-guards.sh"
219
- if [[ ! -x "$GUARDS_SCRIPT" ]]; then
220
- GUARDS_SCRIPT="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/start-guards.sh"
221
- fi
222
- if [[ -x "$GUARDS_SCRIPT" ]]; then
223
- echo -e "${CYAN}🛡️ Background guards:${NC}"
224
- "$GUARDS_SCRIPT" start || true
225
- echo ""
226
- fi
227
-
228
- # Show quick commands
229
- echo -e "${BLUE}╔══════════════════════════════════════════════════════════╗${NC}"
230
- echo -e "${BLUE}║ 🚀 QUICK COMMANDS ║${NC}"
231
- echo -e "${BLUE}╠══════════════════════════════════════════════════════════╣${NC}"
232
- echo -e "${BLUE}║ ${NC}ai-start <feature> ${CYAN}Update evidence & start work${NC} ${BLUE}║${NC}"
233
- echo -e "${BLUE}║ ${NC}./scripts/hooks-system/bin/update-evidence.sh --auto --platforms <platforms>${CYAN}Autonomous refresh${NC} ${BLUE}║${NC}"
234
- echo -e "${BLUE}║ ${NC}git status ${CYAN}Check current changes${NC} ${BLUE}║${NC}"
235
- echo -e "${BLUE}║ ${NC}git log -3 ${CYAN}View recent commits${NC} ${BLUE}║${NC}"
236
- echo -e "${BLUE}║ ${NC}bash audit.sh ${CYAN}Run full audit${NC} ${BLUE}║${NC}"
237
- echo -e "${BLUE}║ ${NC}cat .violations-* ${CYAN}View violations report${NC} ${BLUE}║${NC}"
238
- echo -e "${BLUE}╚══════════════════════════════════════════════════════════╝${NC}"
239
- echo ""
240
-
241
- # Auto-start watchdog (DISABLED - notifications were looping)
242
- # WATCHDOG_PID_FILE="$REPO_ROOT/.ai-watchdog.pid"
243
- # if [[ ! -f "$WATCHDOG_PID_FILE" ]]; then
244
- # echo -e "${CYAN}🐕 Starting AI Watchdog...${NC}"
245
- # bash "$REPO_ROOT/scripts/hooks-system/infrastructure/watchdog/ai-watchdog.sh" start 2>/dev/null || echo " (fswatch not available)"
246
- # echo ""
247
- # fi
248
-
249
- # Show readiness
250
- echo -e "${GREEN}✅ Session loaded - Ready to work!${NC}"
251
- echo ""
252
-
253
- # Reminder with exact command (only if evidence was stale)
254
- if [[ $EVIDENCE_AGE -gt 180 ]]; then
255
- echo -e "${YELLOW}ℹ️ Evidence refreshed. You can start working!${NC}"
256
- echo -e " ${CYAN}To manually refresh: ./scripts/hooks-system/bin/update-evidence.sh --auto --platforms <platforms>${NC}"
257
- echo -e " ${CYAN}(alias: ai-start $CURRENT_BRANCH)${NC}"
258
- elif [[ $EVIDENCE_AGE -gt 0 ]]; then
259
- echo -e "${GREEN}✅ Evidence is fresh - You can start working!${NC}"
260
- fi
261
- echo ""
262
-
263
- # Return control to user's default shell (zsh)
264
- exec "$SHELL"
5
+ bash "$REPO_ROOT/scripts/hooks-system/bin/session-loader.sh" "$@"
@@ -1,190 +1,27 @@
1
1
  #!/bin/bash
2
- # ═══════════════════════════════════════════════════════════════
3
- # Start Guards - Realtime notifications and token monitor
4
- # ═══════════════════════════════════════════════════════════════
5
- # Uso: start-guards.sh start|stop|status|restart
6
- # ─ start: arranca watch-hooks y el monitor de tokens en background
7
- # stop: detiene los procesos y limpia los pid files
8
- # status: muestra estado actual
9
- # restart: stop + start
10
- # ═══════════════════════════════════════════════════════════════
11
-
12
- set -euo pipefail
13
-
14
- REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
15
-
16
- # Load environment defaults
17
- GUARD_ENV_SCRIPT="$REPO_ROOT/scripts/hooks-system/bin/guard-env.sh"
18
- if [[ ! -f "$GUARD_ENV_SCRIPT" ]]; then
19
- GUARD_ENV_SCRIPT="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/guard-env.sh"
20
- fi
21
- if [[ ! -f "$GUARD_ENV_SCRIPT" ]]; then
22
- GUARD_ENV_SCRIPT="$REPO_ROOT/bin/guard-env.sh"
23
- fi
24
- if [[ -f "$GUARD_ENV_SCRIPT" ]]; then
25
- source "$GUARD_ENV_SCRIPT"
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
+
6
+ LOCK_DIR="$REPO_ROOT/.audit_tmp/guard-supervisor.lock"
7
+ if [[ -d "$LOCK_DIR" ]]; then
8
+ if ! ps -ax -o command= | grep -F "$REPO_ROOT/scripts/hooks-system/bin/guard-supervisor.js" | grep -v grep >/dev/null 2>&1; then
9
+ if ! ps -ax -o command= | grep -F "$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/scripts/hooks-system/bin/guard-supervisor.js" | grep -v grep >/dev/null 2>&1; then
10
+ if ! ps -ax -o command= | grep -F "$REPO_ROOT/node_modules/pumuki-ast-hooks/scripts/hooks-system/bin/guard-supervisor.js" | grep -v grep >/dev/null 2>&1; then
11
+ rm -rf "$LOCK_DIR" 2>/dev/null || true
12
+ fi
13
+ fi
14
+ fi
26
15
  fi
27
-
28
- REALTIME_PID_FILE="$REPO_ROOT/.realtime-guard.pid"
29
- REALTIME_LOG="$REPO_ROOT/.audit-reports/watch-hooks.log"
30
-
31
- GUARD_SUPERVISOR="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/bin/guard-supervisor.js"
32
- if [[ ! -f "$GUARD_SUPERVISOR" ]]; then
33
- GUARD_SUPERVISOR="$REPO_ROOT/bin/guard-supervisor.js"
16
+ IMPL="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/scripts/hooks-system/bin/start-guards.sh"
17
+ if [[ -f "$IMPL" ]]; then
18
+ exec bash "$IMPL" "$@"
34
19
  fi
35
- REALTIME_CMD="node $GUARD_SUPERVISOR"
36
20
 
37
- TOKEN_PID_FILE="$REPO_ROOT/.token-monitor-guard.pid"
38
- TOKEN_LOG="$REPO_ROOT/.audit-reports/token-monitor-loop.log"
39
-
40
- TOKEN_LOOP="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks/infrastructure/watchdog/token-monitor-loop.sh"
41
- if [[ ! -f "$TOKEN_LOOP" ]]; then
42
- TOKEN_LOOP="$REPO_ROOT/infrastructure/watchdog/token-monitor-loop.sh"
21
+ IMPL="$REPO_ROOT/node_modules/pumuki-ast-hooks/scripts/hooks-system/bin/start-guards.sh"
22
+ if [[ -f "$IMPL" ]]; then
23
+ exec bash "$IMPL" "$@"
43
24
  fi
44
- TOKEN_CMD="bash $TOKEN_LOOP"
45
-
46
- mkdir -p "$REPO_ROOT/.audit-reports"
47
- EVIDENCE_FILE="$REPO_ROOT/.AI_EVIDENCE.json"
48
-
49
- needs_evidence_refresh() {
50
- if [[ ! -f "$EVIDENCE_FILE" ]]; then
51
- return 0
52
- fi
53
-
54
- if ! command -v jq >/dev/null 2>&1; then
55
- return 0
56
- fi
57
-
58
- local answered
59
- answered=$(jq -r '.protocol_3_questions.answered // "false"' "$EVIDENCE_FILE" 2>/dev/null)
60
- if [[ "$answered" != "true" ]]; then
61
- return 0
62
- fi
63
-
64
- if jq -r '.protocol_3_questions | to_entries[] | .value' "$EVIDENCE_FILE" 2>/dev/null | grep -q "TODO"; then
65
- return 0
66
- fi
67
-
68
- local timestamp
69
- timestamp=$(jq -r '.timestamp // empty' "$EVIDENCE_FILE" 2>/dev/null)
70
- if [[ -z "$timestamp" ]]; then
71
- return 0
72
- fi
73
-
74
- local diff
75
- diff=$(python3 - <<PY
76
- import sys
77
- from datetime import datetime, timezone
78
-
79
- ts = "$timestamp"
80
-
81
- try:
82
- dt = datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
83
- now_utc = datetime.now(timezone.utc)
84
- diff = now_utc - dt
85
- print(int(diff.total_seconds()))
86
- except Exception:
87
- print(999999)
88
- PY
89
- )
90
- if [[ -z "$diff" ]]; then
91
- return 0
92
- fi
93
-
94
- if (( diff > 600 )); then
95
- return 0
96
- fi
97
-
98
- return 1
99
- }
100
-
101
- ensure_evidence_refresh() {
102
- if needs_evidence_refresh; then
103
- echo "⚙️ Refreshing .AI_EVIDENCE.json before starting guards..."
104
- CURRENT_BRANCH=$(git -C "$REPO_ROOT" branch --show-current 2>/dev/null || echo "manual-update")
105
- BRANCH_LOWER=$(echo "$CURRENT_BRANCH" | tr '[:upper:]' '[:lower:]')
106
-
107
- PLATFORMS="backend"
108
-
109
- if [[ "$BRANCH_LOWER" == *"frontend"* || "$BRANCH_LOWER" == *"web"* ]]; then
110
- PLATFORMS="frontend"
111
- elif [[ "$BRANCH_LOWER" == *"ios"* || "$BRANCH_LOWER" == *"swift"* ]]; then
112
- PLATFORMS="ios"
113
- elif [[ "$BRANCH_LOWER" == *"android"* || "$BRANCH_LOWER" == *"kotlin"* ]]; then
114
- PLATFORMS="android"
115
- fi
116
-
117
- bash "$REPO_ROOT/scripts/hooks-system/bin/update-evidence.sh" --auto --platforms "$PLATFORMS" "$CURRENT_BRANCH"
118
- fi
119
- }
120
-
121
- is_running() {
122
- local pid_file="$1"
123
- [[ -f "$pid_file" ]] || return 1
124
- local pid
125
- pid=$(cat "$pid_file" 2>/dev/null || echo "")
126
- [[ -n "$pid" ]] && ps -p "$pid" > /dev/null 2>&1
127
- }
128
-
129
- start_process() {
130
- local pid_file="$1"
131
- local command="$2"
132
- local log_file="$3"
133
-
134
- if is_running "$pid_file"; then
135
- echo "Already running ($(cat "$pid_file")) -> $command"
136
- return 0
137
- fi
138
-
139
- nohup bash -c "$command" >> "$log_file" 2>&1 &
140
- local pid=$!
141
- echo "$pid" > "$pid_file"
142
- echo "Started ($pid) -> $command"
143
- }
144
-
145
- stop_process() {
146
- local pid_file="$1"
147
- if ! is_running "$pid_file"; then
148
- [[ -f "$pid_file" ]] && rm -f "$pid_file"
149
- return 0
150
- fi
151
- local pid
152
- pid=$(cat "$pid_file")
153
- kill "$pid" 2>/dev/null || true
154
- rm -f "$pid_file"
155
- echo "Stopped process $pid"
156
- }
157
-
158
- status_process() {
159
- local name="$1"
160
- local pid_file="$2"
161
- if is_running "$pid_file"; then
162
- echo "[$name] running (PID $(cat "$pid_file"))"
163
- else
164
- echo "[$name] stopped"
165
- fi
166
- }
167
25
 
168
- case "${1:-status}" in
169
- start)
170
- ensure_evidence_refresh
171
- start_process "$REALTIME_PID_FILE" "$REALTIME_CMD" "$REALTIME_LOG"
172
- start_process "$TOKEN_PID_FILE" "$TOKEN_CMD" "$TOKEN_LOG"
173
- ;;
174
- stop)
175
- stop_process "$REALTIME_PID_FILE"
176
- stop_process "$TOKEN_PID_FILE"
177
- ;;
178
- status)
179
- status_process "realtime-guard" "$REALTIME_PID_FILE"
180
- status_process "token-monitor" "$TOKEN_PID_FILE"
181
- ;;
182
- restart)
183
- "$0" stop
184
- "$0" start
185
- ;;
186
- *)
187
- echo "Usage: $0 {start|stop|status|restart}"
188
- exit 1
189
- ;;
190
- esac
26
+ echo "start-guards.sh implementation not found. Please reinstall dependencies." >&2
27
+ exit 1