osvm 0.8.3

OpenSVM CLI tool for managing SVM nodes and deployments
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
/**
 * Multi-page Navigation System with Search
 * Handles page transitions, search functionality, and keyboard navigation
 */

// ===== GLOBAL STATE =====
let currentPage = 'home';
let searchIndex = [];
let isSearchOpen = false;
let searchResults = [];

// ===== PAGE ROUTING =====
const pages = {
    'home': {
        title: 'OSVM CLI - Home',
        file: 'pages/home.html',
        keywords: ['home', 'overview', 'introduction', 'getting started']
    },
    'installation': {
        title: 'Installation Guide',
        file: 'pages/installation.html',
        keywords: ['install', 'setup', 'download', 'requirements']
    },
    'plugins': {
        title: 'Plugin System',
        file: 'pages/plugins.html',
        keywords: ['plugins', 'extensions', 'commands', 'tools', 'themes']
    },
    'themes': {
        title: 'Themes & Customization',
        file: 'pages/themes.html',
        keywords: ['themes', 'styling', 'customization', 'colors', 'appearance']
    },
    'ai-integration': {
        title: 'AI Integration',
        file: 'pages/ai.html',
        keywords: ['ai', 'artificial intelligence', 'analysis', 'security', 'audit']
    },
    'mcp-servers': {
        title: 'MCP Servers',
        file: 'pages/mcp.html',
        keywords: ['mcp', 'model context protocol', 'servers', 'blockchain', 'data']
    },
    'node-deployment': {
        title: 'Node Deployment',
        file: 'pages/deployment.html',
        keywords: ['deployment', 'nodes', 'validators', 'rpc', 'ssh']
    },
    'api-reference': {
        title: 'API Reference',
        file: 'pages/api.html',
        keywords: ['api', 'reference', 'commands', 'documentation']
    }
};

/**
 * Initialize navigation system
 */
function initNavigation() {
    // Build search index
    buildSearchIndex();

    // Setup keyboard shortcuts
    setupKeyboardShortcuts();

    // Setup navigation links
    setupNavigationLinks();

    // Setup search functionality
    setupSearchSystem();

    // Load initial page
    const initialPage = getPageFromURL() || 'home';
    navigateToPage(initialPage, false);

    console.log('🧭 Navigation system initialized');
}

/**
 * Navigate to a specific page with smooth transition
 */
async function navigateToPage(pageId, addToHistory = true) {
    if (!pages[pageId]) {
        console.error(`Page not found: ${pageId}`);
        return;
    }

    const page = pages[pageId];

    // Update URL if needed
    if (addToHistory) {
        const newURL = pageId === 'home' ? '/' : `/${pageId}`;
        history.pushState({ page: pageId }, page.title, newURL);
    }

    // Update document title
    document.title = page.title;

    // Start page transition
    await startPageTransition();

    try {
        // Load page content
        const content = await loadPageContent(page.file);

        // Update content
        updatePageContent(content);

        // Update navigation state
        updateNavigationState(pageId);

        // Complete transition
        await completePageTransition();

        // Update current page
        currentPage = pageId;

        // Process cross-links for the new page
        processPageCrossLinks();

        console.log(`📄 Navigated to page: ${pageId}`);

    } catch (error) {
        console.error('Failed to load page:', error);
        showErrorPage();
    }
}

/**
 * Start page transition animation
 */
async function startPageTransition() {
    const content = document.querySelector('.page-content');
    if (content) {
        content.classList.add('page-transition-out');
        await new Promise(resolve => setTimeout(resolve, 150));
    }
}

/**
 * Complete page transition animation
 */
async function completePageTransition() {
    const content = document.querySelector('.page-content');
    if (content) {
        content.classList.remove('page-transition-out');
        content.classList.add('page-transition-in');

        // Remove transition class after animation
        setTimeout(() => {
            content.classList.remove('page-transition-in');
        }, 300);
    }
}

/**
 * Load page content from file
 */
async function loadPageContent(filePath) {
    const response = await fetch(filePath);
    if (!response.ok) {
        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }
    return await response.text();
}

/**
 * Update page content
 */
function updatePageContent(content) {
    const contentContainer = document.querySelector('.page-content');
    if (contentContainer) {
        contentContainer.innerHTML = content;

        // Reinitialize any interactive elements
        initializePageElements();
    }
}

/**
 * Update navigation state
 */
function updateNavigationState(activePageId) {
    // Update active nav link
    document.querySelectorAll('.nav-link').forEach(link => {
        link.classList.remove('active');
        if (link.dataset.page === activePageId) {
            link.classList.add('active');
        }
    });

    // Update breadcrumbs if present
    updateBreadcrumbs(activePageId);
}

/**
 * Get page ID from current URL
 */
function getPageFromURL() {
    const path = window.location.pathname;
    if (path === '/' || path === '/index.html') {
        return 'home';
    }

    const pageId = path.replace(/^\//, '').replace(/\.html$/, '');
    return pages[pageId] ? pageId : null;
}

/**
 * Setup keyboard shortcuts
 */
function setupKeyboardShortcuts() {
    document.addEventListener('keydown', (e) => {
        // Ctrl+K or Cmd+K for search
        if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
            e.preventDefault();
            toggleSearch();
            return;
        }

        // Escape to close search
        if (e.key === 'Escape' && isSearchOpen) {
            closeSearch();
            return;
        }

        // Handle search navigation
        if (isSearchOpen) {
            handleSearchKeyboard(e);
            return;
        }

        // Page navigation shortcuts
        if (e.altKey) {
            switch (e.key) {
                case '1':
                    e.preventDefault();
                    navigateToPage('home');
                    break;
                case '2':
                    e.preventDefault();
                    navigateToPage('installation');
                    break;
                case '3':
                    e.preventDefault();
                    navigateToPage('plugins');
                    break;
                case '4':
                    e.preventDefault();
                    navigateToPage('themes');
                    break;
            }
        }
    });
}

