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

fix: track last_seen , add missing cli permission management scripts … #44

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Jan 5, 2025

…, fix broadcast permission

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced configuration with improved readability for encoding formats.
    • Added client admin status tracking.
    • Introduced last seen timestamp for clients.
    • New command-line tools for managing client message permissions.
  • Improvements

    • Updated broadcast message handling with admin checks.
    • More granular control over client message propagation and escalation.
  • Changes

    • Removed can_broadcast attribute from client connections.
    • Replaced previous listen command with a new implementation.

Copy link

coderabbitai bot commented Jan 5, 2025

Walkthrough

This pull request introduces enhancements to the HiveMind core system, focusing on configuration, protocol, and command-line interface modifications. The changes include reformatting the allowed_encodings in the configuration for improved readability, adding an is_admin attribute and a last_seen timestamp to client connections, and introducing new commands for managing client message permissions. These updates aim to provide more flexibility and control over client interactions within the HiveMind network.

Changes

File Change Summary
hivemind_core/config.py Reformatted allowed_encodings for readability; added module key to network_protocol, removing previous hivemind-http-plugin entries.
hivemind_core/protocol.py Added is_admin (default False) and last_seen (default -1) attributes to HiveMindClientConnection; removed can_broadcast attribute; added update_last_seen method to HiveMindListenerProtocol.
hivemind_core/scripts.py Added new CLI commands: listen, allow_escalate, blacklist_escalate, allow_propagate, blacklist_propagate.

Possibly related PRs

  • feat!: config file + dynamic plugins #30: The changes in the configuration file _DEFAULT dictionary and the introduction of a new structure for network protocols in the main PR relate directly to the enhancements proposed in this PR, which also focuses on configuration management and dynamic plugins.
  • feat:multiple_net_protos #46: This PR modifies the _DEFAULT configuration dictionary, specifically the allowed_encodings and network_protocol sections, which aligns with the changes made in the main PR regarding the same sections in the configuration file.

Suggested Labels

feature

Suggested Reviewers

  • goldyfruit

Poem

🐰 Hop, hop, encoding's new delight!
Permissions dance in rabbit's sight
Timestamps track each client's way
Admin powers now hold sway
HiveMind grows with playful might! 🌐


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5494393 and 1517019.

📒 Files selected for processing (3)
  • hivemind_core/config.py (2 hunks)
  • hivemind_core/protocol.py (5 hunks)
  • hivemind_core/scripts.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hivemind_core/config.py
🔇 Additional comments (8)
hivemind_core/scripts.py (5)

52-57: LGTM!

The function is well-structured and follows the single responsibility principle.


207-220: LGTM!

The function is well-implemented with proper database handling, user feedback, and error handling.


223-236: LGTM!

The function is well-implemented with proper database handling, user feedback, and error handling.


239-252: LGTM!

The function is well-implemented with proper database handling, user feedback, and error handling.


255-268: LGTM!

The function is well-implemented with proper database handling, user feedback, and error handling.

hivemind_core/protocol.py (3)

86-87: LGTM!

The new attributes are well-defined with appropriate type hints and default values.


290-296: LGTM!

The method is well-implemented with proper database handling and debug logging.


583-583: LGTM!

The permission check has been correctly updated to use the new is_admin attribute.


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.

@github-actions github-actions bot added fix and removed fix labels Jan 5, 2025
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: 1

🧹 Nitpick comments (9)
hivemind_core/scripts.py (8)

207-221: Consider abstracting repeated logic for can_escalate.
This command largely duplicates the pattern used in other “allow” commands. Factor out common logic if possible.


223-237: Consider refactoring repeated blacklist logic for can_escalate.
Again, this is almost identical to the “allow-escalate” counterpart. You could unify “allow”/“blacklist” toggling in a single helper function.


239-253: Same duplication pattern for can_propagate.
Centralizing allow/blacklist operations in a utility method might reduce code duplication and potential bugs.


255-269: Repeated code for blacklist-propagate.
The logic is practically identical to its “allow” counterpart. Please consider consolidating them.


Line range hint 273-289: Add input validation for skills and consider code reuse.
Although this effectively blocks skill usage, you might want stricter validation or a shared helper for blacklisting.


Line range hint 294-309: Symmetry with “blacklist-skill,” but no immediate issues.
Same repetition concerns apply. If you anticipate more management commands, unify them in a shared method.


Line range hint 314-329: Check for case sensitivity or input verification on intent IDs.
You might want to normalize or validate intent IDs (e.g. lowercasing) before blacklisting.


Line range hint 334-349: “allow-intent” logic is sound, but repetitive.
Further extraction to a helper would make this more maintainable.

hivemind_core/protocol.py (1)

86-87: New attributes for administration and last-seen tracking.
Adding is_admin and last_seen is straightforward. Consider persisting is_admin in the database if you need it to be durable across restarts.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 387ea72 and 5494393.

📒 Files selected for processing (3)
  • hivemind_core/config.py (1 hunks)
  • hivemind_core/protocol.py (5 hunks)
  • hivemind_core/scripts.py (3 hunks)
🔇 Additional comments (5)
hivemind_core/scripts.py (1)

170-171: No immediate concerns.
This section is just a heading comment, no issues found.

hivemind_core/protocol.py (4)

3-3: Time import is valid.
Used for last_seen functionality. No issues here.


290-295: Ensure update_last_seen handles non-existent users gracefully.
If a record for the given API key is missing, you might raise an exception or handle it differently.


410-411: Periodic last_seen updates look correct.
This ensures the timestamp reflects every message, which is helpful for active/inactive client tracking.


581-581: Broadcast now restricted to admins.
Replacing can_broadcast with is_admin enforces more centralized control. Looks good.

hivemind_core/config.py Outdated Show resolved Hide resolved
@github-actions github-actions bot added fix and removed fix labels Jan 5, 2025
@JarbasAl JarbasAl requested a review from goldyfruit January 5, 2025 20:54
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: 0

🧹 Nitpick comments (3)
hivemind_core/scripts.py (2)

170-172: Consolidate permission management code under one section.
The file organizes message permissions in a dedicated section. Consider grouping it in a single sub-module or helper class to reduce duplication and improve maintainability as the command set grows.


223-237: Blacklist-escalate command matches allow-escalate structure.
This mirrored approach keeps code consistent. However, consider deduplicating the shared logic (e.g., retrieving the user and toggling flags).

hivemind_core/protocol.py (1)

581-581: Admin-only broadcast enforcement.
Replacing the deprecated can_broadcast check with is_admin is a valid approach if the new requirement is to restrict broadcasting strictly to admins. However, if partial broadcast privileges are needed for other user classes, you might reintroduce a separate permission field.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 387ea72 and 5494393.

📒 Files selected for processing (3)
  • hivemind_core/config.py (1 hunks)
  • hivemind_core/protocol.py (5 hunks)
  • hivemind_core/scripts.py (3 hunks)
🔇 Additional comments (9)
hivemind_core/config.py (1)

12-16: Expansion of allowed encodings appears consistent.
Increasing the set of encodings is beneficial for flexibility. Test these new encodings throughout the system to ensure stability and compatibility with all permitted ciphers.

hivemind_core/scripts.py (4)

52-58: Server listen command looks good.
The listen command provides a clear and direct way to launch the HiveMind service. No issues here.


207-221: Allow-escalate command flows nicely.
The logic for enabling escalation permissions is straightforward and consistent with the existing pattern of reading the client from the database, modifying attributes, then persisting changes.


239-253: Allow-propagate logic aligns with existing patterns.
Everything looks consistent and straightforward.


255-269: Blacklist-propagate command is consistent.
Again, very similar structure to the other permission toggles, which is good for consistency.

hivemind_core/protocol.py (4)

3-3: Time import is used appropriately.
This import helps facilitate the last_seen updates.


86-87: New attributes for admin rights and last_seen.
Introducing is_admin and last_seen clarifies usage for broadcast privileges and tracking. Ensure that is_admin is thoroughly tested and reflected in the database if persistence is needed.


290-295: Updating last_seen in the client database.
This is beneficial for auditing and analytics. Confirm that frequent writes to the database do not degrade performance at scale.


410-411: Unobtrusive timestamp update.
Inserting update_last_seen at the end of handle_message ensures that every message refreshes the timestamp. This placement should reliably capture user activity.

@github-actions github-actions bot added fix and removed fix labels Jan 7, 2025
@JarbasAl JarbasAl merged commit d450f3d into dev Jan 7, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant