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

feat!: config file + dynamic plugins #30

Merged
merged 3 commits into from
Dec 29, 2024
Merged

feat!: config file + dynamic plugins #30

merged 3 commits into from
Dec 29, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Dec 29, 2024

dynamically load available plugins

move to config file instead of overcomplicating cli arguments

Summary by CodeRabbit

Release Notes for HiveMind Core

  • Documentation

    • Comprehensive README update with new sections on modular design, server anatomy, plugins, and contributing
    • Enhanced project description and feature explanations
  • Configuration

    • Introduced new server configuration management system
    • Simplified configuration file handling with default settings
  • Dependency Updates

    • Updated package dependencies
    • Removed HiveMind presence dependency
    • Upgraded ovos-bus-client, json-database, and hivemind-plugin-manager versions
  • Code Refactoring

    • Streamlined protocol and database initialization
    • Simplified command-line interface for client management
    • Removed database-specific parameters from various functions
  • Service Improvements

    • Enhanced logging messages
    • More modular protocol handling
    • Simplified service initialization process

Copy link

coderabbitai bot commented Dec 29, 2024

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f00b736 and 5080dc1.

📒 Files selected for processing (1)
  • README.md (11 hunks)

Walkthrough

This pull request introduces significant changes to the HiveMind Core project, focusing on enhancing modularity, configuration management, and simplifying protocol handling. The modifications span across multiple files, including README.md, configuration management, database initialization, protocol handling, and service configuration. The changes aim to provide a more flexible and user-friendly approach to setting up and managing HiveMind services, with a strong emphasis on plugin support and centralized configuration.

Changes

File Change Summary
README.md Comprehensive restructuring with new sections on modular design, server anatomy, plugins, and project overview
hivemind_core/__main__.py Simplified HiveMindService instantiation by removing explicit protocol parameters
hivemind_core/config.py Added get_server_config() for centralized configuration management using JSON storage
hivemind_core/database.py Refactored ClientDatabase to use configuration-based initialization
hivemind_core/protocol.py Introduced ClientCallbacks class for structured event handling
hivemind_core/scripts.py Removed database-related parameters from command functions
hivemind_core/service.py Added protocol retrieval functions and updated logging
requirements.txt Updated dependency versions and removed HiveMind_presence

Sequence Diagram

sequenceDiagram
    participant User
    participant ConfigManager
    participant ServiceInitializer
    participant ProtocolFactory
    participant HiveMindService

    User->>ConfigManager: Request server configuration
    ConfigManager-->>User: Return configuration
    User->>ServiceInitializer: Initialize service
    ServiceInitializer->>ProtocolFactory: Get protocols
    ProtocolFactory-->>ServiceInitializer: Return protocol classes
    ServiceInitializer->>HiveMindService: Create service instance
    HiveMindService->>HiveMindService: Configure and run
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • goldyfruit

Poem

🐰 A Rabbit's Ode to HiveMind's New Design

Modular magic, config so bright,
Protocols dancing with pure delight,
Plugins weaving their flexible spell,
HiveMind evolves, and all is well!
🚀 Code hopping to a simpler design


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (7)
hivemind_core/database.py (1)

12-20: Consider validating config keys before usage
While this refactor simplifies setup by retrieving the database backend from config, the code assumes "module" is always present in config["database"]. If “module” is missing or if config.get(name, {}) doesn't match expectations, it could lead to runtime errors. Adding a fallback or explicit error logging for missing keys would improve robustness.

hivemind_core/config.py (1)

28-36: Graceful configuration file creation
Merging _DEFAULT into a fresh config ensures the user always has valid defaults. If partial updates or advanced merges are needed later, consider deeper merges or version checks.

hivemind_core/protocol.py (1)

192-192: [Optional] Validate external dictionary usage for clients.
The attribute clients = {} is declared at the class level but also used in instance methods. If multiple protocol instances are created, they might share state unintentionally. Consider whether this should be an instance attribute.

README.md (4)

136-136: Consider removing the $ or showing command output to silence MD014.