/**
 * Setup navigation links
 */
function setupNavigationLinks() {
    // Handle navigation clicks
    document.addEventListener('click', (e) => {
        const navLink = e.target.closest('[data-page]');
        if (navLink) {
            e.preventDefault();
            const pageId = navLink.dataset.page;
            navigateToPage(pageId);
        }

        // Handle cross-links
        const crossLink = e.target.closest('[data-cross-link]');
        if (crossLink) {
            e.preventDefault();
            const pageId = crossLink.dataset.crossLink;
            navigateToPage(pageId);
        }
    });

    // Handle browser back/forward
    window.addEventListener('popstate', (e) => {
        const pageId = e.state?.page || getPageFromURL() || 'home';
        navigateToPage(pageId, false);
    });
}

/**
 * Build search index from all pages
 */
async function buildSearchIndex() {
    searchIndex = [];

    for (const [pageId, page] of Object.entries(pages)) {
        try {
            const content = await loadPageContent(page.file);

            // Extract text content (simple approach)
            const tempDiv = document.createElement('div');
            tempDiv.innerHTML = content;
            const textContent = tempDiv.textContent || tempDiv.innerText || '';

            // Create search entries
            const entries = extractSearchEntries(textContent, pageId, page);
            searchIndex.push(...entries);

        } catch (error) {
            console.warn(`Failed to index page ${pageId}:`, error);
        }
    }

    console.log(`🔍 Search index built with ${searchIndex.length} entries`);
}

/**
 * Extract search entries from page content
 */
function extractSearchEntries(content, pageId, page) {
    const entries = [];

    // Add page title and keywords
    entries.push({
        title: page.title,
        content: page.keywords.join(' '),
        page: pageId,
        type: 'page',
        score: 100
    });

    // Extract headings and commands
    const lines = content.split('\n');
    let currentSection = '';

    for (let i = 0; i < lines.length; i++) {
        const line = lines[i].trim();

        // Check for headings
        const headingMatch = line.match(/^#+\s+(.+)$/);
        if (headingMatch) {
            currentSection = headingMatch[1];
            entries.push({
                title: currentSection,
                content: line,
                page: pageId,
                type: 'heading',
                score: 80
            });
            continue;
        }

        // Check for commands
        const commandMatch = line.match(/\$\s+(osvm\s+.+?)(?:\s*#|$)/);
        if (commandMatch) {
            entries.push({
                title: commandMatch[1],
                content: `${currentSection} - ${line}`,
                page: pageId,
                type: 'command',
                score: 90
            });
            continue;
        }

        // Check for important terms
        if (line.length > 20 && line.length < 200) {
            entries.push({
                title: line.substring(0, 50) + (line.length > 50 ? '...' : ''),
                content: line,
                page: pageId,
                type: 'content',
                score: 50
            });
        }
    }

    return entries;
}

/**
 * Initialize interactive elements on the current page
 */
function initializePageElements() {
    // Reinitialize copy buttons
    if (window.initCopyButtons) {
        window.initCopyButtons();
    }

    // Reinitialize any other interactive elements
    if (window.initTabs) {
        window.initTabs();
    }

    // Add micro-animations to new elements
    addMicroAnimations();
}

/**
 * Add micro-animations to page elements
 */
function addMicroAnimations() {
    // Animate elements that come into view
    const animatedElements = document.querySelectorAll('.command-example, .feature-card, .code-block');

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate-in');
                observer.unobserve(entry.target);
            }
        });
    }, {
        threshold: 0.1,
        rootMargin: '50px'
    });

    animatedElements.forEach(el => {
        el.classList.add('animate-ready');
        observer.observe(el);
    });
}

/**
 * Process cross-links in the current page
 */
function processPageCrossLinks() {
    const content = document.querySelector('.page-content');
    if (!content) return;

    // Define cross-link patterns
    const crossLinks = {
        'plugin': 'plugins',
        'plugins': 'plugins',
        'theme': 'themes',
        'themes': 'themes',
        'AI': 'ai-integration',
        'artificial intelligence': 'ai-integration',
        'MCP': 'mcp-servers',
        'Model Context Protocol': 'mcp-servers',
        'deployment': 'node-deployment',
        'install': 'installation',
        'API': 'api-reference'
    };

    // Process text nodes to add cross-links
    const walker = document.createTreeWalker(
        content,
        NodeFilter.SHOW_TEXT,
        null,
        false
    );

    const textNodes = [];
    let node;
    while (node = walker.nextNode()) {
        if (node.parentElement.tagName !== 'A' &&
            node.parentElement.tagName !== 'CODE' &&
            node.parentElement.tagName !== 'PRE') {
            textNodes.push(node);
        }
    }

    textNodes.forEach(textNode => {
        let content = textNode.textContent;
        let hasChanges = false;

        for (const [term, pageId] of Object.entries(crossLinks)) {
            if (pageId !== currentPage && content.includes(term)) {
                const regex = new RegExp(`\\b${term}\\b`, 'gi');
                content = content.replace(regex, `<a href="#" data-cross-link="${pageId}" class="cross-link">$&</a>`);
                hasChanges = true;
            }
        }

        if (hasChanges) {
            const wrapper = document.createElement('span');
            wrapper.innerHTML = content;
            textNode.parentNode.replaceChild(wrapper, textNode);
        }
    });
}

// Make navigation functions available globally
window.navigateToPage = navigateToPage;
window.initNavigation = initNavigation;