feat(6855): the plugin asks before a session writes to a project other than its own
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Failing after 1m27s
CI & Build / integration (push) Successful in 2m1s
CI & Build / Build & push image (push) Skipped

plugin/hooks/grimoire_project_fence.sh runs as PreToolUse on editor writes,
Bash and Grimoire's tools. A session belongs to the project its starting
directory resolves to (CLAUDE_PROJECT_DIR: a .grimoire marker, else the git
remote's binding). A session that starts outside any project belongs to the
first one it enters, which PostToolUse on enter_project records.

These acts stop on permissionDecision "ask", with the server's reason naming
the other project:
- an edit in another project's repo or a worktree of it;
- a git commit, push, merge, rebase, pull, cherry-pick, revert, tag, am, reset
  or worktree add there, found through git -C, a cd before it, or the shell's
  current directory;
- a Grimoire write that lands in another project.

A live probe showed "ask" holds in bypassPermissions. Filing an issue and
every read go ahead. An edit or git command in the session's own repo, and any
tool named like a read, never calls the server. Grimoire writes send only
their short arguments, so the URL stays small.

When the instance doesn't answer, the act goes ahead and the hook says once
per outage that it couldn't check. check_plugin.py now holds one outage line
per hook and has a smoke event for the fence.

GET /api/plugin/write-scope takes fallback_project_id for the entered project.

tests/test_project_fence.py drives the hook against real git repos and a
stand-in server. tests/test_write_scope.py holds the hook's
FENCE_READ_PREFIXES equal to services/write_scope.READ_PREFIXES. The plugin
README and PACKAGING describe the fence, and the plugin is minted to
2026.11.05.0245.

Milestone 583, step 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 21:45:37 -05:00
co-authored by Claude Opus 5.5
parent 16b1d68ebd
commit 805fda5cb1
9 changed files with 519 additions and 7 deletions
+26
View File
@@ -69,6 +69,16 @@ def test_a_reference_is_an_argument_the_tool_takes_and_not_also_a_locator():
assert arg not in WRITE_TARGETS[tool], f"{tool}.{arg} is both a locator and a reference"
def test_the_fence_hook_skips_exactly_the_read_prefixes_the_server_names():
import re
from pathlib import Path
hook = Path(__file__).resolve().parents[1] / "plugin" / "hooks" / "grimoire_project_fence.sh"
found = re.search(r'^FENCE_READ_PREFIXES="([^"]*)"$', hook.read_text(), re.M)
assert found, "grimoire_project_fence.sh no longer declares FENCE_READ_PREFIXES"
assert tuple(found.group(1).split()) == write_scope.READ_PREFIXES
def test_no_write_tool_carries_a_read_prefix():
# The fence hook skips the server for these prefixes, so a write named
# like a read would pass unchecked.
@@ -212,6 +222,22 @@ async def test_the_route_resolves_a_target_repo_to_its_project():
assert check.call_args.kwargs["act"] == "git push in"
async def test_a_session_whose_directory_resolves_to_nothing_belongs_to_the_project_it_entered():
from grimoire.app import create_app
from grimoire.routes import plugin
app = create_app()
check = AsyncMock(return_value={"allowed": True, "targets": [], "issue": False, "reason": ""})
url = ("/api/plugin/write-scope?fallback_project_id=7"
"&tool=add_task_log&input=%7B%22task_id%22%3A5%7D")
async with app.test_request_context(url):
g.user = SimpleNamespace(id=1)
with patch.object(plugin.write_scope_svc, "check_act", check), \
patch.object(plugin, "can_read_project", AsyncMock(return_value=True)):
await plugin.write_scope.__wrapped__()
assert check.call_args.args == (1, 7)
async def test_the_route_refuses_input_that_is_not_an_object():
from grimoire.app import create_app
from grimoire.routes import plugin