-$ hivemind-core listen
+hivemind-core listen
🧰 Tools
🪛 Markdownlint (0.37.0)

136-136: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


206-206: Same MD014 consideration for “$ hivemind-core add-client” usage.

-$ hivemind-core add-client ...
+hivemind-core add-client ...
🧰 Tools
🪛 Markdownlint (0.37.0)

206-206: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


220-220: Again, consider removing the $ or showing sample output for the list command.

🧰 Tools
🪛 Markdownlint (0.37.0)

220-220: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


344-344: Remove the $ or show command output as with prior commands.

🧰 Tools
🪛 Markdownlint (0.37.0)

344-344: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 732e839 and f00b736.

📒 Files selected for processing (8)
  • README.md (11 hunks)
  • hivemind_core/__main__.py (1 hunks)
  • hivemind_core/config.py (1 hunks)
  • hivemind_core/database.py (1 hunks)
  • hivemind_core/protocol.py (6 hunks)
  • hivemind_core/scripts.py (13 hunks)
  • hivemind_core/service.py (3 hunks)
  • requirements.txt (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
hivemind_core/protocol.py

215-215: Do not use bare except

(E722)


220-220: Do not use bare except

(E722)


281-281: Do not use bare except

(E722)


286-286: Do not use bare except

(E722)


308-308: Do not use bare except

(E722)


313-313: Do not use bare except

(E722)


333-333: Do not use bare except

(E722)


338-338: Do not use bare except

(E722)

🪛 LanguageTool
README.md

[uncategorized] ~54-~54: The abbreviation “e.g.” (= for example) requires two periods.
Context: ...hat to do you the received binary data, eg. process incoming audio. Each component...

(E_G)

🪛 Markdownlint (0.37.0)
README.md

136-136: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


206-206: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


220-220: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


344-344: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)

🔇 Additional comments (56)
hivemind_core/database.py (1)

5-6: Imports for configuration and database factory look appropriate
This new approach centralizes configuration handling via get_server_config() and adds flexibility for different database modules. No issues spotted here.

hivemind_core/service.py (10)

2-8: Refined imports
Using Callable, Optional, Type from the typing module and pulling in get_server_config() aligns well with this file’s expanded scope for configurable protocols.


14-18: Agent protocol retrieval
The get_agent_protocol function delegates retrieval to a plugin factory. This is a clear approach that helps keep agent logic decoupled from the service.


20-24: Network protocol retrieval
Same pattern as the agent protocol. Code is consistent and straightforward.


26-32: Optional binary protocol
Returning a dummy fallback if module is None nicely handles the absence of a binary protocol. This design choice is clean and avoids unwanted exceptions.


36-36: Updated service logs
Renaming log messages for "hivemind-core" ensures consistent branding and clarity.

Also applies to: 40-40, 44-44, 48-48, 52-52


99-99: Service set_alive call
Ensuring the service status is set to “alive” immediately after instantiation is aligned with the ProcessStatus usage.


102-103: Transition to started status
This signals that initialization is proceeding. The usage is consistent with the rest of the status flow.


105-106: Agent protocol instantiation
Passing a dedicated config object into the factory’s protocol class is a good step toward plugin autonomy. This clarifies the boundary between the HiveMind core and plugin logic.

Also applies to: 108-108


112-115: Binary protocol support
The optional binary protocol is instantiated here, bridging agent protocol objects if configured. This design keeps agent/binary responsibilities neatly separated.


125-126: Network protocol construction
The same pattern ensures consistency: fetch class + config from get_network_protocol(). Easy to follow, and the logging of network_class.__name__ helps with debugging.

Also applies to: 128-128

hivemind_core/__main__.py (1)

5-5: Simplified instantiation
Constructing HiveMindService() with no extra arguments enforces the new centralized configuration approach. This streamlines usage and eliminates repeated CLI arguments.

hivemind_core/config.py (1)

7-27: Centralized default configuration
Defining _DEFAULT sets a clear baseline for protocols and database modules. This is an effective way to ensure minimal required configuration, particularly for newbies or quick setups.

hivemind_core/scripts.py (13)

