rename(547): the server is grimoire — package, image, DB defaults, backups
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 56s
CI & Build / integration (push) Successful in 1m4s
CI & Build / Python tests (push) Successful in 1m55s
CI & Build / Build & push image (push) Successful in 44s

Step 2 of the Scribe -> Grimoire rename.

- src/scribe -> src/grimoire, and every import, patch target, module path,
  hypercorn entry point and `python -m grimoire.restore` with it; pyproject,
  uv.lock and the frontend package are named grimoire.
- Image git.fabledsword.com/bvandeusen/fabledgrimoire; CI's Postgres service
  runs as grimoire / grimoire_test.
- Compose files default the DB user, database and (prod) volume to grimoire,
  each overridable from .env, so an install created as Scribe keeps its data
  by setting POSTGRES_USER, POSTGRES_DB and PGDATA_VOLUME.
- Backups are written as grimoire-<ts>.tar with format grimoire-backup-tar.
  Archives named scribe-* with the scribe-backup-tar manifest still restore
  and are still counted at the destination (folder and S3), with tests.
- Exports, the MCP auth realm, the ASGI scope key and the persistent logger
  carry the new name.

Kept on purpose: the secret-sealing key label stays "scribe.secrets.v1",
because every stored secret was derived under it.

Plugin identity (plugin name, hooks, env vars, .scribe marker, skills) is
step 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 10:50:45 -04:00
co-authored by Claude Opus 5.5
parent e99f1169f7
commit 0f5ef0be63
447 changed files with 3611 additions and 3558 deletions
+68 -68
View File
@@ -13,11 +13,11 @@ _NO_MATCH = {"duplicate": None, "canonical": None}
@pytest.mark.asyncio
async def test_create_system_returns_dict():
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value=_NO_MATCH)
svc.create_system = AsyncMock(return_value=fake_system(name="Reader"))
from scribe.mcp.tools.systems import create_system
from grimoire.mcp.tools.systems import create_system
result = await create_system(project_id=5, name="Reader", description="pdf reader")
assert result["name"] == "Reader"
# An unmatched name is a project-specific area: created, no offer, no fuss.
@@ -26,11 +26,11 @@ async def test_create_system_returns_dict():
@pytest.mark.asyncio
async def test_create_system_no_access_raises():
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value=_NO_MATCH)
svc.create_system = AsyncMock(return_value=None)
from scribe.mcp.tools.systems import create_system
from grimoire.mcp.tools.systems import create_system
with pytest.raises(ValueError):
await create_system(project_id=5, name="Reader")
@@ -44,10 +44,10 @@ async def test_create_system_applies_an_exact_area_and_offers_a_similar_one():
judgment call, so it is only OFFERED: applying it silently is how a
cross-project rule ends up surfacing in the wrong project.
"""
from scribe.mcp.tools.systems import create_system
from grimoire.mcp.tools.systems import create_system
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value={
"duplicate": None,
"canonical": {"id": 3, "name": "CI & Release", "basis": "exact"},
@@ -57,8 +57,8 @@ async def test_create_system_applies_an_exact_area_and_offers_a_similar_one():
assert svc.create_system.await_args.kwargs["canonical_id"] == 3
assert "canonical_note" in exact and "canonical_suggestion" not in exact
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value={
"duplicate": None,
"canonical": {"id": 3, "name": "CI & Release", "basis": "overlap", "score": 0.33},
@@ -72,9 +72,9 @@ async def test_create_system_applies_an_exact_area_and_offers_a_similar_one():
@pytest.mark.asyncio
async def test_create_system_duplicate_names_the_existing_one_and_creates_nothing():
from scribe.mcp.tools.systems import create_system
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
from grimoire.mcp.tools.systems import create_system
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value={
"duplicate": {"id": 4, "name": "Reader"}, "canonical": None,
})
@@ -90,11 +90,11 @@ async def test_get_system_splits_records_by_kind():
issue = fake_task(id=10, task_kind="issue", milestone_id=None)
work = fake_task(id=11, milestone_id=None)
note = fake_note(id=12, status=None, milestone_id=None)
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.get_system = AsyncMock(return_value=fake_system(id=3))
svc.list_records_for_system = AsyncMock(return_value=[issue, work, note])
from scribe.mcp.tools.systems import get_system
from grimoire.mcp.tools.systems import get_system
result = await get_system(system_id=3)
assert [r["id"] for r in result["issues"]] == [10]
assert [r["id"] for r in result["tasks"]] == [11]
@@ -104,12 +104,12 @@ async def test_get_system_splits_records_by_kind():
@pytest.mark.asyncio
async def test_path_patterns_reach_the_service_from_both_tools():
"""Omitted means unchanged; an empty list is a value — it clears them."""
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.assess_system_name = AsyncMock(return_value=_NO_MATCH)
svc.create_system = AsyncMock(return_value=fake_system(name="Billing"))
svc.update_system = AsyncMock(return_value=fake_system(name="Billing"))
from scribe.mcp.tools.systems import create_system, update_system
from grimoire.mcp.tools.systems import create_system, update_system
await create_system(project_id=5, name="Billing", path_patterns=["src/billing"])
assert svc.create_system.await_args.kwargs["path_patterns"] == ["src/billing"]
await update_system(system_id=1, name="Billing")
@@ -120,10 +120,10 @@ async def test_path_patterns_reach_the_service_from_both_tools():
@pytest.mark.asyncio
async def test_update_system_not_found_raises():
with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \
patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.update_system = AsyncMock(return_value=None)
from scribe.mcp.tools.systems import update_system
from grimoire.mcp.tools.systems import update_system
with pytest.raises(ValueError):
await update_system(system_id=99, name="x")
@@ -131,13 +131,13 @@ async def test_update_system_not_found_raises():
@pytest.mark.asyncio
async def test_create_task_issue_sets_kind_provenance_and_systems():
note = MagicMock(); note.id = 50; note.to_dict.return_value = {"id": 50, "task_kind": "issue"}
with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \
patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("scribe.mcp.tools.tasks.systems_svc") as systems_svc:
with patch("grimoire.mcp.tools.tasks.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("grimoire.mcp.tools.tasks.systems_svc") as systems_svc:
notes_svc.create_note = AsyncMock(return_value=note)
systems_svc.set_record_systems = AsyncMock(return_value=[2, 3])
systems_svc.list_record_systems = AsyncMock(return_value=[])
from scribe.mcp.tools.tasks import create_task
from grimoire.mcp.tools.tasks import create_task
result = await create_task(title="bug", kind="issue", system_ids=[2, 3], arose_from_id=9)
_, kwargs = notes_svc.create_note.call_args
assert kwargs["task_kind"] == "issue"
@@ -150,9 +150,9 @@ async def test_create_task_issue_sets_kind_provenance_and_systems():
async def test_untagged_hint_names_the_projects_systems():
sys_a = MagicMock(); sys_a.id = 1; sys_a.name = "workers"
sys_b = MagicMock(); sys_b.id = 2; sys_b.name = "scrape-pipeline"
with patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.systems_svc") as svc:
svc.list_systems = AsyncMock(return_value=[sys_a, sys_b])
from scribe.mcp.tools.systems import untagged_systems_hint
from grimoire.mcp.tools.systems import untagged_systems_hint
hint = await untagged_systems_hint(1, 5)
assert "workers" in hint and "scrape-pipeline" in hint
assert "system_ids" in hint
@@ -161,9 +161,9 @@ async def test_untagged_hint_names_the_projects_systems():
@pytest.mark.asyncio
async def test_untagged_hint_zero_systems_prompts_first_create_and_fails_open():
from scribe.mcp.tools.systems import untagged_systems_hint
with patch("scribe.mcp.tools.systems.systems_svc") as svc, \
patch("scribe.mcp.tools.systems.notes_svc") as notes:
from grimoire.mcp.tools.systems import untagged_systems_hint
with patch("grimoire.mcp.tools.systems.systems_svc") as svc, \
patch("grimoire.mcp.tools.systems.notes_svc") as notes:
# Zero Systems in a YOUNG project (below the bootstrap threshold):
# the mild question stays proportionate — it must prompt the FIRST
# create_system, not go silent.
@@ -171,7 +171,7 @@ async def test_untagged_hint_zero_systems_prompts_first_create_and_fails_open():
notes.list_notes = AsyncMock(return_value=([], 3))
hint = await untagged_systems_hint(1, 5)
assert "no Systems yet" in hint and "create_system" in hint
with patch("scribe.mcp.tools.systems.systems_svc") as svc:
with patch("grimoire.mcp.tools.systems.systems_svc") as svc:
# A hint must never break a create — DB failure degrades to no hint.
svc.list_systems = AsyncMock(side_effect=RuntimeError("db down"))
assert await untagged_systems_hint(1, 5) is None
@@ -184,10 +184,10 @@ async def test_untagged_hint_escalates_in_a_mature_zero_systems_project():
project's OWN evidence — record count and recent titles — and demand a
concrete deliverable, because that is the property separating the nudges
that convert from the prose that doesn't."""
from scribe.mcp.tools.systems import untagged_systems_hint
from grimoire.mcp.tools.systems import untagged_systems_hint
recent = [fake_note(title="Fix scrape retry backoff"), fake_note(title="Worker pool sizing")]
with patch("scribe.mcp.tools.systems.systems_svc") as svc, \
patch("scribe.mcp.tools.systems.notes_svc") as notes:
with patch("grimoire.mcp.tools.systems.systems_svc") as svc, \
patch("grimoire.mcp.tools.systems.notes_svc") as notes:
svc.list_systems = AsyncMock(return_value=[])
notes.list_notes = AsyncMock(return_value=(recent, 282))
# The standard names come from the GLOBAL catalog,
@@ -218,10 +218,10 @@ async def test_bootstrap_ask_still_asks_when_the_catalog_is_unreachable():
catalog read fails (or an install has an empty one), the ask must still
carry the project's evidence and demand the same deliverable — degrading to
a weaker nudge is acceptable, going silent is not."""
from scribe.mcp.tools.systems import untagged_systems_hint
from grimoire.mcp.tools.systems import untagged_systems_hint
recent = [fake_note(title="Fix scrape retry backoff")]
with patch("scribe.mcp.tools.systems.systems_svc") as svc, \
patch("scribe.mcp.tools.systems.notes_svc") as notes:
with patch("grimoire.mcp.tools.systems.systems_svc") as svc, \
patch("grimoire.mcp.tools.systems.notes_svc") as notes:
svc.list_systems = AsyncMock(return_value=[])
notes.list_notes = AsyncMock(return_value=(recent, 282))
svc.standard_systems = AsyncMock(side_effect=RuntimeError("db down"))
@@ -233,12 +233,12 @@ async def test_bootstrap_ask_still_asks_when_the_catalog_is_unreachable():
@pytest.mark.asyncio
async def test_bootstrap_ask_stays_quiet_below_threshold_and_fails_open():
from scribe.mcp.tools import systems as tools
with patch("scribe.mcp.tools.systems.notes_svc") as notes:
from grimoire.mcp.tools import systems as tools
with patch("grimoire.mcp.tools.systems.notes_svc") as notes:
notes.list_notes = AsyncMock(
return_value=([], tools._BOOTSTRAP_MIN_RECORDS - 1))
assert await tools.bootstrap_systems_ask(1, 5) is None
with patch("scribe.mcp.tools.systems.notes_svc") as notes:
with patch("grimoire.mcp.tools.systems.notes_svc") as notes:
# The record count is decoration on a hint on a create — three layers
# deep, nothing there may break the call.
notes.list_notes = AsyncMock(side_effect=RuntimeError("db down"))
@@ -249,10 +249,10 @@ async def test_bootstrap_ask_stays_quiet_below_threshold_and_fails_open():
async def test_populated_vocabulary_never_counts_records():
"""The bootstrap query is zero-state-only: once Systems exist the hint
must not spend a count query per untagged record."""
from scribe.mcp.tools.systems import untagged_systems_hint
from grimoire.mcp.tools.systems import untagged_systems_hint
sys_a = MagicMock(); sys_a.id = 1; sys_a.name = "workers"
with patch("scribe.mcp.tools.systems.systems_svc") as svc, \
patch("scribe.mcp.tools.systems.notes_svc") as notes:
with patch("grimoire.mcp.tools.systems.systems_svc") as svc, \
patch("grimoire.mcp.tools.systems.notes_svc") as notes:
svc.list_systems = AsyncMock(return_value=[sys_a])
notes.list_notes = AsyncMock()
hint = await untagged_systems_hint(1, 5)
@@ -271,15 +271,15 @@ async def test_populated_vocabulary_never_counts_records():
async def test_create_task_untagged_in_project_carries_the_question():
note = MagicMock(); note.id = 60; note.to_dict.return_value = {"id": 60}
sys_a = MagicMock(); sys_a.id = 4; sys_a.name = "plugin-hooks"
with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \
patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("scribe.mcp.tools.tasks.dedup_svc") as dedup_svc, \
patch("scribe.mcp.tools.systems.systems_svc") as seam_svc:
with patch("grimoire.mcp.tools.tasks.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("grimoire.mcp.tools.tasks.dedup_svc") as dedup_svc, \
patch("grimoire.mcp.tools.systems.systems_svc") as seam_svc:
notes_svc.create_note = AsyncMock(return_value=note)
dedup_svc.find_duplicate_note = AsyncMock(return_value=None)
seam_svc.list_record_systems = AsyncMock(return_value=[])
seam_svc.list_systems = AsyncMock(return_value=[sys_a])
from scribe.mcp.tools.tasks import create_task
from grimoire.mcp.tools.tasks import create_task
result = await create_task(title="untagged", project_id=5)
assert "plugin-hooks" in result["systems_hint"]
@@ -291,16 +291,16 @@ async def test_create_task_tagged_shows_systems_and_projectless_gets_neither():
# mutation leak into the second create's response.
note.to_dict.side_effect = lambda: {"id": 61}
tagged_sys = MagicMock(); tagged_sys.to_dict.return_value = {"id": 4, "name": "plugin-hooks"}
with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \
patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("scribe.mcp.tools.tasks.dedup_svc") as dedup_svc, \
patch("scribe.mcp.tools.tasks.systems_svc") as systems_svc, \
patch("scribe.mcp.tools.systems.systems_svc") as seam_svc:
with patch("grimoire.mcp.tools.tasks.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("grimoire.mcp.tools.tasks.dedup_svc") as dedup_svc, \
patch("grimoire.mcp.tools.tasks.systems_svc") as systems_svc, \
patch("grimoire.mcp.tools.systems.systems_svc") as seam_svc:
notes_svc.create_note = AsyncMock(return_value=note)
dedup_svc.find_duplicate_note = AsyncMock(return_value=None)
systems_svc.set_record_systems = AsyncMock()
seam_svc.list_record_systems = AsyncMock(return_value=[tagged_sys])
from scribe.mcp.tools.tasks import create_task
from grimoire.mcp.tools.tasks import create_task
tagged = await create_task(title="tagged", project_id=5, system_ids=[4])
seam_svc.list_record_systems = AsyncMock(return_value=[])
orphan = await create_task(title="orphan", project_id=0)
@@ -318,15 +318,15 @@ async def test_get_task_shows_the_records_systems_on_read():
note.deleted_at = None; note.parent_id = None
note.to_dict.return_value = {"id": 70, "task_kind": "work"}
tagged_sys = MagicMock(); tagged_sys.to_dict.return_value = {"id": 2, "name": "exporter"}
with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \
patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("scribe.mcp.tools.tasks.access_svc") as access_svc, \
patch("scribe.mcp.tools.tasks.record_pulled"), \
patch("scribe.mcp.tools.systems.systems_svc") as seam_svc:
with patch("grimoire.mcp.tools.tasks.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("grimoire.mcp.tools.tasks.access_svc") as access_svc, \
patch("grimoire.mcp.tools.tasks.record_pulled"), \
patch("grimoire.mcp.tools.systems.systems_svc") as seam_svc:
notes_svc.get_note_for_user = AsyncMock(return_value=(note, "owner"))
access_svc.describe_provenance = AsyncMock(return_value={})
seam_svc.list_record_systems = AsyncMock(return_value=[tagged_sys])
from scribe.mcp.tools.tasks import get_task
from grimoire.mcp.tools.tasks import get_task
result = await get_task(task_id=70)
assert result["systems"] == [{"id": 2, "name": "exporter"}]
@@ -336,11 +336,11 @@ async def test_add_task_log_on_untagged_project_task_asks_the_question():
"""Logging work IS working in some area — the strongest moment to ask."""
log = MagicMock(); log.to_dict.return_value = {"id": 9, "task_id": 70}
task = MagicMock(); task.user_id = 1; task.project_id = 5
with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \
patch("scribe.mcp.tools.tasks.task_logs_svc") as logs_svc, \
patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("scribe.mcp.tools.systems.systems_svc") as seam_svc, \
patch("scribe.mcp.tools.systems.notes_svc") as seam_notes:
with patch("grimoire.mcp.tools.tasks.current_user_id", return_value=1), \
patch("grimoire.mcp.tools.tasks.task_logs_svc") as logs_svc, \
patch("grimoire.mcp.tools.tasks.notes_svc") as notes_svc, \
patch("grimoire.mcp.tools.systems.systems_svc") as seam_svc, \
patch("grimoire.mcp.tools.systems.notes_svc") as seam_notes:
logs_svc.create_log = AsyncMock(return_value=log)
notes_svc.get_note_for_user = AsyncMock(return_value=(task, "owner"))
seam_svc.list_record_systems = AsyncMock(return_value=[])
@@ -348,6 +348,6 @@ async def test_add_task_log_on_untagged_project_task_asks_the_question():
# Young project: below the bootstrap threshold, so the mild
# question is the expected form here.
seam_notes.list_notes = AsyncMock(return_value=([], 2))
from scribe.mcp.tools.tasks import add_task_log
from grimoire.mcp.tools.tasks import add_task_log
result = await add_task_log(task_id=70, content="progress")
assert "no Systems yet" in result["systems_hint"]