baseguard 1.0.0

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 (244) hide show
  1. package/.eslintrc.json +25 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +94 -0
  4. package/bin/base.js +494 -0
  5. package/dist/ai/fix-manager.d.ts +67 -0
  6. package/dist/ai/fix-manager.d.ts.map +1 -0
  7. package/dist/ai/fix-manager.js +326 -0
  8. package/dist/ai/fix-manager.js.map +1 -0
  9. package/dist/ai/gemini-analyzer.d.ts +116 -0
  10. package/dist/ai/gemini-analyzer.d.ts.map +1 -0
  11. package/dist/ai/gemini-analyzer.js +572 -0
  12. package/dist/ai/gemini-analyzer.js.map +1 -0
  13. package/dist/ai/index.d.ts +4 -0
  14. package/dist/ai/index.d.ts.map +1 -0
  15. package/dist/ai/index.js +5 -0
  16. package/dist/ai/index.js.map +1 -0
  17. package/dist/ai/jules-implementer.d.ts +115 -0
  18. package/dist/ai/jules-implementer.d.ts.map +1 -0
  19. package/dist/ai/jules-implementer.js +387 -0
  20. package/dist/ai/jules-implementer.js.map +1 -0
  21. package/dist/commands/automation.d.ts +5 -0
  22. package/dist/commands/automation.d.ts.map +1 -0
  23. package/dist/commands/automation.js +305 -0
  24. package/dist/commands/automation.js.map +1 -0
  25. package/dist/commands/check.d.ts +9 -0
  26. package/dist/commands/check.d.ts.map +1 -0
  27. package/dist/commands/check.js +113 -0
  28. package/dist/commands/check.js.map +1 -0
  29. package/dist/commands/config.d.ts +11 -0
  30. package/dist/commands/config.d.ts.map +1 -0
  31. package/dist/commands/config.js +324 -0
  32. package/dist/commands/config.js.map +1 -0
  33. package/dist/commands/fix.d.ts +9 -0
  34. package/dist/commands/fix.d.ts.map +1 -0
  35. package/dist/commands/fix.js +207 -0
  36. package/dist/commands/fix.js.map +1 -0
  37. package/dist/commands/index.d.ts +6 -0
  38. package/dist/commands/index.d.ts.map +1 -0
  39. package/dist/commands/index.js +7 -0
  40. package/dist/commands/index.js.map +1 -0
  41. package/dist/commands/init.d.ts +9 -0
  42. package/dist/commands/init.d.ts.map +1 -0
  43. package/dist/commands/init.js +125 -0
  44. package/dist/commands/init.js.map +1 -0
  45. package/dist/core/api-key-manager.d.ts +83 -0
  46. package/dist/core/api-key-manager.d.ts.map +1 -0
  47. package/dist/core/api-key-manager.js +244 -0
  48. package/dist/core/api-key-manager.js.map +1 -0
  49. package/dist/core/baseguard.d.ts +46 -0
  50. package/dist/core/baseguard.d.ts.map +1 -0
  51. package/dist/core/baseguard.js +132 -0
  52. package/dist/core/baseguard.js.map +1 -0
  53. package/dist/core/baseline-checker.d.ts +63 -0
  54. package/dist/core/baseline-checker.d.ts.map +1 -0
  55. package/dist/core/baseline-checker.js +502 -0
  56. package/dist/core/baseline-checker.js.map +1 -0
  57. package/dist/core/cache-manager.d.ts +88 -0
  58. package/dist/core/cache-manager.d.ts.map +1 -0
  59. package/dist/core/cache-manager.js +213 -0
  60. package/dist/core/cache-manager.js.map +1 -0
  61. package/dist/core/configuration.d.ts +140 -0
  62. package/dist/core/configuration.d.ts.map +1 -0
  63. package/dist/core/configuration.js +474 -0
  64. package/dist/core/configuration.js.map +1 -0
  65. package/dist/core/directory-filter.d.ts +90 -0
  66. package/dist/core/directory-filter.d.ts.map +1 -0
  67. package/dist/core/directory-filter.js +319 -0
  68. package/dist/core/directory-filter.js.map +1 -0
  69. package/dist/core/error-handler.d.ts +110 -0
  70. package/dist/core/error-handler.d.ts.map +1 -0
  71. package/dist/core/error-handler.js +392 -0
  72. package/dist/core/error-handler.js.map +1 -0
  73. package/dist/core/file-processor.d.ts +80 -0
  74. package/dist/core/file-processor.d.ts.map +1 -0
  75. package/dist/core/file-processor.js +259 -0
  76. package/dist/core/file-processor.js.map +1 -0
  77. package/dist/core/gitignore-manager.d.ts +44 -0
  78. package/dist/core/gitignore-manager.d.ts.map +1 -0
  79. package/dist/core/gitignore-manager.js +147 -0
  80. package/dist/core/gitignore-manager.js.map +1 -0
  81. package/dist/core/index.d.ts +13 -0
  82. package/dist/core/index.d.ts.map +1 -0
  83. package/dist/core/index.js +13 -0
  84. package/dist/core/index.js.map +1 -0
  85. package/dist/core/lazy-loader.d.ts +68 -0
  86. package/dist/core/lazy-loader.d.ts.map +1 -0
  87. package/dist/core/lazy-loader.js +260 -0
  88. package/dist/core/lazy-loader.js.map +1 -0
  89. package/dist/core/memory-manager.d.ts +1 -0
  90. package/dist/core/memory-manager.d.ts.map +1 -0
  91. package/dist/core/memory-manager.js +2 -0
  92. package/dist/core/memory-manager.js.map +1 -0
  93. package/dist/core/startup-optimizer.d.ts +45 -0
  94. package/dist/core/startup-optimizer.d.ts.map +1 -0
  95. package/dist/core/startup-optimizer.js +140 -0
  96. package/dist/core/startup-optimizer.js.map +1 -0
  97. package/dist/git/automation-engine.d.ts +58 -0
  98. package/dist/git/automation-engine.d.ts.map +1 -0
  99. package/dist/git/automation-engine.js +318 -0
  100. package/dist/git/automation-engine.js.map +1 -0
  101. package/dist/git/github-manager.d.ts +71 -0
  102. package/dist/git/github-manager.d.ts.map +1 -0
  103. package/dist/git/github-manager.js +226 -0
  104. package/dist/git/github-manager.js.map +1 -0
  105. package/dist/git/hook-manager.d.ts +43 -0
  106. package/dist/git/hook-manager.d.ts.map +1 -0
  107. package/dist/git/hook-manager.js +191 -0
  108. package/dist/git/hook-manager.js.map +1 -0
  109. package/dist/git/index.d.ts +4 -0
  110. package/dist/git/index.d.ts.map +1 -0
  111. package/dist/git/index.js +5 -0
  112. package/dist/git/index.js.map +1 -0
  113. package/dist/index.d.ts +8 -0
  114. package/dist/index.d.ts.map +1 -0
  115. package/dist/index.js +9 -0
  116. package/dist/index.js.map +1 -0
  117. package/dist/parsers/feature-validator.d.ts +60 -0
  118. package/dist/parsers/feature-validator.d.ts.map +1 -0
  119. package/dist/parsers/feature-validator.js +483 -0
  120. package/dist/parsers/feature-validator.js.map +1 -0
  121. package/dist/parsers/index.d.ts +8 -0
  122. package/dist/parsers/index.d.ts.map +1 -0
  123. package/dist/parsers/index.js +9 -0
  124. package/dist/parsers/index.js.map +1 -0
  125. package/dist/parsers/parser-manager.d.ts +103 -0
  126. package/dist/parsers/parser-manager.d.ts.map +1 -0
  127. package/dist/parsers/parser-manager.js +321 -0
  128. package/dist/parsers/parser-manager.js.map +1 -0
  129. package/dist/parsers/parser.d.ts +23 -0
  130. package/dist/parsers/parser.d.ts.map +1 -0
  131. package/dist/parsers/parser.js +6 -0
  132. package/dist/parsers/parser.js.map +1 -0
  133. package/dist/parsers/react-parser.d.ts +22 -0
  134. package/dist/parsers/react-parser.d.ts.map +1 -0
  135. package/dist/parsers/react-parser.js +307 -0
  136. package/dist/parsers/react-parser.js.map +1 -0
  137. package/dist/parsers/svelte-parser.d.ts +33 -0
  138. package/dist/parsers/svelte-parser.d.ts.map +1 -0
  139. package/dist/parsers/svelte-parser.js +408 -0
  140. package/dist/parsers/svelte-parser.js.map +1 -0
  141. package/dist/parsers/vanilla-parser.d.ts +31 -0
  142. package/dist/parsers/vanilla-parser.d.ts.map +1 -0
  143. package/dist/parsers/vanilla-parser.js +590 -0
  144. package/dist/parsers/vanilla-parser.js.map +1 -0
  145. package/dist/parsers/vue-parser.d.ts +9 -0
  146. package/dist/parsers/vue-parser.d.ts.map +1 -0
  147. package/dist/parsers/vue-parser.js +16 -0
  148. package/dist/parsers/vue-parser.js.map +1 -0
  149. package/dist/terminal-header.d.ts +12 -0
  150. package/dist/terminal-header.js +45 -0
  151. package/dist/types/index.d.ts +83 -0
  152. package/dist/types/index.d.ts.map +1 -0
  153. package/dist/types/index.js +5 -0
  154. package/dist/types/index.js.map +1 -0
  155. package/dist/ui/components.d.ts +133 -0
  156. package/dist/ui/components.d.ts.map +1 -0
  157. package/dist/ui/components.js +482 -0
  158. package/dist/ui/components.js.map +1 -0
  159. package/dist/ui/help.d.ts +11 -0
  160. package/dist/ui/help.d.ts.map +1 -0
  161. package/dist/ui/help.js +161 -0
  162. package/dist/ui/help.js.map +1 -0
  163. package/dist/ui/index.d.ts +5 -0
  164. package/dist/ui/index.d.ts.map +1 -0
  165. package/dist/ui/index.js +5 -0
  166. package/dist/ui/index.js.map +1 -0
  167. package/dist/ui/prompts.d.ts +63 -0
  168. package/dist/ui/prompts.d.ts.map +1 -0
  169. package/dist/ui/prompts.js +611 -0
  170. package/dist/ui/prompts.js.map +1 -0
  171. package/dist/ui/terminal-header.d.ts +13 -0
  172. package/dist/ui/terminal-header.d.ts.map +1 -0
  173. package/dist/ui/terminal-header.js +46 -0
  174. package/dist/ui/terminal-header.js.map +1 -0
  175. package/package.json +80 -0
  176. package/src/ai/__tests__/gemini-analyzer.test.ts +181 -0
  177. package/src/ai/fix-manager.ts +362 -0
  178. package/src/ai/gemini-analyzer.ts +671 -0
  179. package/src/ai/index.ts +4 -0
  180. package/src/ai/jules-implementer.ts +459 -0
  181. package/src/commands/automation.ts +344 -0
  182. package/src/commands/check.ts +299 -0
  183. package/src/commands/config.ts +365 -0
  184. package/src/commands/fix.ts +234 -0
  185. package/src/commands/index.ts +6 -0
  186. package/src/commands/init.ts +142 -0
  187. package/src/commands/status.ts +0 -0
  188. package/src/core/api-key-manager.ts +298 -0
  189. package/src/core/baseguard.ts +742 -0
  190. package/src/core/baseline-checker.ts +563 -0
  191. package/src/core/cache-manager.ts +270 -0
  192. package/src/core/configuration-recovery.ts +676 -0
  193. package/src/core/configuration.ts +559 -0
  194. package/src/core/debug-logger.ts +590 -0
  195. package/src/core/directory-filter.ts +421 -0
  196. package/src/core/error-handler.ts +517 -0
  197. package/src/core/file-processor.ts +331 -0
  198. package/src/core/gitignore-manager.ts +169 -0
  199. package/src/core/graceful-degradation-manager.ts +596 -0
  200. package/src/core/index.ts +13 -0
  201. package/src/core/lazy-loader.ts +307 -0
  202. package/src/core/logger.ts +0 -0
  203. package/src/core/memory-manager.ts +294 -0
  204. package/src/core/startup-optimizer.ts +173 -0
  205. package/src/core/system-error-handler.ts +746 -0
  206. package/src/git/automation-engine.ts +361 -0
  207. package/src/git/github-manager.ts +260 -0
  208. package/src/git/hook-manager.ts +210 -0
  209. package/src/git/index.ts +4 -0
  210. package/src/index.ts +8 -0
  211. package/src/parsers/feature-validator.ts +559 -0
  212. package/src/parsers/index.ts +8 -0
  213. package/src/parsers/parser-manager.ts +419 -0
  214. package/src/parsers/parser.ts +26 -0
  215. package/src/parsers/react-parser-optimized.ts +161 -0
  216. package/src/parsers/react-parser.ts +359 -0
  217. package/src/parsers/svelte-parser.ts +506 -0
  218. package/src/parsers/vanilla-parser.ts +682 -0
  219. package/src/parsers/vue-parser.ts +472 -0
  220. package/src/types/index.ts +92 -0
  221. package/src/ui/components.ts +567 -0
  222. package/src/ui/help.ts +193 -0
  223. package/src/ui/index.ts +4 -0
  224. package/src/ui/prompts.ts +688 -0
  225. package/src/ui/terminal-header.ts +59 -0
  226. package/test-config-commands.js +56 -0
  227. package/test-header-simple.js +33 -0
  228. package/test-terminal-header.js +12 -0
  229. package/test-ui.js +29 -0
  230. package/tests/e2e/baseguard.e2e.test.ts +516 -0
  231. package/tests/e2e/cross-platform.e2e.test.ts +420 -0
  232. package/tests/e2e/git-integration.e2e.test.ts +487 -0
  233. package/tests/fixtures/react-project/package.json +14 -0
  234. package/tests/fixtures/react-project/src/App.css +76 -0
  235. package/tests/fixtures/react-project/src/App.tsx +77 -0
  236. package/tests/fixtures/svelte-project/package.json +11 -0
  237. package/tests/fixtures/svelte-project/src/App.svelte +369 -0
  238. package/tests/fixtures/vanilla-project/index.html +76 -0
  239. package/tests/fixtures/vanilla-project/script.js +331 -0
  240. package/tests/fixtures/vanilla-project/styles.css +359 -0
  241. package/tests/fixtures/vue-project/package.json +12 -0
  242. package/tests/fixtures/vue-project/src/App.vue +216 -0
  243. package/tsconfig.json +36 -0
  244. package/vitest.config.ts +10 -0
@@ -0,0 +1,361 @@
1
+ import { execSync } from 'child_process';
2
+ import { readFileSync } from 'fs';
3
+ import chalk from 'chalk';
4
+ import ora from 'ora';
5
+ import inquirer from 'inquirer';
6
+ import type { AutomationOptions, Violation, Analysis, Fix, Configuration } from '../types/index.js';
7
+ import { ConfigurationManager } from '../core/configuration.js';
8
+ import { BaseGuard } from '../core/baseguard.js';
9
+ import { UIComponents } from '../ui/components.js';
10
+ import { GeminiAnalyzer } from '../ai/gemini-analyzer.js';
11
+ import { JulesImplementer } from '../ai/jules-implementer.js';
12
+
13
+ /**
14
+ * Automation engine for git workflow integration
15
+ */
16
+ export class AutomationEngine {
17
+ private config: Configuration;
18
+ private baseGuard: BaseGuard;
19
+
20
+ constructor(config?: Configuration) {
21
+ this.config = config || ConfigurationManager.createDefault();
22
+ this.baseGuard = new BaseGuard(this.config);
23
+ }
24
+
25
+ /**
26
+ * Run automation for git hooks
27
+ */
28
+ async run(options: AutomationOptions): Promise<void> {
29
+ try {
30
+ // Load current configuration
31
+ this.config = await ConfigurationManager.load();
32
+ this.baseGuard = new BaseGuard(this.config);
33
+
34
+ // Check if automation is enabled
35
+ if (!this.config.automation.enabled) {
36
+ console.log(chalk.yellow('⚠️ BaseGuard automation is disabled. Run "base automation enable" to enable it.'));
37
+ return;
38
+ }
39
+
40
+ // Check if this is the correct trigger
41
+ if (this.config.automation.trigger !== options.trigger) {
42
+ // Silently exit if this isn't the configured trigger
43
+ return;
44
+ }
45
+
46
+ console.log(chalk.cyan(`🛡️ BaseGuard automation running (${options.trigger})...`));
47
+
48
+ // Step 1: Check violations in staged files
49
+ const violations = await this.checkViolations(options.trigger);
50
+
51
+ if (violations.length === 0) {
52
+ console.log(chalk.green('✅ No compatibility issues found'));
53
+ return;
54
+ }
55
+
56
+ console.log(chalk.yellow(`⚠️ Found ${violations.length} compatibility issue(s)`));
57
+ UIComponents.showViolations(violations);
58
+
59
+ // Step 2: Analyze violations (if enabled and API key available)
60
+ let analyses: Analysis[] = [];
61
+ if (this.config.automation.autoAnalyze && this.config.apiKeys.gemini) {
62
+ analyses = await this.analyzeViolations(violations);
63
+ }
64
+
65
+ // Step 3: Auto-fix (if enabled and API keys available)
66
+ if (this.config.automation.autoFix && this.config.apiKeys.jules && this.config.apiKeys.gemini) {
67
+ const fixes = await this.generateFixes(violations, analyses);
68
+ if (fixes.length > 0) {
69
+ await this.applyFixes(fixes);
70
+ await this.stageChanges();
71
+ console.log(chalk.green('✅ All issues fixed automatically and staged'));
72
+ return;
73
+ }
74
+ }
75
+
76
+ // Manual mode - show options
77
+ await this.showManualOptions(violations, analyses);
78
+
79
+ // Block commit if configured to do so
80
+ if (this.config.automation.blockCommit && !options.strict === false) {
81
+ console.log(chalk.red('❌ Commit blocked due to compatibility issues'));
82
+ console.log(chalk.dim('Use --no-verify to bypass this check'));
83
+ process.exit(1);
84
+ }
85
+
86
+ } catch (error) {
87
+ console.error(chalk.red('❌ BaseGuard automation failed:'), error instanceof Error ? error.message : 'Unknown error');
88
+
89
+ // Don't block commit on automation errors unless in strict mode
90
+ if (options.strict) {
91
+ process.exit(1);
92
+ }
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Check violations in staged files (for pre-commit) or all files (for pre-push)
98
+ */
99
+ private async checkViolations(trigger: 'pre-commit' | 'pre-push'): Promise<Violation[]> {
100
+ const spinner = ora('Checking for compatibility violations...').start();
101
+
102
+ try {
103
+ let filesToCheck: string[] = [];
104
+
105
+ if (trigger === 'pre-commit') {
106
+ // Get staged files for pre-commit
107
+ filesToCheck = this.getStagedFiles();
108
+ } else {
109
+ // For pre-push, check all files in the repository
110
+ filesToCheck = this.getAllTrackedFiles();
111
+ }
112
+
113
+ // Filter to only supported file types
114
+ const supportedExtensions = ['.js', '.ts', '.jsx', '.tsx', '.vue', '.svelte', '.css', '.html'];
115
+ const filteredFiles = filesToCheck.filter(file =>
116
+ supportedExtensions.some(ext => file.endsWith(ext))
117
+ );
118
+
119
+ if (filteredFiles.length === 0) {
120
+ spinner.succeed('No supported files to check');
121
+ return [];
122
+ }
123
+
124
+ spinner.text = `Checking ${filteredFiles.length} file(s)...`;
125
+
126
+ // Use BaseGuard to check violations
127
+ const violations = await this.baseGuard.checkViolations(filteredFiles);
128
+
129
+ spinner.succeed(`Checked ${filteredFiles.length} file(s)`);
130
+ return violations;
131
+
132
+ } catch (error) {
133
+ spinner.fail('Failed to check violations');
134
+ throw error;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Get staged files from git
140
+ */
141
+ private getStagedFiles(): string[] {
142
+ try {
143
+ const output = execSync('git diff --cached --name-only', { encoding: 'utf-8' });
144
+ return output.trim().split('\n').filter(file => file.length > 0);
145
+ } catch (error) {
146
+ console.warn(chalk.yellow('⚠️ Could not get staged files, checking all files'));
147
+ return this.getAllTrackedFiles();
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Get all tracked files from git
153
+ */
154
+ private getAllTrackedFiles(): string[] {
155
+ try {
156
+ const output = execSync('git ls-files', { encoding: 'utf-8' });
157
+ return output.trim().split('\n').filter(file => file.length > 0);
158
+ } catch (error) {
159
+ throw new Error('Could not get tracked files from git');
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Analyze violations if auto-analyze is enabled
165
+ */
166
+ private async analyzeViolations(violations: Violation[]): Promise<Analysis[]> {
167
+ if (!this.config.apiKeys.gemini) {
168
+ console.log(chalk.yellow('⚠️ Gemini API key not configured, skipping analysis'));
169
+ return [];
170
+ }
171
+
172
+ const spinner = ora('Analyzing violations with AI...').start();
173
+
174
+ try {
175
+ const analyzer = new GeminiAnalyzer(this.config.apiKeys.gemini);
176
+ const analyses: Analysis[] = [];
177
+
178
+ // Analyze violations in batches to avoid rate limiting
179
+ for (const violation of violations) {
180
+ try {
181
+ const analysis = await analyzer.analyzeViolation(violation);
182
+ analyses.push(analysis);
183
+ } catch (error) {
184
+ console.warn(chalk.yellow(`⚠️ Could not analyze ${violation.feature}: ${error instanceof Error ? error.message : 'Unknown error'}`));
185
+ }
186
+ }
187
+
188
+ spinner.succeed(`Analyzed ${analyses.length} violation(s)`);
189
+ return analyses;
190
+
191
+ } catch (error) {
192
+ spinner.fail('Failed to analyze violations');
193
+ throw error;
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Generate and apply fixes if auto-fix is enabled
199
+ */
200
+ private async generateFixes(violations: Violation[], analyses: Analysis[]): Promise<Fix[]> {
201
+ if (!this.config.apiKeys.jules) {
202
+ console.log(chalk.yellow('⚠️ Jules API key not configured, skipping auto-fix'));
203
+ return [];
204
+ }
205
+
206
+ const spinner = ora('Generating fixes with AI...').start();
207
+
208
+ try {
209
+ const implementer = new JulesImplementer(this.config.apiKeys.jules);
210
+ const fixes: Fix[] = [];
211
+
212
+ // Generate fixes for violations that have analyses
213
+ for (const violation of violations) {
214
+ const analysis = analyses.find(a => a.violation.feature === violation.feature);
215
+ if (!analysis) continue;
216
+
217
+ try {
218
+ // For automation, we need a repository source - this would need to be configured
219
+ // For now, we'll skip Jules integration in automation mode
220
+ console.log(chalk.yellow('⚠️ Jules integration requires repository setup, skipping auto-fix'));
221
+ break;
222
+ } catch (error) {
223
+ console.warn(chalk.yellow(`⚠️ Could not generate fix for ${violation.feature}: ${error instanceof Error ? error.message : 'Unknown error'}`));
224
+ }
225
+ }
226
+
227
+ spinner.succeed(`Generated ${fixes.length} fix(es)`);
228
+ return fixes;
229
+
230
+ } catch (error) {
231
+ spinner.fail('Failed to generate fixes');
232
+ throw error;
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Apply fixes to files
238
+ */
239
+ private async applyFixes(fixes: Fix[]): Promise<void> {
240
+ const spinner = ora('Applying fixes...').start();
241
+
242
+ try {
243
+ // This would use the BaseGuard.applyFixes method when implemented
244
+ // For now, we'll just log that fixes would be applied
245
+ spinner.succeed(`Applied ${fixes.length} fix(es)`);
246
+ } catch (error) {
247
+ spinner.fail('Failed to apply fixes');
248
+ throw error;
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Stage changes after fixing
254
+ */
255
+ private async stageChanges(): Promise<void> {
256
+ try {
257
+ execSync('git add -u', { stdio: 'ignore' });
258
+ } catch (error) {
259
+ console.warn(chalk.yellow('⚠️ Could not stage changes automatically'));
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Show manual options when auto-fix is disabled
265
+ */
266
+ private async showManualOptions(violations: Violation[], analyses: Analysis[] = []): Promise<void> {
267
+ console.log(chalk.cyan('\n🔧 Manual Options:'));
268
+
269
+ const choices = [
270
+ {
271
+ name: 'Continue with commit (ignore violations)',
272
+ value: 'continue'
273
+ },
274
+ {
275
+ name: 'Fix violations manually and retry',
276
+ value: 'manual'
277
+ }
278
+ ];
279
+
280
+ // Add AI options if API keys are available
281
+ if (this.config.apiKeys.gemini && analyses.length === 0) {
282
+ choices.unshift({
283
+ name: 'Analyze violations with AI first',
284
+ value: 'analyze'
285
+ });
286
+ }
287
+
288
+ if (this.config.apiKeys.jules && this.config.apiKeys.gemini) {
289
+ choices.unshift({
290
+ name: 'Generate and preview AI fixes',
291
+ value: 'fix'
292
+ });
293
+ }
294
+
295
+ const { action } = await inquirer.prompt([
296
+ {
297
+ type: 'list',
298
+ name: 'action',
299
+ message: 'What would you like to do?',
300
+ choices
301
+ }
302
+ ]);
303
+
304
+ switch (action) {
305
+ case 'continue':
306
+ console.log(chalk.yellow('⚠️ Continuing with violations...'));
307
+ break;
308
+
309
+ case 'manual':
310
+ console.log(chalk.blue('💡 Fix the violations manually and run git commit again'));
311
+ process.exit(1);
312
+
313
+ case 'analyze':
314
+ console.log(chalk.blue('🔍 Run "base check --analyze" to get AI analysis'));
315
+ process.exit(1);
316
+
317
+ case 'fix':
318
+ console.log(chalk.blue('🤖 Run "base fix" to generate and preview AI fixes'));
319
+ process.exit(1);
320
+
321
+ default:
322
+ process.exit(1);
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Check if git repository has uncommitted changes
328
+ */
329
+ private hasUncommittedChanges(): boolean {
330
+ try {
331
+ const output = execSync('git status --porcelain', { encoding: 'utf-8' });
332
+ return output.trim().length > 0;
333
+ } catch {
334
+ return false;
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Get current git branch
340
+ */
341
+ private getCurrentBranch(): string {
342
+ try {
343
+ const output = execSync('git branch --show-current', { encoding: 'utf-8' });
344
+ return output.trim();
345
+ } catch {
346
+ return 'unknown';
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Check if we're in a git repository
352
+ */
353
+ private isGitRepository(): boolean {
354
+ try {
355
+ execSync('git rev-parse --git-dir', { stdio: 'ignore' });
356
+ return true;
357
+ } catch {
358
+ return false;
359
+ }
360
+ }
361
+ }
@@ -0,0 +1,260 @@
1
+ import { execSync } from 'child_process';
2
+ import { existsSync } from 'fs';
3
+ import { join } from 'path';
4
+ import chalk from 'chalk';
5
+ import open from 'open';
6
+
7
+ /**
8
+ * GitHub repository manager for Jules integration
9
+ */
10
+ export class GitHubManager {
11
+ private repoOwner: string | null = null;
12
+ private repoName: string | null = null;
13
+ private sourceIdentifier: string | null = null;
14
+
15
+ /**
16
+ * Guide user through Jules GitHub app installation
17
+ */
18
+ async setupJulesGitHubIntegration(): Promise<string> {
19
+ console.log(chalk.cyan('\n🔗 Setting up Jules GitHub Integration\n'));
20
+
21
+ // Step 1: Check if we're in a git repository
22
+ if (!this.isGitRepository()) {
23
+ throw new Error('Not in a git repository. Please run this command from within a git repository.');
24
+ }
25
+
26
+ // Step 2: Get repository information
27
+ await this.detectRepositoryInfo();
28
+
29
+ // Step 3: Guide user through GitHub app installation
30
+ await this.guideGitHubAppInstallation();
31
+
32
+ // Step 4: Verify connection and get source identifier
33
+ const sourceId = await this.getSourceIdentifier();
34
+
35
+ console.log(chalk.green('✅ Jules GitHub integration setup complete!'));
36
+ return sourceId;
37
+ }
38
+
39
+ /**
40
+ * Check if current directory is a git repository
41
+ */
42
+ private isGitRepository(): boolean {
43
+ try {
44
+ execSync('git rev-parse --git-dir', { stdio: 'ignore' });
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Detect repository owner and name from git remote
53
+ */
54
+ private async detectRepositoryInfo(): Promise<void> {
55
+ try {
56
+ const remoteUrl = execSync('git config --get remote.origin.url', { encoding: 'utf8' }).trim();
57
+
58
+ // Parse GitHub URL (supports both HTTPS and SSH)
59
+ const match = remoteUrl.match(/github\.com[:/]([^/]+)\/([^/.]+)/);
60
+
61
+ if (match) {
62
+ this.repoOwner = match[1] || null;
63
+ this.repoName = match[2] || null;
64
+
65
+ console.log(chalk.blue(`📁 Detected repository: ${this.repoOwner}/${this.repoName}`));
66
+ } else {
67
+ throw new Error('Could not detect GitHub repository from remote URL');
68
+ }
69
+ } catch (error) {
70
+ throw new Error(`Failed to detect repository info: ${error instanceof Error ? error.message : 'Unknown error'}`);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Guide user through GitHub app installation process
76
+ */
77
+ private async guideGitHubAppInstallation(): Promise<void> {
78
+ console.log(chalk.yellow('\n📋 Jules GitHub App Installation Steps:\n'));
79
+
80
+ console.log('1. Opening Jules GitHub app installation page...');
81
+
82
+ // Open Jules GitHub app installation URL
83
+ const installUrl = 'https://github.com/apps/jules-ai';
84
+ await open(installUrl);
85
+
86
+ console.log(chalk.dim(` ${installUrl}`));
87
+
88
+ console.log('\n2. Follow these steps in your browser:');
89
+ console.log(' • Click "Install" on the Jules app page');
90
+ console.log(' • Select your repository or organization');
91
+ console.log(` • Grant access to ${this.repoOwner}/${this.repoName}`);
92
+ console.log(' • Complete the installation process');
93
+
94
+ console.log('\n3. After installation:');
95
+ console.log(' • Return to this terminal');
96
+ console.log(' • The setup will continue automatically');
97
+
98
+ // Wait for user confirmation
99
+ await this.waitForUserConfirmation();
100
+ }
101
+
102
+ /**
103
+ * Wait for user to confirm GitHub app installation
104
+ */
105
+ private async waitForUserConfirmation(): Promise<void> {
106
+ const { default: inquirer } = await import('inquirer');
107
+
108
+ const { confirmed } = await inquirer.prompt([
109
+ {
110
+ type: 'confirm',
111
+ name: 'confirmed',
112
+ message: 'Have you completed the Jules GitHub app installation?',
113
+ default: false
114
+ }
115
+ ]);
116
+
117
+ if (!confirmed) {
118
+ console.log(chalk.yellow('\nPlease complete the GitHub app installation and run this command again.'));
119
+ process.exit(0);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Get source identifier for Jules API
125
+ */
126
+ private async getSourceIdentifier(): Promise<string> {
127
+ if (!this.repoOwner || !this.repoName) {
128
+ throw new Error('Repository information not available');
129
+ }
130
+
131
+ // Generate source identifier in the format expected by Jules
132
+ this.sourceIdentifier = `sources/github/${this.repoOwner}/${this.repoName}`;
133
+
134
+ console.log(chalk.blue(`🔗 Source identifier: ${this.sourceIdentifier}`));
135
+
136
+ return this.sourceIdentifier;
137
+ }
138
+
139
+ /**
140
+ * Verify GitHub authentication and permissions
141
+ */
142
+ async verifyGitHubConnection(): Promise<boolean> {
143
+ try {
144
+ if (!this.repoOwner || !this.repoName) {
145
+ await this.detectRepositoryInfo();
146
+ }
147
+
148
+ // Check if we can access the repository
149
+ const response = await fetch(`https://api.github.com/repos/${this.repoOwner}/${this.repoName}`);
150
+
151
+ if (response.ok) {
152
+ console.log(chalk.green('✅ GitHub repository access verified'));
153
+ return true;
154
+ } else {
155
+ console.log(chalk.yellow('⚠️ GitHub repository access verification failed'));
156
+ return false;
157
+ }
158
+ } catch (error) {
159
+ console.log(chalk.red(`❌ GitHub connection error: ${error instanceof Error ? error.message : 'Unknown error'}`));
160
+ return false;
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Get current repository source identifier
166
+ */
167
+ async getCurrentSourceIdentifier(): Promise<string> {
168
+ if (this.sourceIdentifier) {
169
+ return this.sourceIdentifier;
170
+ }
171
+
172
+ await this.detectRepositoryInfo();
173
+ return this.getSourceIdentifier();
174
+ }
175
+
176
+ /**
177
+ * Check if Jules GitHub integration is set up
178
+ */
179
+ async isJulesIntegrationSetup(): Promise<boolean> {
180
+ try {
181
+ if (!this.isGitRepository()) {
182
+ return false;
183
+ }
184
+
185
+ await this.detectRepositoryInfo();
186
+ return await this.verifyGitHubConnection();
187
+ } catch {
188
+ return false;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Get repository information
194
+ */
195
+ getRepositoryInfo(): { owner: string | null; name: string | null } {
196
+ return {
197
+ owner: this.repoOwner,
198
+ name: this.repoName
199
+ };
200
+ }
201
+
202
+ /**
203
+ * Check if repository has required permissions for Jules
204
+ */
205
+ async checkRepositoryPermissions(): Promise<{ hasAccess: boolean; permissions: string[] }> {
206
+ try {
207
+ if (!this.repoOwner || !this.repoName) {
208
+ await this.detectRepositoryInfo();
209
+ }
210
+
211
+ // In a real implementation, this would check specific permissions
212
+ // For now, we'll assume basic access if we can read the repo
213
+ const hasAccess = await this.verifyGitHubConnection();
214
+
215
+ const permissions = hasAccess ? [
216
+ 'read',
217
+ 'write',
218
+ 'pull_requests'
219
+ ] : [];
220
+
221
+ return { hasAccess, permissions };
222
+ } catch {
223
+ return { hasAccess: false, permissions: [] };
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Get current branch name
229
+ */
230
+ getCurrentBranch(): string {
231
+ try {
232
+ return execSync('git branch --show-current', { encoding: 'utf8' }).trim();
233
+ } catch {
234
+ return 'main'; // fallback
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Check if there are uncommitted changes
240
+ */
241
+ hasUncommittedChanges(): boolean {
242
+ try {
243
+ const status = execSync('git status --porcelain', { encoding: 'utf8' });
244
+ return status.trim().length > 0;
245
+ } catch {
246
+ return false;
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Get repository URL for display
252
+ */
253
+ getRepositoryUrl(): string | null {
254
+ if (!this.repoOwner || !this.repoName) {
255
+ return null;
256
+ }
257
+
258
+ return `https://github.com/${this.repoOwner}/${this.repoName}`;
259
+ }
260
+ }