Skip to content

heymegabyte/agent-skills / 06-build-and-slice-loop

build-and-slice-loop

Verified

Use when implementing features or streaming OnePrompt site builds. Complete vertical slices with real content, strict TypeScript and Zod. Parallel section/data work, deterministic assembly, granular patches and immediate valid previews.

FileKindSize
SKILL.mdskill md7.2 KB
admin-dashboard.mdmarkdown5.5 KB
ai-chat-widget.mdmarkdown6.0 KB
blog-and-content-engine.mdmarkdown6.2 KB
build-breaking-rules.mdmarkdown7.4 KB
chat-native-dashboard.mdmarkdown3.6 KB
contact-forms-and-endpoints.mdmarkdown6.7 KB
copilot-and-ai-features.mdmarkdown7.4 KB
custom-error-pages.mdmarkdown4.5 KB
data-tables.mdmarkdown7.7 KB
domain-provisioning.mdmarkdown4.6 KB
easter-eggs.mdmarkdown4.7 KB
empty-states-and-loading.mdmarkdown5.7 KB
file-uploads-and-storage.mdmarkdown6.7 KB
internationalization.mdmarkdown4.3 KB
keyboard-shortcuts-and-command-palette.mdmarkdown6.7 KB
microcopy-library.mdmarkdown8.0 KB
notification-center.mdmarkdown8.4 KB
onboarding-and-first-run.mdmarkdown5.0 KB
pre-digested-builds.mdmarkdown3.6 KB
pwa-kit.mdmarkdown6.8 KB
realtime-and-websockets.mdmarkdown7.2 KB
rich-text-editor.mdmarkdown7.4 KB
site-search.mdmarkdown4.0 KB
stripe-first-donations.mdmarkdown10.7 KB
web-manifest-system.mdmarkdown11.9 KB
webhook-system.mdmarkdown9.5 KB

keyboard-shortcuts-and-command-palette.md

View on GitHub
---
name: "Keyboard Shortcuts and Command Palette"
version: "2.0.0"
updated: "2026-04-23"
description: "Full command palette (Cmd+K) like Linear/Notion for SaaS products. Keyboard shortcut overlay (press ? for help). Keyboard-first navigation for power users. Includes search integration, quick actions, and theme toggle. Accessible, with ARIA roles and screen reader support."
---

# Keyboard Shortcuts and Command Palette

## When to Include

- SaaS products with 3+ pages
- Developer tools
- Products targeting power users
- Any product with search (pairs with `06/site-search`)

## Command Palette (Cmd+K)

### Focus contract (***NON-NEGOTIABLE***)

- Opening the palette or AI chat via `Meta+K`/`Ctrl+K` MUST focus the text input on the same frame — caret blinking, zero extra clicks
- Use `autofocus` on the input AND a programmatic `requestAnimationFrame(()=>input.focus({preventScroll:true}))` after the `hidden=false`/open-state flip (covers React re-render, View Transitions, and `@starting-style` enter)
- If the modal is already open, re-pressing Cmd+K re-focuses and `input.select()`s existing text
- Esc returns focus to the triggering element (a11y)
- Playwright test — `await page.keyboard.press('Meta+K'); await expect(page.locator('#cmdInput')).toBeFocused();` — failure = build fail

### HTML

```html
<div id="cmdPalette" class="cmd-palette" hidden role="dialog" aria-label="Command palette">
  <div class="cmd-backdrop" onclick="closePalette()"></div>
  <div class="cmd-container">
    <input type="text" id="cmdInput" placeholder="Type a command or search..."
           role="combobox" aria-autocomplete="list" aria-expanded="true"
           aria-controls="cmdResults" autofocus>
    <ul id="cmdResults" class="cmd-results" role="listbox">
      <!-- Results populated dynamically -->
    </ul>
    <div class="cmd-footer">
      <span><kbd>↑↓</kbd> Navigate</span>
      <span><kbd>↵</kbd> Select</span>
      <span><kbd>Esc</kbd> Close</span>
    </div>
  </div>
</div>
```

### JavaScript

```javascript
// Command registry
const commands = [
  // Navigation
  { id: 'home', label: 'Go to Home', shortcut: 'g h', action: () => location.href = '/' },
  { id: 'about', label: 'Go to About', action: () => location.href = '/about' },
  { id: 'pricing', label: 'Go to Pricing', action: () => location.href = '/pricing' },
  { id: 'blog', label: 'Go to Blog', action: () => location.href = '/blog' },
  { id: 'contact', label: 'Go to Contact', action: () => location.href = '/contact' },
  // Actions
  { id: 'search', label: 'Search...', shortcut: '/', action: openSearch },
  { id: 'theme', label: 'Toggle Dark/Light Mode', shortcut: 't', action: toggleTheme },
  { id: 'shortcuts', label: 'Show Keyboard Shortcuts', shortcut: '?', action: showShortcuts },
  // Admin (if authenticated)
  { id: 'admin', label: 'Open Admin Dashboard', action: () => location.href = '/admin' },
];

// Open palette
document.addEventListener('keydown', (e) => {
  if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
    e.preventDefault();
    openPalette();
  }
  if (e.key === 'Escape') closePalette();
  if (e.key === '?' && !isInputFocused()) showShortcuts();
});

function openPalette() {
  const palette = document.getElementById('cmdPalette');
  palette.hidden = false;
  document.getElementById('cmdInput').focus();
  renderResults(commands);
}

function closePalette() {
  document.getElementById('cmdPalette').hidden = true;
}

// Fuzzy filter
document.getElementById('cmdInput')?.addEventListener('input', (e) => {
  const query = e.target.value.toLowerCase();
  const filtered = commands.filter(c =>
    c.label.toLowerCase().includes(query) || c.id.includes(query)
  );
  renderResults(filtered);
});

// Arrow key navigation
let selectedIndex = 0;
document.getElementById('cmdInput')?.addEventListener('keydown', (e) => {
  const results = document.querySelectorAll('.cmd-result');
  if (e.key === 'ArrowDown') { selectedIndex = Math.min(selectedIndex + 1, results.length - 1); e.preventDefault(); }
  if (e.key === 'ArrowUp') { selectedIndex = Math.max(selectedIndex - 1, 0); e.preventDefault(); }
  if (e.key === 'Enter') { results[selectedIndex]?.click(); e.preventDefault(); }
  results.forEach((r, i) => r.classList.toggle('selected', i === selectedIndex));
});

function renderResults(items) {
  selectedIndex = 0;
  const list = document.getElementById('cmdResults');
  list.innerHTML = items.map((cmd, i) => `
    <li class="cmd-result ${i === 0 ? 'selected' : ''}" role="option" onclick="${cmd.id}Action()">
      <span>${cmd.label}</span>
      ${cmd.shortcut ? `<kbd>${cmd.shortcut}</kbd>` : ''}
    </li>
  `).join('');
}
```

### Styling

```css
.cmd-palette { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: flex-start; justify-content: center; padding-top: 20vh; }
.cmd-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.cmd-container { position: relative; width: 560px; background: #0f0f1f; border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.cmd-container input { width: 100%; padding: 1rem 1.25rem; background: transparent; border: none; border-bottom: 1px solid rgba(255,255,255,0.06); color: #f0f0f5; font-size: 1rem; outline: none; }
.cmd-results { list-style: none; padding: 0.5rem 0; margin: 0; max-height: 300px; overflow-y: auto; }
.cmd-result { padding: 0.75rem 1.25rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; color: #a0a0b5; }
.cmd-result.selected, .cmd-result:hover { background: rgba(0, 229, 255, 0.08); color: #f0f0f5; }
.cmd-result kbd { font-size: 0.75rem; background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px; }
.cmd-footer { padding: 0.5rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.06); font-size: 0.75rem; color: #606080; display: flex; gap: 1rem; }
.cmd-footer kbd { font-size: 0.7rem; background: rgba(255,255,255,0.06); padding: 1px 4px; border-radius: 3px; }
```

## Shortcut Overlay (Press ?)

```html
<div id="shortcutOverlay" class="shortcut-overlay" hidden>
  <h3>Keyboard Shortcuts</h3>
  <table>
    <tr><td><kbd>Cmd+K</kbd></td><td>Open command palette</td></tr>
    <tr><td><kbd>/</kbd></td><td>Focus search</td></tr>
    <tr><td><kbd>?</kbd></td><td>Show this help</td></tr>
    <tr><td><kbd>g h</kbd></td><td>Go to Home</td></tr>
    <tr><td><kbd>t</kbd></td><td>Toggle theme</td></tr>
    <tr><td><kbd>Esc</kbd></td><td>Close overlay</td></tr>
  </table>
</div>
```

## Accessibility

- `role="dialog"` on palette, `role="combobox"` on input, `role="listbox"` on results
- Arrow keys navigate, Enter selects, Escape closes
- All shortcuts skip when user is typing in an input/textarea
- Screen reader announces selected item
- Reduced motion — no transition animations on palette open/close
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall