Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nomos/level_0/types/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions nomos/llm/council_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions nomos/nat/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
69 changes: 67 additions & 2 deletions tests/test_nat_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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"])
Expand Down
Loading