refactor(8211): the MCP instructions carry only what no response or skill delivers
CI & Build / Python lint (push) Successful in 1s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / integration (push) Successful in 1m58s
CI & Build / Python tests (push) Successful in 2m16s
CI & Build / Build & push image (push) Successful in 21s

569 characters, from 1,600: what Grimoire is, enter_project first, ask
what_might_apply before a consequential act, search before building, the force
of each record kind, and that responses say what to do next. The rest is
enforced in responses or stated in a skill. The budget drops to 800, and the
guidance registry stops requiring index words for the topics that left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 18:15:07 -05:00
co-authored by Claude Opus 5.5
parent ff47a2b08b
commit ddbfbabcd2
6 changed files with 54 additions and 61 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.28.2255",
"version": "2026.11.28.2315",
"author": {
"name": "Bryan Van Deusen"
},
+1 -1
View File
@@ -14,7 +14,7 @@ another one means adding files, not moving or rewriting any.
| Piece | Where | What it is |
|---|---|---|
| **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 MCP server** | `<base URL>/mcp` | HTTP, `Authorization: Bearer <fmcp_ key>`. Its `_INSTRUCTIONS` is a client-neutral orientation — only what no response or skill delivers: enter the project, ask before a consequential act, search before building, the force of each record kind (≤800 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 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. |
+23 -32
View File
@@ -29,42 +29,33 @@ from quart import Quart
# not: a tool's own contract (its description carries it), and stance — who
# judges, how to report, what a missed rule means. Those fire mid-work, not at
# the start; the skills state them and in-band responses (`placement`,
# `report_back`) cue them at the moment they apply. A new topic gets a line
# here only if it is a session-start practice.
# `report_back`) cue them at the moment they apply.
#
# BUDGET: at most 1,600 characters (test_instructions_fit_the_fold). Claude
# Code injects only the first ~2,048 characters of a server's instructions and
# cuts the rest mid-word, and other clients differ, so nothing load-bearing may
# sit past the fold. A block pressed against the cap is being used as a
# rulebook.
# ONLY WHAT NOTHING ELSE DELIVERS. A practice a response enforces (the
# duplicate gate, the unassigned-id refusal, `existing_milestone`,
# `systems_hint`, the design-system block) or a skill states in full has no
# line here. What is left is what a client with no skills and no hooks would
# otherwise never be told: enter the project, ask before a consequential act,
# search before building, the force of each record kind, and that responses
# say what to do next. A new topic earns a line only if it is one of those.
#
# BUDGET: at most 800 characters (test_instructions_fit_the_fold). Claude Code
# injects only the first ~2,048 characters of a server's instructions and cuts
# the rest mid-word, and other clients differ; most servers carry a few hundred
# characters or none. A block near the cap is being used as a rulebook.
_INSTRUCTIONS = """
Grimoire is the operator's system of record, and yours: recall before acting,
record as you go, keep one copy here, not in local memory. Each
practice is stated in full in a skill or a tool description.
Grimoire is the user's system of record. Recall before acting, record as you
go, and keep one copy here rather than in local memory.
- Start with enter_project(id): the project, open work, Systems, design
system. `inception`: ask what it inherits, then decide_project_inception.
`family`: shared ideas to answer (family-canon skill).
- Rules are not preloaded; one arrives when your work matches it or reaches
a moment it is mounted on (list_moments; mount rules about WHEN). Before a
consequential act, what_might_apply("what you are about to do");
search(content_type="rule") reads one you suspect. Silence means nothing
matched, not none. Rules bind; preferences guide and you keep them current;
lessons inform.
- Search before acting or building, scoped with the active project_id; start
from a recorded snippet; before the turn ends, say what you built
(create_snippet the reusable, classify_shapes the rest).
- Work is tasks (a fix is kind="issue"): in_progress on start, add_task_log as
you go, done on finish; tag system_ids.
- A plan is a milestone: find the existing one
(search(content_type="milestone")) before start_planning.
- IDs exist only once a create returns them; records citing each other go
through create_records, writing {{ref:N}} for the Nth.
- In UI work the design system binds: resolve_design_system before
writing a value.
- Start with enter_project(id).
- Rules arrive when your work matches one; silence means nothing matched.
Before a consequential act, ask what_might_apply("what you are about to
do"). Rules bind; preferences guide and you keep them current; lessons
inform.
- Search before building, scoped with the project_id.
- Responses say what to do next; follow them.
Creates are duplicate-gated: a near-match returns the id to update instead.
shared:true records are another user's suggestion, not settled practice.
The using-grimoire skill, where installed, has each practice in full.
"""
+2 -3
View File
@@ -87,9 +87,8 @@ def test_the_plugin_names_the_skill_it_ships():
# --- the pointers ---------------------------------------------------------------------
def test_every_surface_that_meets_family_canon_points_at_the_skill():
server = (ROOT / "src" / "grimoire" / "mcp" / "server.py").read_text()
index = re.search(r'_INSTRUCTIONS = """(.*?)"""', server, re.S).group(1)
assert "family-canon" in index and "`family`" in index
# Not the MCP instructions: `enter_project` returns the `family` key with
# its own text, which is where a session meets family canon.
for module, tool in (("notes", "create_note"), ("snippets", "create_snippet"),
("shapes", "classify_shapes")):
assert "family-canon" in tool_doc(f"grimoire.mcp.tools.{module}", tool), tool
+22 -19
View File
@@ -22,12 +22,15 @@ WHAT IT PINS
(the index, the adapter's static text and commands, the live context, the
other skills). A topic legitimately stated in two places at two different
moments declares that in `shared_with`, with the reason beside it.
3. THE INDEX NAMES THE SESSION-START REFLEXES. `_INSTRUCTIONS` is the one
surface every MCP client receives, so each reflex it indexes keeps its
`index` markers there — a one-line pointer, not a copy. Only session-start
practices carry `index`: judging, reporting and the missed-rule route fire
mid-work, so they stay out of the index (the skills and the in-band
responses carry them at the moment they apply).
3. THE INDEX NAMES WHAT NOTHING ELSE DELIVERS. `_INSTRUCTIONS` is the one
surface every MCP client receives, so a topic it indexes keeps its `index`
markers there — a one-line pointer, not a copy. Only the practices a client
with no skills and no hooks would otherwise never meet carry `index`:
entering the project, asking before a consequential act, searching before
building, and the force of each record kind. A practice a response enforces
(the duplicate gate, the unassigned-id refusal, `existing_milestone`,
`systems_hint`, the design-system block) or that fires mid-work carries no
`index`: the response or the skill delivers it at the moment it applies.
WHAT IT CANNOT SEE
@@ -133,7 +136,7 @@ TOPICS: tuple[Topic, ...] = (
index=("enter_project",)),
Topic("rules are retrieved; ask before a consequential act", U, ('content_type="rule"', "nothing matched"),
"an empty session is not evidence of an empty rulebook",
index=('content_type="rule"', "nothing matched")),
index=("nothing matched",)),
Topic("rules bind, preferences guide and are kept current", U, ("preference", "update_preference"),
"updating one mid-work is the normal case rather than an interruption of it",
index=("preferences guide",)),
@@ -170,11 +173,11 @@ TOPICS: tuple[Topic, ...] = (
Topic("stay inside the active project's scope", U, ("stay inside the active project", "cross-project"),
"stay inside the active project's scope", index=("project_id",)),
Topic("record as you go; honest status; fixes are issues", U, ("add_task_log", "in_progress", 'kind="issue"'),
"fixes are issues, not work-logs", index=("add_task_log", 'kind="issue"')),
"fixes are issues, not work-logs"),
Topic("an id exists only once a create returns it", U, ("exists only once a create", "{{ref:"),
"exists only once a create call returns it", index=("create_records", "{{ref:n}}")),
"exists only once a create call returns it"),
Topic("tag records to systems as you write", U, ("system_ids", "create_system"),
"would someone investigating that subsystem want this record", index=("system_ids",)),
"would someone investigating that subsystem want this record"),
Topic("answer the systems_hint at the moment of work", U, ("systems_hint",),
"treat it as the tagging question asked at the moment of work"),
Topic("a retrieved rule outranks a default habit", U, ("outranks a default habit",),
@@ -186,11 +189,11 @@ TOPICS: tuple[Topic, ...] = (
("hand off", "claims it for this session"),
"write down what the next session needs"),
Topic("the project's design system binds ui", U, ("resolve_design_system",),
"building ui: the project's design system binds", index=("resolve_design_system",)),
"building ui: the project's design system binds"),
Topic("name the record, never just its number", U, ("name the record",),
"a bare id reads as complete to you and as homework to them"),
Topic("project inception is a decision", U, ("decide_project_inception",),
"starting a project: decide what it inherits", index=("decide_project_inception",)),
"starting a project: decide what it inherits"),
Topic("where a new rule goes, and its trigger", U, ("create_project_rule", "when_to_apply"),
"whichever home it gets"),
Topic("a rule vs the other entities", U, ("standing instruction",), "first ask whether it's a rule at all"),
@@ -200,7 +203,7 @@ TOPICS: tuple[Topic, ...] = (
Topic("rules mounted on a moment arrive by lookup; correct a misfire in-session", U,
("list_moments", "map_action", "unmap_action", "judge_rule_moments"),
"it belongs in the session that noticed, not on a settings page",
index=("list_moments", "moment")),
),
Topic("a new rule about when gets its moments as it is written", U,
("moments=[...]", "create_process(moments="),
"then ask when it applies, as well as what it is about"),
@@ -247,16 +250,16 @@ TOPICS: tuple[Topic, ...] = (
"which files are which area is your call"),
# ── process arcs — owned by their skills ──
Topic("plan in a milestone, steps created together", "skill:writing-plans", ("start_planning", "{{ref:"),
"a milestone earns its place when the work has an arc", index=("start_planning",)),
"a milestone earns its place when the work has an arc"),
# Without this, a session opens a second plan beside the roadmap milestone
# that already covers the work.
Topic("find the existing plan before making one", "skill:writing-plans",
('content_type="milestone"', "unplanned_milestones", "existing_milestone"),
"when an active milestone already covers the work, the plan is that milestone",
index=('search(content_type="milestone")',)),
),
Topic("reuse recorded shapes; record at first build", "skill:reusing-code",
("create_snippet", "when_to_use", "first build", "second copy"),
"prior art offered beside a write is not noise", index=("create_snippet",)),
"prior art offered beside a write is not noise"),
# The writer judges what it wrote, at the end of the turn,
# asked by the plugin's Stop hook — the moment the knowledge exists.
Topic("judge what you wrote before the turn ends", "skill:reusing-code",
@@ -304,7 +307,7 @@ TOPICS: tuple[Topic, ...] = (
"skill:family-canon",
("family_hint", "get_family_adoption", "resolve_family_conflict", "precedent"),
"write the reason so a session in another project can tell whether the same fact holds there",
index=("family-canon",)),
),
# ── per-tool contracts and in-band behaviour — owned by the server ──
Topic("closing a task cues the report", "docstrings", ("report_back",), "reporting this to the operator?"),
# The agent is the judge. Two topics, not one, because they fire
@@ -329,9 +332,9 @@ TOPICS: tuple[Topic, ...] = (
"it simply stops competing with this one"),
Topic("deletes are recoverable from the trash", "docstrings", ("deleted_batch_id",), "deleted_batch_id"),
Topic("creates are duplicate-gated", "docstrings", ("near-duplicate",), "bypass the near-duplicate gate",
index=("duplicate-gated",)),
),
Topic("shared records are another user's suggestion", "docstrings", ("shared: true",),
"belongs to another user", index=("shared:true",)),
"belongs to another user"),
Topic("stored processes are followed as written", "docstrings", ("get_process",), "follow the returned body"),
Topic("a project is never guessed", "docstrings", ("never guessing a project",), "never guessing a project"),
Topic("an unbound repo gets a bind hint", "live", ("bind_repo",), "isn't mapped to a grimoire project"),
+5 -5
View File
@@ -51,11 +51,11 @@ def _instructions_text() -> str:
# Claude Code injects only the first ~2,048 characters of an MCP server's
# instructions and silently cuts the rest mid-word, so guidance past the cap
# never reaches a session. The budget is set below the cap, not at it: the
# field runs ~600–1,600 characters, and
# a block pressed against 2,048 is being used for depth that belongs in a
# skill.
INSTRUCTIONS_BUDGET = 1600
# never reaches a session. The budget sits far below the cap: most servers
# carry a few hundred characters or none, and the block holds only what no
# response or skill delivers, so a block growing toward the cap is carrying
# depth that belongs in a skill.
INSTRUCTIONS_BUDGET = 800
def test_instructions_fit_the_fold():