Skip to content

chore(refactor): improve maintability and API documentation#114

Open
slowy07 wants to merge 1 commit into
opengeos:mainfrom
slowy07:registry
Open

chore(refactor): improve maintability and API documentation#114
slowy07 wants to merge 1 commit into
opengeos:mainfrom
slowy07:registry

Conversation

@slowy07

@slowy07 slowy07 commented Jun 14, 2026

Copy link
Copy Markdown
Member

refactor GeoTool registry implementation to improve maintability clarity, and long-term scalability while preserving existing behaviour

  • Add cached package availability checks using lru_cache.
  • Add unregister() and require() registry operations

Summary by CodeRabbit

  • New Features

    • Tools now support explicit availability specifications for fast-mode and full-mode operations, improving context-aware tool selection.
  • Improvements

    • Enhanced tool confirmation requirement handling for more accurate user guidance.
    • More efficient tool registry and availability checking.

refactor GeoTool registry implementation to improve maintability
clarity, and long-term scalability while preserving existing behaviour

- Add cached package availability checks using lru_cache.
- Add unregister() and require() registry operations

Signed-off-by: slowy07 <slowy.arfy@proton.me>
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

geoagent/core/registry.py was refactored to expand GeoToolMeta with a needs_confirmation property and to_dict() serializer, rework GeoToolRegistry with a _tools dict and new query methods (unregister, require, exists, list_tools, get_tools_for_context, tool_requiring_confirmation), replace needs_user_confirmation, add a cached package_available() helper, and update collect_tools_for_context() to delegate to the registry.

Changes

GeoToolMeta & GeoToolRegistry API Refactor

Layer / File(s) Summary
GeoToolMeta properties and GeoToolRegistry refactor
geoagent/core/registry.py
Imports gain asdict, lru_cache, and importlib. GeoToolMeta adds needs_confirmation (derived from requires_confirmation, destructive, long_running) and to_dict(). GeoToolRegistry switches internal storage to a _tools dict; adds unregister, require, exists, list_tools, get_tools_for_context, and tool_requiring_confirmation; removes needs_user_confirmation. Registration rebuilds GeoToolMeta from provided meta including extra fields. Fast-mode filtering moves into get_tools_for_context using available_in and FAST_TOOL_FALLBACK.
Package availability caching and context collection
geoagent/core/registry.py
package_available() replaces the loop-based __import__ check and is cached via lru_cache; packages_available() delegates to it via all(). collect_tools_for_context() translates the fast boolean into a context string ("fast"/"full") and delegates filtering to registry.get_tools_for_context().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop, hop, the registry grew,
New methods and metas, shiny and new!
needs_confirmation? Check with a flair,
lru_cache keeps packages with care.
Context is "fast" or "full", never in doubt —
The bunny refactored everything out! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and overly broad, using non-descriptive terms like 'improve maintability' that don't convey the specific changes (refactored registry API, cached package checks, new methods). Consider a more specific title like 'refactor(registry): add context-aware tool filtering and unregister/require methods' to better communicate the key changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@geoagent/core/registry.py`:
- Around line 42-46: In the asdict serialization block, line 45 incorrectly
assigns the list of requires_packages to the requires_confirmation key, causing
the confirmation flag to be overwritten. Change the key on line 45 from
requires_confirmation to requires_packages so that data["requires_packages"] =
list(self.requires_packages) correctly serializes the packages field without
overwriting the confirmation flag.
- Around line 189-190: The condition at lines 189-190 in
geoagent/core/registry.py treats any context value that isn't exactly "fast" as
valid and returns all tool_objects, which is a "fail open" pattern. This means
typos like "Fast" or unknown context values will silently expose every tool
instead of being rejected. Replace the current `if context != "fast"` logic with
explicit validation that only accepts known valid context values (like "fast"
and "full") and raises an error for any unrecognized context, ensuring that
unknown or mistyped contexts fail explicitly rather than defaulting to exposing
all tools.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c3291f08-d0b1-47d8-b3ab-71a6a6b3cbcc

📥 Commits

Reviewing files that changed from the base of the PR and between 5e758b5 and 3a8b081.

📒 Files selected for processing (1)
  • geoagent/core/registry.py

Comment thread geoagent/core/registry.py
Comment on lines +42 to +46
data = asdict(self)

data["available_in"] = list(self.available_in)
data["requires_confirmation"] = list(self.requires_packages)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix the serializer key for requires_packages.

Line 45 currently overwrites requires_confirmation with the package list, so get_all_tools_config() emits the wrong schema and loses the actual confirmation flag for every tool.

🐛 Proposed fix
         data = asdict(self)

         data["available_in"] = list(self.available_in)
-        data["requires_confirmation"] = list(self.requires_packages)
+        data["requires_packages"] = list(self.requires_packages)

         return data
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@geoagent/core/registry.py` around lines 42 - 46, In the asdict serialization
block, line 45 incorrectly assigns the list of requires_packages to the
requires_confirmation key, causing the confirmation flag to be overwritten.
Change the key on line 45 from requires_confirmation to requires_packages so
that data["requires_packages"] = list(self.requires_packages) correctly
serializes the packages field without overwriting the confirmation flag.

Comment thread geoagent/core/registry.py
Comment on lines +189 to +190
if context != "fast":
return list(tool_objects)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reject unknown contexts instead of failing open.

Lines 189-190 treat anything except "fast" as "full". A typo like "Fast" or any future restricted context will silently expose every tool instead of preserving the filtered set.

🛡️ Proposed fix
-        if context != "fast":
+        if context == "full":
             return list(tool_objects)
+        if context != "fast":
+            raise ValueError(f"Unknown tool context '{context}'")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@geoagent/core/registry.py` around lines 189 - 190, The condition at lines
189-190 in geoagent/core/registry.py treats any context value that isn't exactly
"fast" as valid and returns all tool_objects, which is a "fail open" pattern.
This means typos like "Fast" or unknown context values will silently expose
every tool instead of being rejected. Replace the current `if context != "fast"`
logic with explicit validation that only accepts known valid context values
(like "fast" and "full") and raises an error for any unrecognized context,
ensuring that unknown or mistyped contexts fail explicitly rather than
defaulting to exposing all tools.

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.

1 participant