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
+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), and syncs your saved Grimoire Processes as skills (/grimoire:sync).",
"version": "2026.11.23.0004",
"version": "2026.11.23.0005",
"author": {
"name": "Bryan Van Deusen"
},
+3 -3
View File
@@ -15,7 +15,7 @@ another one means adding files, not moving or rewriting any.
|---|---|---|
| **The skills** | `plugin/skills/*/SKILL.md` | Agent Skills (the open SKILL.md format). They state every Grimoire reflex in full and name no client. `tests/test_guidance_ownership.py` fails if a skill names a particular client, or references anything outside its own folder. Every client package ships this folder verbatim. |
| **The MCP server** | `<base URL>/mcp` | HTTP, `Authorization: Bearer <fmcp_ key>`. Its `_INSTRUCTIONS` is a client-neutral orientation — the workflow across tools (≤1,600 chars); each tool's description carries its contract; in-band responses (`placement`, `report_back`, `systems_hint`, the duplicate gate, the guessed-id refusal) fire in every client. |
| **The adapter API** | `<base URL>/api/plugin/*` | Endpoints any client's hooks can call with the same key. `GET`, so read scope is enough: `context` (live session state), `retrieve` (rules, preferences and notes for a message), `prior-art` (records and shape-ledger hints for code being written), `tool-rules` (rules for a command about to run), `moment-tools` (which tools reach a mounted moment), `shape-check` (definitions written this turn that nobody has judged), `claim-session` / `release-session` (task claims), `write-scope` (which project a pending write lands in, and whether this session may make it), `processes` (stored Processes to expose as skills). `POST`, so write scope: `moment` (rules mounted on the moments a tool call reaches), `rule-opened` (a rule was read), `reply-rules` (the finished reply, held for an unopened rule or — when the turn closed a task — for missing completion sections). |
| **The adapter API** | `<base URL>/api/plugin/*` | Endpoints any client's hooks can call with the same key. `GET`, so read scope is enough: `context` (live session state), `retrieve` (rules, preferences and notes for a message), `prior-art` (records and shape-ledger hints for code being written), `tool-rules` (rules for a command about to run), `moment-tools` (which tools reach a mounted moment), `shape-check` (definitions written this turn that nobody has judged), `claim-session` / `release-session` (task claims), `write-scope` (which project a pending write lands in, and whether this session may make it), `processes` (stored Processes to expose as skills). `POST`, so write scope: `moment` (rules mounted on the moments a tool call reaches), `rule-opened` (a rule was read), `reply-rules` (the finished reply, held for an unopened rule set to hold or — when the turn closed a task — for missing completion sections). |
| **The API key** | Grimoire → Settings → MCP Access | One `fmcp_` key per install. Write scope covers the MCP tools and every hook; a read key runs only the `GET` hooks. |
## Added by each client
@@ -40,9 +40,9 @@ another one means adding files, not moving or rewriting any.
| `hooks/grimoire_after_write.sh` | PostToolUse on shell commands: the same check for code written through the shell. |
| `hooks/grimoire_tool_rules.sh` | PreToolUse on shell commands: `GET /api/plugin/tool-rules`. |
| `hooks/grimoire_project_fence.sh` | PreToolUse on editor writes, shell commands and Grimoire's tools: `GET /api/plugin/write-scope` for an act aimed at another project, answered `ask` with the reason; PostToolUse on `enter_project` remembers the project a session without one entered. |
| `hooks/grimoire_moment.sh` | PreToolUse on every tool: the rules mounted on the moments the call reaches, `POST /api/plugin/moment`; skips tools `GET /api/plugin/moment-tools` says reach nothing mounted, and Grimoire's own (their responses carry `moment_rules`). |
| `hooks/grimoire_moment.sh` | PreToolUse on every tool: the rules mounted on the moments the call reaches, `POST /api/plugin/moment`; skips tools `GET /api/plugin/moment-tools` says reach nothing mounted, and Grimoire's own (their responses carry `moment_rules`). Denies the call when the response's `decision` is `enforce` (every time) or `hold` (once per rule and session). |
| `hooks/grimoire_reply_check.sh` | Stop: sends the finished reply to `POST /api/plugin/reply-rules` — the rules mounted on the reply moments, and the reply against every rule's trigger, and — when the turn closed a task — the completion-section check; holds once per rule, with the reason the server returns, and never holds the rewrite. |
| `hooks/grimoire_shape_check.sh` | Stop: sends the definitions the turn wrote (the write hooks' `<sid>.written.ids` ledger) to `GET /api/plugin/shape-check`; blocks once, with the reason the server returns, so the agent judges what it built. |
| `hooks/grimoire_shape_check.sh` | Stop: sends the definitions the turn wrote (the write hooks' `<sid>.written.ids` ledger) to `GET /api/plugin/shape-check` and keeps the `note` it returns for the next prompt, which `grimoire_autoinject.sh` carries as `carry`, so the agent judges what it built. Never blocks. |
| `hooks/grimoire_record_opened.sh` | PostToolUse on `get_rule`: notes the rule as read in the session ledger and `POST /api/plugin/rule-opened`. |
| `hooks/grimoire_record_outcome.sh` | PostToolUse on `rule_outcome`: notes the rule as acted on, locally, for the session-scoped readout. |
| `hooks/grimoire_claim_session.sh` | PostToolUse on `update_task` / `add_task_log`: `GET /api/plugin/claim-session`, so the task comes back after a compaction. |
+11 -7
View File
@@ -97,7 +97,9 @@ On install you'll be asked for:
→ `POST /api/plugin/moment`: the rules mounted on the moments the call
reaches. It skips tools that `GET /api/plugin/moment-tools` says reach
nothing mounted, and Grimoire's own tools, whose responses carry
`moment_rules`.
`moment_rules`. A rule set to enforce refuses the call (every time it is
reached); one set to hold denies it once until it has been read, never on a
file edit.
- `hooks/hooks.json` → PostToolUse hooks on Grimoire's `get_rule`,
`rule_outcome`, `update_task` and `add_task_log`: they keep the session's
ledgers of rules opened and acted on (`get_rule` also reports to
@@ -115,7 +117,8 @@ On install you'll be asked for:
duplicate arm and the outage line are shared in `hooks/grimoire_defs.sh`.
- `hooks/hooks.json` → Stop hook (`hooks/grimoire_reply_check.sh`): sends the
reply that ends the turn to `POST /api/plugin/reply-rules`, which holds it
once for an unopened rule mounted on the reply moments or matching the reply.
once for an unopened rule set to hold (or enforce) that is mounted on the
reply moments or matches the reply. A rule set to inform never holds it.
When the turn closed a Grimoire task (`update_task`/`create_task` with status
done), the same request has the server check the reply for the completion
sections — where the work sits, what needs you, what comes next. If they are
@@ -127,11 +130,12 @@ On install you'll be asked for:
write hooks note every definition a write names (and every new file) in a
session ledger; at the end of the turn this sends them to
`GET /api/plugin/shape-check`, which answers with the ones nobody has judged.
If any are, it blocks once with the server's reason, asking the agent that
wrote them to say what each is — reusable (record a snippet), an instance or
variant of one, or a one-off — in one `classify_shapes` call. Same discipline
as the report check: never twice, never without a recorded check. Outcomes
land under category `plugin`, action `shape_check`.
If any are, the server's note rides the next prompt (the prompt hook sends it
as `carry`), asking the agent that wrote them to say what each is — reusable
(record a snippet), an instance or variant of one, or a one-off — in one
`classify_shapes` call. It never holds the reply; the stop after that prompt
records whether the lines were judged. Outcomes land under category
`plugin`, action `shape_check`.
- `skills/` → the universal process-skills, surfaced by description match.
- `hooks/grimoire_sync_processes.sh` (a 2nd SessionStart hook) + the `/grimoire:sync`
command → generate `~/.claude/skills/grimoire-proc-*` stubs from your Grimoire
+15 -1
View File
@@ -134,10 +134,24 @@ if [ -n "$session_id" ]; then
[ -n "$shapes_seen" ] && exclude_q="${exclude_q}&shapes_seen=${shapes_seen}"
fi
# What the last stop left for this prompt: the definitions its turn wrote
# that nobody has judged (grimoire_shape_check.sh). Carried to the server, which
# fits it into the one payload, and removed once the server has answered.
carry_q=""
carry_file=""
if [ -n "$session_id" ]; then
carry_file="${TMPDIR:-/tmp}/grimoire-shapecheck/${safe_sid}.note"
if [ -s "$carry_file" ]; then
carry_enc=$(head -c 2000 "$carry_file" 2>/dev/null | grimoire_urlenc) || carry_enc=""
[ -n "$carry_enc" ] && carry_q="&carry=${carry_enc}"
fi
fi
body=$(curl -fsS --max-time 5 \
-H "Authorization: Bearer ${token}" \
"${url%/}/api/plugin/retrieve?q=${q_enc}${ctx_q}${repo_q}${exclude_q}" 2>/dev/null) || exit 0
"${url%/}/api/plugin/retrieve?q=${q_enc}${ctx_q}${repo_q}${exclude_q}${carry_q}" 2>/dev/null) || exit 0
[ -n "$body" ] || exit 0
[ -n "$carry_q" ] && rm -f "$carry_file" 2>/dev/null
body_flat=$(printf '%s' "$body" | grimoire_json_flat)
context=$(grimoire_json_pick "$body_flat" '.context')
+30 -1
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# Grimoire — PreToolUse moment arm: rules MOUNTED on a moment arrive when the
# moment happens.
# moment happens — beside the act, or, for a rule set to enforce or hold, in
# front of it.
#
# The other PreToolUse arms search: they turn the act into a query and hope a
# rule's words resemble it. A mount needs no resemblance. The operator said
@@ -148,6 +149,34 @@ body_flat=$(printf '%s' "$body" | grimoire_json_flat)
grimoire_json_list "$body_flat" '.rule_ids' | grimoire_rules_append "$rulefile"
grimoire_json_list "$body_flat" '.shape_keys' | grimoire_shapes_append "$shapefile"
# ── The act itself: refused, held for one read, or let through ───────────
#
# The server decides and supplies the words (`decision`); this hook only
# carries them. A rule set to ENFORCE refuses the call every time it is
# reached — the operator drew that line, and it moves when they change the
# rule, not when the agent has read it. A rule set to HOLD asks for one read
# before the act, once per rule and under the session cap that the act
# checkpoint and the reply hold share, so a mis-set rule costs one round trip
# rather than a session that cannot move.
d_kind=$(grimoire_json_pick "$body_flat" '.decision.kind')
d_reason=$(grimoire_json_pick "$body_flat" '.decision.reason')
d_rule=$(grimoire_json_list "$body_flat" '.decision.rule_ids' | head -n 1)
if [ -n "$d_reason" ]; then
case "$d_kind" in
enforce)
grimoire_json_deny PreToolUse "$d_reason"
exit 0
;;
hold)
if [ -n "$d_rule" ] \
&& grimoire_checkpoint_allowed "$state_dir/${safe_sid}.checkpoint.ids" "$d_rule"; then
grimoire_json_deny PreToolUse "$d_reason"
exit 0
fi
;;
esac
fi
context=$(grimoire_json_pick "$body_flat" '.context')
[ -n "$context" ] || exit 0
grimoire_json_out PreToolUse "$context"
+3 -1
View File
@@ -6,7 +6,9 @@
# tool call misses it. This hook sends the finished reply to the server, which
# checks it twice over: the rules MOUNTED on the reply moments, and the reply
# text against every rule's trigger, as the backstop for whatever the earlier
# arms missed. An unopened rule from either half holds the reply for one read.
# arms missed. An unopened rule set to hold, from either half, holds the reply
# for one read; a rule set to inform was delivered before the reply and never
# holds it.
#
# ONE END-OF-TURN REQUEST. When the turn closed a task, the same request
# carries the task ids and the server also checks the reply for the completion
+6 -5
View File
@@ -31,13 +31,14 @@ event_flat=$(printf '%s' "$event" | grimoire_json_flat)
session_id=$(grimoire_json_pick "$event_flat" '.session_id')
[ -n "$session_id" ] || exit 0
# The moment arm's per-session files (its tool cache and the acts ledger) and
# the fence's (the project the session entered, its outage marker) describe a
# session that is over, on any exit — a clear included, since the next
# conversation is a new session id.
# The moment arm's per-session files (its tool cache and the acts ledger), the
# shape check's (a note waiting for a prompt) and the fence's (the project the
# session entered, its outage marker) describe a session that is over, on any
# exit — a clear included, since the next conversation is a new session id.
safe_sid=$(printf '%s' "$session_id" | tr -c 'A-Za-z0-9._-' '_')
rm -f "${TMPDIR:-/tmp}/grimoire-moment/${safe_sid}".* \
"${TMPDIR:-/tmp}/grimoire-fence/${safe_sid}".* 2>/dev/null || true
"${TMPDIR:-/tmp}/grimoire-fence/${safe_sid}".* \
"${TMPDIR:-/tmp}/grimoire-shapecheck/${safe_sid}".* 2>/dev/null || true
reason=$(grimoire_json_pick "$event_flat" '.reason')
[ "$reason" = "clear" ] && exit 0
+60 -48
View File
@@ -1,29 +1,31 @@
#!/usr/bin/env bash
# Grimoire plugin — Stop hook: the turn's new shapes are judged by the agent
# that wrote them.
# that wrote them, at the start of its next turn.
#
# The write hooks (grimoire_prior_art.sh, grimoire_after_write.sh) append every
# definition a write names to a session ledger, `<sid>.written.ids`
# (`path<TAB>kind<TAB>name`, see grimoire_written_append). At the end of the
# turn this hook sends that ledger to the instance, which answers with what
# nobody has judged yet. If anything is, the hook blocks ONCE, in the server's
# words: the agent that built the code is the one participant who knows what
# it is, and the end of the turn is the last moment that is still true.
# nobody has judged yet as a `note`. The hook leaves the note for
# grimoire_autoinject.sh, which carries it into the next prompt's payload: the
# agent that built the code is the one participant who knows what it is, and
# the next turn of the same session still does.
#
# THE SAME DISCIPLINE AS the completion-section check in grimoire_reply_check.sh:
# - it blocks only on a `reason` the instance returned, which it returns
# only for a block it RECORDED — an unconfigured or unreachable instance
# never stops a session, and every intervention is one the numbers see;
# - never twice for one turn: the stop that follows its own block
# (`stop_hook_active` with this hook's marker present) is recorded as
# judged_after_block / left_after_block and let through;
# - another plugin's block loop is left alone (active, no marker).
# IT NEVER HOLDS THE REPLY. A held reply is rewritten, and a hold on every turn
# that wrote code made most replies cost two. The question waits one prompt
# instead, and is asked inside that prompt's budget.
#
# THE LEDGER IS CONSUMED, NOT TURN-STAMPED. Everything written since the last
# stop this hook answered is "this turn". It is emptied once the instance has
# answered — after a pass, or after the post-block stop — and KEPT when the
# instance could not be reached, so the question is asked at the next stop
# that can be answered rather than silently dropped.
# THE STATE, in <TMPDIR>/grimoire-shapecheck:
# <sid>.note — the note, until a prompt carries it (the prompt hook
# removes it once the instance has answered);
# <sid>.asked — the lines that note named. At the first stop after the note
# was carried, they go back as `phase=after`, which records
# whether they were judged, and are then forgotten.
# A note no prompt has carried yet (two stops in a row) is asked again with
# that turn's writes added, so nothing is dropped and nothing is asked twice.
#
# Silent on outage: the ledger is kept when the instance could not be reached,
# so the question is asked at the next stop that can be answered.
#
# Config (same as the other hooks):
# CLAUDE_PLUGIN_OPTION_API_ENDPOINT base URL, no trailing slash
@@ -43,36 +45,33 @@ session_id=$(grimoire_json_pick "$event_flat" '.session_id')
active=$(grimoire_json_pick "$event_flat" '.stop_hook_active')
event_cwd=$(grimoire_json_pick "$event_flat" '.cwd')
[ -n "$session_id" ] || exit 0
# The stop after another hook held the reply: this turn's writes were already
# sent at the stop before it.
[ "$active" = "true" ] && exit 0
safe_sid=$(printf '%s' "$session_id" | tr -c 'A-Za-z0-9._-' '_')
ledger="${TMPDIR:-/tmp}/grimoire-priorart/${safe_sid}.written.ids"
state_dir="${TMPDIR:-/tmp}/grimoire-shapecheck"
mkdir -p "$state_dir" 2>/dev/null || true
marker="$state_dir/${safe_sid}.blocked"
note_file="$state_dir/${safe_sid}.note"
asked_file="$state_dir/${safe_sid}.asked"
if [ "$active" = "true" ]; then
# A Stop hook already blocked this stop. Another plugin's → nothing to add.
[ -f "$marker" ] || exit 0
phase=after
else
rm -f "$marker" 2>/dev/null || true
phase=check
# A note no prompt has carried: its lines join this turn's, asked afresh.
if [ -f "$note_file" ]; then
if [ -s "$asked_file" ]; then
mkdir -p "$(dirname "$ledger")" 2>/dev/null || true
cat "$asked_file" >> "$ledger" 2>/dev/null || true
fi
rm -f "$note_file" "$asked_file" 2>/dev/null || true
fi
if [ ! -s "$ledger" ]; then
rm -f "$marker" 2>/dev/null || true
exit 0
fi
[ -s "$asked_file" ] || [ -s "$ledger" ] || exit 0
grimoire_config || exit 0
# Unique lines, oldest first, capped: the request stays a GET (a read-scoped
# key runs the plugin), and a turn that wrote more than this generated code.
written=$(awk '!seen[$0]++' "$ledger" 2>/dev/null | head -n 80)
written_enc=$(printf '%s' "$written" | grimoire_urlenc) || exit 0
dir="${event_cwd:-${CLAUDE_PROJECT_DIR:-$PWD}}"
q="phase=${phase}&written=${written_enc}"
scope_q=""
scope=$(grimoire_scope_query "$dir")
[ -n "$scope" ] && q="${q}&${scope}"
[ -n "$scope" ] && scope_q="&${scope}"
# The repo rides along even when a marker names the project: the instance
# needs it to tell the agent which repo a just-written shape belongs to.
case "$scope" in
@@ -81,25 +80,38 @@ case "$scope" in
remote=$(git -C "$dir" remote get-url origin 2>/dev/null || true)
if [ -n "$remote" ]; then
remote_enc=$(printf '%s' "$remote" | grimoire_urlenc) || remote_enc=""
[ -n "$remote_enc" ] && q="${q}&repo=${remote_enc}"
[ -n "$remote_enc" ] && scope_q="${scope_q}&repo=${remote_enc}"
fi
;;
esac
# Unique lines, oldest first, capped: the request stays a GET (a read-scoped
# key runs the plugin), and a turn that wrote more than this generated code.
_unique() { awk '!seen[$0]++' "$1" 2>/dev/null | head -n 80; }
# The note a prompt carried: were its lines judged since?
if [ -s "$asked_file" ]; then
asked_enc=$(_unique "$asked_file" | grimoire_urlenc) || asked_enc=""
if [ -n "$asked_enc" ] && curl -fsS --max-time 4 \
-H "Authorization: Bearer ${token}" \
"${url%/}/api/plugin/shape-check?phase=after&written=${asked_enc}${scope_q}" \
>/dev/null 2>&1; then
rm -f "$asked_file" 2>/dev/null || true
fi
fi
[ -s "$ledger" ] || exit 0
written=$(_unique "$ledger")
written_enc=$(printf '%s' "$written" | grimoire_urlenc) || exit 0
answer=$(curl -fsS --max-time 4 \
-H "Authorization: Bearer ${token}" \
"${url%/}/api/plugin/shape-check?${q}" 2>/dev/null) || exit 0 # unreachable: keep the ledger
"${url%/}/api/plugin/shape-check?phase=check&written=${written_enc}${scope_q}" 2>/dev/null) \
|| exit 0 # unreachable: keep the ledger
if [ "$phase" = "after" ]; then
rm -f "$marker" "$ledger" 2>/dev/null || true
exit 0
note=$(grimoire_json_pick "$(printf '%s' "$answer" | grimoire_json_flat)" '.note')
if [ -n "$note" ]; then
printf '%s' "$note" > "$note_file" 2>/dev/null || true
printf '%s\n' "$written" > "$asked_file" 2>/dev/null || true
fi
reason=$(grimoire_json_pick "$(printf '%s' "$answer" | grimoire_json_flat)" '.reason')
if [ -z "$reason" ]; then
rm -f "$ledger" 2>/dev/null || true
exit 0
fi
: > "$marker" 2>/dev/null || true
printf '{"decision":"block","reason":"%s"}\n' "$(printf '%s' "$reason" | grimoire_json_escape)"
rm -f "$ledger" 2>/dev/null || true
exit 0