|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Demonstration script to show that the new AutoBot approach works |
| 4 | + * This script demonstrates: |
| 5 | + * 1. Documentation loading works correctly |
| 6 | + * 2. Enhanced system instruction is generated properly |
| 7 | + * 3. Key SHAFT topics are included in the context |
| 8 | + */ |
| 9 | + |
| 10 | +import { loadDocumentation, getGitHubRepositoryContext } from './netlify/functions/docs-loader.mjs'; |
| 11 | + |
| 12 | +console.log('==========================================='); |
| 13 | +console.log('AutoBot Documentation-Based Approach Demo'); |
| 14 | +console.log('===========================================\n'); |
| 15 | + |
| 16 | +// Step 1: Load Documentation |
| 17 | +console.log('Step 1: Loading Documentation...'); |
| 18 | +console.log('─────────────────────────────────────────'); |
| 19 | +const startTime = Date.now(); |
| 20 | +const documentation = loadDocumentation(); |
| 21 | +const githubContext = getGitHubRepositoryContext(); |
| 22 | +const loadTime = Date.now() - startTime; |
| 23 | + |
| 24 | +if (!documentation || !githubContext) { |
| 25 | + console.error('❌ FAILED: Could not load documentation'); |
| 26 | + process.exit(1); |
| 27 | +} |
| 28 | + |
| 29 | +console.log(`✅ SUCCESS: Loaded ${documentation.length.toLocaleString()} characters in ${loadTime}ms`); |
| 30 | +console.log(` - Documentation: ${documentation.length.toLocaleString()} chars`); |
| 31 | +console.log(` - GitHub Context: ${githubContext.length.toLocaleString()} chars`); |
| 32 | +console.log(); |
| 33 | + |
| 34 | +// Step 2: Show what's included |
| 35 | +console.log('Step 2: Documentation Content Analysis'); |
| 36 | +console.log('─────────────────────────────────────────'); |
| 37 | + |
| 38 | +// Count documents |
| 39 | +const docCount = (documentation.match(/## Document:/g) || []).length; |
| 40 | +console.log(`✅ Loaded ${docCount} documentation files`); |
| 41 | + |
| 42 | +// Show key topics included |
| 43 | +const keyTopics = { |
| 44 | + 'Web/GUI Testing': documentation.includes('Element_Actions'), |
| 45 | + 'API Testing': documentation.includes('Request_Builder'), |
| 46 | + 'Mobile Testing': documentation.includes('mobile'), |
| 47 | + 'Database Testing': documentation.includes('DB_Actions'), |
| 48 | + 'CLI Testing': documentation.includes('Terminal_Actions'), |
| 49 | + 'Configuration': documentation.includes('properties'), |
| 50 | + 'Validations': documentation.includes('Validations'), |
| 51 | + 'Browser Actions': documentation.includes('Browser_Actions'), |
| 52 | +}; |
| 53 | + |
| 54 | +console.log('\n📚 Key Topics Included:'); |
| 55 | +for (const [topic, included] of Object.entries(keyTopics)) { |
| 56 | + console.log(` ${included ? '✅' : '❌'} ${topic}`); |
| 57 | +} |
| 58 | +console.log(); |
| 59 | + |
| 60 | +// Step 3: Show sample content |
| 61 | +console.log('Step 3: Sample Documentation Content'); |
| 62 | +console.log('─────────────────────────────────────────'); |
| 63 | + |
| 64 | +// Find and show a sample from API documentation |
| 65 | +const apiDocStart = documentation.indexOf('## Document: Keywords/API/Request_Builder.md'); |
| 66 | +if (apiDocStart > -1) { |
| 67 | + const apiSample = documentation.substring(apiDocStart, apiDocStart + 500); |
| 68 | + console.log('Sample from API Request Builder documentation:\n'); |
| 69 | + console.log(apiSample); |
| 70 | + console.log('...\n'); |
| 71 | +} |
| 72 | + |
| 73 | +// Step 4: Enhanced System Instruction |
| 74 | +console.log('Step 4: Enhanced System Instruction Generation'); |
| 75 | +console.log('─────────────────────────────────────────'); |
| 76 | + |
| 77 | +const systemInstruction = 'You are AutoBot, a helpful SHAFT assistant.'; |
| 78 | +const enhancedSystemInstruction = `${documentation}\n\n${githubContext}\n\n---\n\n${systemInstruction}\n\nIMPORTANT: Use ONLY the documentation provided above.`; |
| 79 | + |
| 80 | +console.log(`✅ Enhanced instruction length: ${enhancedSystemInstruction.length.toLocaleString()} characters`); |
| 81 | +console.log(` - Within Gemini limit (500KB): ${enhancedSystemInstruction.length < 500000 ? 'YES ✅' : 'NO ❌'}`); |
| 82 | +console.log(` - Includes full documentation: ${enhancedSystemInstruction.includes('SHAFT Engine User Guide') ? 'YES ✅' : 'NO ❌'}`); |
| 83 | +console.log(` - Includes GitHub context: ${enhancedSystemInstruction.includes('github.com/ShaftHQ') ? 'YES ✅' : 'NO ❌'}`); |
| 84 | +console.log(); |
| 85 | + |
| 86 | +// Step 5: Demonstrate searchable content |
| 87 | +console.log('Step 5: Demonstrate Question-Answer Capability'); |
| 88 | +console.log('─────────────────────────────────────────'); |
| 89 | + |
| 90 | +const sampleQuestions = [ |
| 91 | + { q: 'How to create an API instance?', search: 'SHAFT.API' }, |
| 92 | + { q: 'How to perform browser actions?', search: 'Browser_Actions' }, |
| 93 | + { q: 'How to configure SHAFT?', search: 'properties' }, |
| 94 | + { q: 'How to validate elements?', search: 'Element_Validations' }, |
| 95 | +]; |
| 96 | + |
| 97 | +console.log('Sample questions that can be answered from the loaded documentation:\n'); |
| 98 | +for (const { q, search } of sampleQuestions) { |
| 99 | + const canAnswer = documentation.includes(search); |
| 100 | + console.log(`Q: "${q}"`); |
| 101 | + console.log(` ${canAnswer ? '✅' : '❌'} Information available (contains "${search}")\n`); |
| 102 | +} |
| 103 | + |
| 104 | +// Step 6: Show the difference from old approach |
| 105 | +console.log('Step 6: Comparison with Old Approach'); |
| 106 | +console.log('─────────────────────────────────────────'); |
| 107 | +console.log('OLD APPROACH (Google Search Grounding):'); |
| 108 | +console.log(' ❌ Fetches data from internet at runtime'); |
| 109 | +console.log(' ❌ May include third-party sources'); |
| 110 | +console.log(' ❌ Results can vary based on search results'); |
| 111 | +console.log(' ❌ Depends on external Google Search API'); |
| 112 | +console.log(' ❌ Cannot trace answer to specific documentation'); |
| 113 | +console.log(); |
| 114 | +console.log('NEW APPROACH (Local Documentation):'); |
| 115 | +console.log(' ✅ Uses only official SHAFT documentation'); |
| 116 | +console.log(' ✅ No external API calls during queries'); |
| 117 | +console.log(' ✅ Consistent, reproducible answers'); |
| 118 | +console.log(' ✅ All answers traceable to docs'); |
| 119 | +console.log(' ✅ Documentation loaded once and cached'); |
| 120 | +console.log(); |
| 121 | + |
| 122 | +// Summary |
| 123 | +console.log('==========================================='); |
| 124 | +console.log('Summary'); |
| 125 | +console.log('==========================================='); |
| 126 | +console.log(`✅ Documentation loaded successfully (${docCount} files)`); |
| 127 | +console.log(`✅ Enhanced instruction generated (${(enhancedSystemInstruction.length / 1024).toFixed(1)} KB)`); |
| 128 | +console.log(`✅ All key SHAFT topics included`); |
| 129 | +console.log(`✅ Ready to provide accurate, documentation-based answers`); |
| 130 | +console.log('✅ No internet searches or external dependencies'); |
| 131 | +console.log('\n🎉 The new AutoBot approach is working correctly!\n'); |
0 commit comments