diff --git a/frontend/src/components/WeightProposals.vue b/frontend/src/components/WeightProposals.vue
index cbb4863f..037fdd9c 100644
--- a/frontend/src/components/WeightProposals.vue
+++ b/frontend/src/components/WeightProposals.vue
@@ -99,7 +99,8 @@ onMounted(load);
Suggested from each rule's text and what happened when it reached sessions. Inform is a
line beside the work; hold makes the act or reply wait until the rule has been read once
(file edits are never held); enforce refuses the act it governs. A trigger reaches the
- rule exactly, by the tool, path, command or word the act carries.
+ rule exactly, by the tool, path, command or word the act carries; a rule with triggers
+ holds or refuses only the acts they match, and elsewhere it is a line.
-
diff --git a/src/grimoire/services/retrieval_pipeline.py b/src/grimoire/services/retrieval_pipeline.py
index 35db53f7..26ac82f4 100644
--- a/src/grimoire/services/retrieval_pipeline.py
+++ b/src/grimoire/services/retrieval_pipeline.py
@@ -1748,10 +1748,13 @@ async def run_moment_arm(
by_moment = {hit["moment"]: hit for hit in reached}
# (rule, at, where, specificity) for every candidate line.
cands = []
+ # A mounted rule whose unscoped trigger also matched this act was
+ # reached by its trigger: it ranks, and may stop the act, as one.
+ fired_ids = {rule.id for rule, _trig in fired}
for rule, at in pairs or []:
if board is not None and (rule.id, at) in board.gated:
continue
- met = board is not None and (rule.id, at) in board.matched
+ met = board is not None and ((rule.id, at) in board.matched or rule.id in fired_ids)
cands.append((rule, at, f"at {at}, reached by {_reached_by(by_moment.get(at, {}))}",
rule_order.BY_TRIGGER if met else rule_order.BY_MOUNT))
taken = {c[0].id for c in cands}
@@ -1762,9 +1765,16 @@ async def run_moment_arm(
cands.append((rule, trig.key, f"its trigger {trig.describe()} matched this act",
rule_order.BY_TRIGGER))
# Read before retirement: a rule that enforces does so on every act it
- # reaches, however often this session has been shown it.
+ # reaches, however often this session has been shown it. A rule with
+ # triggers of its own stops only an act one of them matched: its
+ # triggers name the acts it governs, and its moment is broader (a
+ # rule about pushing to `main` mounted on work.deliver would hold
+ # every push to `dev`). Reached by the mount alone, it is a line.
+ triggered = board.triggered if board is not None else set()
decision = act_decision(
- [(rule, at, where) for rule, at, where, _s in cands], held=moment.held,
+ [(rule, at, where) for rule, at, where, spec in cands
+ if spec == rule_order.BY_TRIGGER or rule.id not in triggered],
+ held=moment.held,
)
gone = await _retired(io, moment, [rule for rule, _a, _w, _s in cands])
if gone:
diff --git a/src/grimoire/services/rule_triggers.py b/src/grimoire/services/rule_triggers.py
index 6c2165e9..e70cceb6 100644
--- a/src/grimoire/services/rule_triggers.py
+++ b/src/grimoire/services/rule_triggers.py
@@ -247,11 +247,15 @@ class Board:
condition this act did not meet: not delivered. `matched` — conditional
mounts this act met: delivered as triggered. `fired` — rules an unscoped
trigger delivers on this act, each with the trigger that fired.
+ `triggered` — every in-scope rule that has a trigger at all, whether or
+ not this act met it: such a rule names the acts it governs, so a mount
+ alone shows it beside the work and only its trigger can stop an act.
"""
gated: set[tuple[int, str]] = field(default_factory=set)
matched: set[tuple[int, str]] = field(default_factory=set)
fired: list[tuple[object, Trigger]] = field(default_factory=list)
+ triggered: set[int] = field(default_factory=set)
async def board(
@@ -261,6 +265,8 @@ async def board(
"""Check every in-scope trigger against this act (or this text)."""
out = Board()
for rule, triggers in await _in_scope(user_id, project_id):
+ if triggers:
+ out.triggered.add(rule.id)
first_unscoped = None
for trig in triggers:
hit = matches(trig, tool, tool_input, text)
diff --git a/tests/test_rule_triggers.py b/tests/test_rule_triggers.py
index 1b2e0a91..83d8dc3c 100644
--- a/tests/test_rule_triggers.py
+++ b/tests/test_rule_triggers.py
@@ -148,5 +148,32 @@ async def test_a_rule_both_mounted_and_fired_is_delivered_once():
assert result.shown_rule_ids == [1]
+async def test_a_rule_with_triggers_stops_only_the_acts_they_match():
+ # Rule 2 holds pushes to main; mounted on work.deliver it reaches every
+ # push, and only its own trigger may make one wait.
+ guard = _r(2, enforcement="hold")
+ pairs = [(guard, "work.deliver")]
+ deliver = [{"moment": "work.deliver", "tool": "Bash", "match": "git push", "via": "default"}]
+ to_dev = rt.Board(triggered={2})
+ result = await _arm(pairs, to_dev, reached=deliver)
+ assert result.decision == {} and result.shown_rule_ids == [2]
+ to_main = rt.Board(triggered={2}, fired=[(guard, T("command", "git push origin main"))])
+ result = await _arm(pairs, to_main, reached=deliver)
+ assert result.decision["kind"] == "hold" and result.decision["rule_ids"] == [2]
+ # With no trigger of its own, the mount is all that says where it applies.
+ result = await _arm(pairs, rt.Board(), reached=deliver)
+ assert result.decision["kind"] == "hold"
+
+
+async def test_the_board_lists_every_rule_that_has_a_trigger(monkeypatch):
+ monkeypatch.setattr(rt, "_in_scope", AsyncMock(return_value=[
+ (_r(1), [T("path", "alembic/**", "work.change")]),
+ (_r(2), [T("command", "git push origin main")]),
+ (_r(3), []),
+ ]))
+ out = await rt.board(1, 2, tool="Bash", tool_input={"command": "ls"})
+ assert out.triggered == {1, 2}
+
+
def test_triggered_outranks_mounted_in_the_one_order():
assert rule_order.BY_TRIGGER > rule_order.BY_MOUNT > rule_order.BY_RESEMBLANCE