caxton 0.1.4

A secure WebAssembly runtime for multi-agent systems
Documentation
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
#!/usr/bin/env node

/**
 * Build and Deployment Issues Checker for Caxton Website
 * Validates Jekyll build process, GitHub Pages compatibility, and deployment configuration
 */

const fs = require('fs');
const path = require('path');
const { execSync, exec } = require('child_process');

class BuildDeploymentChecker {
    constructor() {
        // Determine correct paths - look for website directory from current working directory
        let sitePath = path.join(process.cwd(), 'website');
        let rootPath = process.cwd();

        // If running from validation directory, go up to project root
        if (process.cwd().includes('scripts/validation')) {
            sitePath = path.join(process.cwd(), '..', '..', 'website');
            rootPath = path.join(process.cwd(), '..', '..');
        }

        this.sitePath = sitePath;
        this.rootPath = rootPath;
        this.results = {
            jekyll: { configured: false, issues: [] },
            github: { configured: false, issues: [] },
            build: { successful: false, issues: [] },
            dependencies: { issues: [] },
            assets: { issues: [] },
            config: { issues: [] },
            performance: { issues: [] }
        };
    }

    async run() {
        console.log('🔍 Starting Build/Deployment Issues Check...');
        console.log(`Site Path: ${this.sitePath}`);
        console.log(`Root Path: ${this.rootPath}`);
        console.log(''.repeat(60));

        try {
            await this.checkJekyllConfiguration();
            await this.checkGitHubPagesCompatibility();
            await this.checkDependencies();
            await this.validateAssets();
            await this.testBuildProcess();
            await this.checkDeploymentConfiguration();
            await this.performanceChecks();
            this.generateReport();
        } catch (error) {
            console.error('❌ Error during build/deployment check:', error.message);
            process.exit(1);
        }
    }

    async checkJekyllConfiguration() {
        console.log('\n🔧 Checking Jekyll Configuration...');

        const configPath = path.join(this.sitePath, '_config.yml');

        if (!fs.existsSync(configPath)) {
            this.results.jekyll.issues.push('Missing _config.yml file');
            console.log('  ❌ No _config.yml found');
            return;
        }

        console.log('  ✅ _config.yml found');
        this.results.jekyll.configured = true;

        const config = fs.readFileSync(configPath, 'utf8');
        await this.validateJekyllConfig(config);
    }

    async validateJekyllConfig(config) {
        // Check essential configuration
        const essentialSettings = [
            { key: 'title', required: true },
            { key: 'description', required: true },
            { key: 'url', required: true },
            { key: 'baseurl', required: false },
            { key: 'markdown', required: false, recommended: 'kramdown' },
            { key: 'highlighter', required: false, recommended: 'rouge' }
        ];

        essentialSettings.forEach(setting => {
            const hasKey = config.includes(`${setting.key}:`);

            if (setting.required && !hasKey) {
                this.results.jekyll.issues.push(`Missing required setting: ${setting.key}`);
                console.log(`   Missing: ${setting.key}`);
            } else if (hasKey) {
                console.log(`   Found: ${setting.key}`);

                if (setting.recommended) {
                    const valueMatch = config.match(new RegExp(`${setting.key}:\\s*(.+)`));
                    if (valueMatch && !valueMatch[1].includes(setting.recommended)) {
                        this.results.jekyll.issues.push(`Consider using ${setting.recommended} for ${setting.key}`);
                        console.log(`    Recommended: ${setting.key}: ${setting.recommended}`);
                    }
                }
            }
        });

        // Check for GitHub Pages compatibility
        if (config.includes('plugins:')) {
            const pluginSection = this.extractConfigSection(config, 'plugins');
            this.validatePlugins(pluginSection);
        }

        // Check for safe mode compatibility
        if (config.includes('safe: false')) {
            this.results.jekyll.issues.push('safe: false may not work on GitHub Pages');
            console.log('  ⚠️  safe: false detected');
        }

        // Check for custom gems that might not be supported
        this.checkUnsupportedFeatures(config);
    }

    extractConfigSection(config, section) {
        const regex = new RegExp(`${section}:\\s*\\n((\\s+-.+\\n)*|(\\s+[^\\n]+\\n)*)`, 'g');
        const match = config.match(regex);
        return match ? match[0] : '';
    }

    validatePlugins(pluginSection) {
        const supportedPlugins = [
            'jekyll-coffeescript',
            'jekyll-default-layout',
            'jekyll-gist',
            'jekyll-github-metadata',
            'jekyll-paginate',
            'jekyll-relative-links',
            'jekyll-optional-front-matter',
            'jekyll-readme-index',
            'jekyll-redirect-from',
            'jekyll-sass-converter',
            'jekyll-sitemap',
            'jekyll-swiss',
            'jekyll-theme-architect',
            'jekyll-theme-cayman',
            'jekyll-theme-dinky',
            'jekyll-theme-hacker',
            'jekyll-theme-leap-day',
            'jekyll-theme-merlot',
            'jekyll-theme-midnight',
            'jekyll-theme-minimal',
            'jekyll-theme-modernist',
            'jekyll-theme-primer',
            'jekyll-theme-slate',
            'jekyll-theme-tactile',
            'jekyll-theme-time-machine',
            'jekyll-titles-from-headings',
            'jemoji',
            'kramdown',
            'liquid',
            'rouge',
            'safe_yaml'
        ];

        const pluginMatches = pluginSection.match(/- ([\w-]+)/g) || [];
        pluginMatches.forEach(match => {
            const plugin = match.replace('- ', '');
            if (!supportedPlugins.includes(plugin)) {
                this.results.jekyll.issues.push(`Unsupported plugin for GitHub Pages: ${plugin}`);
                console.log(`    Unsupported plugin: ${plugin}`);
            } else {
                console.log(`   Supported plugin: ${plugin}`);
            }
        });
    }

