Skip to content

feat(app): Enhanced slash commands with app navigation and fixes#543

Open
benzntech wants to merge 1 commit intoslopus:mainfrom
benzntech:feat/slash-commands-enhancement
Open

feat(app): Enhanced slash commands with app navigation and fixes#543
benzntech wants to merge 1 commit intoslopus:mainfrom
benzntech:feat/slash-commands-enhancement

Conversation

@benzntech
Copy link

@benzntech benzntech commented Feb 5, 2026

Summary

This PR enhances the slash command system with context-aware app navigation commands, bug fixes from code review, and improved code quality. The implementation is inspired by HAPI's extensible architecture while maintaining existing patterns.

New Features

1. App Navigation Commands

Add navigation slash commands that work in both web app and Telegram:

  • /home - Navigate to home screen
  • /sessions - View all active sessions
  • /profiles - Manage profiles
  • /settings - Open settings
  • /help - Show help (context-aware: alert in Telegram, navigation in web)

2. Context-Aware Display

// Enable app commands when needed
const suggestions = await searchCommands(sessionId, query, {
    includeAppCommands: true  // Show navigation commands
});

3. Command Handler Hook

New useCommandHandler hook with:

  • Automatic routing based on command source (app/sdk/builtin)
  • Telegram haptic feedback integration
  • Clear callback API for SDK commands
  • TypeScript support with CommandItem interface

4. Command Source Tracking

interface CommandItem {
    command: string;
    description?: string;
    source?: 'builtin' | 'sdk' | 'app';  // Track command origin
}

Bug Fixes

Fix #182: Commands filtered by first letter

Problem: Only commands starting with 'c' appeared in autocomplete (iOS bug)

Solution: Fuse.js fuzzy search searches across all command names and descriptions, not filtered by first letter.

Code:

const fuse = new Fuse(commands, {
    keys: [
        { name: 'command', weight: 0.7 },
        { name: 'description', weight: 0.3 }
    ]
});

Remove 'help' Conflict

Problem: help was in both IGNORED_COMMANDS and APP_COMMANDS

Solution: Removed from ignore list since we provide it as an app navigation command.

Improved Duplicate Detection

Problem: Only checked DEFAULT_COMMANDS for duplicates, could miss conflicts with APP_COMMANDS

Solution:

// Before: Only checked defaults
if (!commands.find(c => c.command === cmd)) { ... }

// After: Checks all existing commands
const existingCommand = commands.find(c => c.command === cmd);
if (!existingCommand) { ... }

Fixed React Dependency Arrays

Problem: options object in dependencies caused unnecessary re-renders

Solution: Destructure callbacks at hook top level:

const { onCommandExecuted, onUnknownCommand, onSdkCommand } = options;
// Use individual callbacks in dependency array

Code Quality Improvements

1. Exported Command Constants

Before: Command lists duplicated in two files

After: Single source of truth

// suggestionCommands.ts
export const APP_COMMAND_NAMES = ['home', 'sessions', ...] as const;
export const BUILTIN_COMMAND_NAMES = ['compact', 'clear'] as const;

// useCommandHandler.ts
import { APP_COMMAND_NAMES, BUILTIN_COMMAND_NAMES } from '@/sync/suggestionCommands';

2. Clear SDK Command API

Before: SDK commands had no handler (unclear behavior)

After: Explicit callback:

const { executeCommandItem } = useCommandHandler({
    onSdkCommand: (cmd) => {
        sendMessageToCLI(`/${cmd}`);  // Clear contract
    }
});

Documentation

SLASH_COMMANDS.md

Complete implementation guide with:

  • Architecture diagram
  • Usage examples
  • Command definitions
  • Testing checklist
  • Integration guide

CODE_REVIEW_FIXES.md

All fixes applied with before/after code examples and migration guide.

RELATED_ISSUES.md

Analysis of existing issues and PRs:

Testing

  • TypeScript type checking passes
  • Fuzzy search works across all commands (not filtered by first letter)
  • App navigation commands work in web app
  • App navigation commands work in Telegram
  • No duplicate commands in autocomplete
  • Haptic feedback works in Telegram Web App
  • Help command shows different UI (alert vs navigation)
  • SDK commands trigger onSdkCommand callback
  • Builtin commands send to CLI
  • No unnecessary re-renders

Performance

✅ Optimized dependency arrays
✅ Fuse.js fuzzy search (typo-tolerant)
✅ No caching issues (reads fresh from session metadata)

Backward Compatibility

No breaking changes except:

  • SDK commands now require onSdkCommand callback (previously unclear)
  • includeAppCommands defaults to false (opt-in)

Related Issues & PRs

Migration Guide

For Existing Code Using Autocomplete

Before:

const suggestions = await searchCommands(sessionId, query);
// Only shows builtin + SDK commands

After:

const suggestions = await searchCommands(sessionId, query, {
    includeAppCommands: true  // Add navigation commands
});

For SDK Command Handling

Before:

const { executeCommandItem } = useCommandHandler();
// SDK commands did nothing

After:

const { executeCommandItem } = useCommandHandler({
    onSdkCommand: (cmd) => sendMessageToCLI(`/${cmd}`)
});

Next Steps (Future Work)

  1. User-defined commands (Issue Doesn't pick up "custom commands" #203) - Scan ~/.claude/commands/ like HAPI
  2. Command categories - Group commands by type
  3. Command aliases - /h/help, /s/sessions
  4. Keyboard shortcuts - Cmd+K to open command palette

Summary: This PR provides a production-ready slash command system with app navigation, fixes existing bugs, and improves code quality. The implementation is backward-compatible with clear migration paths.

@benzntech
Copy link
Author

Additional Note: Telegram Integration

This PR also lays the groundwork for Telegram Mini App slash commands. While the full Telegram integration (files like useTelegramCommands.ts, TELEGRAM_COMMANDS.md) is not included in this PR, the core slash command system now supports:

  1. Context-aware commands - includeAppCommands flag
  2. Haptic feedback - Telegram Web App integration in useCommandHandler
  3. Source tracking - source: 'app' for navigation commands
  4. Extensible architecture - Easy to add Telegram-specific commands

The Telegram-specific files can be added in a follow-up PR once this foundation is merged.

Testing in Telegram Web App

import { useCommandHandler } from '@/hooks/useCommandHandler';
import { useTelegram } from '@/hooks/useTelegram';

function ChatInput() {
    const { isTelegramWebApp } = useTelegram();
    const { executeCommandItem } = useCommandHandler({
        onSdkCommand: (cmd) => sendMessageToCLI(`/${cmd}`)
    });

    // Commands work seamlessly in Telegram
    // Haptic feedback automatically provided
}

Let me know if you'd like the full Telegram integration included or prefer it as a separate PR!

This PR improves the slash command system with context-aware navigation
commands, bug fixes, and better code quality.

## Changes

### New Features
- Add app navigation commands (/home, /sessions, /profiles, /settings, /help)
- Context-aware command display (includeAppCommands flag)
- Command handler hook with Telegram integration
- Haptic feedback for Telegram Web App
- Command source tracking (builtin/sdk/app)

### Bug Fixes
- Fix slopus#182: Removed filter that only showed commands starting with 'c'
- Remove 'help' from IGNORED_COMMANDS to prevent conflicts
- Improve duplicate command detection (checks all commands, not just defaults)
- Fix React dependency arrays to prevent unnecessary re-renders

### Code Quality
- Export command name constants to avoid duplication
- Add onSdkCommand callback for clear API contract
- Better TypeScript types with source field

## Testing
- TypeScript type checking passes
- Fuzzy search works across all commands
- App navigation commands work in web and Telegram
- No duplicate commands in autocomplete
- Haptic feedback works in Telegram
- Help command shows different UI in web vs Telegram

## Related Issues
- Fixes slopus#182 (commands filtered by first letter)
- Addresses slopus#14 (slash command handling - reviewed ignore list)
- Compatible with PR slopus#495 (preset messages)
@benzntech benzntech force-pushed the feat/slash-commands-enhancement branch from 9e0672b to 92dfdea Compare February 5, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only slash commands starting with c

1 participant