-
Notifications
You must be signed in to change notification settings - Fork 1
[Hook architecture](16) Put the demo-freeze hook onto the shared hook code #731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 18 commits into
main
from
plan/hook-architecture-16-put-the-demo-freeze-hook-onto-the-shared-hook-code
Sep 17, 2026
+133
−13
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
027cc35
invoker: wf-1789406883560-32/implement-hook-build-the-lever — Put the…
bbebd6e
invoker: wf-1789406883560-32/verify-hook-build-the-lever — Run the de…
5c0096b
invoker: wf-1789406883560-32/scrub-handoff-artifacts — Terminal read-…
eccbe83
Merge experiment/wf-1789406883560-32/scrub-handoff-artifacts/g1.t5.a-…
EdbertChan 7757396
invoker: wf-1789406886887-33/implement-hook-cat-mode-default — Put th…
13ec88c
invoker: wf-1789406886887-33/verify-hook-cat-mode-default — Run the d…
163d9e8
invoker: wf-1789406886887-33/scrub-handoff-artifacts — Terminal read-…
87798db
Merge experiment/wf-1789406886887-33/scrub-handoff-artifacts/g1.t5.a-…
EdbertChan 49b348f
invoker: wf-1789406891093-34/implement-hook-categorical-scope-guard —…
fcfbe21
invoker: wf-1789406891093-34/verify-hook-categorical-scope-guard — Ru…
0cc8306
invoker: wf-1789406891093-34/scrub-handoff-artifacts — Terminal read-…
2b76f0a
Merge experiment/wf-1789406891093-34/scrub-handoff-artifacts/g1.t5.a-…
EdbertChan c67ac17
invoker: wf-1789406894793-35/implement-hook-demo-freeze — Put the dem…
60c89ff
invoker: wf-1789406894793-35/implement-hook-demo-freeze — Put the dem…
b9e01d7
invoker: wf-1789406894793-35/verify-hook-demo-freeze — Run the determ…
63cf3dd
invoker: wf-1789406894793-35/scrub-handoff-artifacts — Terminal read-…
f60edf6
Merge experiment/wf-1789406894793-35/scrub-handoff-artifacts/g1.t8.a-…
EdbertChan 2145fbf
Merge remote-tracking branch 'origin/main' into plan/hook-architectur…
EdbertChan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| HERE = os.path.dirname(os.path.abspath(__file__)) | ||
| HOOK_DIR = os.path.dirname(HERE) | ||
| ENTRYPOINT = os.path.join(HOOK_DIR, "claude_pretooluse_check.py") | ||
|
|
||
|
|
||
| def write_marker(lines: list[str]) -> str: | ||
| handle = tempfile.NamedTemporaryFile("w", suffix=".demo-freeze", delete=False, encoding="utf-8") | ||
| with handle: | ||
| handle.write("\n".join(lines) + "\n") | ||
| return handle.name | ||
|
|
||
|
|
||
| def run_entrypoint(payload: dict[str, object], env: dict[str, str]) -> subprocess.CompletedProcess[str]: | ||
| merged_env = os.environ.copy() | ||
| merged_env.update(env) | ||
| return subprocess.run( | ||
| [sys.executable, ENTRYPOINT], | ||
| input=json.dumps(payload), | ||
| capture_output=True, | ||
| text=True, | ||
| env=merged_env, | ||
| ) | ||
|
|
||
|
|
||
| class SdkModeTest(unittest.TestCase): | ||
| def test_mode_override_warn_changes_block_to_warning(self) -> None: | ||
| marker = write_marker(["/tmp/demo/call.html"]) | ||
| try: | ||
| result = run_entrypoint( | ||
| {"tool_name": "Edit", "tool_input": {"file_path": "/tmp/demo/call.html"}}, | ||
| { | ||
| "DEMO_FREEZE_FILE": marker, | ||
| "CATSTACK_HOOK_MODE_DEMO_FREEZE": "warn", | ||
| }, | ||
| ) | ||
| finally: | ||
| os.unlink(marker) | ||
|
|
||
| self.assertEqual(0, result.returncode, result.stderr) | ||
| self.assertEqual("", result.stderr) | ||
| rendered = json.loads(result.stdout) | ||
| self.assertIn( | ||
| "Demo surface frozen", | ||
| rendered["hookSpecificOutput"]["additionalContext"], | ||
| ) | ||
|
|
||
| def test_mode_stop_still_blocks_by_default(self) -> None: | ||
| marker = write_marker(["/tmp/demo/call.html"]) | ||
| try: | ||
| result = run_entrypoint( | ||
| {"tool_name": "Edit", "tool_input": {"file_path": "/tmp/demo/call.html"}}, | ||
| {"DEMO_FREEZE_FILE": marker}, | ||
| ) | ||
| finally: | ||
| os.unlink(marker) | ||
|
|
||
| self.assertEqual(2, result.returncode) | ||
| self.assertIn("Demo surface frozen", result.stderr) | ||
|
|
||
| def test_each_finding_writes_one_event_row_with_rule_id(self) -> None: | ||
| marker = write_marker(["/tmp/demo/call.html"]) | ||
| try: | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| result = run_entrypoint( | ||
| { | ||
| "tool_name": "Edit", | ||
| "session_id": "demo-freeze-sdk-mode", | ||
| "tool_input": {"file_path": "/tmp/demo/call.html"}, | ||
| }, | ||
| { | ||
| "DEMO_FREEZE_FILE": marker, | ||
| "CATSTACK_HOOK_METRICS_DIR": tmp, | ||
| "CATSTACK_HOOK_MODE_DEMO_FREEZE": "warn", | ||
| }, | ||
| ) | ||
| rows = [ | ||
| json.loads(line) | ||
| for file in Path(tmp).glob("events-*.jsonl") | ||
| for line in file.read_text(encoding="utf-8").splitlines() | ||
| ] | ||
| finally: | ||
| os.unlink(marker) | ||
|
|
||
| self.assertEqual(0, result.returncode, result.stderr) | ||
| self.assertEqual(1, len(rows)) | ||
| self.assertEqual("demo-freeze", rows[0]["hook"]) | ||
| self.assertEqual("demo-freeze.frozen-path", rows[0]["rule_id"]) | ||
| self.assertEqual("warn", rows[0]["mode"]) | ||
| self.assertEqual("override", rows[0]["mode_source"]) | ||
| self.assertEqual("warned", rows[0]["action"]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installed hook cannot import shared runtime
High Severity
The new
_sdkimport walks two directories up from this script. The installed command runs from~/.claude/hooks/demo-freeze, andinstall.shnever links_sdknext to that folder, so the process dies on import. Claude then fail-opens and a frozen demo path is no longer blocked.Reviewed by Cursor Bugbot for commit f60edf6. Configure here.