Skip to content

Conversation

@NerdsCorp
Copy link
Owner

No description provided.

Previously, commands configured with a leading "/" (like "/ping") in
commands_config.json would not work when sent from mesh without the
slash (as "ping"). The keyword command section was explicitly checking
that configured commands didn't start with "/" before matching.

This fix normalizes both the configured command and the incoming
message by stripping any leading "/" before comparison. Now commands
work consistently regardless of:
- How they're configured (with or without "/" in config)
- How they're sent from mesh (with or without "/")

Example: "/ping" in config now works when sent as either "ping" or "/ping"
The handle_command function receives args (text after the command) as
its second parameter, but was incorrectly trying to remove the command
length from it again. This caused user input to be corrupted.

Example of the bug:
- Input: "/ai test question"
- cmd="/ai", full_text="test question" (already args only)
- Old code: user_prompt = "test question"[3:] = "t question" ❌
- Fixed: user_prompt = "test question" ✓

This affected:
- AI commands (/ai, /bot, /query, /data) - line 686
- Emergency commands (/emergency, /911) - line 702
- Config-based slash commands - line 740

Now all slash commands correctly receive the full user input.
Previously, the system had complex logic to handle commands with and
without slashes, resulting in confusing behavior and bugs. This commit
completely simplifies the approach:

BEFORE:
- Separate handling for "/command" vs "command"
- Section 2: Slash commands (if text.startswith("/"))
- Section 3: Keyword commands (explicitly excluded commands with "/")
- Commands in config needed "/" to work via slash handler
- Inconsistent behavior between mesh and other sources

AFTER:
- Single unified command matching system
- ALL slashes are stripped and ignored during matching
- Commands work identically whether sent as "ping" or "/ping"
- Commands in config work whether stored as "ping" or "/ping"
- Much simpler code flow with less duplication

Changes:
1. handle_command() now normalizes cmd by stripping "/" at entry
2. All command checks updated: "/about" → "about", etc.
3. Removed separate slash command section entirely
4. Unified command matching tries built-in then config commands
5. "ai on/off" updated to work without requiring "/"
6. Help command now shows normalized command names

Result: Commands just work consistently across all entry points,
regardless of slash usage in config or user messages.
Fixed issues found during code review:

1. REMOVED duplicate command definitions:
   - "ai", "bot", "query", "data" were hardcoded in handle_command
     AND defined in commands_config.json
   - Now only in config, avoiding conflicting behavior

2. REMOVED duplicate config command loop:
   - Config commands were checked in BOTH handle_command AND parse_incoming_text
   - The loop in parse_incoming_text was unreachable dead code
   - Now config commands only checked in parse_incoming_text where we have
     access to channel context (needed for AI channel auto-activation)

3. UPDATED help command list:
   - Added "time" and "sms" to built-in commands list
   - Was showing outdated list of built-in commands

4. CLARIFIED code structure:
   - handle_command: Only built-in commands (about, time, whereami, etc.)
   - parse_incoming_text: Config-based commands with full channel context

Result: Cleaner separation of concerns, no duplicate logic, proper
channel activation for AI commands from config.
Removed ALL references to "/" from the entire codebase:

CODE CHANGES (main.py):
- Removed .lstrip('/') from handle_command (line 678)
- Removed .lstrip('/') from help command list (line 703)
- Removed .lstrip('/') from parse_incoming_text first_word (line 758)
- Removed .lstrip('/') from config command matching (line 782)
- Removed all normalization variables and comments about slashes
- Updated comment: "no slash required" → "word-based"

CONFIG CHANGES (commands_config.json):
- Removed "/" from ALL command names:
  - /ping → ping
  - /weather → weather
  - /hello → hello (also updated message text)
  - /funfact → funfact
  - /joke → joke
  - /define → define
  - /translate → translate
  - /calc → calc
  - /inspire → inspire
  - /date → date
  - /time → curtime (renamed to avoid conflict with built-in)
  - /random → random
  - /rock → rock
  - /sport → sport
  - /recipe → recipe

RESULT:
The system now works purely on word matching with ZERO slash logic.
Users send commands as plain words: "ping", "ai test", "help", etc.
No more slash normalization, no more confusion, just simple word matching.
@NerdsCorp NerdsCorp merged commit 2a97b2c into main Jan 18, 2026
1 check failed
@NerdsCorp NerdsCorp deleted the claude/fix-mesh-commands-QuaxK branch January 18, 2026 05:44
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.

2 participants