Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support for Custom Commands #409

Open
tusharmath opened this issue Feb 27, 2025 · 3 comments · May be fixed by #416
Open

Feature Request: Support for Custom Commands #409

tusharmath opened this issue Feb 27, 2025 · 3 comments · May be fixed by #416

Comments

@tusharmath
Copy link
Collaborator

Feature Request: Support for Custom Commands

Overview

Currently, Code-Forge supports built-in commands like /new and /info. This feature request proposes extending the command system to support a standardized format for custom commands that can trigger custom event handling.

For example: /dispatch-gh-issue Create an issue to update the version of tokio would fire an event with name "gh-issue" and value "Create an issue to update the version of tokio", which could then trigger custom handling.

Background

Built-in commands are currently handled through the Command enum and parsed in the Command::parse method. We need to extend this to support custom commands with a consistent interface using the /dispatch-event_name value format.

User Experience

Users would be able to:

  1. Type a command like /dispatch-gh-issue Update tokio version in the console
  2. Have the command parsed into an event with name "gh-issue" and value "Update tokio version"
  3. The dispatch system would handle this event and provide appropriate feedback

Command Format Specification

  1. Format: /dispatch-event_name value

    • All text after /dispatch- up to the first space (or end of string) is the event name
    • All text after the first space (if any) is the event value
  2. Event Name Requirements:

    • Can contain alphanumeric characters, underscores (_), and hyphens (-)
    • No maximum length restriction
    • No reserved names (internal events can be dispatched)
  3. Event Value Behavior:

    • Values can be empty
    • Spaces in values are preserved exactly as entered (no trimming)
    • If there's no space after the event name, the event has an empty value
  4. Examples:

    • /dispatch-gh-issue Create new issue → name: "gh-issue", value: "Create new issue"
    • /dispatch-notify → name: "notify", value: "" (empty)
    • /dispatch-log-error Error message with spaces → name: "log-error", value: "Error message with spaces" (spaces preserved)

Proposed Implementation Changes

API Layer Changes

  1. Add a new dispatch method to the API trait to handle custom command events
  2. Implement this method in ForgeAPI to properly handle dispatch events

Command System Changes

  1. Update the Command enum with a new Dispatch variant that includes:

    • name: The event name portion
    • value: The event value portion
  2. Enhance the command parser to recognize the /dispatch- prefix and properly extract the event name and value

Orchestrator Changes

  1. Ensure the orchestrator can handle the custom events generated by dispatch commands
  2. Use the existing event handling infrastructure for processing these events

Main Application Flow Changes

  1. Update the main command processing loop to handle the new Dispatch command variant
  2. Use the new dispatch API method to process these commands

Files to Modify

  1. crates/forge_api/src/lib.rs - Add the dispatch method to the API trait
  2. crates/forge_api/src/api.rs - Implement the dispatch method in ForgeAPI
  3. crates/forge_main/src/model.rs - Update the Command enum and parse method
  4. crates/forge_main/src/main.rs (or wherever the main loop is) - Update to handle dispatch commands
  5. crates/forge_domain/src/dispatch_event.rs - Potentially enhance to make custom event handling more robust

Rust Best Practices

  1. Error Handling: Use proper error types and propagation with anyhow::Result
  2. Async/Await: Ensure all async code is properly handled and awaited
  3. Strong Typing: Use properly typed enums and structs rather than strings where possible
  4. Documentation: Add proper rustdoc comments to all new APIs
  5. Testing: Write unit and integration tests for the new functionality
  6. Separation of Concerns: Keep the command parsing logic separate from the execution logic

Considerations

  1. Validation: Consider validating that event names only contain alphanumeric characters, underscores, and hyphens
  2. Performance: Ensure the dispatcher can handle rapid command execution
  3. Error Handling: Provide clear error messages when commands fail
  4. Backwards Compatibility: Ensure existing code using the API doesn't break

Suggested Implementation Timeline

  1. Add the API::dispatch method and implement it in ForgeAPI
  2. Update the Command enum with the new Dispatch variant
  3. Modify the command parser to detect and handle dispatch commands
  4. Update the application flow to use the new dispatch method
  5. Add tests to verify the functionality
  6. Update documentation to explain the dispatch command feature

Encouragement

When implementing this feature, consider using Code-Forge itself! The codebase is well structured for iterative development, and you can use Code-Forge to:

  1. Navigate through the codebase
  2. Understand the existing patterns
  3. Generate test cases
  4. Refine the implementation

Additional Ideas for Future

  1. Allow registering command handlers programmatically for specific event names
  2. Support tab completion for common dispatch event names
  3. Add a help system that shows available dispatch commands
  4. Add support for structured data in event values (like JSON)
@tusharmath
Copy link
Collaborator Author

/bounty $100

Copy link

algora-pbc bot commented Feb 27, 2025

💎 $100 bounty • Tailcall Inc.

Steps to solve:

  1. Start working: Comment /attempt #409 with your implementation plan
  2. Submit work: Create a pull request including /claim #409 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

🙏 Thank you for contributing to antinomyhq/forge!
🧐 Checkout our guidelines before you get started.
💵 More about our bounty program.

Attempt Started (GMT+0) Solution
🟢 @onyedikachi-david #416

Copy link

algora-pbc bot commented Feb 28, 2025

💡 @onyedikachi-david submitted a pull request that claims the bounty. You can visit your bounty board to reward.

amitksingh1490 added a commit that referenced this issue Mar 13, 2025
- Add Command::Dispatch variant for '/dispatch-event_name value' format
- Update command parsing to recognize and extract event names and values
- Add dispatch method to API trait and implement in ForgeAPI
- Update UI to handle dispatch commands
- Add tests for verifying dispatch command parsing
- Add documentation for feature in CUSTOM_COMMANDS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant