-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-ai-tools.js
More file actions
1179 lines (1000 loc) · 35.1 KB
/
setup-ai-tools.js
File metadata and controls
1179 lines (1000 loc) · 35.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/**
* ContextHub Setup Script for Node.js
* Cross-platform JavaScript implementation of the setup process
*/
const fs = require('fs').promises;
const path = require('path');
const { program } = require('commander');
const inquirer = require('inquirer');
const AIToolDetector = require('./scripts/ai-tool-detector');
const MASTER_FILE = '.ai-context.md';
const BACKUP_DIR = '.ai-tools-backup';
const AIDER_CONFIG = '.aider.conf.yml';
const AI_CONFIGS = {
'CLAUDE.md': 'Claude Code configuration',
'.cursorrules': 'Cursor IDE configuration',
'.github/copilot-instructions.md': 'GitHub Copilot configuration',
'.codeium/instructions.md': 'Codeium configuration',
'.continue/context.md': 'Continue configuration'
};
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
purple: '\x1b[35m',
cyan: '\x1b[36m'
};
const banner = `
██████╗ ██████╗ ███╗ ██╗████████╗███████╗██╗ ██╗████████╗██╗ ██╗██╗ ██╗██████╗
██╔════╝██╔═══██╗████╗ ██║╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝██║ ██║██║ ██║██╔══██╗
██║ ██║ ██║██╔██╗ ██║ ██║ █████╗ ╚███╔╝ ██║ ███████║██║ ██║██████╔╝
██║ ██║ ██║██║╚██╗██║ ██║ ██╔══╝ ██╔██╗ ██║ ██╔══██║██║ ██║██╔══██╗
╚██████╗╚██████╔╝██║ ╚████║ ██║ ███████╗██╔╝ ██╗ ██║ ██║ ██║╚██████╔╝██████╔╝
╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝
`;
class ContextHubSetup {
constructor(options = {}) {
this.workingDir = options.workingDir || process.cwd();
this.masterFile = path.join(this.workingDir, MASTER_FILE);
this.backupDir = path.join(this.workingDir, BACKUP_DIR);
this.useSymlinks = options.useSymlinks !== false;
this.force = options.force || false;
this.verbose = options.verbose || false;
this.interactive = options.interactive !== false;
this.selectedTools = options.tools || [];
this.detectedTools = [];
this.setupMode = options.setupMode || null; // 'smart', 'manual', or null (auto-detect)
this.configuredTools = []; // Track which tools were actually configured
this.timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
this.stats = {
created: 0,
backed_up: 0,
errors: 0
};
}
/**
* Log message with color
*/
log = (message, color = null) => {
if (color && colors[color]) {
console.log(`${colors[color]}${message}${colors.reset}`);
} else {
console.log(message);
}
}
/**
* Log info message
*/
logInfo = (message) => {
this.log(`[INFO] ${message}`, 'blue');
}
/**
* Log success message
*/
logSuccess = (message) => {
this.log(`[SUCCESS] ${message}`, 'green');
}
/**
* Log warning message
*/
logWarning = (message) => {
this.log(`[WARNING] ${message}`, 'yellow');
}
/**
* Log error message
*/
logError = (message) => {
this.log(`[ERROR] ${message}`, 'red');
}
/**
* Check if symlinks are supported on this platform
*/
checkSymlinkSupport = async () => {
const testDir = path.join(this.workingDir, '.symlink-test');
const testFile = path.join(testDir, 'test.txt');
const testLink = path.join(testDir, 'test-link.txt');
try {
await fs.mkdir(testDir, { recursive: true });
await fs.writeFile(testFile, 'test');
await fs.symlink(testFile, testLink);
const stats = await fs.lstat(testLink);
const canSymlink = stats.isSymbolicLink();
return canSymlink;
} catch (error) {
return false;
} finally {
// Always cleanup, regardless of success or failure
try {
await fs.unlink(testLink).catch(() => {});
await fs.unlink(testFile).catch(() => {});
await fs.rmdir(testDir).catch(() => {});
} catch (cleanupError) {
// Ignore cleanup errors
}
}
}
/**
* Create master configuration file
*/
createMasterConfig = async () => {
try {
await fs.access(this.masterFile);
this.logInfo(`Master configuration file already exists: ${MASTER_FILE}`);
return true;
} catch (error) {
// File doesn't exist, create it
}
this.logInfo(`Creating master configuration file: ${MASTER_FILE}`);
const template = `# AI Context Configuration
## Project Overview
<!-- Add your project description here -->
## Architecture
<!-- Describe your project architecture -->
## Coding Standards
<!-- Define your coding standards and conventions -->
### TypeScript/JavaScript
- Use strict type checking
- Prefer const over let
- Use meaningful variable names
- Add JSDoc comments for public APIs
### React (if applicable)
- Use functional components with hooks
- Implement proper error boundaries
- Use React.memo for performance optimization
### Python (if applicable)
- Follow PEP 8 style guidelines
- Use type hints
- Write comprehensive docstrings
- Use virtual environments
## Testing Strategy
<!-- Describe your testing approach -->
## Performance Requirements
<!-- List performance requirements -->
## Security Guidelines
<!-- Security best practices for this project -->
<!-- Tool-specific sections -->
<!-- AI:CLAUDE -->
<!-- Claude-specific instructions here -->
<!-- /AI:CLAUDE -->
<!-- AI:CURSOR -->
<!-- Cursor-specific instructions here -->
<!-- /AI:CURSOR -->
<!-- AI:COPILOT -->
<!-- GitHub Copilot-specific instructions here -->
<!-- /AI:COPILOT -->
<!-- AI:CODEIUM -->
<!-- Codeium-specific instructions here -->
<!-- /AI:CODEIUM -->
`;
try {
await fs.writeFile(this.masterFile, template, 'utf8');
this.logSuccess(`Created ${MASTER_FILE} with basic template`);
return true;
} catch (error) {
this.logError(`Failed to create master config: ${error.message}`);
return false;
}
}
/**
* Create backup directory
*/
createBackupDir = async () => {
try {
await fs.mkdir(this.backupDir, { recursive: true });
this.logInfo(`Created backup directory: ${BACKUP_DIR}`);
// Add to .gitignore if it exists
const gitignorePath = path.join(this.workingDir, '.gitignore');
try {
const gitignoreContent = await fs.readFile(gitignorePath, 'utf8');
if (!gitignoreContent.includes(BACKUP_DIR)) {
await fs.appendFile(gitignorePath, `\n# AI tools backup\n${BACKUP_DIR}/\n`);
this.logInfo(`Added ${BACKUP_DIR} to .gitignore`);
}
} catch (error) {
// .gitignore doesn't exist or couldn't be read, continue
}
return true;
} catch (error) {
this.logError(`Failed to create backup directory: ${error.message}`);
return false;
}
}
/**
* Backup existing file
*/
backupExistingFile = async (filePath) => {
try {
await fs.access(filePath);
const fileName = path.basename(filePath);
const backupFile = path.join(this.backupDir, `${fileName}_${this.timestamp}`);
await fs.copyFile(filePath, backupFile);
this.logInfo(`Backed up existing ${path.relative(this.workingDir, filePath)} to ${path.relative(this.workingDir, backupFile)}`);
this.stats.backed_up++;
// Remove original file
await fs.unlink(filePath);
return true;
} catch (error) {
if (error.code === 'ENOENT') {
// File doesn't exist, no need to backup
return true;
}
this.logError(`Failed to backup ${filePath}: ${error.message}`);
return false;
}
}
/**
* Ensure directory exists
*/
ensureDirectory = async (filePath) => {
const dir = path.dirname(filePath);
if (dir !== this.workingDir) {
try {
await fs.mkdir(dir, { recursive: true });
this.logInfo(`Created directory: ${path.relative(this.workingDir, dir)}`);
} catch (error) {
this.logError(`Failed to create directory ${dir}: ${error.message}`);
return false;
}
}
return true;
}
/**
* Create symlink
*/
createSymlink = async (target, linkPath, description) => {
try {
const relativePath = path.relative(this.workingDir, linkPath);
// Ensure directory exists
if (!(await this.ensureDirectory(linkPath))) {
return false;
}
// Backup existing file
if (!(await this.backupExistingFile(linkPath))) {
return false;
}
// Create symlink
const relativeTarget = path.relative(path.dirname(linkPath), target);
await fs.symlink(relativeTarget, linkPath);
this.logSuccess(`Created symlink: ${relativePath} → ${MASTER_FILE} (${description})`);
this.stats.created++;
return true;
} catch (error) {
this.logError(`Failed to create symlink ${linkPath}: ${error.message}`);
this.stats.errors++;
return false;
}
}
/**
* Create file copy
*/
createFileCopy = async (source, destPath, description) => {
try {
const relativePath = path.relative(this.workingDir, destPath);
// Ensure directory exists
if (!(await this.ensureDirectory(destPath))) {
return false;
}
// Backup existing file
if (!(await this.backupExistingFile(destPath))) {
return false;
}
// Copy file
await fs.copyFile(source, destPath);
this.logSuccess(`Created copy: ${relativePath} ← ${MASTER_FILE} (${description})`);
this.stats.created++;
return true;
} catch (error) {
this.logError(`Failed to create copy ${destPath}: ${error.message}`);
this.stats.errors++;
return false;
}
}
/**
* Create Aider configuration
*/
createAiderConfig = async () => {
const aiderPath = path.join(this.workingDir, AIDER_CONFIG);
try {
await fs.access(aiderPath);
this.logInfo(`Aider configuration already exists: ${AIDER_CONFIG}`);
return true;
} catch (error) {
// File doesn't exist, create it
}
this.logInfo(`Creating Aider configuration: ${AIDER_CONFIG}`);
const aiderContent = `# Aider configuration
# This file is managed by ContextHub
# Edit .ai-context.md instead
# Model settings
model: gpt-4
# Auto-commit settings
auto-commits: true
dirty-commits: true
# Context settings
read: ${MASTER_FILE}
`;
try {
await fs.writeFile(aiderPath, aiderContent, 'utf8');
this.logSuccess(`Created ${AIDER_CONFIG}`);
return true;
} catch (error) {
this.logError(`Failed to create Aider config: ${error.message}`);
return false;
}
}
/**
* Verify setup
*/
verifySetup = async () => {
this.logInfo('Verifying setup...');
let failed = 0;
// Check master file
try {
await fs.access(this.masterFile);
this.logSuccess(`✓ ${MASTER_FILE}`);
} catch (error) {
this.logError(`✗ ${MASTER_FILE} (missing)`);
failed++;
}
// If no configured tools tracked (e.g., standalone verify), check all existing files
const toolConfigMapping = {
'claude': 'CLAUDE.md',
'cursor': '.cursorrules',
'copilot': '.github/copilot-instructions.md',
'codeium': '.codeium/instructions.md',
'continue': '.continue/context.md'
};
let toolsToCheck = this.configuredTools;
// If configuredTools is empty (standalone verify), detect existing configs
if (toolsToCheck.length === 0) {
for (const [tool, configFile] of Object.entries(toolConfigMapping)) {
try {
await fs.access(path.join(this.workingDir, configFile));
toolsToCheck.push(tool);
} catch (error) {
// File doesn't exist, skip
}
}
// Check for Aider config
try {
await fs.access(path.join(this.workingDir, AIDER_CONFIG));
toolsToCheck.push('aider');
} catch (error) {
// File doesn't exist, skip
}
}
for (const tool of toolsToCheck) {
if (tool === 'aider') {
// Check Aider config separately
try {
await fs.access(path.join(this.workingDir, AIDER_CONFIG));
this.logSuccess(`✓ ${AIDER_CONFIG} (exists)`);
} catch (error) {
this.logError(`✗ ${AIDER_CONFIG} (missing)`);
failed++;
}
} else if (toolConfigMapping[tool]) {
const configFile = toolConfigMapping[tool];
const configPath = path.join(this.workingDir, configFile);
try {
const stats = await fs.lstat(configPath);
if (stats.isSymbolicLink()) {
const target = await fs.readlink(configPath);
this.logSuccess(`✓ ${configFile} → ${target}`);
} else {
this.logSuccess(`✓ ${configFile} (copy)`);
}
} catch (error) {
this.logError(`✗ ${configFile} (missing)`);
failed++;
}
}
}
if (failed === 0) {
this.logSuccess('All configurations verified successfully!');
return true;
} else {
this.logError('Some configurations failed verification');
return false;
}
}
/**
* Print banner
*/
printBanner = () => {
console.log(colors.cyan + banner + colors.reset);
console.log(colors.cyan + 'Unified Configuration for AI Coding Assistants' + colors.reset);
console.log(colors.purple + 'Setting up symlinks for Claude Code, Cursor, GitHub Copilot, and more...' + colors.reset);
console.log('');
}
/**
* Run AI tool detection
*/
runAIToolDetection = async () => {
const detector = new AIToolDetector({
workingDir: this.workingDir,
verbose: this.verbose
});
try {
const results = await detector.detectAllTools();
this.detectedTools = results.recommendations;
// Print results once
detector.printResults(results);
return results;
} catch (error) {
this.logWarning(`AI tool detection failed: ${error.message}`);
return { recommendations: { highConfidence: [], suggested: [], optional: [] } };
}
}
/**
* Setup mode selection
*/
selectSetupMode = async (detectionResults) => {
// If setup mode is forced via CLI, use that
if (this.setupMode) {
return this.setupMode;
}
if (!this.interactive) {
return 'smart'; // Default to smart mode for non-interactive
}
const hasDetections = detectionResults.recommendations.highConfidence.length > 0 ||
detectionResults.recommendations.suggested.length > 0;
if (!hasDetections) {
// No detections found, go straight to manual mode
this.logInfo('No AI tools detected. Using manual selection mode.');
return 'manual';
}
console.log('\n🎛️ Choose your setup approach:');
const modeChoices = [
{
name: '🧠 Smart Setup (Recommended) - Use detected tools with customization',
value: 'smart',
short: 'Smart'
},
{
name: '👤 Manual Setup - Choose tools without detection influence',
value: 'manual',
short: 'Manual'
},
{
name: '🔍 Detection Only - See detections, then decide later',
value: 'detect-only',
short: 'Detect Only'
}
];
const modeAnswer = await inquirer.prompt([
{
type: 'list',
name: 'mode',
message: 'How would you like to set up ContextHub?',
choices: modeChoices,
default: 'smart'
}
]);
return modeAnswer.mode;
}
/**
* Manual tool selection (no detection influence)
*/
manualToolSelection = async () => {
const allTools = [
{ key: 'claude', name: 'Claude Code', description: 'Anthropic\'s AI assistant' },
{ key: 'cursor', name: 'Cursor', description: 'AI-powered code editor' },
{ key: 'copilot', name: 'GitHub Copilot', description: 'GitHub\'s AI pair programmer' },
{ key: 'codeium', name: 'Codeium', description: 'Free AI code completion' },
{ key: 'continue', name: 'Continue', description: 'Open-source AI code assistant' },
{ key: 'aider', name: 'Aider', description: 'AI pair programming in terminal' }
];
const choices = allTools.map(tool => ({
name: `${tool.name} - ${tool.description}`,
value: tool.key,
checked: false
}));
console.log('\n📋 Select AI tools to configure:');
const answers = await inquirer.prompt([
{
type: 'checkbox',
name: 'selectedTools',
message: 'Which AI tools would you like to set up?',
choices: choices,
validate: function(answer) {
if (answer.length < 1) {
return 'You must choose at least one AI tool.';
}
return true;
}
}
]);
// Ask for confirmation with summary
console.log('\n📊 Setup Summary:');
answers.selectedTools.forEach(tool => {
const toolInfo = allTools.find(t => t.key === tool);
console.log(` ✅ ${toolInfo.name}`);
});
const confirmAnswer = await inquirer.prompt([
{
type: 'confirm',
name: 'proceed',
message: 'Proceed with this configuration?',
default: true
}
]);
if (!confirmAnswer.proceed) {
console.log('\nSetup cancelled. Run contexthub again to restart.');
process.exit(0);
}
return answers.selectedTools;
}
/**
* Smart tool selection (with detection influence)
*/
smartToolSelection = async (detectionResults) => {
const choices = [];
const { highConfidence, suggested, optional } = detectionResults.recommendations;
// Add detected tools with confidence indicators
highConfidence.forEach(tool => {
choices.push({
name: `${tool.name} (✅ detected with ${Math.round(tool.confidence)}% confidence)`,
value: tool.tool,
checked: true
});
});
suggested.forEach(tool => {
choices.push({
name: `${tool.name} (🔍 suggested, ${Math.round(tool.confidence)}% confidence)`,
value: tool.tool,
checked: true
});
});
optional.forEach(tool => {
choices.push({
name: `${tool.name} (💡 some evidence, ${Math.round(tool.confidence)}% confidence)`,
value: tool.tool,
checked: false
});
});
// Add remaining tools that weren't detected
const allDetectedTools = [...highConfidence, ...suggested, ...optional].map(t => t.tool);
const allAvailableTools = [
{ key: 'claude', name: 'Claude Code' },
{ key: 'cursor', name: 'Cursor' },
{ key: 'copilot', name: 'GitHub Copilot' },
{ key: 'codeium', name: 'Codeium' },
{ key: 'continue', name: 'Continue' },
{ key: 'aider', name: 'Aider' }
];
allAvailableTools.forEach(tool => {
if (!allDetectedTools.includes(tool.key)) {
choices.push({
name: `${tool.name} (not detected)`,
value: tool.key,
checked: false
});
}
});
console.log('\n📋 Customize your tool selection:');
console.log(' ✅ = High confidence 🔍 = Suggested 💡 = Optional');
const answers = await inquirer.prompt([
{
type: 'checkbox',
name: 'selectedTools',
message: 'Customize your tool selection:',
choices: choices,
validate: function(answer) {
if (answer.length < 1) {
return 'You must choose at least one AI tool.';
}
return true;
}
}
]);
// Show what was auto-selected vs manually chosen
const autoSelected = [...highConfidence, ...suggested].map(t => t.tool);
const manuallyAdded = answers.selectedTools.filter(t => !autoSelected.includes(t));
const manuallyRemoved = autoSelected.filter(t => !answers.selectedTools.includes(t));
if (manuallyAdded.length > 0 || manuallyRemoved.length > 0) {
console.log('\n📝 Changes from smart recommendations:');
if (manuallyAdded.length > 0) {
console.log(` ➕ Added: ${manuallyAdded.join(', ')}`);
}
if (manuallyRemoved.length > 0) {
console.log(` ➖ Removed: ${manuallyRemoved.join(', ')}`);
}
}
return answers.selectedTools;
}
/**
* Enhanced interactive tool selection
*/
interactiveToolSelection = async (detectionResults) => {
if (!this.interactive) {
return this.selectedTools.length > 0 ? this.selectedTools : ['claude', 'cursor', 'copilot'];
}
// Step 1: Choose setup mode
const setupMode = await this.selectSetupMode(detectionResults);
if (setupMode === 'detect-only') {
console.log('\n🔍 Detection complete! Run contexthub again to proceed with setup.');
process.exit(0);
}
// Step 2: Tool selection based on mode
let selectedTools;
if (setupMode === 'manual') {
selectedTools = await this.manualToolSelection();
} else {
selectedTools = await this.smartToolSelection(detectionResults);
}
return selectedTools;
}
/**
* Generate smart configuration template based on project type and selected tools
*/
generateSmartTemplate = async (projectType, selectedTools) => {
let template = `# AI Context Configuration
## Project Overview
<!-- Add your project description here -->
## Architecture
<!-- Describe your project architecture -->
## Coding Standards
<!-- Define your coding standards and conventions -->
`;
// Add project-specific sections based on detected project type
if (projectType.includes('React')) {
template += `### React Development
- Use functional components with hooks
- Implement proper error boundaries
- Use React.memo for performance optimization
- Follow React Hook rules strictly
- Use TypeScript for type safety
`;
}
if (projectType.includes('Node.js')) {
template += `### Node.js Development
- Use async/await over callbacks
- Implement proper error handling
- Use environment variables for configuration
- Follow Express.js best practices if applicable
`;
}
if (projectType.includes('Python')) {
template += `### Python Development
- Follow PEP 8 style guidelines
- Use type hints for better code clarity
- Write comprehensive docstrings
- Use virtual environments
- Implement proper exception handling
`;
}
if (projectType.includes('TypeScript')) {
template += `### TypeScript
- Use strict mode
- Prefer interfaces over types for object shapes
- Use proper return types for all functions
- Avoid 'any' type unless absolutely necessary
`;
}
template += `## Testing Strategy
<!-- Describe your testing approach -->
## Performance Requirements
<!-- List performance requirements -->
## Security Guidelines
<!-- Security best practices for this project -->
<!-- Tool-specific sections -->
`;
// Add tool-specific sections for selected tools
if (selectedTools.includes('claude')) {
template += `<!-- AI:CLAUDE -->
Focus on code quality, security, and performance optimization.
Provide detailed explanations for complex algorithms.
<!-- /AI:CLAUDE -->
`;
}
if (selectedTools.includes('cursor')) {
template += `<!-- AI:CURSOR -->
Prefer concise, efficient code solutions.
Use modern JavaScript/TypeScript features.
<!-- /AI:CURSOR -->
`;
}
if (selectedTools.includes('copilot')) {
template += `<!-- AI:COPILOT -->
GitHub Copilot-specific instructions here.
Focus on GitHub best practices and collaborative development.
<!-- /AI:COPILOT -->
`;
}
if (selectedTools.includes('codeium')) {
template += `<!-- AI:CODEIUM -->
Codeium-specific instructions here.
Emphasize clean, readable code structure.
<!-- /AI:CODEIUM -->
`;
}
return template;
}
/**
* Create master configuration file with smart template
*/
createMasterConfigWithTemplate = async (template) => {
try {
await fs.access(this.masterFile);
if (!this.force) {
this.logInfo(`Master configuration file already exists: ${MASTER_FILE}`);
return true;
} else {
this.logInfo(`Force mode: overwriting existing ${MASTER_FILE}`);
}
} catch (error) {
// File doesn't exist, create it
}
this.logInfo(`Creating smart configuration file: ${MASTER_FILE}`);
try {
await fs.writeFile(this.masterFile, template, 'utf8');
this.logSuccess(`Created ${MASTER_FILE} with intelligent template`);
return true;
} catch (error) {
this.logError(`Failed to create ${MASTER_FILE}: ${error.message}`);
return false;
}
}
/**
* Run the setup process
*/
setup = async () => {
try {
this.printBanner();
this.logInfo('Starting ContextHub intelligent setup...');
console.log('');
// Run AI tool detection
const detectionResults = await this.runAIToolDetection();
// Interactive tool selection (if enabled)
const selectedTools = await this.interactiveToolSelection(detectionResults);
console.log('');
this.logInfo(`Selected tools: ${selectedTools.join(', ')}`);
console.log('');
// Check symlink support
if (this.useSymlinks) {
const canSymlink = await this.checkSymlinkSupport();
if (!canSymlink) {
this.logWarning('Symlinks not supported on this platform. Using file copying instead.');
this.useSymlinks = false;
} else {
this.logInfo('Using symlinks');
}
} else {
this.logInfo('Using file copying (compatibility mode)');
}
// Create backup directory
if (!(await this.createBackupDir())) {
return false;
}
// Generate smart configuration template
const smartTemplate = await this.generateSmartTemplate(detectionResults.projectType || [], selectedTools);
// Create master config with smart template
if (!(await this.createMasterConfigWithTemplate(smartTemplate))) {
return false;
}
// Create configurations for selected AI tools only
this.logInfo('Creating configurations for selected AI tools...');
console.log('');
const toolConfigMapping = {
'claude': ['CLAUDE.md', 'Claude Code configuration'],
'cursor': ['.cursorrules', 'Cursor IDE configuration'],
'copilot': ['.github/copilot-instructions.md', 'GitHub Copilot configuration'],
'codeium': ['.codeium/instructions.md', 'Codeium configuration'],
'continue': ['.continue/context.md', 'Continue configuration']
};
for (const tool of selectedTools) {
if (toolConfigMapping[tool]) {
const [configFile, description] = toolConfigMapping[tool];
const configPath = path.join(this.workingDir, configFile);
if (this.useSymlinks) {
await this.createSymlink(this.masterFile, configPath, description);
} else {
await this.createFileCopy(this.masterFile, configPath, description);
}
// Track configured tools
this.configuredTools.push(tool);
}
}
// Create Aider config if selected
if (selectedTools.includes('aider')) {
await this.createAiderConfig();
this.configuredTools.push('aider');
}
// Print summary
console.log('');
this.logInfo('Setup Summary:');
this.logInfo(`- Master file: ${MASTER_FILE}`);
this.logInfo(`- Successful configurations: ${this.stats.created}/${selectedTools.length}`);
this.logInfo(`- Files backed up: ${this.stats.backed_up}`);
this.logInfo(`- Backup directory: ${BACKUP_DIR}`);
this.logInfo(`- Method: ${this.useSymlinks ? 'Symlinks' : 'File copying'}`);
// Verify setup
console.log('');
const verifyResult = await this.verifySetup();
console.log('');
if (this.stats.created === selectedTools.length && verifyResult) {
this.logSuccess('🎉 ContextHub setup completed successfully!');
console.log('');
console.log(colors.cyan + 'Next steps:' + colors.reset);
console.log(`1. Edit ${colors.yellow}${MASTER_FILE}${colors.reset} to add your project context`);
console.log('2. All AI tools will automatically use the unified configuration');
console.log(`3. Check our examples at: ${colors.blue}https://github.com/seshanpillay25/contexthub/tree/main/examples${colors.reset}`);
console.log('');
console.log(colors.green + 'Happy coding with your AI assistants! 🤖' + colors.reset);
return true;
} else {
this.logWarning('Setup completed with some issues. Please check the logs above.');
console.log('');
console.log(colors.yellow + 'If you need help:' + colors.reset);
console.log(`- Check our troubleshooting guide: ${colors.blue}https://github.com/seshanpillay25/contexthub/blob/main/docs/troubleshooting.md${colors.reset}`);
console.log(`- Open an issue: ${colors.blue}https://github.com/seshanpillay25/contexthub/issues${colors.reset}`);
return false;
}
} catch (error) {
this.logError(`Setup failed: ${error.message}`);
return false;
}
}
}