    checkUnsupportedFeatures(config) {
        const unsupportedFeatures = [
            { pattern: /custom_plugins/, message: 'Custom plugins not supported on GitHub Pages' },
            { pattern: /gems:/, message: 'Use plugins: instead of gems: for GitHub Pages' },
            { pattern: /^(?!#).*\.rb$/, message: 'Ruby plugins not supported on GitHub Pages' }
        ];

        unsupportedFeatures.forEach(feature => {
            if (config.match(feature.pattern)) {
                this.results.jekyll.issues.push(feature.message);
                console.log(`    ${feature.message}`);
            }
        });
    }

    async checkGitHubPagesCompatibility() {
        console.log('\n🐙 Checking GitHub Pages Compatibility...');

        // Check if this is a GitHub repository
        const gitPath = path.join(this.rootPath, '.git');
        if (!fs.existsSync(gitPath)) {
            this.results.github.issues.push('Not a Git repository');
            console.log('  ❌ Not a Git repository');
            return;
        }

        // Check for GitHub Pages workflow
        const workflowsPath = path.join(this.rootPath, '.github', 'workflows');
        if (fs.existsSync(workflowsPath)) {
            const workflowFiles = fs.readdirSync(workflowsPath);
            const jekyllWorkflow = workflowFiles.find(file =>
                file.includes('jekyll') || file.includes('pages') || file.includes('deploy')
            );

            if (jekyllWorkflow) {
                console.log(`   GitHub Actions workflow found: ${jekyllWorkflow}`);
                this.results.github.configured = true;
                await this.validateGitHubWorkflow(path.join(workflowsPath, jekyllWorkflow));
            } else {
                this.results.github.issues.push('No GitHub Pages deployment workflow found');
                console.log('  ⚠️  No GitHub Pages workflow detected');
            }
        }

        // Check repository structure
        this.checkRepositoryStructure();
    }

    async validateGitHubWorkflow(workflowPath) {
        const workflow = fs.readFileSync(workflowPath, 'utf8');

        // Check for required workflow components
        const requiredComponents = [
            { pattern: /actions\/checkout/, name: 'checkout action' },
            { pattern: /actions\/configure-pages/, name: 'configure-pages action' },
            { pattern: /actions\/upload-pages-artifact/, name: 'upload-pages-artifact action' },
            { pattern: /actions\/deploy-pages/, name: 'deploy-pages action' }
        ];

        requiredComponents.forEach(component => {
            if (workflow.match(component.pattern)) {
                console.log(`     ${component.name} configured`);
            } else {
                this.results.github.issues.push(`Missing workflow component: ${component.name}`);
                console.log(`      Missing: ${component.name}`);
            }
        });

        // Check for proper permissions
        if (!workflow.includes('pages: write')) {
            this.results.github.issues.push('Workflow missing pages: write permission');
            console.log('    ⚠️  Missing pages: write permission');
        }

        if (!workflow.includes('id-token: write')) {
            this.results.github.issues.push('Workflow missing id-token: write permission');
            console.log('    ⚠️  Missing id-token: write permission');
        }
    }

    checkRepositoryStructure() {
        // Check for proper source directory structure
        const expectedDirs = ['_layouts', '_includes', '_sass', 'assets'];
        expectedDirs.forEach(dir => {
            const dirPath = path.join(this.sitePath, dir);
            if (fs.existsSync(dirPath)) {
                console.log(`   Found: ${dir}/`);
            } else {
                console.log(`    Optional: ${dir}/ not found`);
            }
        });

        // Check for CNAME file (if using custom domain)
        const cnamePath = path.join(this.sitePath, 'CNAME');
        if (fs.existsSync(cnamePath)) {
            const cname = fs.readFileSync(cnamePath, 'utf8').trim();
            console.log(`   Custom domain configured: ${cname}`);
        }
    }

    async checkDependencies() {
        console.log('\n📦 Checking Dependencies...');

        const gemfilePath = path.join(this.sitePath, 'Gemfile');
        if (!fs.existsSync(gemfilePath)) {
            this.results.dependencies.issues.push('No Gemfile found');
            console.log('  ❌ No Gemfile found');
            return;
        }

        console.log('  ✅ Gemfile found');
        const gemfile = fs.readFileSync(gemfilePath, 'utf8');

        // Check for essential gems
        const essentialGems = [
            { name: 'jekyll', pattern: /gem\s+["']jekyll["']/ },
            { name: 'github-pages', pattern: /gem\s+["']github-pages["']/ }
        ];

        let hasJekyll = false;
        let hasGitHubPages = false;

        essentialGems.forEach(gem => {
            if (gemfile.match(gem.pattern)) {
                console.log(`   ${gem.name} dependency found`);
                if (gem.name === 'jekyll') hasJekyll = true;
                if (gem.name === 'github-pages') hasGitHubPages = true;
            }
        });

        if (!hasJekyll && !hasGitHubPages) {
            this.results.dependencies.issues.push('Missing Jekyll or github-pages gem');
            console.log('  ❌ Missing Jekyll dependency');
        }

        // Check for Gemfile.lock
        const gemfileLockPath = path.join(this.sitePath, 'Gemfile.lock');
        if (fs.existsSync(gemfileLockPath)) {
            console.log('  ✅ Gemfile.lock found');
        } else {
            this.results.dependencies.issues.push('Gemfile.lock missing - run bundle install');
            console.log('  ⚠️  Gemfile.lock missing');
        }

        // Try to check bundle status (if bundler is available)
        try {
            execSync('which bundle', { cwd: this.sitePath, stdio: 'pipe' });
            console.log('  ✅ Bundler available');

            try {
                execSync('bundle check', { cwd: this.sitePath, stdio: 'pipe' });
                console.log('  ✅ Bundle dependencies satisfied');
            } catch (error) {
                this.results.dependencies.issues.push('Bundle dependencies not satisfied - run bundle install');
                console.log('  ⚠️  Bundle dependencies not satisfied');
            }
        } catch (error) {
            console.log('  ℹ️  Bundler not available - cannot check bundle status');
        }
    }

    async validateAssets() {
        console.log('\n🎨 Validating Assets...');

        const assetsPath = path.join(this.sitePath, 'assets');
        if (!fs.existsSync(assetsPath)) {
            this.results.assets.issues.push('No assets directory found');
            console.log('  ⚠️  No assets/ directory');
            return;
        }

        console.log('  ✅ Assets directory found');

        // Check asset structure
        const assetDirs = ['css', 'js', 'img', 'images'];
        assetDirs.forEach(dir => {
            const dirPath = path.join(assetsPath, dir);
            if (fs.existsSync(dirPath)) {
                const files = fs.readdirSync(dirPath);
                console.log(`   ${dir}/: ${files.length} files`);

                // Check for large files
                files.forEach(file => {
                    const filePath = path.join(dirPath, file);
                    const stats = fs.statSync(filePath);
                    const sizeKB = Math.round(stats.size / 1024);

                    if (sizeKB > 500 && (file.endsWith('.jpg') || file.endsWith('.png') || file.endsWith('.gif'))) {
                        this.results.assets.issues.push(`Large image file: ${dir}/${file} (${sizeKB}KB)`);
                        console.log(`      Large file: ${file} (${sizeKB}KB)`);
                    } else if (sizeKB > 100 && (file.endsWith('.css') || file.endsWith('.js'))) {
                        this.results.assets.issues.push(`Large CSS/JS file: ${dir}/${file} (${sizeKB}KB)`);
                        console.log(`      Large file: ${file} (${sizeKB}KB)`);
                    }
                });
            }
        });

        // Check for SCSS compilation
        const sassPath = path.join(this.sitePath, '_sass');
        const cssPath = path.join(assetsPath, 'css');

        if (fs.existsSync(sassPath) && fs.existsSync(cssPath)) {
            console.log('  ✅ SCSS structure detected');

            // Check for main.scss or similar
            const cssFiles = fs.readdirSync(cssPath);
            const scssFiles = cssFiles.filter(f => f.endsWith('.scss'));

            if (scssFiles.length === 0) {
                this.results.assets.issues.push('SCSS directory found but no .scss files in assets/css/');
                console.log('    ⚠️  No .scss files in assets/css/');
            } else {
                console.log(`     Found ${scssFiles.length} SCSS files`);
            }
        }
    }

    async testBuildProcess() {
        console.log('\n🔨 Testing Build Process...');

        // Check if Jekyll is available
        try {
            const jekyllVersion = execSync('jekyll --version', { cwd: this.sitePath, stdio: 'pipe', timeout: 10000 });
            console.log(`   Jekyll available: ${jekyllVersion.toString().trim()}`);
        } catch (error) {
            console.log('  ⚠️  Jekyll not available in PATH');

            // Try with bundle exec
            try {
                const bundleJekyll = execSync('bundle exec jekyll --version', { cwd: this.sitePath, stdio: 'pipe', timeout: 10000 });
                console.log(`   Jekyll via Bundle: ${bundleJekyll.toString().trim()}`);
            } catch (bundleError) {
                this.results.build.issues.push('Jekyll not available (try: gem install jekyll)');
                console.log('  ❌ Jekyll not available via bundle either');
                return;
            }
        }

        // Attempt a dry-run build
        try {
            console.log('  🔄 Attempting dry-run build...');

            const buildCommand = fs.existsSync(path.join(this.sitePath, 'Gemfile'))
                ? 'bundle exec jekyll build --dry-run --trace'
                : 'jekyll build --dry-run --trace';

            const buildOutput = execSync(buildCommand, {
                cwd: this.sitePath,
                stdio: 'pipe',
                timeout: 30000,
                encoding: 'utf8'
            });

            console.log('  ✅ Dry-run build successful');
            this.results.build.successful = true;

            // Parse build output for warnings
            this.parseBuildOutput(buildOutput);

        } catch (error) {
            this.results.build.successful = false;
            this.results.build.issues.push(`Build failed: ${error.message}`);
            console.log(`   Build failed: ${error.message}`);

            // Try to extract useful error information
            if (error.stdout) {
                const errorLines = error.stdout.toString().split('\n')
                    .filter(line => line.includes('ERROR') || line.includes('Error'))
                    .slice(0, 3); // Limit to first 3 errors

                errorLines.forEach(line => {
                    console.log(`    ${line.trim()}`);
                });
            }
        }
    }

    parseBuildOutput(output) {
        const lines = output.split('\n');

        lines.forEach(line => {
            if (line.includes('WARN')) {
                this.results.build.issues.push(`Build warning: ${line.trim()}`);
                console.log(`      ${line.trim()}`);
            }

            if (line.includes('Deprecation')) {
                this.results.build.issues.push(`Deprecation: ${line.trim()}`);
                console.log(`      ${line.trim()}`);
            }
        });
    }

    async checkDeploymentConfiguration() {
        console.log('\n🚀 Checking Deployment Configuration...');

        // Check for GitHub repository settings (if possible)
        const configPath = path.join(this.sitePath, '_config.yml');
        if (fs.existsSync(configPath)) {
            const config = fs.readFileSync(configPath, 'utf8');

            // Check URL configuration
            const urlMatch = config.match(/url:\s*["']?([^"'\n]+)["']?/);
            const baseurlMatch = config.match(/baseurl:\s*["']?([^"'\n]+)["']?/);

            if (urlMatch) {
                console.log(`   Site URL configured: ${urlMatch[1]}`);
            } else {
                this.results.config.issues.push('Site URL not configured');
                console.log('  ⚠️  Site URL not configured');
            }

            if (baseurlMatch) {
                console.log(`   Base URL configured: ${baseurlMatch[1]}`);
            }
        }

        // Check for proper 404 page
        const notFoundPages = ['404.html', '404.md'];
        let has404 = false;

        notFoundPages.forEach(page => {
            if (fs.existsSync(path.join(this.sitePath, page))) {
                console.log(`   Custom 404 page: ${page}`);
                has404 = true;
            }
        });

        if (!has404) {
            this.results.config.issues.push('No custom 404 page found');
            console.log('  ⚠️  No custom 404 page');
        }

        // Check for robots.txt
        const robotsPath = path.join(this.sitePath, 'robots.txt');
        if (fs.existsSync(robotsPath)) {
            console.log('  ✅ robots.txt found');
        } else {
            console.log('  ℹ️  No robots.txt (optional)');
        }

        // Check for sitemap generation
        if (fs.existsSync(configPath)) {
            const config = fs.readFileSync(configPath, 'utf8');
            if (config.includes('jekyll-sitemap')) {
                console.log('  ✅ Sitemap plugin configured');
            } else {
                console.log('  ℹ️  No sitemap plugin (consider adding jekyll-sitemap)');
            }
        }
    }

    async performanceChecks() {
        console.log('\n⚡ Performance Checks...');

        // Check for asset optimization
        const assetsPath = path.join(this.sitePath, 'assets');
        if (fs.existsSync(assetsPath)) {
            // Check for minification
            const cssPath = path.join(assetsPath, 'css');
            if (fs.existsSync(cssPath)) {
                const cssFiles = fs.readdirSync(cssPath);
                const minifiedCss = cssFiles.filter(f => f.includes('.min.'));

                if (minifiedCss.length === 0 && cssFiles.length > 0) {
                    this.results.performance.issues.push('No minified CSS files detected');
                    console.log('  ⚠️  No minified CSS detected');
                }
            }

            const jsPath = path.join(assetsPath, 'js');
            if (fs.existsSync(jsPath)) {
                const jsFiles = fs.readdirSync(jsPath);
                const minifiedJs = jsFiles.filter(f => f.includes('.min.'));

                if (minifiedJs.length === 0 && jsFiles.length > 0) {
                    this.results.performance.issues.push('No minified JavaScript files detected');
                    console.log('  ⚠️  No minified JS detected');
                }
            }
        }

        // Check Jekyll configuration for performance
        const configPath = path.join(this.sitePath, '_config.yml');
        if (fs.existsSync(configPath)) {
            const config = fs.readFileSync(configPath, 'utf8');

            // Check for compression
            if (config.includes('compress_html')) {
                console.log('  ✅ HTML compression configured');
            } else {
                this.results.performance.issues.push('HTML compression not configured');
                console.log('  ⚠️  No HTML compression');
            }

            // Check SASS compression
            if (config.includes('style: compressed')) {
                console.log('  ✅ SASS compression configured');
            } else {
                this.results.performance.issues.push('SASS compression not configured');
                console.log('  ⚠️  No SASS compression');
            }
        }
    }

    generateReport() {
        console.log('\n' + '='.repeat(60));
        console.log('📋 BUILD/DEPLOYMENT ISSUES REPORT');
        console.log('='.repeat(60));

        // Configuration Summary
        console.log('\n🔧 Jekyll Configuration:');
        console.log(`   Configured: ${this.results.jekyll.configured ? 'Yes' : 'No'}`);
        console.log(`   Issues: ${this.results.jekyll.issues.length}`);

        console.log('\n🐙 GitHub Pages:');
        console.log(`   Configured: ${this.results.github.configured ? 'Yes' : 'No'}`);
        console.log(`   Issues: ${this.results.github.issues.length}`);

        console.log('\n🔨 Build Process:');
        console.log(`   Successful: ${this.results.build.successful ? 'Yes' : 'No'}`);
        console.log(`   Issues: ${this.results.build.issues.length}`);

        // Dependencies Summary
        console.log('\n📦 Dependencies:');
        console.log(`   Issues: ${this.results.dependencies.issues.length}`);

        // Assets Summary
        console.log('\n🎨 Assets:');
        console.log(`   Issues: ${this.results.assets.issues.length}`);

        // Performance Summary
        console.log('\n⚡ Performance:');
        console.log(`   Issues: ${this.results.performance.issues.length}`);

        // All Issues
        const allIssues = [
            ...this.results.jekyll.issues.map(i => ({ type: 'Jekyll', issue: i })),
            ...this.results.github.issues.map(i => ({ type: 'GitHub', issue: i })),
            ...this.results.build.issues.map(i => ({ type: 'Build', issue: i })),
            ...this.results.dependencies.issues.map(i => ({ type: 'Dependencies', issue: i })),
            ...this.results.assets.issues.map(i => ({ type: 'Assets', issue: i })),
            ...this.results.config.issues.map(i => ({ type: 'Config', issue: i })),
            ...this.results.performance.issues.map(i => ({ type: 'Performance', issue: i }))
        ];

        if (allIssues.length > 0) {
            console.log('\n🔍 ALL ISSUES:');
            console.log('-'.repeat(60));

            const groupedIssues = {};
            allIssues.forEach(item => {
                if (!groupedIssues[item.type]) {
                    groupedIssues[item.type] = [];
                }
                groupedIssues[item.type].push(item.issue);
            });

            Object.keys(groupedIssues).forEach(type => {
                console.log(`\n${type}:`);
                groupedIssues[type].forEach(issue => {
                    console.log(`   ${issue}`);
                });
            });
        }

        // Build/Deploy Recommendations
        console.log('\n💡 BUILD/DEPLOYMENT RECOMMENDATIONS:');
        console.log('-'.repeat(60));

        const recommendations = [
            '• Ensure Jekyll and all dependencies are properly installed',
            '• Test builds locally before pushing to repository',
            '• Use GitHub Actions workflow for consistent deployments',
            '• Configure asset compression and minification',
            '• Implement proper error handling and 404 pages',
            '• Monitor build logs for warnings and deprecations',
            '• Keep Jekyll and plugins updated to latest stable versions',
            '• Use bundle exec for consistent gem versions',
            '• Consider using Jekyll environments for different configs'
        ];

        recommendations.forEach(rec => console.log(rec));

        // Save detailed report
        const reportData = {
            timestamp: new Date().toISOString(),
            results: this.results,
            recommendations: recommendations
        };

        fs.writeFileSync(
            '/workspaces/caxton/scripts/validation/build-deployment-report.json',
            JSON.stringify(reportData, null, 2)
        );

        console.log('\n📁 Detailed report saved to: build-deployment-report.json');

        const hasCriticalErrors = !this.results.build.successful ||
                                !this.results.jekyll.configured ||
                                this.results.dependencies.issues.length > 0;

        if (hasCriticalErrors) {
            console.log('\n🚨 CRITICAL ISSUES DETECTED - Build/deployment may fail');
            process.exit(1);
        }
    }
}

// Run if called directly
if (require.main === module) {
    const checker = new BuildDeploymentChecker();
    checker.run();
}

module.exports = BuildDeploymentChecker;