-
Notifications
You must be signed in to change notification settings - Fork 63
CM-62984 add codex cli support refactored #461
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c0bc036
CM-64678: refactor ai-guardrails to single-file-per-IDE abstraction
Ilanlido cdf856d
Merge remote-tracking branch 'origin/main' into CM-62984-add-codex-cl…
Ilanlido 2a42a9f
CM-62984: add Codex CLI support to ai-guardrails
Ilanlido 960a7c1
CM-62984: log file paths via %s + dict (codebase convention)
Ilanlido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Shared plugin-resolution helpers for IDE integrations. | ||
|
|
||
| Both Claude Code and Codex use the same ``<plugin>@<marketplace>`` key convention | ||
| and emit the same telemetry shape — only the marketplace layout and manifest | ||
| location differ. ``walk_enabled_plugins`` is the IDE-agnostic loop; each IDE | ||
| supplies the two callables that vary (``locate_dir`` + ``read_plugin``). | ||
| """ | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Any, Callable, Optional | ||
|
|
||
| from cycode.logger import get_logger | ||
|
|
||
| logger = get_logger('AI Guardrails Plugins') | ||
|
|
||
|
|
||
| def load_plugin_json(path: Path) -> Optional[dict]: | ||
| """Load a JSON file inside a plugin directory; None if missing or invalid.""" | ||
| if not path.exists(): | ||
| return None | ||
| try: | ||
| return json.loads(path.read_text(encoding='utf-8')) | ||
| except Exception as e: | ||
| logger.debug('Failed to load plugin file, %s', {'path': str(path)}, exc_info=e) | ||
| return None | ||
|
|
||
|
|
||
| def walk_enabled_plugins( | ||
| plugin_entries: dict[str, Any], | ||
| is_enabled: Callable[[Any], bool], | ||
| locate_dir: Callable[[str, str], Optional[Path]], | ||
| read_plugin: Callable[[Path], tuple[dict, dict]], | ||
| ) -> tuple[dict, dict]: | ||
| """Iterate enabled plugins; merge their MCP servers and metadata. | ||
|
|
||
| Args: | ||
| plugin_entries: ``{<plugin>@<marketplace>: settings}`` map from the IDE config. | ||
| is_enabled: returns True if ``settings`` indicates the plugin is on | ||
| (e.g. ``bool(settings)`` for Claude, ``settings.get('enabled')`` for Codex). | ||
| locate_dir: given ``(plugin_name, marketplace)``, returns the plugin's | ||
| filesystem path or None if it can't be resolved. | ||
| read_plugin: given the plugin path, returns ``(entry_fields, servers)``: | ||
| ``entry_fields`` are extra metadata to attach to the inventory entry | ||
| (name/version/description/...), ``servers`` are MCP servers contributed. | ||
|
|
||
| Returns ``(merged_mcp_servers, enriched_plugins)``. Plugin keys without | ||
| ``@`` (or that fail to resolve to a directory) still appear in the | ||
| inventory with just ``{'enabled': True}`` so we don't silently drop them. | ||
| """ | ||
| merged_mcp: dict = {} | ||
| enriched: dict = {} | ||
|
|
||
| for plugin_key, settings in plugin_entries.items(): | ||
| if not is_enabled(settings): | ||
| continue | ||
|
|
||
| entry: dict = {'enabled': True} | ||
| enriched[plugin_key] = entry | ||
|
|
||
| if '@' not in plugin_key: | ||
| continue | ||
| plugin_name, marketplace = plugin_key.split('@', 1) | ||
|
|
||
| plugin_dir = locate_dir(plugin_name, marketplace) | ||
| if plugin_dir is None: | ||
|
Ilanlido marked this conversation as resolved.
|
||
| continue | ||
|
|
||
| plugin_fields, servers = read_plugin(plugin_dir) | ||
| entry.update(plugin_fields) | ||
| merged_mcp.update(servers) | ||
|
|
||
| return merged_mcp, enriched | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.