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
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:
@@ -1,12 +1,14 @@
|
||||
"""The end-of-turn shape check: the write hooks note what each
|
||||
write defined, and the Stop hook asks the instance which of those nobody has
|
||||
judged, blocking once in the server's words.
|
||||
write defined, the Stop hook asks the instance which of those nobody has
|
||||
judged, and the answer rides the next prompt rather than holding the reply.
|
||||
|
||||
Runs the real shell against the shared HTTP sink. What it pins: the write
|
||||
hooks' ledger (a Write of a new file adds a `file` line; a skipped path adds
|
||||
nothing); silence with nothing written; a block only on a reason the instance
|
||||
returned; the post-block stop recorded and let through; another hook's block
|
||||
loop left alone; the ledger kept when the instance could not be reached.
|
||||
nothing); silence with nothing written; the Stop hook never blocks; a note
|
||||
only when the instance returned one, carried by the next prompt and then
|
||||
gone; the stop after that prompt records the answer; a note no prompt carried
|
||||
is asked again with the next turn's writes; another hook's block loop left
|
||||
alone; the ledger kept when the instance could not be reached.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -23,7 +25,8 @@ from tests.helpers import http_sink
|
||||
HOOKS = Path(__file__).resolve().parents[1] / "plugin" / "hooks"
|
||||
CHECK = HOOKS / "grimoire_shape_check.sh"
|
||||
PRIOR_ART = HOOKS / "grimoire_prior_art.sh"
|
||||
REASON = "SERVER REASON: judge what you wrote"
|
||||
PROMPT = HOOKS / "grimoire_autoinject.sh"
|
||||
NOTE = "SERVER NOTE: judge what you wrote"
|
||||
|
||||
|
||||
def _env(tmp_path, url="http://127.0.0.1:9"):
|
||||
@@ -127,7 +130,7 @@ def test_a_skipped_path_notes_nothing(tmp_path):
|
||||
# ── the Stop hook asks ────────────────────────────────────────────────────
|
||||
|
||||
def test_nothing_written_is_silent_and_asks_nothing(tmp_path):
|
||||
with http_sink(b'{"status":"ok","reason":"x"}') as (port, seen):
|
||||
with http_sink(b'{"status":"ok","note":"x"}') as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
assert _stop(env, _repo(tmp_path)) == ""
|
||||
assert seen == []
|
||||
@@ -144,32 +147,84 @@ def test_all_judged_passes_silently_and_empties_the_ledger(tmp_path):
|
||||
assert not ledger.exists()
|
||||
|
||||
|
||||
def test_unjudged_blocks_once_in_the_servers_words_then_records_the_answer(tmp_path):
|
||||
reply = json.dumps({"status": "ok", "outcome": "blocked", "reason": REASON}).encode()
|
||||
def _note_file(tmp_path, session="s1"):
|
||||
return tmp_path / "grimoire-shapecheck" / f"{session}.note"
|
||||
|
||||
|
||||
def _asked_file(tmp_path, session="s1"):
|
||||
return tmp_path / "grimoire-shapecheck" / f"{session}.asked"
|
||||
|
||||
|
||||
def _prompt(env, cwd, text="carry on", session="s1"):
|
||||
out = subprocess.run(
|
||||
["bash", str(PROMPT)],
|
||||
input=json.dumps({"session_id": session, "prompt": text, "cwd": str(cwd),
|
||||
"transcript_path": "/nonexistent",
|
||||
"hook_event_name": "UserPromptSubmit"}),
|
||||
capture_output=True, text=True, env=env, timeout=30,
|
||||
)
|
||||
assert out.returncode == 0, out.stderr
|
||||
return out.stdout.strip()
|
||||
|
||||
|
||||
def test_unjudged_is_noted_for_the_next_prompt_and_never_holds_the_reply(tmp_path):
|
||||
reply = json.dumps({"status": "ok", "outcome": "noted", "note": NOTE,
|
||||
"context": "", "note_ids": []}).encode()
|
||||
with http_sink(reply) as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
repo = _repo(tmp_path)
|
||||
ledger = _write_ledger(tmp_path, ["web/A.svelte\tfile\tA"])
|
||||
assert json.loads(_stop(env, repo)) == {"decision": "block", "reason": REASON}
|
||||
assert ledger.exists(), "kept, so the stop after the block asks about the same set"
|
||||
|
||||
# The stop after the block: recorded, never blocked, ledger consumed.
|
||||
assert _stop(env, repo, active=True) == ""
|
||||
assert [q["phase"] for q in seen] == [["check"], ["after"]]
|
||||
assert _stop(env, repo) == "", "the reply goes out as written"
|
||||
assert _note_file(tmp_path).read_text() == NOTE
|
||||
assert _asked_file(tmp_path).read_text().splitlines() == ["web/A.svelte\tfile\tA"]
|
||||
assert not ledger.exists()
|
||||
assert _stop(env, repo, active=True) == ""
|
||||
assert len(seen) == 2
|
||||
|
||||
# The next prompt carries the note, and it is gone once answered.
|
||||
_prompt(env, repo)
|
||||
assert seen[-1]["carry"] == [NOTE]
|
||||
assert not _note_file(tmp_path).exists()
|
||||
|
||||
# The stop after it records whether the noted lines were judged.
|
||||
assert _stop(env, repo) == ""
|
||||
assert seen[-1]["phase"] == ["after"]
|
||||
assert seen[-1]["written"] == ["web/A.svelte\tfile\tA"]
|
||||
assert not _asked_file(tmp_path).exists()
|
||||
before = len(seen)
|
||||
assert _stop(env, repo) == ""
|
||||
assert len(seen) == before, "asked once, recorded once"
|
||||
|
||||
|
||||
def test_no_block_without_a_reason_from_the_instance(tmp_path):
|
||||
def test_a_note_no_prompt_carried_is_asked_again_with_the_next_turns_writes(tmp_path):
|
||||
reply = json.dumps({"status": "ok", "outcome": "noted", "note": NOTE}).encode()
|
||||
with http_sink(reply) as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
repo = _repo(tmp_path)
|
||||
_write_ledger(tmp_path, ["a.py\tsym\tfirst"])
|
||||
_stop(env, repo)
|
||||
_write_ledger(tmp_path, ["b.py\tsym\tsecond"])
|
||||
_stop(env, repo)
|
||||
assert seen[-1]["phase"] == ["check"]
|
||||
assert seen[-1]["written"] == ["b.py\tsym\tsecond\na.py\tsym\tfirst"]
|
||||
assert [q["phase"] for q in seen] == [["check"], ["check"]], "no prompt read it: no answer to record"
|
||||
|
||||
|
||||
def test_the_stop_hook_never_blocks(tmp_path):
|
||||
"""Structural, and able to fail: no decision is ever printed."""
|
||||
code = [ln for ln in CHECK.read_text().splitlines() if not ln.lstrip().startswith("#")]
|
||||
assert not any('"decision"' in ln or "block" in ln for ln in code)
|
||||
|
||||
|
||||
def test_no_note_without_one_from_the_instance(tmp_path):
|
||||
with http_sink(b'{"status":"ok"}') as (port, _seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
_write_ledger(tmp_path, ["a.py\tsym\thelper"])
|
||||
ledger = _write_ledger(tmp_path, ["a.py\tsym\thelper"])
|
||||
assert _stop(env, _repo(tmp_path)) == ""
|
||||
assert not _note_file(tmp_path).exists()
|
||||
assert not ledger.exists()
|
||||
|
||||
|
||||
def test_another_hooks_block_loop_is_left_alone(tmp_path):
|
||||
with http_sink(b'{"status":"ok","reason":"x"}') as (port, seen):
|
||||
with http_sink(b'{"status":"ok","note":"x"}') as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
ledger = _write_ledger(tmp_path, ["a.py\tsym\thelper"])
|
||||
assert _stop(env, _repo(tmp_path), active=True) == ""
|
||||
|
||||
Reference in New Issue
Block a user