acgs-haystack 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. acgs_haystack-0.2.0/CHANGELOG.md +41 -0
  2. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/PKG-INFO +36 -3
  3. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/README.md +34 -1
  4. acgs_haystack-0.2.0/examples/deny_and_audit.py +73 -0
  5. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/pyproject.toml +2 -2
  6. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/src/haystack_integrations/hooks/acgs/_governance.py +19 -11
  7. acgs_haystack-0.2.0/tests/test_compatibility.py +28 -0
  8. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/test_examples.py +33 -0
  9. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/test_governance.py +48 -0
  10. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/test_strategy.py +9 -0
  11. acgs_haystack-0.1.0/CHANGELOG.md +0 -18
  12. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/.gitignore +0 -0
  13. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/LICENSE +0 -0
  14. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/examples/quickstart.py +0 -0
  15. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/src/haystack_integrations/hooks/acgs/__init__.py +0 -0
  16. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/src/haystack_integrations/hooks/acgs/py.typed +0 -0
  17. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/src/haystack_integrations/hooks/acgs/strategy.py +0 -0
  18. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/__init__.py +0 -0
  19. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/conftest.py +0 -0
  20. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/fakes.py +0 -0
  21. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/test_agent.py +0 -0
  22. {acgs_haystack-0.1.0 → acgs_haystack-0.2.0}/tests/test_default_constitution.py +0 -0
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## 0.2.0 (2026-11-20)
10
+
11
+ ### Added
12
+
13
+ - Offline `examples/deny_and_audit.py`: one allowed and one denied Haystack tool call, with an application
14
+ decision trail.
15
+ - Compatibility coverage for nested JSON-native arguments and bytes/bytearray formatting with acgs-lite 4.0.0.
16
+
17
+ ### Changed
18
+
19
+ - Document the compatibility matrix: the default/test Hatch environments resolve acgs-lite 4.0.0, and the CI
20
+ `test-min` job tests the 3.0.1 floor. Runtime support remains `acgs-lite>=3.0.1,<5`.
21
+ - Clarify that the adapter validates formatted text and does not issue signed receipts.
22
+
23
+ ## [0.1.1] - 2026-10-20
24
+
25
+ ### Fixed
26
+
27
+ - When a blocking rule and a review rule both match a tool call, the denial reason now lists only the blocking
28
+ rules after "Blocked by" and names the matched review rules separately ("Review rules that also matched: ...").
29
+ Previously the review rule was also listed under "Blocked by". The verdict was already `deny` and is unchanged;
30
+ `rule_ids` still contains every matched rule.
31
+
32
+ ## [0.1.0] - 2026-10-19
33
+
34
+ ### Added
35
+
36
+ - `ACGSConfirmationStrategy`, a Haystack Human-in-the-Loop `ConfirmationStrategy` for use with the native
37
+ `ConfirmationHook` at the `before_tool` hook point.
38
+ - `format_tool_call`, the documented text representation of a tool call that ACGS rules are evaluated against.
39
+ - Fail-closed handling: errors during evaluation or review reject the tool call.
40
+ - Optional `review_strategy` for rules that require human review; modified parameters are evaluated again.
41
+ - `to_dict` / `from_dict` serialization.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: acgs-haystack
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: ACGS rule-based tool-call governance for the Haystack Agent before_tool hook
5
5
  Project-URL: Documentation, https://github.com/acgs-ai/acgs-haystack#readme
6
6
  Project-URL: Issues, https://github.com/acgs-ai/acgs-haystack/issues
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: >=3.11
22
- Requires-Dist: acgs-lite<4,>=3.0.1
22
+ Requires-Dist: acgs-lite<5,>=3.0.1
23
23
  Requires-Dist: haystack-ai>=3.0.0
24
24
  Description-Content-Type: text/markdown
25
25
 
@@ -52,7 +52,38 @@ its tools, or the chat generator.
52
52
  pip install acgs-haystack
53
53
  ```
54
54
 
55
- Requires Python 3.11+, `haystack-ai>=3.0.0` and `acgs-lite>=3.0.1`.
55
+ Requires Python 3.11+, `haystack-ai>=3.0.0` and `acgs-lite>=3.0.1,<5`.
56
+
57
+ ### Compatibility
58
+
59
+ | Component | Supported range | 0.2.0 validation |
60
+ |---|---|---|
61
+ | acgs-lite | `>=3.0.1,<5` | 4.0.0 tested in the default/test Hatch environments (latest allowed); 3.0.1 floor tested by the CI `test-min` job |
62
+ | Haystack | `>=3.0.0` | 3.5.0 in the default/test environments; 3.0.0 in `test-min` |
63
+ | Python | `>=3.11` | CI tests Python 3.11, 3.12 and 3.13 |
64
+
65
+ This project uses Hatch environments and has no lockfile. The adapter formats arguments as text and calls
66
+ `GovernanceEngine.validate`. It does not select the production authorization profile or issue signed receipts.
67
+ Bytes and bytearray arguments remain scalar text for rule matching.
68
+
69
+ acgs-lite 4 is a major release. Its production profile of `GovernedCallable` requires an Ed25519
70
+ receipt signer, governed payloads are JSON-only, and `GovernedAgent` no longer passes per-call keyword arguments to
71
+ rule conditions (see the [acgs-lite changelog](https://github.com/acgs-ai/acgs-lite/blob/main/CHANGELOG.md)). This
72
+ adapter works with both majors, but a fresh environment installs the newest version allowed. To stay on 3.x, also
73
+ require `"acgs-lite<4"`, for example `pip install acgs-haystack "acgs-lite<4"`.
74
+
75
+ ### Offline deny-and-audit example
76
+
77
+ Run [examples/deny_and_audit.py](examples/deny_and_audit.py) without an API key:
78
+
79
+ ```console
80
+ hatch run python examples/deny_and_audit.py
81
+ ```
82
+
83
+ A scripted chat generator requests one allowed note and one denied note through the Haystack Agent's
84
+ `ConfirmationHook`. Only the allowed tool executes, then the example prints both decisions with tool name,
85
+ verdict, reason and rule IDs. This application trail omits argument values and stays in memory; it is not a signed
86
+ receipt or a durable engine audit log. Haystack telemetry is disabled before importing the framework.
56
87
 
57
88
  ## Usage
58
89
 
@@ -170,6 +201,8 @@ not checked by an ACGS strategy registered under `"*"`.
170
201
  | Any exception while formatting, validating, or reviewing | reject (fail-closed) |
171
202
 
172
203
  A matched blocking rule is never downgraded to review because a review rule matched as well.
204
+ The denial reason then lists only the blocking rules after "Blocked by" and names the matched review
205
+ rules separately.
173
206
 
174
207
  `ACGSConfirmationStrategy.evaluate(tool_name, params)` returns the underlying `GovernanceDecision`
175
208
  (`verdict`, `reason`, `rule_ids`, `warning_rule_ids`, `error`) without running anything.
@@ -27,7 +27,38 @@ its tools, or the chat generator.
27
27
  pip install acgs-haystack
28
28
  ```
29
29
 
30
- Requires Python 3.11+, `haystack-ai>=3.0.0` and `acgs-lite>=3.0.1`.
30
+ Requires Python 3.11+, `haystack-ai>=3.0.0` and `acgs-lite>=3.0.1,<5`.
31
+
32
+ ### Compatibility
33
+
34
+ | Component | Supported range | 0.2.0 validation |
35
+ |---|---|---|
36
+ | acgs-lite | `>=3.0.1,<5` | 4.0.0 tested in the default/test Hatch environments (latest allowed); 3.0.1 floor tested by the CI `test-min` job |
37
+ | Haystack | `>=3.0.0` | 3.5.0 in the default/test environments; 3.0.0 in `test-min` |
38
+ | Python | `>=3.11` | CI tests Python 3.11, 3.12 and 3.13 |
39
+
40
+ This project uses Hatch environments and has no lockfile. The adapter formats arguments as text and calls
41
+ `GovernanceEngine.validate`. It does not select the production authorization profile or issue signed receipts.
42
+ Bytes and bytearray arguments remain scalar text for rule matching.
43
+
44
+ acgs-lite 4 is a major release. Its production profile of `GovernedCallable` requires an Ed25519
45
+ receipt signer, governed payloads are JSON-only, and `GovernedAgent` no longer passes per-call keyword arguments to
46
+ rule conditions (see the [acgs-lite changelog](https://github.com/acgs-ai/acgs-lite/blob/main/CHANGELOG.md)). This
47
+ adapter works with both majors, but a fresh environment installs the newest version allowed. To stay on 3.x, also
48
+ require `"acgs-lite<4"`, for example `pip install acgs-haystack "acgs-lite<4"`.
49
+
50
+ ### Offline deny-and-audit example
51
+
52
+ Run [examples/deny_and_audit.py](examples/deny_and_audit.py) without an API key:
53
+
54
+ ```console
55
+ hatch run python examples/deny_and_audit.py
56
+ ```
57
+
58
+ A scripted chat generator requests one allowed note and one denied note through the Haystack Agent's
59
+ `ConfirmationHook`. Only the allowed tool executes, then the example prints both decisions with tool name,
60
+ verdict, reason and rule IDs. This application trail omits argument values and stays in memory; it is not a signed
61
+ receipt or a durable engine audit log. Haystack telemetry is disabled before importing the framework.
31
62
 
32
63
  ## Usage
33
64
 
@@ -145,6 +176,8 @@ not checked by an ACGS strategy registered under `"*"`.
145
176
  | Any exception while formatting, validating, or reviewing | reject (fail-closed) |
146
177
 
147
178
  A matched blocking rule is never downgraded to review because a review rule matched as well.
179
+ The denial reason then lists only the blocking rules after "Blocked by" and names the matched review
180
+ rules separately.
148
181
 
149
182
  `ACGSConfirmationStrategy.evaluate(tool_name, params)` returns the underlying `GovernanceDecision`
150
183
  (`verdict`, `reason`, `rule_ids`, `warning_rule_ids`, `error`) without running anything.
@@ -0,0 +1,73 @@
1
+ """Run one allowed and one denied Haystack tool call offline, then print a decision trail."""
2
+
3
+ import json
4
+ import os
5
+ from dataclasses import asdict
6
+ from typing import Annotated, Any
7
+
8
+ # Disable telemetry before importing Haystack; the scripted generator uses no model service.
9
+ os.environ["HAYSTACK_TELEMETRY_ENABLED"] = "False"
10
+
11
+ from haystack import component
12
+ from haystack.components.agents import Agent
13
+ from haystack.dataclasses import ChatMessage, ToolCall
14
+ from haystack.hooks.human_in_the_loop import ConfirmationHook
15
+ from haystack.tools import tool
16
+
17
+ from haystack_integrations.hooks.acgs import ACGSConfirmationStrategy, GovernanceDecision
18
+
19
+
20
+ class AuditedStrategy(ACGSConfirmationStrategy):
21
+ """Collect decisions through the public API without retaining argument values."""
22
+
23
+ def __init__(self) -> None:
24
+ super().__init__()
25
+ self.decisions: list[GovernanceDecision] = []
26
+
27
+ def evaluate(self, tool_name: str, tool_params: dict[str, Any]) -> GovernanceDecision:
28
+ decision = super().evaluate(tool_name, tool_params)
29
+ self.decisions.append(decision)
30
+ return decision
31
+
32
+
33
+ @component
34
+ class ScriptedChatGenerator:
35
+ """Request two prewritten tool calls, then finish without a network request."""
36
+
37
+ def __init__(self) -> None:
38
+ self.step = 0
39
+
40
+ @component.output_types(replies=list[ChatMessage])
41
+ def run(self, messages: list[ChatMessage], tools: Any = None, **kwargs: Any) -> dict[str, Any]:
42
+ self.step += 1
43
+ if self.step > 1:
44
+ return {"replies": [ChatMessage.from_assistant("Done.")]}
45
+ calls = [
46
+ ToolCall(id=f"note-{index}", tool_name="record_note", arguments={"body": body})
47
+ for index, body in enumerate(["The meeting starts at noon.", "The admin password is demo-secret."])
48
+ ]
49
+ return {"replies": [ChatMessage.from_assistant(tool_calls=calls)]}
50
+
51
+
52
+ @tool
53
+ def record_note(body: Annotated[str, "Message body"]) -> str:
54
+ """Record a demo note by printing it locally."""
55
+ print(f"Executed record_note: {body}")
56
+ return "Note recorded."
57
+
58
+
59
+ def main() -> None:
60
+ strategy = AuditedStrategy()
61
+ agent = Agent(
62
+ chat_generator=ScriptedChatGenerator(),
63
+ tools=[record_note],
64
+ hooks={"before_tool": [ConfirmationHook(confirmation_strategies={"*": strategy})]},
65
+ )
66
+ agent.run(messages=[ChatMessage.from_user("Record the two notes.")])
67
+ print("Audit trail (application decisions):")
68
+ for decision in strategy.decisions:
69
+ print(json.dumps(asdict(decision), sort_keys=True))
70
+
71
+
72
+ if __name__ == "__main__":
73
+ main()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "acgs-haystack"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "ACGS rule-based tool-call governance for the Haystack Agent before_tool hook"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -22,7 +22,7 @@ classifiers = [
22
22
  "Programming Language :: Python :: Implementation :: CPython",
23
23
  "Typing :: Typed",
24
24
  ]
25
- dependencies = ["haystack-ai>=3.0.0", "acgs-lite>=3.0.1,<4"]
25
+ dependencies = ["haystack-ai>=3.0.0", "acgs-lite>=3.0.1,<5"]
26
26
 
27
27
  [project.urls]
28
28
  Documentation = "https://github.com/acgs-ai/acgs-haystack#readme"
@@ -69,6 +69,7 @@ class GovernanceDecision:
69
69
  :param verdict: The verdict the adapter maps to a native framework decision.
70
70
  :param tool_name: Name of the evaluated tool.
71
71
  :param reason: Human-readable explanation. It names matched rules but never includes argument values.
72
+ For ``DENY`` it starts with ``Blocked by`` followed by the blocking rules only.
72
73
  :param rule_ids: IDs of the blocking or review rules that matched, in match order.
73
74
  :param warning_rule_ids: IDs of non-blocking (warn) rules that matched.
74
75
  :param error: Set when the verdict is ``DENY`` because evaluation itself failed.
@@ -182,7 +183,9 @@ class ToolCallGovernor:
182
183
  - anything else (``block``, ``block_and_notify``, ``halt_and_alert``, a rule ID that is not in
183
184
  the constitution, an unknown action, or an invalid result without violations): ``DENY``.
184
185
 
185
- A blocking rule is never downgraded to ``REVIEW`` because a review rule matched as well.
186
+ A blocking rule is never downgraded to ``REVIEW`` because a review rule matched as well. In
187
+ that case the reason names only the blocking rules after ``Blocked by`` and lists the matched
188
+ review rules separately; ``rule_ids`` still contains every matched rule in match order.
186
189
  Any exception raised while formatting or validating also yields ``DENY``.
187
190
  """
188
191
 
@@ -268,29 +271,34 @@ class ToolCallGovernor:
268
271
  reason="ACGS reported the call as invalid without naming a rule.",
269
272
  warning_rule_ids=warnings,
270
273
  )
271
- actions = [self._workflow_action(rule_id) for rule_id in rule_ids]
272
- details = "; ".join(self._describe(rule_id) for rule_id in rule_ids)
273
- if all(action in _REVIEW_ACTIONS for action in actions):
274
+ review_ids = tuple(rule_id for rule_id in rule_ids if self._workflow_action(rule_id) in _REVIEW_ACTIONS)
275
+ blocking_ids = tuple(rule_id for rule_id in rule_ids if rule_id not in review_ids)
276
+ if not blocking_ids:
274
277
  return GovernanceDecision(
275
278
  verdict=Verdict.REVIEW,
276
279
  tool_name=tool_name,
277
- reason=f"Human review required by {details}.",
280
+ reason=f"Human review required by {self._describe(review_ids)}.",
278
281
  rule_ids=rule_ids,
279
282
  warning_rule_ids=warnings,
280
283
  )
284
+ reason = f"Blocked by {self._describe(blocking_ids)}."
285
+ if review_ids:
286
+ reason += f" Review rules that also matched: {self._describe(review_ids)}."
281
287
  return GovernanceDecision(
282
288
  verdict=Verdict.DENY,
283
289
  tool_name=tool_name,
284
- reason=f"Blocked by {details}.",
290
+ reason=reason,
285
291
  rule_ids=rule_ids,
286
292
  warning_rule_ids=warnings,
287
293
  )
288
294
 
289
- def _describe(self, rule_id: str) -> str:
290
- rule = self._rules.get(rule_id)
291
- if rule is None:
292
- return f"ACGS rule {rule_id}"
293
- return f"ACGS rule {rule_id} ({rule.text})"
295
+ def _describe(self, rule_ids: Sequence[str]) -> str:
296
+ """Join ``ACGS rule <id> (<text>)`` descriptions for ``rule_ids``; unknown IDs have no text."""
297
+ parts = []
298
+ for rule_id in rule_ids:
299
+ rule = self._rules.get(rule_id)
300
+ parts.append(f"ACGS rule {rule_id}" if rule is None else f"ACGS rule {rule_id} ({rule.text})")
301
+ return "; ".join(parts)
294
302
 
295
303
  @staticmethod
296
304
  def _log(decision: GovernanceDecision) -> None:
@@ -0,0 +1,28 @@
1
+ """Regression checks for the adapter boundary with acgs-lite 4.x and the 3.0.1 floor."""
2
+
3
+ from typing import Any
4
+
5
+ import pytest
6
+
7
+ from haystack_integrations.hooks.acgs import ACGSConfirmationStrategy, Verdict, format_tool_call
8
+
9
+
10
+ @pytest.mark.parametrize("binary_type", [bytes, bytearray])
11
+ def test_binary_arguments_remain_scalar_and_match_rules(binary_type: Any) -> None:
12
+ arguments = {"items": [{"body": binary_type(b"password")}]}
13
+ rendered = format_tool_call("record_note", arguments)
14
+ assert "items[0].body: " in rendered
15
+ assert "password" in rendered
16
+ assert "body[0]" not in rendered
17
+ decision = ACGSConfirmationStrategy().evaluate("record_note", arguments)
18
+ assert decision.verdict is Verdict.DENY
19
+ assert decision.error is None
20
+ assert "ACGS-006" in decision.rule_ids
21
+
22
+
23
+ @pytest.mark.parametrize("body", ["Meeting at noon", "password"])
24
+ def test_nested_json_arguments_with_default_unsigned_configuration(body: str) -> None:
25
+ arguments: dict[str, Any] = {"items": [{"body": body, "values": [None, True, False, 7, 1.5, {}, []]}]}
26
+ decision = ACGSConfirmationStrategy().evaluate("record_note", arguments)
27
+ assert decision.verdict is (Verdict.DENY if body == "password" else Verdict.ALLOW)
28
+ assert decision.error is None
@@ -5,9 +5,13 @@
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ import json
9
+ import os
8
10
  import runpy
11
+ import socket
9
12
  import textwrap
10
13
  from pathlib import Path
14
+ from typing import Any
11
15
 
12
16
  import pytest
13
17
 
@@ -29,6 +33,35 @@ def test_quickstart_example_runs(capsys: pytest.CaptureFixture[str]) -> None:
29
33
  assert "ACGS-006" in out
30
34
 
31
35
 
36
+ def test_deny_and_audit_runs_offline_without_api_keys(
37
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
38
+ ) -> None:
39
+ for key in list(os.environ):
40
+ if key.endswith("API_KEY"):
41
+ monkeypatch.delenv(key)
42
+ # Register the example's environment change so monkeypatch restores the original value.
43
+ monkeypatch.setenv("HAYSTACK_TELEMETRY_ENABLED", "False")
44
+
45
+ def no_network(*args: Any, **kwargs: Any) -> None:
46
+ pytest.fail("The offline example attempted a network connection")
47
+
48
+ monkeypatch.setattr(socket.socket, "connect", no_network)
49
+ monkeypatch.setattr(socket.socket, "connect_ex", no_network)
50
+ monkeypatch.setattr(socket, "create_connection", no_network)
51
+ runpy.run_path(str(ROOT / "examples" / "deny_and_audit.py"), run_name="__main__")
52
+ output = capsys.readouterr().out
53
+ execution, audit = output.split("Audit trail (application decisions):\n")
54
+ assert execution == "Executed record_note: The meeting starts at noon.\n"
55
+ decisions = [json.loads(line) for line in audit.splitlines()]
56
+ assert [decision["verdict"] for decision in decisions] == ["allow", "deny"]
57
+ assert [decision["tool_name"] for decision in decisions] == ["record_note", "record_note"]
58
+ assert decisions[0]["rule_ids"] == []
59
+ assert decisions[1]["rule_ids"] == ["ACGS-006"]
60
+ assert "Blocked by" in decisions[1]["reason"]
61
+ assert all(decision["error"] is None for decision in decisions)
62
+ assert "demo-secret" not in output
63
+
64
+
32
65
  def _python_blocks(markdown: str) -> list[str]:
33
66
  blocks, current, inside = [], [], False
34
67
  for line in markdown.splitlines():
@@ -160,6 +160,37 @@ class TestVerdictMapping:
160
160
  assert decision.verdict is Verdict.DENY
161
161
  assert set(decision.rule_ids) == {"T-REVIEW", "T-BLOCK"}
162
162
 
163
+ def test_mixed_match_names_only_blocking_rules_under_blocked_by(self, governor: ToolCallGovernor) -> None:
164
+ # Regression (0.1.0): the review rule was listed under "Blocked by" next to the blocking rule.
165
+ decision = governor.evaluate("t", {"a": "refund and delete everything"})
166
+ assert decision.reason == (
167
+ "Blocked by ACGS rule T-BLOCK (no deletes). "
168
+ "Review rules that also matched: ACGS rule T-REVIEW (refunds need review)."
169
+ )
170
+
171
+ def test_mixed_match_with_several_rules_of_each_kind(self, governor: ToolCallGovernor) -> None:
172
+ decision = governor.evaluate("t", {"a": "wire transfer refund, exfiltrate, then delete everything"})
173
+ assert decision.verdict is Verdict.DENY
174
+ blocked, _, review = decision.reason.partition(" Review rules that also matched: ")
175
+ assert blocked.startswith("Blocked by ")
176
+ assert "T-BLOCK" in blocked
177
+ assert "T-NOTIFY" in blocked
178
+ assert "T-REVIEW" not in blocked
179
+ assert "T-ESCALATE" not in blocked
180
+ assert "T-REVIEW" in review
181
+ assert "T-ESCALATE" in review
182
+ assert "T-BLOCK" not in review
183
+ assert "T-NOTIFY" not in review
184
+ assert set(decision.rule_ids) == {"T-BLOCK", "T-NOTIFY", "T-REVIEW", "T-ESCALATE"}
185
+
186
+ def test_block_only_reason_has_no_review_section(self, governor: ToolCallGovernor) -> None:
187
+ decision = governor.evaluate("t", {"a": "delete everything"})
188
+ assert decision.reason == "Blocked by ACGS rule T-BLOCK (no deletes)."
189
+
190
+ def test_review_only_reason(self, governor: ToolCallGovernor) -> None:
191
+ decision = governor.evaluate("t", {"a": "refund order 7"})
192
+ assert decision.reason == "Human review required by ACGS rule T-REVIEW (refunds need review)."
193
+
163
194
  def test_default_constitution_is_used_when_none_given(self) -> None:
164
195
  governor = ToolCallGovernor(agent_id="x")
165
196
  assert governor.constitution.hash == Constitution.default().hash
@@ -216,6 +247,23 @@ class TestFailClosed:
216
247
  decision = governor.evaluate("t", {})
217
248
  assert decision.verdict is Verdict.DENY
218
249
  assert decision.rule_ids == ("NOT-IN-CONSTITUTION",)
250
+ assert decision.reason == "Blocked by ACGS rule NOT-IN-CONSTITUTION."
251
+
252
+ def test_unknown_rule_id_next_to_review_rule_is_listed_as_blocking(self, monkeypatch: pytest.MonkeyPatch) -> None:
253
+ governor = ToolCallGovernor(ALL_RULES, agent_id="t")
254
+ violations = [
255
+ Violation("T-REVIEW", "refunds need review", Severity.HIGH, "x", "custom"),
256
+ Violation("NOT-IN-CONSTITUTION", "x", Severity.HIGH, "x", "custom"),
257
+ ]
258
+ result = ValidationResult(valid=False, constitutional_hash=ALL_RULES.hash, violations=violations)
259
+ monkeypatch.setattr(governor._engine, "validate", lambda *_a, **_k: result)
260
+ decision = governor.evaluate("t", {})
261
+ assert decision.verdict is Verdict.DENY
262
+ assert decision.rule_ids == ("T-REVIEW", "NOT-IN-CONSTITUTION")
263
+ assert decision.reason == (
264
+ "Blocked by ACGS rule NOT-IN-CONSTITUTION. "
265
+ "Review rules that also matched: ACGS rule T-REVIEW (refunds need review)."
266
+ )
219
267
 
220
268
  def test_invalid_result_without_violations_denies(self, monkeypatch: pytest.MonkeyPatch) -> None:
221
269
  governor = ToolCallGovernor(ALL_RULES, agent_id="t")
@@ -161,6 +161,15 @@ class TestFailClosed:
161
161
  strategy = ACGSConfirmationStrategy(constitution=CONSTITUTION, review_strategy=RaisingStrategy()) # type: ignore[arg-type]
162
162
  assert _run(strategy, {"action": "refund and delete everything"}).execute is False
163
163
 
164
+ def test_mixed_match_feedback_names_only_the_blocking_rule_as_blocking(self) -> None:
165
+ # Regression (0.1.0): the review rule was listed under "Blocked by" next to the blocking rule.
166
+ decision = _run(ACGSConfirmationStrategy(constitution=CONSTITUTION), {"action": "refund and delete everything"})
167
+ assert decision.execute is False
168
+ assert decision.feedback == (
169
+ "Tool call 'payments' was not executed. Blocked by ACGS rule T-BLOCK (no deletes). "
170
+ "Review rules that also matched: ACGS rule T-REVIEW (refunds need review)."
171
+ )
172
+
164
173
 
165
174
  class TestAsync:
166
175
  async def test_allow_and_deny(self) -> None:
@@ -1,18 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project are documented in this file.
4
- The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
- [Semantic Versioning](https://semver.org/).
6
-
7
- ## [Unreleased]
8
-
9
- ## [0.1.0] - Unreleased
10
-
11
- ### Added
12
-
13
- - `ACGSConfirmationStrategy`, a Haystack Human-in-the-Loop `ConfirmationStrategy` for use with the native
14
- `ConfirmationHook` at the `before_tool` hook point.
15
- - `format_tool_call`, the documented text representation of a tool call that ACGS rules are evaluated against.
16
- - Fail-closed handling: errors during evaluation or review reject the tool call.
17
- - Optional `review_strategy` for rules that require human review; modified parameters are evaluated again.
18
- - `to_dict` / `from_dict` serialization.
File without changes
File without changes