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
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:
@@ -105,12 +105,11 @@ def checkpoint_for(
|
||||
floor; only a hit the corpus is confident about is allowed to stop
|
||||
anything.
|
||||
|
||||
2. IT IS A RULE, NEVER A PREFERENCE. A preference says how something has
|
||||
been done before and following it is what keeps work consistent; a rule
|
||||
says what happens if you do not. Stopping an act over a preference
|
||||
would assert a force the record explicitly does not claim, and
|
||||
`_rule_hint_line` already keeps that distinction in the one word that
|
||||
names it.
|
||||
2. IT IS A RULE DECLARED TO HOLD (`rule_order.holds`): `hold` or
|
||||
`enforce`, never `inform`, never a preference. A preference says how
|
||||
something has been done before; an `inform` rule asked to be put beside
|
||||
the work. Stopping an act over either would assert a force the record
|
||||
does not claim.
|
||||
|
||||
3. THE SESSION HAS NOT OPENED IT. `held` is observable — a PostToolUse
|
||||
hook watches for the `get_rule` call — so this is a recorded
|
||||
@@ -134,7 +133,7 @@ def checkpoint_for(
|
||||
score, rule = kept[0]
|
||||
if score < floor:
|
||||
return {}
|
||||
if getattr(rule, "kind", "") == "preference":
|
||||
if not rule_order.holds(rule):
|
||||
return {}
|
||||
if rule.id in held:
|
||||
return {}
|
||||
@@ -545,6 +544,12 @@ class RuleMoment:
|
||||
held: frozenset[int] = frozenset()
|
||||
"""Rules the session has OPENED."""
|
||||
|
||||
elsewhere: frozenset[int] = frozenset()
|
||||
"""Rules that arrive at an act — mounted on a moment a tool call reaches,
|
||||
or triggered by a tool, path or command — and so are not delivered here
|
||||
by resemblance. A reminder read at the act is the one acted on; the same
|
||||
line at the prompt competes with the request it came beside."""
|
||||
|
||||
|
||||
@dataclass
|
||||
class RuleResult:
|
||||
@@ -563,6 +568,11 @@ class RuleResult:
|
||||
|
||||
checkpoint: dict = field(default_factory=dict)
|
||||
|
||||
decision: dict = field(default_factory=dict)
|
||||
"""The moment arm's answer for the act itself, empty when the act goes
|
||||
ahead: `{"kind": "enforce" | "hold", "rule_ids", "reason"}`. See
|
||||
`act_decision`."""
|
||||
|
||||
line_rule_ids: list[int] = field(default_factory=list)
|
||||
"""The rule behind each of `lines`, in order, when a caller added lines
|
||||
of its own after the arm's; empty means `shown_rule_ids` lines up."""
|
||||
@@ -644,6 +654,8 @@ async def _ranked(
|
||||
# this done" asserts a force the record does not have.
|
||||
hits = [(score, rule) for score, rule in hits
|
||||
if getattr(rule, "kind", None) == kind]
|
||||
if moment.elsewhere:
|
||||
hits = [(score, rule) for score, rule in hits if rule.id not in moment.elsewhere]
|
||||
kept = _rule_band(hits) if band else hits
|
||||
# The gate is part of the cut, like the band: what it turns away is not
|
||||
# shown, so it is not in the row's results either.
|
||||
@@ -1749,11 +1761,16 @@ async def run_moment_arm(
|
||||
taken.add(rule.id)
|
||||
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.
|
||||
decision = act_decision(
|
||||
[(rule, at, where) for rule, at, where, _s in cands], held=moment.held,
|
||||
)
|
||||
gone = await _retired(io, moment, [rule for rule, _a, _w, _s in cands])
|
||||
if gone:
|
||||
cands = [c for c in cands if c[0].id not in gone]
|
||||
if not cands:
|
||||
return RuleResult()
|
||||
return RuleResult(decision=decision)
|
||||
# The one delivery order (services/rule_order.py), then the cap — so
|
||||
# what a crowded moment drops is the lowest-ranked, not the last
|
||||
# mounted. Ties keep catalog order.
|
||||
@@ -1798,7 +1815,83 @@ async def run_moment_arm(
|
||||
lines=lines, rule_ids=rule_ids,
|
||||
shown_rule_ids=[rule.id for rule, _at, _where in shown],
|
||||
shown=[(None, rule) for rule, _at, _where in shown],
|
||||
decision=decision,
|
||||
)
|
||||
except Exception: # noqa: BLE001 - a recall aid never breaks its act
|
||||
logger.debug("%s arm failed", MOMENT_RULE_SOURCE, exc_info=True)
|
||||
return RuleResult()
|
||||
|
||||
|
||||
def act_decision(reached: list[tuple], *, held: frozenset[int] = frozenset()) -> dict:
|
||||
"""What the act itself is told, from the rules its moments and triggers reached.
|
||||
|
||||
`reached` is `(rule, at, where)` for every rule the act reached, in any
|
||||
order. Sync and pure, so it can be read against a fixed list.
|
||||
|
||||
- A rule declared `enforce` REFUSES the act, every time it is reached:
|
||||
`{"kind": "enforce", ...}` with the rules' own words as the reason. It
|
||||
is a boundary the operator drew, and the act is the place it is drawn —
|
||||
reaching it by mount or trigger is a structural fact, never a
|
||||
resemblance. Opening the rule does not lift it; changing the rule does.
|
||||
- Otherwise the first rule declared `hold` that the session has not
|
||||
opened HOLDS the act for one read: `{"kind": "hold", ...}`. The client
|
||||
holds a rule once per session and caps holds per session, as at the act
|
||||
checkpoint.
|
||||
- Otherwise `{}`: the act goes ahead, with any lines beside it.
|
||||
|
||||
A preference never refuses or holds (`rule_order.force`).
|
||||
"""
|
||||
enforced = [item for item in reached if rule_order.force(item[0]) == "enforce"]
|
||||
if enforced:
|
||||
return {"kind": "enforce", "rule_ids": [rule.id for rule, _a, _w in enforced],
|
||||
"reason": enforce_reason(enforced)}
|
||||
for rule, at, where in reached:
|
||||
if rule_order.force(rule) == "hold" and rule.id not in held:
|
||||
return {"kind": "hold", "rule_ids": [rule.id],
|
||||
"reason": hold_reason(rule, at=at, where=where)}
|
||||
return {}
|
||||
|
||||
|
||||
def enforce_reason(enforced: list[tuple]) -> str:
|
||||
"""The text the agent reads instead of the act running, for an `enforce` rule.
|
||||
|
||||
Says which rule drew the line and where, gives its own words, and names
|
||||
who can move it: the operator, by changing the rule. A rule reached by
|
||||
the wrong act is a misfire the reader can record in one call.
|
||||
"""
|
||||
parts = []
|
||||
for rule, at, where in enforced:
|
||||
statement = _statement_excerpt(rule)
|
||||
parts.append(
|
||||
f"“{rule.title}” (Rule {rule.id}, {where})"
|
||||
+ (f": {statement}" if statement else "")
|
||||
)
|
||||
first_rule, first_at, _w = enforced[0]
|
||||
noun = "a rule" if len(enforced) == 1 else "rules"
|
||||
return (
|
||||
f"Not run: this act reaches {noun} the operator set to enforce. "
|
||||
+ " · ".join(parts)
|
||||
+ ". An enforced rule stops the act rather than sitting beside it, and "
|
||||
"opening it does not lift it. If the operator has asked for this act, "
|
||||
"tell them which rule stopped it: they lift it by changing the rule's "
|
||||
"enforcement or its trigger. If the rule has nothing to do with this "
|
||||
f"act, rule_misfired({first_rule.id}, \"{first_at}\", why) records that."
|
||||
)
|
||||
|
||||
|
||||
def hold_reason(rule, *, at: str, where: str) -> str:
|
||||
"""The text the agent reads instead of the act running, for a `hold` rule.
|
||||
|
||||
A practice on the act checkpoint's model: one read, then the act may be
|
||||
re-submitted unchanged.
|
||||
"""
|
||||
trigger = (getattr(rule, "when_to_apply", "") or "").strip()
|
||||
return (
|
||||
f"Held for one read. “{rule.title}” (Rule {rule.id}, {where}) is set to "
|
||||
f"hold the work it governs, and this session has not opened it"
|
||||
+ (f" — it applies when {trigger}" if trigger else "")
|
||||
+ f". Read it with get_rule({rule.id}), then re-submit this call — "
|
||||
"unchanged if the rule does not apply, which is a judgement only you "
|
||||
"can make. If it has nothing to do with this act, "
|
||||
f"rule_misfired({rule.id}, \"{at}\", why) records that."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user