Repository navigation
Make background review toolsets configurable #45014
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,3 +237,91 @@ def close(self): | |
| f"disabled_toolsets mismatch: {captured.get('disabled_toolsets')!r} " | ||
| f"vs expected {agent.disabled_toolsets!r}" | ||
| ) | ||
|
|
||
|
|
||
| def test_default_config_keeps_background_review_toolsets_safe(): | ||
| """Background review defaults must preserve the existing memory+skills sandbox.""" | ||
| from hermes_cli.config import DEFAULT_CONFIG | ||
|
|
||
| assert DEFAULT_CONFIG["memory"]["review_toolsets"] == ["memory", "skills"] | ||
|
|
||
|
|
||
| def test_background_review_whitelist_uses_configured_review_toolsets(): | ||
| """Operators can opt review forks into deterministic persistence toolsets.""" | ||
| import run_agent | ||
|
|
||
| agent = _make_agent_stub(run_agent.AIAgent) | ||
| captured = {} | ||
| tool_def_calls = [] | ||
|
|
||
| class _Recorder: | ||
| def __init__(self, *args, **kwargs): | ||
| self._cached_system_prompt = None | ||
| self._memory_write_origin = None | ||
| self._memory_write_context = None | ||
| self._memory_store = None | ||
| self._memory_enabled = None | ||
| self._user_profile_enabled = None | ||
| self._memory_nudge_interval = None | ||
| self._skill_nudge_interval = None | ||
| self.suppress_status_output = None | ||
| self.session_start = None | ||
| self.session_id = None | ||
|
|
||
| def run_conversation(self, *args, **kwargs): | ||
| raise RuntimeError("stop after whitelist setup — don't call the API") | ||
|
|
||
| def shutdown_memory_provider(self): | ||
| pass | ||
|
|
||
| def close(self): | ||
| pass | ||
|
|
||
| def fake_get_tool_definitions(*, enabled_toolsets=None, quiet_mode=False, skip_tool_search_assembly=False, **kwargs): | ||
| tool_def_calls.append((list(enabled_toolsets or []), skip_tool_search_assembly)) | ||
| if list(enabled_toolsets or []) == ["memory", "skills", "mcp-gbrain"]: | ||
| # The raw pass includes the actual MCP persistence tool; the normal | ||
| # pass may collapse it behind Tool Search bridge tools. | ||
| if skip_tool_search_assembly: | ||
| return [ | ||
| {"type": "function", "function": {"name": "memory"}}, | ||
| {"type": "function", "function": {"name": "skill_manage"}}, | ||
| {"type": "function", "function": {"name": "mcp_gbrain_put_page"}}, | ||
| ] | ||
| return [ | ||
| {"type": "function", "function": {"name": "memory"}}, | ||
| {"type": "function", "function": {"name": "skill_manage"}}, | ||
| {"type": "function", "function": {"name": "tool_search"}}, | ||
| {"type": "function", "function": {"name": "tool_describe"}}, | ||
| {"type": "function", "function": {"name": "tool_call"}}, | ||
| ] | ||
| return [] | ||
|
|
||
| def fake_set_thread_tool_whitelist(allowed, deny_msg_fmt): | ||
| captured["allowed"] = set(allowed) | ||
| captured["deny_msg_fmt"] = deny_msg_fmt | ||
|
|
||
| with patch.object(run_agent, "AIAgent", _Recorder), \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking coverage gap: this test mocks schema resolution and stops before any tool dispatch. It cannot verify the claimed deferred MCP path, whose real executor scope comes from the inherited |
||
| patch("threading.Thread", _SyncThread), \ | ||
| patch("hermes_cli.config.load_config", return_value={ | ||
| "memory": {"review_toolsets": ["memory", "skills", "mcp-gbrain"]} | ||
| }), \ | ||
| patch("model_tools.get_tool_definitions", side_effect=fake_get_tool_definitions), \ | ||
| patch("hermes_cli.plugins.set_thread_tool_whitelist", side_effect=fake_set_thread_tool_whitelist): | ||
| agent._spawn_background_review( | ||
| messages_snapshot=[], | ||
| review_memory=True, | ||
| review_skills=True, | ||
| ) | ||
|
|
||
| assert (["memory", "skills", "mcp-gbrain"], True) in tool_def_calls | ||
| assert (["memory", "skills", "mcp-gbrain"], False) in tool_def_calls | ||
| assert captured["allowed"] == { | ||
| "memory", | ||
| "skill_manage", | ||
| "mcp_gbrain_put_page", | ||
| "tool_search", | ||
| "tool_describe", | ||
| "tool_call", | ||
| } | ||
| assert "configured background-review toolsets" in captured["deny_msg_fmt"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: this replaces main's current memory-disable gate (
agent/background_review.py:802-808, commit437dcacbb). Because the new default containsmemory, a profile with both_memory_enabledand_user_profile_enabledfalse will again whitelist the built-in memory tool. Compose the configured list with that existing gate instead of replacing it.