humanbehavior-js 0.4.6 → 0.4.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.
Files changed (58) hide show
  1. package/dist/cjs/angular/index.cjs +52 -7
  2. package/dist/cjs/angular/index.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +52 -7
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/install-wizard.cjs +4 -2
  6. package/dist/cjs/install-wizard.cjs.map +1 -1
  7. package/dist/cjs/react/index.cjs +52 -7
  8. package/dist/cjs/react/index.cjs.map +1 -1
  9. package/dist/cjs/remix/index.cjs +52 -7
  10. package/dist/cjs/remix/index.cjs.map +1 -1
  11. package/dist/cjs/svelte/index.cjs +52 -7
  12. package/dist/cjs/svelte/index.cjs.map +1 -1
  13. package/dist/cjs/vue/index.cjs +52 -7
  14. package/dist/cjs/vue/index.cjs.map +1 -1
  15. package/dist/cjs/wizard/index.cjs +3208 -0
  16. package/dist/cjs/wizard/index.cjs.map +1 -0
  17. package/dist/cli/ai-auto-install.js +2024 -0
  18. package/dist/cli/ai-auto-install.js.map +1 -0
  19. package/dist/cli/auto-install.js +4 -2
  20. package/dist/cli/auto-install.js.map +1 -1
  21. package/dist/esm/angular/index.js +52 -7
  22. package/dist/esm/angular/index.js.map +1 -1
  23. package/dist/esm/index.js +52 -7
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/install-wizard.js +4 -2
  26. package/dist/esm/install-wizard.js.map +1 -1
  27. package/dist/esm/react/index.js +52 -7
  28. package/dist/esm/react/index.js.map +1 -1
  29. package/dist/esm/remix/index.js +52 -7
  30. package/dist/esm/remix/index.js.map +1 -1
  31. package/dist/esm/svelte/index.js +52 -7
  32. package/dist/esm/svelte/index.js.map +1 -1
  33. package/dist/esm/vue/index.js +52 -7
  34. package/dist/esm/vue/index.js.map +1 -1
  35. package/dist/esm/wizard/index.js +3178 -0
  36. package/dist/esm/wizard/index.js.map +1 -0
  37. package/dist/index.min.js +1 -1
  38. package/dist/index.min.js.map +1 -1
  39. package/dist/types/angular/index.d.ts +7 -0
  40. package/dist/types/index.d.ts +7 -0
  41. package/dist/types/install-wizard.d.ts +8 -8
  42. package/dist/types/react/index.d.ts +7 -0
  43. package/dist/types/remix/index.d.ts +7 -0
  44. package/dist/types/svelte/index.d.ts +7 -0
  45. package/dist/types/wizard/index.d.ts +489 -0
  46. package/package.json +14 -8
  47. package/rollup.config.js +65 -3
  48. package/src/react/AutoInstallWizard.tsx +1 -1
  49. package/src/tracker.ts +59 -8
  50. package/src/wizard/README.md +114 -0
  51. package/src/wizard/ai/ai-install-wizard.ts +894 -0
  52. package/src/wizard/ai/manual-framework-wizard.ts +236 -0
  53. package/src/wizard/cli/ai-auto-install.ts +369 -0
  54. package/src/{cli → wizard/cli}/auto-install.ts +1 -1
  55. package/src/{install-wizard.ts → wizard/core/install-wizard.ts} +12 -10
  56. package/src/wizard/index.ts +23 -0
  57. package/src/wizard/services/centralized-ai-service.ts +668 -0
  58. package/src/wizard/services/remote-ai-service.ts +224 -0
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Manual Framework Installation Wizard
3
+ *
4
+ * This wizard allows users to manually specify their framework instead of auto-detection.
5
+ * Useful when auto-detection fails or users want more control.
6
+ */
7
+
8
+ import * as fs from 'fs';
9
+ import * as path from 'path';
10
+ import { AutoInstallationWizard, FrameworkInfo, CodeModification, InstallationResult } from '../core/install-wizard';
11
+ import { RemoteAIService } from '../services/remote-ai-service';
12
+
13
+ export interface ManualInstallationResult extends InstallationResult {
14
+ selectedFramework: string;
15
+ manualMode: boolean;
16
+ }
17
+
18
+ export class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
19
+ private selectedFramework: string;
20
+
21
+ constructor(apiKey: string, projectRoot: string = process.cwd(), framework: string) {
22
+ super(apiKey, projectRoot);
23
+ this.selectedFramework = framework.toLowerCase();
24
+ this.framework = this.createFrameworkInfo(this.selectedFramework);
25
+ }
26
+
27
+ /**
28
+ * Manual installation with user-specified framework
29
+ */
30
+ async install(): Promise<ManualInstallationResult> {
31
+ try {
32
+ // Step 1: Handle framework selection
33
+ if (this.selectedFramework === 'auto') {
34
+ // Use full AI detection for "Other" option
35
+ this.framework = await this.runFullDetection();
36
+ } else {
37
+ // Set framework based on user selection
38
+ this.framework = this.createFrameworkInfo(this.selectedFramework);
39
+ if (!this.framework) {
40
+ this.framework = { name: 'unknown', type: 'vanilla' };
41
+ }
42
+
43
+ // Step 2: Run full detection logic to find entry points, file names, etc.
44
+ const detectedFramework = await this.runFullDetection();
45
+
46
+ // Step 3: Merge manual framework with detected details
47
+ this.framework = {
48
+ ...detectedFramework,
49
+ name: this.framework.name,
50
+ type: this.framework.type
51
+ };
52
+ }
53
+
54
+ // Step 4: Install package
55
+ await this.installPackage();
56
+
57
+ // Step 5: Generate and apply code modifications
58
+ const modifications = await this.generateModifications();
59
+ await this.applyModifications(modifications);
60
+
61
+ // Step 6: Generate next steps
62
+ const nextSteps = this.generateManualNextSteps();
63
+
64
+ return {
65
+ success: true,
66
+ framework: this.framework,
67
+ modifications,
68
+ errors: [],
69
+ nextSteps,
70
+ selectedFramework: this.selectedFramework,
71
+ manualMode: true
72
+ };
73
+ } catch (error) {
74
+ return {
75
+ success: false,
76
+ framework: this.framework || { name: 'unknown', type: 'vanilla' },
77
+ modifications: [],
78
+ errors: [error instanceof Error ? error.message : 'Unknown error'],
79
+ nextSteps: [],
80
+ selectedFramework: this.selectedFramework,
81
+ manualMode: true
82
+ };
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Run full detection logic to find entry points, file names, bundler, etc.
88
+ */
89
+ private async runFullDetection(): Promise<FrameworkInfo> {
90
+ if (this.selectedFramework === 'auto') {
91
+ // Use AI service for auto-detection
92
+ const aiService = new RemoteAIService({
93
+ apiEndpoint: 'https://ik3zxh4790.execute-api.us-east-1.amazonaws.com/prod'
94
+ });
95
+
96
+ // Use AI service directly for detection
97
+ const projectFiles = await this.scanProjectFiles();
98
+ const codeSamples = await this.extractCodeSamples(projectFiles);
99
+ const aiAnalysis = await aiService.analyzeCodePatterns(codeSamples);
100
+ return aiAnalysis.framework;
101
+ } else {
102
+ // Use traditional detection for manual frameworks
103
+ const tempWizard = new AutoInstallationWizard(this.apiKey, this.projectRoot);
104
+ const detected = await tempWizard.detectFramework();
105
+ return detected;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Scan project files for analysis
111
+ */
112
+ private async scanProjectFiles(): Promise<string[]> {
113
+ const files: string[] = [];
114
+ const scanDir = (dir: string, depth: number = 0) => {
115
+ if (depth > 3) return; // Limit depth
116
+
117
+ try {
118
+ const items = fs.readdirSync(dir);
119
+ for (const item of items) {
120
+ const fullPath = path.join(dir, item);
121
+ const stat = fs.statSync(fullPath);
122
+
123
+ if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
124
+ scanDir(fullPath, depth + 1);
125
+ } else if (stat.isFile() && this.isRelevantFile(item)) {
126
+ files.push(fullPath);
127
+ }
128
+ }
129
+ } catch (error) {
130
+ // Skip inaccessible directories
131
+ }
132
+ };
133
+
134
+ scanDir(this.projectRoot);
135
+ return files;
136
+ }
137
+
138
+ /**
139
+ * Check if file is relevant for analysis
140
+ */
141
+ private isRelevantFile(filename: string): boolean {
142
+ const relevantExtensions = [
143
+ '.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte', '.html',
144
+ '.json', '.config.js', '.config.ts', '.babelrc', '.eslintrc'
145
+ ];
146
+
147
+ const relevantNames = [
148
+ 'package.json', 'tsconfig.json', 'vite.config', 'webpack.config',
149
+ 'next.config', 'nuxt.config', 'angular.json', 'svelte.config'
150
+ ];
151
+
152
+ return relevantExtensions.some(ext => filename.endsWith(ext)) ||
153
+ relevantNames.some(name => filename.includes(name));
154
+ }
155
+
156
+ /**
157
+ * Extract code samples for AI analysis
158
+ */
159
+ private async extractCodeSamples(files: string[]): Promise<string[]> {
160
+ const samples: string[] = [];
161
+
162
+ for (const file of files.slice(0, 20)) { // Limit to 20 files
163
+ try {
164
+ const content = fs.readFileSync(file, 'utf8');
165
+ const relativePath = path.relative(this.projectRoot, file);
166
+ samples.push(`File: ${relativePath}\n${content.substring(0, 1000)}`);
167
+ } catch (error) {
168
+ // Skip unreadable files
169
+ }
170
+ }
171
+
172
+ return samples;
173
+ }
174
+
175
+ /**
176
+ * Create framework info based on user selection
177
+ */
178
+ private createFrameworkInfo(framework: string): FrameworkInfo {
179
+ const frameworkMap: Record<string, FrameworkInfo> = {
180
+ 'react': { name: 'react', type: 'react' },
181
+ 'nextjs': { name: 'nextjs', type: 'nextjs' },
182
+ 'next': { name: 'nextjs', type: 'nextjs' },
183
+ 'vue': { name: 'vue', type: 'vue' },
184
+ 'nuxt': { name: 'nuxt', type: 'nuxt' },
185
+ 'nuxtjs': { name: 'nuxt', type: 'nuxt' },
186
+ 'angular': { name: 'angular', type: 'angular' },
187
+ 'svelte': { name: 'svelte', type: 'svelte' },
188
+ 'sveltekit': { name: 'svelte', type: 'svelte' },
189
+ 'remix': { name: 'remix', type: 'remix' },
190
+ 'vanilla': { name: 'vanilla', type: 'vanilla' },
191
+ 'node': { name: 'node', type: 'node' },
192
+ 'auto': { name: 'auto-detected', type: 'auto' }
193
+ };
194
+
195
+ return frameworkMap[framework] || { name: framework, type: 'vanilla' };
196
+ }
197
+
198
+ /**
199
+ * Override framework detection to use manual selection
200
+ */
201
+ public async detectFramework(): Promise<FrameworkInfo> {
202
+ return this.framework || { name: 'unknown', type: 'vanilla' };
203
+ }
204
+
205
+ /**
206
+ * Generate next steps with manual mode info
207
+ */
208
+ private generateManualNextSteps(): string[] {
209
+ return [
210
+ '✅ Manual framework installation completed!',
211
+ `🎯 Selected framework: ${this.framework?.name || 'unknown'}`,
212
+ `🔧 Integration strategy: ${this.getIntegrationStrategy()}`,
213
+ '🚀 Your app is now ready to track user behavior',
214
+ '📊 View sessions in your HumanBehavior dashboard'
215
+ ];
216
+ }
217
+
218
+ /**
219
+ * Get integration strategy based on framework
220
+ */
221
+ private getIntegrationStrategy(): string {
222
+ if (!this.framework?.type) return 'script';
223
+
224
+ switch (this.framework.type) {
225
+ case 'react':
226
+ case 'nextjs':
227
+ return 'provider';
228
+ case 'vue':
229
+ return 'plugin';
230
+ case 'angular':
231
+ return 'module';
232
+ default:
233
+ return 'script';
234
+ }
235
+ }
236
+ }
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * AI-Enhanced HumanBehavior SDK Auto-Installation CLI
5
+ *
6
+ * Usage: npx humanbehavior-js ai-auto-install [api-key]
7
+ *
8
+ * This tool uses AI to intelligently detect frameworks, analyze code patterns,
9
+ * and generate optimal integration code that's both future-proof and backward-compatible.
10
+ */
11
+
12
+ import { AIEnhancedInstallationWizard, AIBrowserInstallationWizard } from '../ai/ai-install-wizard';
13
+ import { ManualFrameworkInstallationWizard } from '../ai/manual-framework-wizard';
14
+ import { AutoInstallationWizard } from '../core/install-wizard';
15
+ import { RemoteAIService } from '../services/remote-ai-service';
16
+ import * as readline from 'readline';
17
+ import * as fs from 'fs';
18
+ import * as path from 'path';
19
+
20
+ interface AICLIOptions {
21
+ apiKey?: string;
22
+ projectPath?: string;
23
+ yes?: boolean;
24
+ dryRun?: boolean;
25
+ useAI?: boolean;
26
+ browser?: boolean;
27
+ framework?: string;
28
+ manual?: boolean;
29
+ }
30
+
31
+ class AIAutoInstallCLI {
32
+ private rl: readline.Interface;
33
+ private options: AICLIOptions;
34
+
35
+ constructor(options: AICLIOptions) {
36
+ this.options = options;
37
+ this.rl = readline.createInterface({
38
+ input: process.stdin,
39
+ output: process.stdout
40
+ });
41
+ }
42
+
43
+ async run() {
44
+ console.log('🤖 AI-Enhanced HumanBehavior SDK Auto-Installation');
45
+ console.log('================================================\n');
46
+
47
+ try {
48
+ // Get API key
49
+ const apiKey = await this.getApiKey();
50
+ if (!apiKey) {
51
+ console.error('❌ API key is required');
52
+ process.exit(1);
53
+ }
54
+
55
+ // Get project path
56
+ const projectPath = this.options.projectPath || process.cwd();
57
+
58
+ // Choose installation mode
59
+ const installationMode = await this.chooseInstallationMode();
60
+
61
+ // Confirm installation
62
+ if (!this.options.yes) {
63
+ const confirmed = await this.confirmInstallation(projectPath, installationMode);
64
+ if (!confirmed) {
65
+ console.log('Installation cancelled.');
66
+ process.exit(0);
67
+ }
68
+ }
69
+
70
+ // Run installation
71
+ console.log('🔍 Analyzing your project with AI...');
72
+
73
+ let result;
74
+ if (this.options.browser) {
75
+ const wizard = new AIBrowserInstallationWizard(apiKey);
76
+ result = await wizard.install();
77
+ } else if (installationMode === 'manual') {
78
+ // Manual AI-Enhanced framework selection
79
+ const framework = await this.chooseFramework();
80
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
81
+ result = await wizard.install();
82
+ } else if (installationMode.startsWith('manual:')) {
83
+ // Manual framework selection with pre-selected framework
84
+ const framework = installationMode.split(':')[1];
85
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
86
+ result = await wizard.install();
87
+ } else {
88
+ const wizard = new AutoInstallationWizard(apiKey, projectPath);
89
+ result = await wizard.install();
90
+ }
91
+
92
+ // Display results
93
+ this.displayResults(result, installationMode);
94
+
95
+ } catch (error) {
96
+ console.error('❌ Error:', error instanceof Error ? error.message : error);
97
+ process.exit(1);
98
+ } finally {
99
+ this.rl.close();
100
+ }
101
+ }
102
+
103
+ private async getApiKey(): Promise<string> {
104
+ if (this.options.apiKey) {
105
+ return this.options.apiKey;
106
+ }
107
+
108
+ return new Promise((resolve) => {
109
+ this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
110
+ resolve(answer.trim());
111
+ });
112
+ });
113
+ }
114
+
115
+ private async chooseInstallationMode(): Promise<string> {
116
+ if (this.options.manual && this.options.framework) {
117
+ return `manual:${this.options.framework}`;
118
+ }
119
+ if (this.options.useAI !== undefined) {
120
+ return this.options.useAI ? 'ai' : 'traditional';
121
+ }
122
+
123
+ console.log('🤖 Choose installation mode:');
124
+ console.log('1. Manual AI-Enhanced (recommended) - Choose your framework and use AI for optimization');
125
+ console.log('2. Traditional - Standard framework detection and installation');
126
+ console.log('3. Browser - Browser-based AI detection and code generation\n');
127
+
128
+ return new Promise((resolve) => {
129
+ this.rl.question('Select mode (1-3, default: 1): ', (answer) => {
130
+ const choice = answer.trim() || '1';
131
+ if (choice === '1') resolve('manual');
132
+ else if (choice === '2') resolve('traditional');
133
+ else if (choice === '3') resolve('browser');
134
+ else resolve('manual');
135
+ });
136
+ });
137
+ }
138
+
139
+ private async confirmInstallation(projectPath: string, installationMode: string): Promise<boolean> {
140
+ console.log(`📁 Project path: ${projectPath}`);
141
+ console.log(`🤖 Installation mode: ${this.getInstallationModeDisplay(installationMode)}`);
142
+ console.log('⚠️ This will modify your codebase to integrate HumanBehavior SDK.');
143
+ console.log(' The following changes will be made:');
144
+ console.log(' - Install humanbehavior-js package');
145
+ console.log(' - Analyze code patterns with AI (if enabled)');
146
+ console.log(' - Modify your main app file');
147
+ console.log(' - Create environment files');
148
+ console.log(' - Add AI-optimized SDK initialization code\n');
149
+
150
+ return new Promise((resolve) => {
151
+ this.rl.question('Continue with installation? (y/n): ', (answer) => {
152
+ resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
153
+ });
154
+ });
155
+ }
156
+
157
+ private getInstallationModeDisplay(mode: string): string {
158
+ if (mode === 'manual') return 'Manual AI-Enhanced';
159
+ if (mode === 'traditional') return 'Traditional';
160
+ if (mode.startsWith('manual:')) {
161
+ const framework = mode.split(':')[1];
162
+ return `Manual AI-Enhanced (${framework})`;
163
+ }
164
+ if (mode === 'browser') return 'Browser';
165
+ return 'Unknown';
166
+ }
167
+
168
+ private async chooseFramework(): Promise<string> {
169
+ console.log('\n🎯 Choose your framework:');
170
+ console.log('1. Vanilla JS (HTML)');
171
+ console.log('2. React');
172
+ console.log('3. Next.js');
173
+ console.log('4. Vue');
174
+ console.log('5. Nuxt');
175
+ console.log('6. Angular');
176
+ console.log('7. Svelte');
177
+ console.log('8. Remix');
178
+ console.log('9. Node.js');
179
+ console.log('10. Other (Auto-detect)\n');
180
+
181
+ return new Promise((resolve) => {
182
+ this.rl.question('Select framework (1-10, default: 1): ', (answer) => {
183
+ const choice = answer.trim() || '1';
184
+ const frameworks = ['vanilla', 'react', 'nextjs', 'vue', 'nuxt', 'angular', 'svelte', 'remix', 'node', 'auto'];
185
+ const index = parseInt(choice) - 1;
186
+ resolve(frameworks[index] || 'vanilla');
187
+ });
188
+ });
189
+ }
190
+
191
+ private displayResults(result: any, installationMode: string) {
192
+ if (result.success) {
193
+ console.log('\n✅ Installation completed successfully!');
194
+
195
+ if (installationMode === 'ai' && result.aiAnalysis) {
196
+ console.log(`🎯 AI Analysis Results:`);
197
+ console.log(` Framework: ${result.aiAnalysis.framework.name} (confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%)`);
198
+ console.log(` Integration Strategy: ${result.aiAnalysis.integrationStrategy}`);
199
+ console.log(` Compatibility Mode: ${result.aiAnalysis.compatibilityMode}`);
200
+
201
+ if (result.aiAnalysis.patterns.length > 0) {
202
+ console.log(` Detected Patterns: ${result.aiAnalysis.patterns.length} patterns`);
203
+ }
204
+
205
+ if (result.aiAnalysis.recommendations.length > 0) {
206
+ console.log(` AI Recommendations:`);
207
+ result.aiAnalysis.recommendations.forEach((rec: string) => {
208
+ console.log(` • ${rec}`);
209
+ });
210
+ }
211
+ } else {
212
+ console.log(`📦 Framework detected: ${result.framework.name}`);
213
+ }
214
+
215
+ if (result.framework.bundler) {
216
+ console.log(`🔧 Bundler: ${result.framework.bundler}`);
217
+ }
218
+
219
+ if (result.framework.packageManager) {
220
+ console.log(`📋 Package Manager: ${result.framework.packageManager}`);
221
+ }
222
+
223
+ console.log('\n📝 Changes made:');
224
+ result.modifications.forEach((mod: any) => {
225
+ console.log(` ${mod.action === 'create' ? '➕' : '✏️'} ${mod.description}`);
226
+ console.log(` ${mod.filePath}`);
227
+ });
228
+
229
+ console.log('\n🎯 Next steps:');
230
+ result.nextSteps.forEach((step: string) => {
231
+ console.log(` ${step}`);
232
+ });
233
+
234
+ if (installationMode === 'ai' && result.learningData) {
235
+ console.log('\n🧠 Learning Data:');
236
+ console.log(` Framework: ${result.learningData.framework}`);
237
+ console.log(` Patterns: ${result.learningData.patterns.length} detected`);
238
+ console.log(` Success: ${result.learningData.success ? 'Yes' : 'No'}`);
239
+ }
240
+
241
+ console.log('\n🚀 Your app is now ready to track user behavior!');
242
+ console.log('📊 View sessions in your HumanBehavior dashboard');
243
+
244
+ } else {
245
+ console.log('\n❌ Installation failed:');
246
+ result.errors.forEach((error: string) => {
247
+ console.log(` ${error}`);
248
+ });
249
+
250
+ console.log('\n💡 Try running with --help for more options');
251
+ }
252
+ }
253
+ }
254
+
255
+ // CLI argument parsing
256
+ function parseArgs(): AICLIOptions {
257
+ const args = process.argv.slice(2);
258
+ const options: AICLIOptions = {};
259
+
260
+ for (let i = 0; i < args.length; i++) {
261
+ const arg = args[i];
262
+
263
+ if (arg === '--yes' || arg === '-y') {
264
+ options.yes = true;
265
+ } else if (arg === '--dry-run' || arg === '-d') {
266
+ options.dryRun = true;
267
+ } else if (arg === '--project' || arg === '-p') {
268
+ options.projectPath = args[i + 1];
269
+ i++;
270
+ } else if (arg === '--traditional' || arg === '-t') {
271
+ options.useAI = false;
272
+ } else if (arg === '--browser' || arg === '-b') {
273
+ options.browser = true;
274
+ } else if (arg === '--manual' || arg === '-m') {
275
+ options.manual = true;
276
+ } else if (arg === '--framework' || arg === '-f') {
277
+ options.framework = args[i + 1];
278
+ i++;
279
+ } else if (arg === '--help' || arg === '-h') {
280
+ showHelp();
281
+ process.exit(0);
282
+ } else if (!options.apiKey) {
283
+ options.apiKey = arg;
284
+ }
285
+ }
286
+
287
+ return options;
288
+ }
289
+
290
+ function showHelp() {
291
+ console.log(`
292
+ AI-Enhanced HumanBehavior SDK Auto-Installation CLI
293
+
294
+ Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
295
+
296
+ This tool uses AI to intelligently detect frameworks, analyze code patterns,
297
+ and generate optimal integration code that's both future-proof and backward-compatible.
298
+
299
+ Arguments:
300
+ api-key Your HumanBehavior API key
301
+
302
+ Options:
303
+ -y, --yes Skip all prompts and use defaults
304
+ -d, --dry-run Show what would be changed without making changes
305
+ -p, --project <path> Project directory (default: current directory)
306
+ -t, --traditional Force traditional installation mode
307
+ -b, --browser Browser-based AI installation
308
+ -m, --manual Manual framework selection
309
+ -f, --framework <f> Specify framework for manual mode
310
+ -h, --help Show this help message
311
+
312
+ Installation Modes:
313
+ 1. Manual AI-Enhanced (default): Choose your framework and use AI for optimization
314
+ 2. Traditional: Standard framework detection and installation
315
+ 3. Browser: Browser-based AI detection and code generation
316
+
317
+ Examples:
318
+ npx humanbehavior-js ai-auto-install your-api-key
319
+ npx humanbehavior-js ai-auto-install your-api-key --manual --framework react
320
+ npx humanbehavior-js ai-auto-install your-api-key --traditional
321
+ npx humanbehavior-js ai-auto-install your-api-key --browser
322
+
323
+ Supported Frameworks:
324
+ ✅ React (CRA, Vite, Webpack)
325
+ ✅ Next.js (App Router, Pages Router)
326
+ ✅ Vue (Vue CLI, Vite)
327
+ ✅ Angular
328
+ ✅ Svelte (SvelteKit, Vite)
329
+ ✅ Remix
330
+ ✅ Vanilla JS/TS
331
+ ✅ Node.js (CommonJS & ESM)
332
+
333
+ AI Features:
334
+ 🔍 Intelligent framework detection beyond package.json
335
+ 📊 Code pattern analysis and optimization
336
+ 🔄 Future-proof integration strategies
337
+ 🔙 Backward compatibility with legacy frameworks
338
+ 🧠 Learning from installation patterns
339
+ ⚡ Adaptive code generation for new frameworks
340
+ 🔧 Smart conflict resolution
341
+ 📈 Performance optimization recommendations
342
+
343
+ The AI-enhanced tool will:
344
+ 1. 🔍 Analyze your codebase with AI to detect patterns
345
+ 2. 🎯 Determine optimal integration strategy
346
+ 3. 📦 Install the humanbehavior-js package
347
+ 4. ✏️ Generate AI-optimized integration code
348
+ 5. 🔧 Apply modifications with conflict resolution
349
+ 6. 🧠 Learn from the installation for future improvements
350
+ 7. 🚀 Make your app ready to track user behavior
351
+ `);
352
+ }
353
+
354
+ // Main execution
355
+ const options = parseArgs();
356
+
357
+ // Check if we have enough arguments (api-key is required)
358
+ if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
359
+ showHelp();
360
+ process.exit(0);
361
+ }
362
+
363
+ const cli = new AIAutoInstallCLI(options);
364
+ cli.run().catch((error) => {
365
+ console.error('❌ Fatal error:', error);
366
+ process.exit(1);
367
+ });
368
+
369
+ export { AIAutoInstallCLI };
@@ -9,7 +9,7 @@
9
9
  * to integrate the SDK with minimal user intervention.
10
10
  */
11
11
 
12
- import { AutoInstallationWizard } from '../install-wizard';
12
+ import { AutoInstallationWizard } from '../core/install-wizard';
13
13
  import * as readline from 'readline';
14
14
  import * as fs from 'fs';
15
15
  import * as path from 'path';
@@ -10,7 +10,7 @@ import * as path from 'path';
10
10
 
11
11
  export interface FrameworkInfo {
12
12
  name: string;
13
- type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'node';
13
+ type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'node' | 'auto';
14
14
  bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup';
15
15
  packageManager?: 'npm' | 'yarn' | 'pnpm';
16
16
  hasTypeScript?: boolean;
@@ -34,9 +34,9 @@ export interface InstallationResult {
34
34
  }
35
35
 
36
36
  export class AutoInstallationWizard {
37
- private apiKey: string;
38
- private projectRoot: string;
39
- private framework: FrameworkInfo | null = null;
37
+ protected apiKey: string;
38
+ protected projectRoot: string;
39
+ protected framework: FrameworkInfo | null = null;
40
40
 
41
41
  constructor(apiKey: string, projectRoot: string = process.cwd()) {
42
42
  this.apiKey = apiKey;
@@ -82,7 +82,7 @@ export class AutoInstallationWizard {
82
82
  /**
83
83
  * Detect the current framework and project setup
84
84
  */
85
- private async detectFramework(): Promise<FrameworkInfo> {
85
+ public async detectFramework(): Promise<FrameworkInfo> {
86
86
  const packageJsonPath = path.join(this.projectRoot, 'package.json');
87
87
 
88
88
  if (!fs.existsSync(packageJsonPath)) {
@@ -190,7 +190,7 @@ export class AutoInstallationWizard {
190
190
  /**
191
191
  * Install the SDK package
192
192
  */
193
- private async installPackage(): Promise<void> {
193
+ protected async installPackage(): Promise<void> {
194
194
  const { execSync } = await import('child_process');
195
195
  const command = this.framework?.packageManager === 'yarn'
196
196
  ? 'yarn add humanbehavior-js'
@@ -208,7 +208,7 @@ export class AutoInstallationWizard {
208
208
  /**
209
209
  * Generate code modifications based on framework
210
210
  */
211
- private async generateModifications(): Promise<CodeModification[]> {
211
+ protected async generateModifications(): Promise<CodeModification[]> {
212
212
  const modifications: CodeModification[] = [];
213
213
 
214
214
  switch (this.framework?.type) {
@@ -591,7 +591,7 @@ export default defineNuxtPlugin(() => {
591
591
  /**
592
592
  * Apply modifications to the codebase
593
593
  */
594
- private async applyModifications(modifications: CodeModification[]): Promise<void> {
594
+ protected async applyModifications(modifications: CodeModification[]): Promise<void> {
595
595
  for (const modification of modifications) {
596
596
  try {
597
597
  const dir = path.dirname(modification.filePath);
@@ -1060,7 +1060,8 @@ if (typeof window !== 'undefined') {
1060
1060
  nuxt: 'NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
1061
1061
  remix: 'HUMANBEHAVIOR_API_KEY',
1062
1062
  vanilla: 'HUMANBEHAVIOR_API_KEY',
1063
- node: 'HUMANBEHAVIOR_API_KEY'
1063
+ node: 'HUMANBEHAVIOR_API_KEY',
1064
+ auto: 'HUMANBEHAVIOR_API_KEY'
1064
1065
  };
1065
1066
 
1066
1067
  return envVarNames[framework.type] || 'HUMANBEHAVIOR_API_KEY';
@@ -1086,7 +1087,8 @@ if (typeof window !== 'undefined') {
1086
1087
  nuxt: '.env',
1087
1088
  remix: '.env.local',
1088
1089
  vanilla: '.env',
1089
- node: '.env'
1090
+ node: '.env',
1091
+ auto: '.env'
1090
1092
  };
1091
1093
 
1092
1094
  const defaultFile = defaultFiles[framework.type] || '.env';