1
0
Эх сурвалжийг харах

fix: stop blocking direct edits to state.json (#113)

Audit fixes routinely need dozens of state.json updates that
update_state.py flags cannot express, and the guard hook forced users
to apply them by hand. state.json has its own backup and rebuild path,
so direct edits are safe to allow. Event-store and read-model files
(.story-system/commits/, index.db, vectors.db, projection_log.jsonl)
remain protected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lingfengQAQ 1 долоо хоног өмнө
parent
commit
f3bd9b2637

+ 3 - 1
webnovel-writer/hooks/guard_runtime_write.py

@@ -11,9 +11,11 @@ from typing import Any
 
 
 DISABLE_ENV = "WEBNOVEL_DISABLE_RUNTIME_GUARD_HOOK"
+# state.json is intentionally NOT protected: audits routinely require bulk
+# fixes that update_state.py flags cannot express, and state.json has its own
+# backup + rebuild path (issue #113).
 PROTECTED_SUFFIXES = (
     ".story-system/commits/",
-    ".webnovel/state.json",
     ".webnovel/index.db",
     ".webnovel/vectors.db",
     ".webnovel/memory_scratchpad.json",

+ 25 - 1
webnovel-writer/scripts/tests/test_hooks.py

@@ -47,7 +47,9 @@ def test_guard_blocks_direct_commit_file_write():
     assert "permissionDecision" in proc.stderr
 
 
-def test_guard_blocks_direct_state_write():
+def test_guard_allows_direct_state_write():
+    # issue #113: audit fixes need direct state.json edits; the guard no
+    # longer blocks them.
     proc = _run_guard(
         {
             "tool_name": "Edit",
@@ -55,6 +57,28 @@ def test_guard_blocks_direct_state_write():
         }
     )
 
+    assert proc.returncode == 0
+
+
+def test_guard_allows_bash_state_write():
+    proc = _run_guard(
+        {
+            "tool_name": "Bash",
+            "tool_input": {"command": 'python fix_state.py > "D:/book/.webnovel/state.json"'},
+        }
+    )
+
+    assert proc.returncode == 0
+
+
+def test_guard_still_blocks_index_db_write():
+    proc = _run_guard(
+        {
+            "tool_name": "Edit",
+            "tool_input": {"file_path": r"D:\book\.webnovel\index.db"},
+        }
+    )
+
     assert proc.returncode == 2