8-8: Consolidated imports
Pulling ClientDatabase and HiveMindService into these scripts reflects the new design of simpler commands, each backed by a default config.


57-57: Function signature for add_client
Removed backend arguments align with the new config-based approach. The function remains simpler for end users.


76-76: Database usage
Instantiating ClientDatabase() within a context manager is clean. Logging db.db.__class__.__name__ is also helpful for debugging which plugin is active.


103-104: rename_client function
No more database-specific arguments. This is consistent with the PR’s shift to config-driven usage. The logic remains straightforward.


115-115: delete_client function
Again, usage of the default ClientDatabase() is aligned with the new approach. The function’s code effectively revokes credentials.

Also applies to: 117-118


136-136: list_clients
Lists the table of client data from the default config-based database. Good usage of rich for user-friendly CLI output.

Also applies to: 145-145


160-161: listen
Eliminating many CLI options in favor of a single HiveMindService instantiation drastically simplifies command usage.


168-169: allow_msg
Default database usage. The flow for toggling allowed message types remains understandable, with a short path to success or exit.


185-186: blacklist_msg
Reuses the same approach as allow_msg. The code is consistent, straightforward, and uses the new config system.


202-203: blacklist_skill
Same pattern of removing the DB arguments. The logic to append new skill IDs to the skill blacklist remains intact.


220-221: unblacklist_skill
Allows removing items from a client’s skill blacklist with a simpler database approach.


237-238: blacklist_intent
Similar changes as skill blacklisting. This keeps the code consistent throughout the script.


254-255: unblacklist_intent
Removes an intent ID from the blacklist without referencing any DB-specific CLI arguments.

hivemind_core/protocol.py (1)

26-26: [Optional] Check for references to ClientCallbacks usage.
The new import for ClientCallbacks looks correct. Ensure any references to it are consistent and do not require further changes in the calling code.

requirements.txt (1)

9-12: Ensure compatibility with updated versions.
The bumped versions (hivemind-plugin-manager>=0.3.0,<1.0.0, ovos-bus-client>=1.3.1,<2.0.0, json-database>=0.9.1,<1.0.0) look fine. Confirm that the new package versions are tested with your codebase, especially for any potential breaking changes.

README.md (28)

3-6: Nice introduction to satellites.
These lines effectively explain satellites and central hub roles. The language is clear and user-friendly.


8-12: Scalable environment overview looks good.
The mention of hub-to-hub connections for advanced setups is beneficial.


13-15: Clarify adaptation beyond OVOS.
It’s great that the text highlights adaptability to various AI backends. No changes needed.


16-17: Useful reference to YouTube channel.
Good addition to direct users to demonstrations.


23-30: Key features look consistent with the new architecture.
No issues detected.


46-50: Clear coverage of the architecture.
The high-level description of the key protocol components is thorough.


51-57: Database plugin mention is aligned with broader plugin design.
No major concerns.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~54-~54: The abbreviation “e.g.” (= for example) requires two periods.
Context: ...hat to do you the received binary data, eg. process incoming audio. Each component...

(E_G)


58-65: Config file approach nicely reduces CLI overhead.
Implementation notes look consistent.


66-96: JSON config example is well structured.
Ensure version control or environment documentation clarifies how to override these defaults.


99-100: Separation with horizontal rule is good for readability.
No issues.


101-101: Command-line introduction is concise.
Looks good.


112-112: “Adding a Satellite” heading is straightforward.
No issues.


114-114: Database mention for add-client usage.
Clear example demonstrating the new CLI usage.


129-129: Security note is helpful.
Reminding users about the credentials is essential.


141-152: Plugin overview table is concise and informative.
Great introduction to available plugin categories.


153-163: Client overview is comprehensive.
No concerns.


210-211: Reiterating usage scenario is helpful.
No changes needed.


224-225: Use-cases for listing clients are clear.
No issues.


266-267: Expanding the explanation of allow-msg usage is beneficial.
No concerns.


280-281: blacklist-msg usage is clearly documented.
Good job explaining typical use cases.


294-295: Clear example for blacklist-skill.
No issues.


321-322: Intent blocking usage is well-documented.
No issues.


348-349: Straightforward instructions for listen usage.
No changes necessary.


358-358: Heading for next steps is helpful.
No issues.


360-362: Links to docs and chat are valuable.


368-369: Encourages open source collaboration.
No issues.


381-382: Matrix discussion pointer is relevant.
No changes needed.


384-396: Good callout for beginner-friendly projects.
Inviting community support fosters faster growth.

hivemind_core/protocol.py Show resolved Hide resolved
hivemind_core/protocol.py Show resolved Hide resolved
hivemind_core/protocol.py Show resolved Hide resolved
hivemind_core/protocol.py Show resolved Hide resolved
hivemind_core/protocol.py Show resolved Hide resolved
Comment on lines +34 to +42
## 🔌 Modular Design with Plugins

HiveMind is designed to be modular, allowing you to customize its behavior through plugins managed by the **HiveMind
Plugin Manager**.

- 📚 **Documentation**: [HiveMind Docs](https://jarbashivemind.github.io/HiveMind-community-docs)
- 💬 **Chat**: Join the [HiveMind Matrix Chat](https://matrix.to/#/#jarbashivemind:matrix.org) for news, support, and
discussion.
- **Transport Mechanism** 🚚: The protocol does not specify **how** messages are transported; this is implemented via **network protocol plugins**.
- **Payload Handling** 🤖 : The protocol does not dictate **who** handles the messages; this is implemebted via **agent protocol plugins**.
- **Message Format** 📦: The protocol supports **JSON data** modeled after the `Message` [structure from OVOS](https://jarbashivemind.github.io/HiveMind-community-docs/13_mycroft/) and **binary** data; what happens to the received binary data is implemented via **binary data protocol plugins**.
- **Database**: 🗃️ how client credentials are stored is implemented via **database plugins**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix typo “implemebted” → “implemented”.

- The protocol does not dictate **who** handles the messages; this is implemebted via **agent protocol** plugins.
+ The protocol does not dictate **who** handles the messages; this is implemented via **agent protocol** plugins.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 🔌 Modular Design with Plugins
HiveMind is designed to be modular, allowing you to customize its behavior through plugins managed by the **HiveMind
Plugin Manager**.
- 📚 **Documentation**: [HiveMind Docs](https://jarbashivemind.github.io/HiveMind-community-docs)
- 💬 **Chat**: Join the [HiveMind Matrix Chat](https://matrix.to/#/#jarbashivemind:matrix.org) for news, support, and
discussion.
- **Transport Mechanism** 🚚: The protocol does not specify **how** messages are transported; this is implemented via **network protocol plugins**.
- **Payload Handling** 🤖 : The protocol does not dictate **who** handles the messages; this is implemebted via **agent protocol plugins**.
- **Message Format** 📦: The protocol supports **JSON data** modeled after the `Message` [structure from OVOS](https://jarbashivemind.github.io/HiveMind-community-docs/13_mycroft/) and **binary** data; what happens to the received binary data is implemented via **binary data protocol plugins**.
- **Database**: 🗃️ how client credentials are stored is implemented via **database plugins**
## 🔌 Modular Design with Plugins
HiveMind is designed to be modular, allowing you to customize its behavior through plugins managed by the **HiveMind
Plugin Manager**.
- **Transport Mechanism** 🚚: The protocol does not specify **how** messages are transported; this is implemented via **network protocol plugins**.
- **Payload Handling** 🤖 : The protocol does not dictate **who** handles the messages; this is implemented via **agent protocol plugins**.
- **Message Format** 📦: The protocol supports **JSON data** modeled after the `Message` [structure from OVOS](https://jarbashivemind.github.io/HiveMind-community-docs/13_mycroft/) and **binary** data; what happens to the received binary data is implemented via **binary data protocol plugins**.
- **Database**: 🗃️ how client credentials are stored is implemented via **database plugins**

@JarbasAl JarbasAl merged commit 77e516e into dev Dec 29, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant