From 3f06757411a95ceffeadfad90dc446ad423e9a78 Mon Sep 17 00:00:00 2001 From: Hsin Chen Date: Tue, 24 Nov 2026 16:24:58 -0800 Subject: [PATCH] fix(council): omit generated shell descriptions from review prompts NOMOS-106 --- nomos/level_0/types/intent.py | 2 + nomos/llm/council_agent.py | 5 ++- nomos/nat/functions.py | 2 + tests/test_nat_functions.py | 69 ++++++++++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/nomos/level_0/types/intent.py b/nomos/level_0/types/intent.py index 4f29715d..b18e674b 100644 --- a/nomos/level_0/types/intent.py +++ b/nomos/level_0/types/intent.py @@ -161,6 +161,8 @@ class Intent(BaseModel): # Exact business arguments are needed only while the Council reviews this # request. The durable Intent and signed writ carry the derived operation. _tool_review_material: ToolCallRequest | None = PrivateAttr(default=None) + # Shell authorization records fallback provenance for Council prompt rendering. + _shell_description_generated: bool = PrivateAttr(default=False) # Set only by the council service from its own system one call. The chairman and the # read-only fast path read it here, never from agent-reachable fields. _attestation: AttestationVector | None = PrivateAttr(default=None) diff --git a/nomos/llm/council_agent.py b/nomos/llm/council_agent.py index 7b51b4d7..c4d931ec 100644 --- a/nomos/llm/council_agent.py +++ b/nomos/llm/council_agent.py @@ -369,9 +369,10 @@ def _format_intent_for_review(intent: Intent) -> str: f"**Intent ID:** {intent.intent_id}", f"**Agent:** {intent.agent_id}", f"**Action Type:** {intent.action_type}", - f"**Description:** {intent.description}", - f"**Target Resource:** {intent.target_resource}", ] + if not (intent.command and intent._shell_description_generated): + parts.append(f"**Description:** {intent.description}") + parts.append(f"**Target Resource:** {intent.target_resource}") if intent.command: parts.append("\n## Command") diff --git a/nomos/nat/functions.py b/nomos/nat/functions.py index 44da147c..20608bd9 100644 --- a/nomos/nat/functions.py +++ b/nomos/nat/functions.py @@ -4496,6 +4496,8 @@ async def _authorize( # Keep exact business arguments in process only for this # review; the durable Intent and writ use the derived digest. intent._tool_review_material = input_data.tool_call + elif not input_data.description: + intent._shell_description_generated = True except Exception as e: _stage(stages, tool, "intent_build", stage_start) _stage(stages, tool, "total", total_start) diff --git a/tests/test_nat_functions.py b/tests/test_nat_functions.py index 82e60e6a..878ea4a2 100644 --- a/tests/test_nat_functions.py +++ b/tests/test_nat_functions.py @@ -1002,6 +1002,46 @@ async def test_check_writ_status_rejects_non_owner(self): class TestCouncilServiceWithAgents: """Tests for CouncilService with mock LLM agents.""" + @pytest.mark.asyncio + @pytest.mark.parametrize("description_source", ["omitted", "empty", "explicit-fallback-text"]) + async def test_shell_authorization_renders_only_requester_description( + self, tmp_path, description_source + ): + service = _make_service_with_mock_agents(["approve"], council_key_path=str(tmp_path)) + reviewer = RecordingLLMBackend() + service._agents[0]._backend = reviewer + service._opa_client = AsyncMock() + service._opa_client.evaluate.return_value = OPAPolicyDecision(allow=True) + command = "/bin/echo " + "review-marker " * 8 + "final-argument" + fallback = f"Execute: {command[:80]}" + justification = "Check the shell authorization prompt." + description_arg = { + "omitted": {}, + "empty": {"description": ""}, + "explicit-fallback-text": {"description": fallback}, + }[description_source] + + result = await service.authorize( + AuthorizeInput( + agent_id="agent-1", + command=command, + working_directory="/tmp", + justification=justification, + **description_arg, + ) + ) + + assert result.status == "approved", result.error + assert service._opa_client.evaluate.await_args.args[0]["intent"]["description"] == fallback + prompt = reviewer.calls[0][1].content + description_lines = [ + line for line in prompt.splitlines() if line.startswith("**Description:** ") + ] + description = description_arg.get("description") + assert description_lines == ([f"**Description:** {description}"] if description else []) + assert f"```\n{command}\n```" in prompt + assert f"## Justification\n{justification}" in prompt + @pytest.mark.asyncio @pytest.mark.parametrize( "target", @@ -1111,7 +1151,10 @@ def test_old_shell_request_preserves_writ_digest(self): assert _compute_intent_hash(intent) == baseline_digest @pytest.mark.asyncio - async def test_structured_tool_authorization_reviews_args_and_mints_typed_writ(self): + @pytest.mark.parametrize("description", ["", "Send a requested Slack message"]) + async def test_structured_tool_authorization_reviews_args_and_mints_typed_writ( + self, description + ): from nomos.auth.writ_factory import WritFactory from nomos.crypto.signer_provider import InMemorySigner from nomos.level_0.crypto.signing import KeyPair @@ -1126,7 +1169,7 @@ async def test_structured_tool_authorization_reviews_args_and_mints_typed_writ(s AuthorizeInput( council_id=service.council_id, agent_id="app-service", - description="Send a requested Slack message", + description=description, justification="The user requested this external write", tool_call={ "schema_version": 1, @@ -1155,8 +1198,30 @@ async def test_structured_tool_authorization_reviews_args_and_mints_typed_writ(s == hashlib.sha256(expected_arguments).hexdigest() ) prompt = recording_backend.calls[0][1].content + expected_description = description or "Authorize structured tool call: slack.send_message" + assert f"**Description:** {expected_description}" in prompt.splitlines() assert '"arguments":{"channel":"C123","message":"review this exact text"}' in prompt + @pytest.mark.asyncio + async def test_shell_proposal_renders_requester_description(self): + service = _make_service_with_mock_agents(["approve"]) + reviewer = RecordingLLMBackend() + service._agents[0]._backend = reviewer + description = "Execute: /bin/echo hello" + + result = await service.propose_intent( + ProposeIntentInput( + agent_id="agent-1", + command="/bin/echo hello", + description=description, + target_resource="/tmp", + justification="Check the proposed shell intent prompt.", + ) + ) + + assert result.success + assert f"**Description:** {description}" in reviewer.calls[0][1].content.splitlines() + @pytest.mark.asyncio async def test_unanimous_approve(self): service = _make_service_with_mock_agents(["approve", "approve"])