feat(7731): enforced rules refuse the act, only hold rules hold, and the shape question rides the next prompt
CI & Build / TypeScript typecheck (push) Successful in 38s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m45s
CI & Build / integration (push) Successful in 2m10s
CI & Build / Build & push image (push) Skipped

- A rule set to enforce, reached by a mount or a trigger, refuses the tool
  call in its own words every time (`act_decision`, `/moment` returns
  `decision`, grimoire_moment.sh denies). Opening it does not lift it.
- A rule set to hold denies the call once until read, under the act
  checkpoint's per-rule and per-session guard; file writes are never held.
- The reply hold, the reply backstop and the act checkpoint hold only on rules
  declared hold or enforce (`rule_order.holds`). An inform rule is a line
  beside the work.
- The prompt arm leaves rules that arrive at an act (mounted on a non-reply
  moment, or with a tool/path/command trigger) to that act.
- The end-of-turn shape check no longer blocks: its note is kept for the next
  prompt, carried as `carry` into the one fitted payload, and the stop after
  that prompt records whether the lines were judged (noted /
  judged_after_note / left_after_note).
- Rule editor and list copy say what hold and enforce now do. Plugin
  2026.11.23.0005.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 00:22:56 -05:00
co-authored by Claude Opus 5.5
parent 6b4c24e336
commit 7d46ce0229
23 changed files with 644 additions and 170 deletions
+43 -7
View File
@@ -16,7 +16,7 @@ from __future__ import annotations
import logging
from grimoire.services import hook_payload, moment_actions, reply_shapes
from grimoire.services import hook_payload, moment_actions, reply_shapes, rule_order
from grimoire.services import retrieval_pipeline as rp
logger = logging.getLogger(__name__)
@@ -121,9 +121,43 @@ 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.
if result.decision.get("kind") == "hold" and moment_actions.tool_key(tool) in WRITE_TOOLS:
result.decision = {}
return reached, result
# The file-writing tools, as tool keys: a `hold` rule never holds these.
WRITE_TOOLS = frozenset({"write", "edit", "multiedit", "notebookedit"})
async def routed_to_acts(user_id: int, project_id: int | None = None) -> frozenset[int]:
"""The rules that arrive at an act, so the prompt arm leaves them there.
A rule mounted on a moment some action is mapped to (every moment but the
reply moments), or carrying a `tool`, `path` or `command` trigger, reaches
the session at the call it governs. Delivered at the prompt too, it would
arrive twice, and the first time beside a request it competes with. A
keyword trigger can also match a reply, so it does not count.
"""
from grimoire.services import rule_triggers, rulebooks
mappings = await moment_actions.list_mappings(user_id)
act_moments = sorted({
action.moment for action, _via in moment_actions.effective_actions(mappings)
if not action.moment.startswith("reply.")
})
out = {rule.id for rule, _at in await rulebooks.rules_on_moments(
user_id, act_moments, project_id or None,
)} if act_moments else set()
for rule, triggers in await rule_triggers._in_scope(user_id, project_id or None):
if any(t.kind in ("tool", "path", "command") and not t.moment for t in triggers):
out.add(rule.id)
return frozenset(out)
def shapes_for_act(reached: list[dict], seen: frozenset[str] = frozenset()) -> tuple[list[str], dict[str, str]]:
"""The default reply shapes riding the moments this act reached.
@@ -238,8 +272,8 @@ async def attach_moment_rules(
# your end" gets said — so it is checked twice over: the rules MOUNTED on the
# reply moments (deterministic, somebody said they belong here), and the
# reply text against every rule's trigger (the backstop for whatever the
# earlier arms missed). An unopened rule from either half HOLDS the reply for
# one read, in these words; the hook never holds the rewrite.
# earlier arms missed). An unopened rule set to hold, from either half, HOLDS
# the reply for one read, in these words; the hook never holds the rewrite.
# The reply's head and tail. The embedder reads ~512 tokens, and the part of
# a report that asks something of the reader — "let me know if it works" —
@@ -339,13 +373,15 @@ async def reply_hold(
room = pc.CHECKPOINT_SESSION_CAP - len(stopped)
out: list[dict] = []
# The mounted half: deterministic, so every unopened RULE on these
# moments holds. A preference claims no such force. A mount
# conditional on a trigger holds only when the reply meets it.
# The mounted half: deterministic, so every unopened rule on these
# moments that is declared to hold (`hold` or `enforce`) holds. An
# `inform` rule was put in front of the turn before the reply was
# written, and a preference claims no force. A mount conditional on
# a trigger holds only when the reply meets it.
board = await _board(user_id, project_id, text=reply)
gated = board.gated if board is not None else set()
for rule, at in await rulebooks.rules_on_moments(user_id, names, project_id or None):
if rule.id in skip or rule.kind == "preference" or (rule.id, at) in gated:
if rule.id in skip or not rule_order.holds(rule) or (rule.id, at) in gated:
continue
out.append({"rule_id": rule.id, "title": rule.title, "moment": at,
"trigger": (rule.when_to_apply or "").strip()})