From 6f0368e7703a5cb2c853f34b30fc53ba1da8081c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Mon, 23 Nov 2026 17:59:55 -0500 Subject: [PATCH] feat(7734): the instruction surfaces teach how strongly a rule arrives, what a held or refused call means, and what a quiet moment means - writing-records.md: a new section on declaring enforcement (inform, hold, enforce), the trigger a hold or refusal needs to name its act, and salience. A rule with an exit is a hold; a rule with triggers stops only the acts they match. - moments.md: a held call is read and made again (unchanged if the rule does not bear on it, with rule_misfired); a refused call is the operator's boundary and moves only when they change the rule; a moment sends a few lines in one order and drops the rest, so a quiet moment is not an empty rulebook. - The static context says a rule can hold or refuse a tool call. - create_rule, create_project_rule and update_rule describe enforce as a refusal every time that needs an act, and trigger-only holds. - The cross-project guard words a rule edit on another project as the operator's curation, naming the rule, and no longer suggests filing an issue in its place. _INSTRUCTIONS is at its 1,600-character cap and is left alone: holds and refusals explain themselves when they fire. The guidance ownership test registers the three new topics. Plugin 2026.11.23.2259. Co-Authored-By: Claude Opus 5.5 --- plugin/.claude-plugin/plugin.json | 2 +- plugin/hooks/grimoire_static_context.md | 4 +++ plugin/skills/using-grimoire/SKILL.md | 3 ++ plugin/skills/using-grimoire/moments.md | 18 +++++++++- .../skills/using-grimoire/writing-records.md | 30 +++++++++++++++++ src/grimoire/mcp/tools/rulebooks.py | 33 ++++++++++++++----- src/grimoire/services/write_scope.py | 20 +++++++++++ tests/test_guidance_ownership.py | 14 ++++++++ tests/test_write_scope.py | 13 ++++++++ 9 files changed, 126 insertions(+), 11 deletions(-) diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index d34c508d..97765afc 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -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), and syncs your saved Grimoire Processes as skills (/grimoire:sync).", - "version": "2026.11.23.2234", + "version": "2026.11.23.2259", "author": { "name": "Bryan Van Deusen" }, diff --git a/plugin/hooks/grimoire_static_context.md b/plugin/hooks/grimoire_static_context.md index 9bbae7ce..d8ebe413 100644 --- a/plugin/hooks/grimoire_static_context.md +++ b/plugin/hooks/grimoire_static_context.md @@ -20,6 +20,10 @@ What only Claude Code needs said: or the reply ending a turn reaches a moment of work, the rules mounted on it. Open the ones that apply; using-grimoire says what a quiet turn means and how to correct a moment that fired wrongly. +- **A rule can hold or refuse a tool call.** A held call names its rule and + goes ahead once the rule has been read: read it, then make the call again. + A refused call is a boundary the operator drew; it moves when they change + the rule, so tell them what the rule said. - **Compact at clean seams.** Because work is recorded as you go, a compaction is safe once in-flight state is logged. After finishing a block of work in a long session, log it to Grimoire, then tell the operator it's a good moment to diff --git a/plugin/skills/using-grimoire/SKILL.md b/plugin/skills/using-grimoire/SKILL.md index d066656b..1349ab70 100644 --- a/plugin/skills/using-grimoire/SKILL.md +++ b/plugin/skills/using-grimoire/SKILL.md @@ -283,6 +283,9 @@ bound — confine the session to it: `create_task(project_id=, kind="issue")` with how you found it and the evidence. Reading there is fine; editing its files, committing or pushing in its repo, or changing its records is the operator's call, and the plugin asks. + A rule that lives on another project is different: it is the operator's to + curate from any session, so the plugin names the rule and asks, and the + change goes ahead on their yes instead of becoming an issue. ## Read these when the moment comes diff --git a/plugin/skills/using-grimoire/moments.md b/plugin/skills/using-grimoire/moments.md index a84433a0..06db6425 100644 --- a/plugin/skills/using-grimoire/moments.md +++ b/plugin/skills/using-grimoire/moments.md @@ -7,7 +7,7 @@ proposes mounting or unmounting a rule. ## Contents - What a moment is -- Reading a line that arrived at a moment +- Reading a line that arrived at a moment — and a held or refused call - When the moment is wrong — correct it in the session - When a mounted rule arrives and does not apply - When a line proposes a mount — and how rules are weighed and measured @@ -41,6 +41,22 @@ The reply that ends a turn is a moment too. When a rule mounted at with its name: open it, then send the reply — unchanged, if it already does what the rule asks. The same rule is never held twice. +A call can be held the same way. A rule declared `hold` that the call reaches +stops it once, naming the rule: read it, then make the call again — unchanged +if the rule does not bear on it, and then `rule_misfired` says so. A rule +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. + +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 +how often it has been opened there. What did not fit was left out, and a +rule already shown this session comes back as a short reminder, then not at +all. So a quiet moment means nothing more needed saying there, not that no +rule applies — `what_might_apply` asks for the whole list. + ## When the moment is wrong — correct it in the session A moment can fire on an action that is not that moment here, or an action can diff --git a/plugin/skills/using-grimoire/writing-records.md b/plugin/skills/using-grimoire/writing-records.md index fa27a632..568883d8 100644 --- a/plugin/skills/using-grimoire/writing-records.md +++ b/plugin/skills/using-grimoire/writing-records.md @@ -10,6 +10,7 @@ decides how some area of the work must behave; and before filling ## Contents - Where a new rule goes — its home, its trigger, what already covers the moment - When it applies — the moments a rule, a preference or a process is for +- How strongly it arrives — enforcement, salience, and the act it governs - A ruling goes on the System it governs - A lesson grows each time it proves itself - A lesson names the rule it is an instance of @@ -57,6 +58,35 @@ names the moments the procedure is for, so loading it reaches them and the rules mounted there arrive with it. A rule that only applies inside one procedure mounts on that procedure's own moment, `skill.`. +## How strongly it arrives + +A rule that reaches the work says one of three things, and you declare which +(`enforcement` on `create_rule`, `create_project_rule`, `update_rule`): + +- **`inform`** — a line beside the work. The default, and right for most + rules: the session reads it and applies it. +- **`hold`** — the act or reply it governs waits until the session has read + the rule once; then it goes ahead. For a rule whose miss costs a rewrite: a + merge style, a release step, a check before a reply. +- **`enforce`** — the act is refused, in the rule's own words, every time, + and only a change to the rule moves it. For a boundary the operator draws + with no exceptions a session may judge. Most hard rules have an exit ("unless + the operator asks"), and a rule with an exit is a hold. + +A hold or a refusal stops an act, so give it the act: a `triggers` entry +naming the command head (`git push origin main`), the tool (`create_release`) +or the path (`alembic/versions/*.py`) it governs. A rule with triggers stops +only the acts they match; at the rest of its moments it is a line. Without +one, it stops every act its moment reaches — a rule about pushing to `main` +mounted on `work.deliver` would hold every push to `dev`. + +**`salience`** (`high`, `normal`, `low`) orders it against rules of the same +enforcement when a moment has more to say than fits. A moment sends a few +lines, highest first, and drops the rest — so `high` is for the rule that must +win a crowded moment, and `low` for one worth seeing but rarely decisive. + +A preference never holds or refuses: it arrives as a line, with a salience. + **Before writing one, ask what already covers that moment.** `what_might_apply("the moment you are about to write a record for")` — fifty candidates and no bar, so an existing record cannot hide under a threshold the diff --git a/src/grimoire/mcp/tools/rulebooks.py b/src/grimoire/mcp/tools/rulebooks.py index 1e91c99f..5d7758e0 100644 --- a/src/grimoire/mcp/tools/rulebooks.py +++ b/src/grimoire/mcp/tools/rulebooks.py @@ -535,9 +535,14 @@ async def create_rule( order_index: Display order within the topic (default 0). 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 for one read of it — for a rule whose miss - costs a rewrite. `enforce` checks the act itself — for a hard - boundary. Declare hold or enforce on purpose; most rules inform. + act it governs wait until the session has read the rule once + (file edits are never held) — 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 + an act to refuse. A rule with triggers holds or refuses only the + acts they match; reached by its mount alone it is a line. Declare + hold or enforce on purpose; most rules inform. triggers: What ACT this record applies to, checked exactly rather than by resemblance — a list of {kind, pattern, moment?}. Kinds: `tool` (a tool key, `*` allowed: "update_task"), `path` (a glob @@ -668,9 +673,14 @@ async def create_project_rule( order_index: Display order within the project's rule list (default 0). 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 for one read of it — for a rule whose miss - costs a rewrite. `enforce` checks the act itself — for a hard - boundary. Declare hold or enforce on purpose; most rules inform. + act it governs wait until the session has read the rule once + (file edits are never held) — 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 + an act to refuse. A rule with triggers holds or refuses only the + acts they match; reached by its mount alone it is a line. Declare + hold or enforce on purpose; most rules inform. triggers: What ACT this record applies to, checked exactly rather than by resemblance — a list of {kind, pattern, moment?}. Kinds: `tool` (a tool key, `*` allowed: "update_task"), `path` (a glob @@ -786,9 +796,14 @@ async def update_rule( clear_fields: Names of fields to empty, as above. 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 for one read of it — for a rule whose miss - costs a rewrite. `enforce` checks the act itself — for a hard - boundary. Declare hold or enforce on purpose; most rules inform. + act it governs wait until the session has read the rule once + (file edits are never held) — 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 + an act to refuse. A rule with triggers holds or refuses only the + acts they match; reached by its mount alone it is a line. Declare + hold or enforce on purpose; most rules inform. triggers: What ACT this record applies to, checked exactly rather than by resemblance — a list of {kind, pattern, moment?}. Kinds: `tool` (a tool key, `*` allowed: "update_task"), `path` (a glob diff --git a/src/grimoire/services/write_scope.py b/src/grimoire/services/write_scope.py index bbfe6b19..a7ef7917 100644 --- a/src/grimoire/services/write_scope.py +++ b/src/grimoire/services/write_scope.py @@ -188,6 +188,17 @@ READ_PREFIXES = ( ISSUE_STATUSES = frozenset({"", "todo"}) +# Curating a rule that lives on another project: editing, moving, verifying, +# relating or deleting it. A rule is the operator's standing instruction, not +# that project's work in progress, so the guard names the rule it changes and +# leaves the call to them rather than suggesting an issue in its place. +RULE_CURATION_TOOLS = frozenset({ + "update_rule", "update_preference", "delete_rule", "move_rule", + "mark_rule_verified", "relate_rules", "unrelate_rules", +}) +_RULE_ARGS = ("rule_id", "from_rule_id", "to_rule_id") + + def is_issue_filing(tool: str, args: dict) -> bool: """True for create_task(kind="issue") that opens a fresh, unplanned issue.""" if tool != "create_task": @@ -330,6 +341,15 @@ async def check_act( if tool and is_issue_filing(tool, args): return {"allowed": True, "targets": targets, "issue": True, "reason": ""} there = ", ".join(_named(p, titles) for p in others) + if tool in RULE_CURATION_TOOLS: + rules = sorted({r for name in _RULE_ARGS for r in _positive_ints(args.get(name))}) + which = ", ".join(f"rule {r}" for r in rules) or "a rule" + reason = ( + f"This session belongs to {_named(session_project, titles)}. {tool} changes " + f"{which} of {there}, a different project. Rules are the operator's to " + f"curate from any session: approve if they asked for this change." + ) + return {"allowed": False, "targets": targets, "issue": False, "reason": reason} what = act.strip() or (f"{tool} changes" if tool else "This changes") first = others[0] reason = ( diff --git a/tests/test_guidance_ownership.py b/tests/test_guidance_ownership.py index 0e2d893f..85e7d229 100644 --- a/tests/test_guidance_ownership.py +++ b/tests/test_guidance_ownership.py @@ -207,6 +207,20 @@ TOPICS: tuple[Topic, ...] = ( Topic("a mount that arrives where it does not apply is reported, and reports become the offer", U, ("rule_misfired",), "a rule you read and set aside leaves no trace anyone else can see"), + # How strongly a rule arrives (milestone 639). Declared while the rule is + # written (writing-records.md), and met as a held or refused call or a + # quiet moment (moments.md); the static context carries a short form for + # Claude Code, where a hook is what holds the call. + Topic("a rule declares how strongly it arrives: enforcement, salience, the act it governs", U, + ("enforcement", "salience", "triggers"), + "a rule with an exit is a hold", + shared_with=("docstrings",)), + Topic("a held call is read and made again; a refused call is the operator's boundary", U, + ("held", "refuses the call every time"), + "it moves only when they change the rule"), + Topic("a quiet moment is a budget, not an absence", U, + ("what_might_apply", "short reminder"), + "a quiet moment means nothing more needed saying there"), Topic("a missed when is mounted or mapped, not reworded", U, ("update_rule(moments=",), "first ask whether it missed a when or a what"), diff --git a/tests/test_write_scope.py b/tests/test_write_scope.py index 714bfc74..98677a62 100644 --- a/tests/test_write_scope.py +++ b/tests/test_write_scope.py @@ -152,6 +152,19 @@ async def test_a_write_in_another_project_asks_and_says_how_to_file_an_issue_ins assert 'create_task(project_id=9, kind="issue")' in out["reason"] +async def test_a_rule_edit_in_another_project_names_the_rule_and_suggests_no_issue(): + a, b, c = _patched({9}) + with a, b, c: + out = await check_act(1, 2, tool="update_rule", args={"rule_id": 130, "salience": "low"}) + assert out["allowed"] is False + assert "rule 130 of Elsewhere (project 9)" in out["reason"] + assert "create_task" not in out["reason"] + with a, b, c: + related = await check_act(1, 2, tool="relate_rules", + args={"from_rule_id": 4, "to_rule_id": 130, "kind": "overrides"}) + assert "rule 4, rule 130 of" in related["reason"] + + async def test_filing_an_issue_in_another_project_goes_ahead(): a, b, c = _patched({9}) with a, b, c: