Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
perf(agent): trim workspace access context without changing scope
Xubin Rena27f294f5229
diff --git a/nanobot/agent/tools/runtime_control.py b/nanobot/agent/tools/runtime_control.pyindex 9c31d9a93..9929e47d1 100644--- a/nanobot/agent/tools/runtime_control.py+++ b/nanobot/agent/tools/runtime_control.py@@ -190,15 +190,15 @@ class AgentRuntimeControl:lines = [f"Current project (JSON path): {root}",(- "File access: limited to this project, plus tool-specific allowed paths."+ "File access: project and tool-specific allowed paths only."if status.restrict_to_workspace- else "File access: not restricted to this project."+ else "File access: no workspace restriction."),- "OS permissions and tool-specific rules still apply.",+ "OS permissions and tool rules still apply.",]if self.__target.exec_config.sandbox:lines.append(- "A shell sandbox is configured. Extra shell binds do not grant file-tool access."+ "Shell sandbox configured; extra binds do not grant file-tool access.")return RuntimeContextBlock(source="workspace_access", content=wrap_runtime_context_lines(lines))diff --git a/tests/agent/test_loop_consolidation_tokens.py b/tests/agent/test_loop_consolidation_tokens.pyindex 9ac350940..84cfd7050 100644--- a/tests/agent/test_loop_consolidation_tokens.py+++ b/tests/agent/test_loop_consolidation_tokens.py@@ -77,7 +77,7 @@ async def test_runner_pressure_commits_summary_and_current_delta(tmp_path) -> Noassert "Current checkpoint." in model_request[0]["content"]assert [message["role"] for message in model_request] == ["system", "user"]assert model_request[1]["content"].startswith("continue the task\n\n")- assert "File access: not restricted to this project." in model_request[1]["content"]+ assert "File access: no workspace restriction." in model_request[1]["content"]reloaded = loop.sessions.get_or_create("cli:test")assert reloaded.messages[0]["content"] == "old-user-0"@@ -133,7 +133,7 @@ async def test_ephemeral_runner_pressure_summarizes_without_persisting(tmp_path)model_request = loop.provider.chat_stream_with_retry.await_args_list[1].kwargs["messages"]assert "Transient checkpoint." in model_request[0]["content"]assert model_request[1]["content"].startswith("continue the task\n\n")- assert "File access: not restricted to this project." in model_request[1]["content"]+ assert "File access: no workspace restriction." in model_request[1]["content"]reloaded = loop.sessions.get_or_create("cli:ephemeral")assert reloaded.messages[: len(original_messages)] == original_messagesdiff --git a/tests/agent/tools/test_runtime_control.py b/tests/agent/tools/test_runtime_control.pyindex b89dc58ab..49d8ae84c 100644--- a/tests/agent/tools/test_runtime_control.py+++ b/tests/agent/tools/test_runtime_control.py@@ -403,7 +403,7 @@ async def test_workspace_inspection_reaches_model_from_selected_chat(tmp_path: Pfirst_messages = calls[0].kwargs["messages"]current = first_messages[-1]["content"]assert f"Current project (JSON path): {json.dumps(str(project.resolve()))}" in current- assert "File access: limited to this project" in current+ assert "File access: project and tool-specific allowed paths only." in currentassert calls[1].kwargs["messages"][:len(first_messages)] == first_messagesresults = {msg["tool_call_id"]: msg["content"] for msg in calls[1].kwargs["messages"]@@ -438,8 +438,8 @@ async def test_workspace_context_uses_request_scope_not_active_tool_scope(block = await control.workspace_context(RequestContext("websocket", "chat", workspace_scope=scope))assert json.dumps(str(scope.project_path)) in block.contentassert "old-project" not in block.content- assert ("File access: limited" in block.content) is restricted- assert ("shell sandbox is configured" in block.content) is bool(sandbox)+ assert ("File access: project and tool-specific allowed paths only." in block.content) is restricted+ assert ("Shell sandbox configured" in block.content) is bool(sandbox)assert "OS permissions" in block.contentassert "system-enforced" not in block.contentfinally:@@ -466,7 +466,7 @@ async def test_workspace_context_does_not_require_my_tool(tmp_path: Path) -> Nonprovider.chat_stream_with_retry = AsyncMock(return_value=LLMResponse(content="done"))await loop.process_direct("Read the current project", ephemeral=True)message = provider.chat_stream_with_retry.await_args.kwargs["messages"][-1]- assert "File access: not restricted to this project." in message["content"]+ assert "File access: no workspace restriction." in message["content"]@pytest.mark.asyncio@@ -489,8 +489,8 @@ async def test_access_changes_refresh_only_new_message_and_preserve_prefix(tmp_pfirst, second, third = [LLMProvider._sanitize_empty_content(call.kwargs["messages"]) for call in calls]# Access changes belong to the new request, not a rewrite of the cached history.assert json.dumps(second[:len(first)]) == json.dumps(first)- assert "File access: limited" in first[-1]["content"]- assert "File access: not restricted" in second[-1]["content"]+ assert "File access: project and tool-specific allowed paths only." in first[-1]["content"]+ assert "File access: no workspace restriction." in second[-1]["content"]assert json.dumps(str(other.resolve())) in third[-1]["content"]assert json.dumps(str(project.resolve())) not in third[-1]["content"]assert all(call.kwargs["tools"] == calls[0].kwargs["tools"] for call in calls)@@ -531,7 +531,7 @@ async def test_injected_channel_input_reports_active_tool_scope(tmp_path: Path)calls = loop.provider.chat_stream_with_retry.await_args_listcontext = calls[0].kwargs["messages"][-1]["content"]assert json.dumps(str(project.resolve())) in context- assert "File access: limited" in context+ assert "File access: project and tool-specific allowed paths only." in contextassert any(message.get("role") == "tool" and "active project" in message["content"]for message in calls[1].kwargs["messages"])@@ -594,7 +594,7 @@ async def test_workspace_context_compaction_reuses_serialized_prefix(await loop.process_direct("Check again", session_key=session.key)current = provider.chat_stream_with_retry.await_args.kwargs["messages"][-1]["content"]assert current.count("Current project (JSON path):") == 1- assert "File access: not restricted to this project." in current+ assert "File access: no workspace restriction." in current@pytest.mark.asynciodiff --git a/tests/command/test_compact_command.py b/tests/command/test_compact_command.pyindex b62767342..a6cc36e21 100644--- a/tests/command/test_compact_command.py+++ b/tests/command/test_compact_command.py@@ -141,7 +141,7 @@ async def test_compacted_session_waits_for_new_input_without_continuation(}assert [message["role"] for message in sent] == ["system", "user"]assert sent[1]["content"].startswith("hi\n\n")- assert "File access: not restricted to this project." in sent[1]["content"]+ assert "File access: no workspace restriction." in sent[1]["content"]loop.sessions.invalidate(key)resumed = loop.sessions.get_or_create(key)