Skip to content

Comments

feat: add plugin command API for LLM-free auto-reply commands#1558

Merged
steipete merged 4 commits intoopenclaw:mainfrom
Glucksberg:feat/plugin-command-api
Jan 24, 2026
Merged

feat: add plugin command API for LLM-free auto-reply commands#1558
steipete merged 4 commits intoopenclaw:mainfrom
Glucksberg:feat/plugin-command-api

Conversation

@Glucksberg
Copy link
Contributor

Summary

  • Adds a new API for plugins to register slash commands that execute immediately without invoking the LLM agent
  • Useful for state toggles, status checks, and quick actions
  • Commands are processed before built-in handlers
  • Supports authorization, argument parsing, and validation

Key features:

  • registerCommand() API for plugins to register commands
  • Command validation (reserved names, invalid characters)
  • Authorization enforcement via existing allowlist
  • Input sanitization and error handling
  • Registry locking during execution to prevent modifications

Files changed:

  • src/plugins/commands.ts - Core command registration and execution
  • src/plugins/types.ts - TypeScript types for command definitions
  • src/plugins/registry.ts - Integration with plugin registry
  • src/plugins/runtime.ts - Runtime API exposure
  • src/plugins/loader.ts - Command cleanup on plugin reload
  • src/auto-reply/reply/commands-plugin.ts - Command handler in auto-reply chain
  • src/auto-reply/reply/commands-core.ts - Integration with core command handler
  • docs/plugin.md - Documentation for the new API

Test plan

  • Run pnpm test to verify all tests pass
  • Manually test command registration from a plugin
  • Verify reserved commands cannot be overridden
  • Test authorization enforcement for restricted commands

🤖 Generated with Claude Code

Glucksberg and others added 4 commits January 24, 2026 04:34
This adds a new `api.registerCommand()` method to the plugin API, allowing
plugins to register slash commands that execute without invoking the AI agent.

Features:
- Plugin commands are processed before built-in commands and the agent
- Commands can optionally require authorization
- Commands can accept arguments
- Async handlers are supported

Use case: plugins can implement toggle commands (like /tts_on, /tts_off)
that respond immediately without consuming LLM API calls.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Blockers fixed:
- Fix documentation: requireAuth defaults to true (not false)
- Add command name validation (must start with letter, alphanumeric only)
- Add reserved commands list to prevent shadowing built-in commands
- Emit diagnostic errors for invalid/duplicate command registration

Other improvements:
- Return user-friendly message for unauthorized commands (instead of silence)
- Sanitize error messages to avoid leaking internal details
- Document acceptsArgs behavior when arguments are provided
- Add notes about reserved commands and validation rules to docs

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add clearPluginCommands() call in loadClawdbotPlugins() to ensure
previously registered commands are cleaned up before reloading plugins.
This prevents command conflicts during hot-reload scenarios.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add registry lock during command execution to prevent race conditions
- Add input sanitization for command arguments (defense in depth)
- Validate handler is a function during registration
- Remove redundant case-insensitive regex flag
- Add success logging for command execution
- Simplify handler return type (always returns result now)
- Remove dead code branch in commands-plugin.ts

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@steipete steipete merged commit 6bd6ae4 into openclaw:main Jan 24, 2026
16 of 22 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: 6bd6ae4\n- Merge commit: 6bd6ae4\n\nThanks @Glucksberg!

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