fix(8816): a hold rule holds the first write to a file its own path trigger names
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 10s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Successful in 1m51s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Successful in 24s

A rule set to hold never held a file edit, so rule 198 (services run on
the orchestrator's defaults), even at hold, could only sit beside the
compose-file edit that broke it. The trigger board now names the rules
whose path trigger matched the act, and a write is held only for those:
a mount or a keyword alone still lets a write through. Tool descriptions
and the using-grimoire skill say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-05 22:17:30 -05:00
co-authored by Claude Opus 5.5
parent b67e621adc
commit 72ef1bb45d
7 changed files with 48 additions and 14 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "grimoire",
"description": "Grimoire for Claude Code: connects the grimoire MCP server, adds the hooks that deliver live project state and relevant records at the right moment, ships the shared client-neutral Grimoire skills (using-grimoire, writing-plans, reporting-back, systematic-debugging, verification, brainstorming, reusing-code, shape-accounting, family-canon, reviewing-tests), and syncs your saved Grimoire Processes as skills (/grimoire:sync).",
"version": "2026.12.04.1944",
"version": "2026.12.06.0317",
"author": {
"name": "Bryan Van Deusen"
},
+2 -1
View File
@@ -48,7 +48,8 @@ declared `enforce` refuses the call every time, in its own words: that is a
boundary the operator drew, and it moves only when they change the rule, so
tell them what you were doing and what the rule said. A rule with triggers of
its own holds or refuses only the acts those triggers match; at the rest of
its moments it arrives as a line.
its moments it arrives as a line. A file edit is held only by a rule whose
path trigger names that file.
A moment sends a few lines, not every rule mounted there: ordered by
enforcement, then salience, then how exactly the act reached the rule, then
+2 -1
View File
@@ -255,7 +255,8 @@ async def rules_to_weigh(limit: int = 25, offset: int = 0) -> dict:
- `enforcement`: `inform` is a line beside the work, and is right for
most rules. `hold` makes the act or reply wait until the rule has been
read once in the session (file edits are never held). `enforce` refuses
read once in the session (a file edit only through a path trigger
naming that file). `enforce` refuses
the act the rule governs, in the rule's own words, every time — for a
rule whose breach an act commits and that must never be crossed without
the operator (pushing to a protected branch, a destructive command). A
+3 -3
View File
@@ -553,7 +553,7 @@ async def create_rule(
enforcement: What this rule does when it arrives. `inform` (the
default) puts a line beside the work. `hold` makes the reply or
act it governs wait until the session has read the rule once
(file edits are never held) — for a rule whose miss costs a
(a file edit only through a path trigger naming that file) — for a rule whose miss costs a
rewrite. `enforce` refuses the act it governs, in the rule's own
words, every time — for a boundary only the operator moves; it
needs a trigger, or a mount on a moment an act reaches, to have
@@ -691,7 +691,7 @@ async def create_project_rule(
enforcement: What this rule does when it arrives. `inform` (the
default) puts a line beside the work. `hold` makes the reply or
act it governs wait until the session has read the rule once
(file edits are never held) — for a rule whose miss costs a
(a file edit only through a path trigger naming that file) — for a rule whose miss costs a
rewrite. `enforce` refuses the act it governs, in the rule's own
words, every time — for a boundary only the operator moves; it
needs a trigger, or a mount on a moment an act reaches, to have
@@ -814,7 +814,7 @@ async def update_rule(
enforcement: What this rule does when it arrives. `inform` (the
default for a new rule) puts a line beside the work. `hold` makes the reply or
act it governs wait until the session has read the rule once
(file edits are never held) — for a rule whose miss costs a
(a file edit only through a path trigger naming that file) — for a rule whose miss costs a
rewrite. `enforce` refuses the act it governs, in the rule's own
words, every time — for a boundary only the operator moves; it
needs a trigger, or a mount on a moment an act reaches, to have
+10 -5
View File
@@ -126,11 +126,15 @@ async def deliver_for_act(
result = await deliver_moments(
user_id, reached, project_id=project_id, exclude=exclude, held=held, board=board,
)
# A write is never held for a read: a recall aid does not stand in the
# way of the work. A rule set to enforce still refuses one — that is a
# boundary the operator drew, not a reminder.
# A write is held only by a rule whose own path trigger names the file:
# a rule about a kind of file, set to hold, is read before that file
# changes. Reached by a mount or a keyword alone, a write goes ahead, so a
# recall aid does not stand in the way of ordinary work. A rule set to
# enforce still refuses one. Rules & Governance carries this as a ruling.
if result.decision.get("kind") == "hold" and moment_actions.tool_key(tool) in WRITE_TOOLS:
result.decision = {}
holding = set(result.decision.get("rule_ids") or [])
if not (board is not None and holding & board.path_hits):
result.decision = {}
return reached, result
@@ -159,7 +163,8 @@ async def lessons_for_act(
return [lesson_situations.line(a) for a in arrivals], [a.lesson_id for a in arrivals]
# The file-writing tools, as tool keys: a `hold` rule never holds these.
# The file-writing tools, as tool keys: a `hold` rule holds these only through
# a path trigger that names the file.
WRITE_TOOLS = frozenset({"write", "edit", "multiedit", "notebookedit"})
+5
View File
@@ -250,12 +250,15 @@ class Board:
`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.
`path_hits` — rules with a `path` trigger, scoped or not, that names the
file this act touches: the only rules a hold may hold a write for.
"""
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)
path_hits: set[int] = field(default_factory=set)
async def board(
@@ -270,6 +273,8 @@ async def board(
first_unscoped = None
for trig in triggers:
hit = matches(trig, tool, tool_input, text)
if hit and trig.kind == PATH:
out.path_hits.add(rule.id)
if trig.moment:
pair = (rule.id, trig.moment)
if hit:
+25 -3
View File
@@ -563,23 +563,45 @@ async def test_an_inform_rule_and_a_preference_never_stop_the_act():
assert (await _arm(pairs)).decision == {}
async def _deliver_for(tool, decision):
async def _deliver_for(tool, decision, board=None):
from grimoire.services import moment_actions as ma
with patch.object(ma, "moments_for", AsyncMock(return_value=PUSH)), \
patch.object(md, "_board", AsyncMock(return_value=None)), \
patch.object(md, "_board", AsyncMock(return_value=board)), \
patch.object(md, "deliver_moments",
AsyncMock(return_value=rp.RuleResult(decision=dict(decision)))):
_reached, result = await _REAL_DELIVER(1, tool, {})
return result.decision
async def test_a_write_is_refused_by_an_enforced_rule_but_never_held():
async def test_a_write_is_refused_by_an_enforced_rule_and_held_only_through_a_path_trigger():
from grimoire.services.rule_triggers import Board
hold = {"kind": "hold", "rule_ids": [7], "reason": "read it"}
enforce = {"kind": "enforce", "rule_ids": [6], "reason": "not run"}
assert await _deliver_for("Edit", hold) == {}
assert await _deliver_for("Bash", hold) == hold
assert await _deliver_for("Write", enforce) == enforce
# Rule 7's own path trigger names the file: the write waits for one read.
assert await _deliver_for("Edit", hold, Board(path_hits={7})) == hold
# Another rule's path trigger matched; rule 7 reached the write otherwise.
assert await _deliver_for("Write", hold, Board(path_hits={8})) == {}
async def test_the_board_names_the_rules_a_path_trigger_matched(monkeypatch):
from grimoire.services import rule_triggers as rt
compose = fake_rule(id=198, title="defaults")
keyword = fake_rule(id=5, title="keyword only")
monkeypatch.setattr(rt, "_in_scope", AsyncMock(return_value=[
(compose, [rt.Trigger("keyword", "update_config"), rt.Trigger("path", "**/compose*.yml")]),
(keyword, [rt.Trigger("keyword", "update_config")]),
]))
edit = {"file_path": "/repo/deploy/compose.deploy.yml", "new_string": "update_config:"}
board = await rt.board(1, 2, tool="Edit", tool_input=edit)
assert board.path_hits == {198}
other = await rt.board(1, 2, tool="Edit", tool_input={**edit, "file_path": "/repo/README.md"})
assert other.path_hits == set()
def _decided(tmp_path, decision, session="s-decide"):