Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat: implement documentation search functionality with keyboard shortcut support

Salman Qureshi4885e6d8118c
diff --git a/docs/docs.html b/docs/docs.html
index 79941269..c6c31969 100644
--- a/docs/docs.html
+++ b/docs/docs.html
@@ -282,6 +282,10 @@
<div class="nav-links" id="navLinks">
<a href="index.html">Home</a>
<a href="docs.html" style="color: var(--cyan);">Docs</a>
+ <button class="search-shortcut" id="searchBtn" aria-label="Search" onclick="document.getElementById('searchOverlay').classList.add('open');document.getElementById('searchInput').focus();">
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
+ <kbd id="searchKbdNav"></kbd>
+ </button>
<a href="https://github.com/cosmicstack-labs/mercury-agent" class="github-btn" target="_blank" rel="noopener">
<svg viewBox="0 0 16 16" width="16" height="16" fill="currentColor" style="vertical-align:-2px;"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
<span class="github-btn-text">Star</span>
@@ -1502,6 +1506,179 @@
})
.catch(function () {});
</script>
+
+ <div class="search-overlay" id="searchOverlay">
+ <div class="search-modal" onclick="event.stopPropagation()">
+ <div class="search-input-wrap">
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
+ <input class="search-input" id="searchInput" type="text" placeholder="Search documentation..." autocomplete="off">
+ <span class="search-input-hint" id="searchHintEsc">ESC</span>
+ </div>
+ <div class="search-results" id="searchResults"></div>
+ <div class="search-footer">
+ <span><kbd>↑↓</kbd> navigate</span>
+ <span><kbd>↵</kbd> open</span>
+ <span><kbd id="searchKbdFooter">esc</kbd> close</span>
+ </div>
+ </div>
+ </div>
+
+ <script>
+ (function () {
+ var isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0 ||
+ navigator.userAgent.indexOf('Mac') > -1;
+ var modKey = isMac ? '\u2318' : 'Ctrl';
+ var modKeyShort = isMac ? '\u2318K' : 'Ctrl+K';
+
+ document.getElementById('searchKbdNav').textContent = modKeyShort;
+ document.getElementById('searchKbdFooter').textContent = isMac ? '\u2318K' : 'Ctrl+K';
+
+ var overlay = document.getElementById('searchOverlay');
+ var input = document.getElementById('searchInput');
+ var resultsEl = document.getElementById('searchResults');
+
+ var sections = [];
+ var currentH2 = '';
+
+ document.querySelectorAll('.docs-content h2, .docs-content h3').forEach(function (el) {
+ if (el.tagName === 'H2') currentH2 = el.textContent.trim();
+ sections.push({
+ id: el.id,
+ title: el.textContent.trim(),
+ section: el.tagName === 'H3' ? currentH2 : '',
+ level: el.tagName
+ });
+ });
+
+ var activeIndex = -1;
+ var matchedItems = [];
+
+ function highlight(text, query) {
+ if (!query) return text;
+ var escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ return text.replace(new RegExp('(' + escaped + ')', 'gi'), '<mark>$1</mark>');
+ }
+
+ function search(query) {
+ resultsEl.innerHTML = '';
+ matchedItems = [];
+ activeIndex = -1;
+
+ if (!query.trim()) {
+ sections.slice(0, 8).forEach(function (s) {
+ matchedItems.push(s);
+ var div = document.createElement('a');
+ div.className = 'search-result-item';
+ div.href = '#' + s.id;
+ div.setAttribute('data-index', matchedItems.length - 1);
+ div.innerHTML = (s.section ? '<div class="search-result-section">' + s.section + '</div>' : '') +
+ '<div class="search-result-title">' + s.title + '</div>';
+ div.onclick = function (e) { e.preventDefault(); navigateTo(s.id); };
+ resultsEl.appendChild(div);
+ });
+ return;
+ }
+
+ var q = query.toLowerCase();
+ sections.forEach(function (s) {
+ if (s.title.toLowerCase().indexOf(q) !== -1) {
+ matchedItems.push(s);
+ }
+ });
+
+ if (matchedItems.length === 0) {
+ resultsEl.innerHTML = '<div class="search-empty">No results found</div>';
+ return;
+ }
+
+ matchedItems.forEach(function (s, i) {
+ var div = document.createElement('a');
+ div.className = 'search-result-item';
+ div.href = '#' + s.id;
+ div.setAttribute('data-index', i);
+ div.innerHTML = (s.section ? '<div class="search-result-section">' + highlight(s.section, query) + '</div>' : '') +
+ '<div class="search-result-title">' + highlight(s.title, query) + '</div>';
+ div.onclick = function (e) { e.preventDefault(); navigateTo(s.id); };
+ resultsEl.appendChild(div);
+ });
+
+ setActive(0);
+ }
+
+ function setActive(idx) {
+ if (idx < 0) idx = matchedItems.length - 1;
+ if (idx >= matchedItems.length) idx = 0;
+ activeIndex = idx;
+ var items = resultsEl.querySelectorAll('.search-result-item');
+ items.forEach(function (el, i) {
+ el.classList.toggle('active', i === idx);
+ });
+ if (items[idx]) items[idx].scrollIntoView({ block: 'nearest' });
+ }
+
+ function navigateTo(id) {
+ closeSearch();
+ var target = document.getElementById(id);
+ if (target) {
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
+ target.style.outline = '2px solid var(--cyan)';
+ setTimeout(function () { target.style.outline = ''; }, 1500);
+ }
+ }
+
+ function openSearch() {
+ overlay.classList.add('open');
+ input.value = '';
+ input.focus();
+ search('');
+ }
+
+ function closeSearch() {
+ overlay.classList.remove('open');
+ input.value = '';
+ }
+
+ overlay.addEventListener('click', function (e) {
+ if (e.target === overlay) closeSearch();
+ });
+
+ document.addEventListener('keydown', function (e) {
+ if ((isMac ? e.metaKey : e.ctrlKey) && e.key === 'k') {
+ e.preventDefault();
+ if (overlay.classList.contains('open')) closeSearch();
+ else openSearch();
+ return;
+ }
+ if (!overlay.classList.contains('open')) return;
+
+ if (e.key === 'Escape') {
+ closeSearch();
+ return;
+ }
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ setActive(activeIndex + 1);
+ return;
+ }
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ setActive(activeIndex - 1);
+ return;
+ }
+ if (e.key === 'Enter' && activeIndex >= 0 && activeIndex < matchedItems.length) {
+ e.preventDefault();
+ navigateTo(matchedItems[activeIndex].id);
+ return;
+ }
+ });
+
+ input.addEventListener('input', function () {
+ search(this.value);
+ });
+
+ search('');
+ })();
+ </script>
</body>
</html>
diff --git a/docs/style.css b/docs/style.css
index 562c8f24..0855b031 100644
--- a/docs/style.css
+++ b/docs/style.css
@@ -427,4 +427,180 @@ footer {
.provider-note p {
margin: 0;
+}
+
+/* ── Search ── */
+.search-shortcut {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ background: rgba(255,255,255,0.06);
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ padding: 3px 8px;
+ font-family: var(--font);
+ font-size: 0.75em;
+ color: var(--gray-dim);
+ cursor: pointer;
+ transition: all 0.2s;
+ margin-left: 8px;
+}
+
+.search-shortcut:hover {
+ border-color: var(--cyan-dim);
+ color: var(--gray);
+}
+
+.search-shortcut kbd {
+ font-family: var(--font);
+ font-size: 1em;
+ background: none;
+ padding: 0;
+ border-radius: 0;
+ color: inherit;
+}
+
+.search-overlay {
+ position: fixed;
+ inset: 0;
+ z-index: 200;
+ background: rgba(0, 0, 0, 0.6);
+ backdrop-filter: blur(4px);
+ display: none;
+ align-items: flex-start;
+ justify-content: center;
+ padding-top: 15vh;
+}
+
+.search-overlay.open {
+ display: flex;
+}
+
+.search-modal {
+ width: 100%;
+ max-width: 560px;
+ background: var(--bg-card);
+ border: 1px solid var(--border);
+ border-radius: 12px;
+ box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5), 0 0 80px rgba(0, 212, 255, 0.06);
+ overflow: hidden;
+}
+
+.search-input-wrap {
+ display: flex;
+ align-items: center;
+ padding: 16px 20px;
+ border-bottom: 1px solid var(--border);
+ gap: 10px;
+}
+
+.search-input-wrap svg {
+ flex-shrink: 0;
+ color: var(--gray-dim);
+}
+
+.search-input {
+ flex: 1;
+ background: none;
+ border: none;
+ outline: none;
+ color: var(--white);
+ font-family: var(--font-body);
+ font-size: 1em;
+}
+
+.search-input::placeholder {
+ color: var(--gray-dim);
+}
+
+.search-input-hint {
+ font-family: var(--font);
+ font-size: 0.7em;
+ color: var(--gray-dim);
+ background: rgba(255,255,255,0.06);
+ border: 1px solid var(--border);
+ border-radius: 4px;
+ padding: 2px 6px;
+ white-space: nowrap;
+}
+
+.search-results {
+ max-height: 340px;
+ overflow-y: auto;
+ padding: 8px;
+}
+
+.search-result-item {
+ display: block;
+ padding: 10px 12px;
+ border-radius: 8px;
+ cursor: pointer;
+ text-decoration: none !important;
+ transition: background 0.15s;
+}
+
+.search-result-item:hover,
+.search-result-item.active {
+ background: var(--cyan-glow);
+}
+
+.search-result-item.active {
+ outline: 1px solid var(--cyan-dim);
+}
+
+.search-result-section {
+ font-size: 0.75em;
+ color: var(--gray-dim);
+ margin-bottom: 2px;
+ font-family: var(--font);
+}
+
+.search-result-title {
+ color: var(--white);
+ font-size: 0.92em;
+}
+
+.search-result-title mark {
+ background: rgba(0, 212, 255, 0.25);
+ color: var(--cyan);
+ border-radius: 2px;
+ padding: 0 1px;
+}
+
+.search-empty {
+ padding: 24px 20px;
+ text-align: center;
+ color: var(--gray-dim);
+ font-size: 0.9em;
+}
+
+.search-footer {
+ padding: 8px 16px;
+ border-top: 1px solid var(--border);
+ display: flex;
+ gap: 16px;
+ font-size: 0.72em;
+ color: var(--gray-dim);
+ font-family: var(--font);
+}
+
+.search-footer span {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+}
+
+.search-footer kbd {
+ background: rgba(255,255,255,0.06);
+ border: 1px solid var(--border);
+ border-radius: 3px;
+ padding: 1px 5px;
+ font-family: var(--font);
+ font-size: 1em;
+}
+
+@media (max-width: 600px) {
+ .search-overlay { padding-top: 8vh; }
+ .search-modal { margin: 0 12px; max-width: none; }
+ .search-footer { display: none; }
}
\ No newline at end of file