@leocm/flowcraft 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/lib/config.js +1 -1
- package/package.json +1 -1
- package/setup/.claude/hooks/flowcraft_env.py +25 -0
- package/setup/.claude/hooks/permission-request.py +11 -4
- package/setup/.claude/hooks/stop-check.py +41 -26
- package/setup/.claude/hooks/user-prompt-submit.py +6 -0
- package/setup/.claude/settings.json +0 -4
- package/setup/tests/test_sessionlog_switch.py +199 -0
package/README.md
CHANGED
|
@@ -104,11 +104,11 @@ FLowCraft框架是一套基于 Claude Code 的智能开发流程管理系统。
|
|
|
104
104
|
### 方式零:npm 包安装(跨平台,无 bash 依赖)
|
|
105
105
|
|
|
106
106
|
```bash
|
|
107
|
-
# 打包(仓库内执行,产出 leocm-flowcraft-2.
|
|
107
|
+
# 打包(仓库内执行,产出 leocm-flowcraft-2.2.0.tgz)
|
|
108
108
|
npm pack ./flowcraft
|
|
109
109
|
|
|
110
110
|
# 全局安装后提供 flowcraft 命令
|
|
111
|
-
npm i -g leocm-flowcraft-2.
|
|
111
|
+
npm i -g leocm-flowcraft-2.2.0.tgz
|
|
112
112
|
|
|
113
113
|
# 常用命令(与 install.sh 参数面等价)
|
|
114
114
|
flowcraft install --quick # 项目安装
|
|
@@ -121,6 +121,13 @@ flowcraft install --sessionlog # 分发默认 http://
|
|
|
121
121
|
flowcraft install --sessionlog http://host:8181/api/logs # 分发指定地址
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
本地会话日志开关(`flowcraft.yaml`,默认开;`false` 时停止写入 `.claude/session_log.json`):
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
sessionlog:
|
|
128
|
+
local: false
|
|
129
|
+
```
|
|
130
|
+
|
|
124
131
|
### 方式一:自动安装(推荐)
|
|
125
132
|
|
|
126
133
|
#### 前置条件
|
|
@@ -827,6 +834,11 @@ MIT License
|
|
|
827
834
|
|
|
828
835
|
## 更新日志
|
|
829
836
|
|
|
837
|
+
### v2.2.0 (2026-10-15)
|
|
838
|
+
- 本地会话日志开关:`flowcraft.yaml` 新增 `sessionlog.local`(默认开;false 停止写入 `.claude/session_log.json`)
|
|
839
|
+
- 修复重启/新建会话后首消息卡顿:settings.json 模板不再默认启用未安装插件(enabledPlugins 移除)
|
|
840
|
+
- 守卫根解析对齐:permission-request 子目录会话不再误判 P0 拦截代码写入
|
|
841
|
+
|
|
830
842
|
### v2.1.0 (2026-10-12)
|
|
831
843
|
- Sessionlog 分发改为明确启用:`--sessionlog [url]`(默认不分发;裸旗标分发 `http://127.0.0.1:8181/api/logs`);默认地址 `192.168.2.99`→`127.0.0.1`
|
|
832
844
|
- 守卫修复:`.claude/` 拦截锚定 project_root,用户级 `~/.claude/**`(如计划草稿)放行;白名单补 `plans/`
|
package/lib/config.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
const SESSIONLOG_URL = 'http://127.0.0.1:8181/api/logs';
|
|
8
8
|
|
|
9
9
|
/** 框架版本(与 package.json version / README 一致,发版时两处同步) */
|
|
10
|
-
const FRAMEWORK_VERSION = '2.
|
|
10
|
+
const FRAMEWORK_VERSION = '2.2.0';
|
|
11
11
|
|
|
12
12
|
/** 需要 PATH 注入的 hook 文件清单(对齐 install.sh add_path_to_hooks) */
|
|
13
13
|
const HOOK_FILES = [
|
package/package.json
CHANGED
|
@@ -135,3 +135,28 @@ def extract_nested(raw, key):
|
|
|
135
135
|
# Regex fallback for unparseable payloads
|
|
136
136
|
m = re.search(r'"%s"\s*:\s*"((?:[^"\\]|\\.)*)"' % re.escape(key), text)
|
|
137
137
|
return m.group(1) if m else ""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def sessionlog_local_enabled(project_root: Path = None) -> bool:
|
|
141
|
+
"""Read sessionlog.local from flowcraft.yaml (PRD R1); default True.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
project_root: Project root dir; None resolves via get_project_root().
|
|
145
|
+
Returns:
|
|
146
|
+
False only when flowcraft.yaml sets ``sessionlog.local: false``;
|
|
147
|
+
True otherwise (absent key / malformed config keeps legacy behaviour).
|
|
148
|
+
"""
|
|
149
|
+
try:
|
|
150
|
+
root = Path(project_root) if project_root else get_project_root()
|
|
151
|
+
cfg = root / "flowcraft.yaml"
|
|
152
|
+
if cfg.is_file():
|
|
153
|
+
m = re.search(
|
|
154
|
+
r"^sessionlog:\s*$(?:(?!^[^\s]).)*?^ local:\s*(true|false)",
|
|
155
|
+
cfg.read_text(encoding="utf-8"),
|
|
156
|
+
re.M | re.S,
|
|
157
|
+
)
|
|
158
|
+
if m:
|
|
159
|
+
return m.group(1).lower() != "false"
|
|
160
|
+
except Exception:
|
|
161
|
+
pass
|
|
162
|
+
return True
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""PermissionRequest - generic security permission check (no phase limit)."""
|
|
3
3
|
import json
|
|
4
|
-
import os
|
|
5
4
|
import re
|
|
6
5
|
import sys
|
|
7
|
-
from pathlib import Path
|
|
8
6
|
|
|
9
|
-
from flowcraft_env import extract_nested
|
|
7
|
+
from flowcraft_env import extract_nested, get_project_root
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
def phase_number() -> int:
|
|
13
|
-
|
|
11
|
+
"""Resolve the current SDLC phase (R4: root resolution aligned with other hooks).
|
|
12
|
+
|
|
13
|
+
Uses flowcraft_env.get_project_root() so sessions launched from a project
|
|
14
|
+
subdirectory resolve the same project-state.md as the rest of the hook
|
|
15
|
+
chain (CLAUDE_PROJECT_DIR → cwd walk-up → script-location fallback).
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
Phase number, or 0 when no state file exists (P0 semantics).
|
|
19
|
+
"""
|
|
20
|
+
state_file = get_project_root() / ".claude" / "project-state.md"
|
|
14
21
|
if not state_file.is_file():
|
|
15
22
|
return 0
|
|
16
23
|
try:
|
|
@@ -10,6 +10,7 @@ import time
|
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
|
|
12
12
|
import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
|
|
13
|
+
from flowcraft_env import sessionlog_local_enabled # R1: 本地日志开关
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def _sanitize(text: str) -> str:
|
|
@@ -76,6 +77,43 @@ def _update_decision_marker(project_dir: Path, ai_message: str) -> None:
|
|
|
76
77
|
pass
|
|
77
78
|
|
|
78
79
|
|
|
80
|
+
def _write_session_log(project_dir: Path, session_log: Path, log_script: Path, ai_message: str) -> None:
|
|
81
|
+
"""Write the assistant message to the local session log via log_session.py.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
project_dir: Project root directory.
|
|
85
|
+
session_log: Path to session_log.json.
|
|
86
|
+
log_script: Path to the log_session.py hook script.
|
|
87
|
+
ai_message: Sanitized assistant message text.
|
|
88
|
+
"""
|
|
89
|
+
git_user = "unknown"
|
|
90
|
+
try:
|
|
91
|
+
r = subprocess.run(
|
|
92
|
+
["git", "config", "user.name"],
|
|
93
|
+
capture_output=True,
|
|
94
|
+
text=True,
|
|
95
|
+
timeout=3,
|
|
96
|
+
)
|
|
97
|
+
if r.returncode == 0 and r.stdout.strip():
|
|
98
|
+
git_user = r.stdout.strip()
|
|
99
|
+
except Exception:
|
|
100
|
+
pass
|
|
101
|
+
fd, temp_input = tempfile.mkstemp()
|
|
102
|
+
try:
|
|
103
|
+
with os.fdopen(fd, "w", encoding="utf-8") as tf:
|
|
104
|
+
tf.write(ai_message)
|
|
105
|
+
env = dict(os.environ)
|
|
106
|
+
env["SESSION_LOG"] = str(session_log)
|
|
107
|
+
env["GIT_USER"] = git_user
|
|
108
|
+
env["TEMP_INPUT"] = temp_input
|
|
109
|
+
subprocess.run([sys.executable, str(log_script), "assistant"], env=env)
|
|
110
|
+
finally:
|
|
111
|
+
try:
|
|
112
|
+
os.unlink(temp_input)
|
|
113
|
+
except OSError:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
|
|
79
117
|
def main() -> int:
|
|
80
118
|
raw = sys.stdin.read()
|
|
81
119
|
|
|
@@ -123,32 +161,9 @@ def main() -> int:
|
|
|
123
161
|
pass
|
|
124
162
|
ai_message = _sanitize(ai_message)
|
|
125
163
|
if ai_message:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
["git", "config", "user.name"],
|
|
130
|
-
capture_output=True,
|
|
131
|
-
text=True,
|
|
132
|
-
timeout=3,
|
|
133
|
-
)
|
|
134
|
-
if r.returncode == 0 and r.stdout.strip():
|
|
135
|
-
git_user = r.stdout.strip()
|
|
136
|
-
except Exception:
|
|
137
|
-
pass
|
|
138
|
-
fd, temp_input = tempfile.mkstemp()
|
|
139
|
-
try:
|
|
140
|
-
with os.fdopen(fd, "w", encoding="utf-8") as tf:
|
|
141
|
-
tf.write(ai_message)
|
|
142
|
-
env = dict(os.environ)
|
|
143
|
-
env["SESSION_LOG"] = str(session_log)
|
|
144
|
-
env["GIT_USER"] = git_user
|
|
145
|
-
env["TEMP_INPUT"] = temp_input
|
|
146
|
-
subprocess.run([sys.executable, str(log_script), "assistant"], env=env)
|
|
147
|
-
finally:
|
|
148
|
-
try:
|
|
149
|
-
os.unlink(temp_input)
|
|
150
|
-
except OSError:
|
|
151
|
-
pass
|
|
164
|
+
# R1: 本地日志开关——sessionlog.local=false 时跳过写入(默认开)
|
|
165
|
+
if sessionlog_local_enabled(Path(project_dir)):
|
|
166
|
+
_write_session_log(Path(project_dir), session_log, log_script, ai_message)
|
|
152
167
|
|
|
153
168
|
# R4/R5: 待决决策标记维护(决策卡写入,其余回合清除)
|
|
154
169
|
_update_decision_marker(Path(project_dir), ai_message)
|
|
@@ -7,6 +7,8 @@ import sys
|
|
|
7
7
|
import tempfile
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from flowcraft_env import sessionlog_local_enabled # R1: 本地日志开关
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
def _sanitize(text: str) -> str:
|
|
12
14
|
"""Strip UTF-16 surrogates that json.loads may preserve on Windows."""
|
|
@@ -49,6 +51,10 @@ def main() -> int:
|
|
|
49
51
|
except OSError:
|
|
50
52
|
pass
|
|
51
53
|
|
|
54
|
+
# R1: 本地日志开关——sessionlog.local=false 时跳过写入(默认开)
|
|
55
|
+
if not sessionlog_local_enabled(Path(project_dir)):
|
|
56
|
+
return 0
|
|
57
|
+
|
|
52
58
|
# Get the git user name
|
|
53
59
|
git_user = "unknown"
|
|
54
60
|
try:
|
|
@@ -207,10 +207,6 @@
|
|
|
207
207
|
"command": "python ~/.flowcraft/hooks/dispatch.py statusline",
|
|
208
208
|
"padding": 1
|
|
209
209
|
},
|
|
210
|
-
"enabledPlugins": {
|
|
211
|
-
"superpowers@claude-plugins-official": true,
|
|
212
|
-
"context-hub-plugin@forgetful-plugins": true
|
|
213
|
-
},
|
|
214
210
|
"language": "zh-CN",
|
|
215
211
|
"sandbox": {
|
|
216
212
|
"enabled": true,
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Session-log local switch (PRD R1) + settings template plugin cleanup (PRD R2)
|
|
2
|
+
+ permission-request root fallback (PRD R4).
|
|
3
|
+
|
|
4
|
+
R1: flowcraft.yaml `sessionlog.local` gates local session_log.json writes;
|
|
5
|
+
default (key absent / unparseable) keeps the legacy always-write behaviour.
|
|
6
|
+
R2: the Claude settings template must not enable uninstalled plugins.
|
|
7
|
+
R4: permission-request.py resolves the project root via walk-up, so
|
|
8
|
+
subdirectory-launched sessions see the same phase as the rest of the hooks.
|
|
9
|
+
"""
|
|
10
|
+
import importlib.util
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import pytest
|
|
18
|
+
|
|
19
|
+
HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
|
|
20
|
+
SETTINGS_TEMPLATE = HOOKS.parent / "settings.json"
|
|
21
|
+
sys.path.insert(0, str(HOOKS))
|
|
22
|
+
|
|
23
|
+
# Stub log_session.py: drop a marker next to .claude/ when invoked, so the
|
|
24
|
+
# tests observe the *call*, not the JSON payload.
|
|
25
|
+
STUB_LOG = (
|
|
26
|
+
"from pathlib import Path\n"
|
|
27
|
+
"Path(__file__).resolve().parent.parent.joinpath('log_called.marker').write_text('1', encoding='utf-8')\n"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load_hook_module(name, filename):
|
|
32
|
+
"""Load a hook script as a module for unit tests."""
|
|
33
|
+
spec = importlib.util.spec_from_file_location(name, HOOKS / filename)
|
|
34
|
+
mod = importlib.util.module_from_spec(spec)
|
|
35
|
+
spec.loader.exec_module(mod)
|
|
36
|
+
return mod
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
flowcraft_env = load_hook_module("flowcraft_env_switch_ut", "flowcraft_env.py")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def make_project(root, local=None):
|
|
43
|
+
"""Create a minimal SDLC project; optionally configure sessionlog.local."""
|
|
44
|
+
(root / ".claude").mkdir(parents=True, exist_ok=True)
|
|
45
|
+
(root / ".claude" / "project-state.md").write_text(
|
|
46
|
+
'current_phase: P2\ntask_description: "t"\n', encoding="utf-8"
|
|
47
|
+
)
|
|
48
|
+
hooks = root / ".claude" / "hooks"
|
|
49
|
+
hooks.mkdir(exist_ok=True)
|
|
50
|
+
(hooks / "log_session.py").write_text(STUB_LOG, encoding="utf-8")
|
|
51
|
+
if local is not None:
|
|
52
|
+
(root / "flowcraft.yaml").write_text(
|
|
53
|
+
f"sessionlog:\n local: {str(local).lower()}\n", encoding="utf-8"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run_hook(name, payload, cwd):
|
|
58
|
+
"""Run a hook script against a fake project via CLAUDE_PROJECT_DIR."""
|
|
59
|
+
env = os.environ.copy()
|
|
60
|
+
env["CLAUDE_PROJECT_DIR"] = str(cwd)
|
|
61
|
+
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
62
|
+
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
63
|
+
return subprocess.run(
|
|
64
|
+
[sys.executable, str(HOOKS / name)],
|
|
65
|
+
input=payload,
|
|
66
|
+
capture_output=True,
|
|
67
|
+
encoding="utf-8",
|
|
68
|
+
errors="replace",
|
|
69
|
+
cwd=str(cwd),
|
|
70
|
+
env=env,
|
|
71
|
+
timeout=60,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def marker(root):
|
|
76
|
+
"""Path of the stub log marker file."""
|
|
77
|
+
return root / ".claude" / "log_called.marker"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# ---------- R1: flowcraft.yaml config parsing ----------
|
|
81
|
+
|
|
82
|
+
class TestSessionlogLocalConfig:
|
|
83
|
+
def test_no_yaml_defaults_true(self, tmp_path):
|
|
84
|
+
assert flowcraft_env.sessionlog_local_enabled(tmp_path) is True
|
|
85
|
+
|
|
86
|
+
def test_false_disables(self, tmp_path):
|
|
87
|
+
(tmp_path / "flowcraft.yaml").write_text("sessionlog:\n local: false\n", encoding="utf-8")
|
|
88
|
+
assert flowcraft_env.sessionlog_local_enabled(tmp_path) is False
|
|
89
|
+
|
|
90
|
+
def test_true_enables(self, tmp_path):
|
|
91
|
+
(tmp_path / "flowcraft.yaml").write_text("sessionlog:\n local: true\n", encoding="utf-8")
|
|
92
|
+
assert flowcraft_env.sessionlog_local_enabled(tmp_path) is True
|
|
93
|
+
|
|
94
|
+
def test_malformed_yaml_defaults_true(self, tmp_path):
|
|
95
|
+
(tmp_path / "flowcraft.yaml").write_text("sessionlog: [broken\n", encoding="utf-8")
|
|
96
|
+
assert flowcraft_env.sessionlog_local_enabled(tmp_path) is True
|
|
97
|
+
|
|
98
|
+
def test_other_section_local_not_misread(self, tmp_path):
|
|
99
|
+
"""审查修复: 其他配置节的缩进 local: 不得被误读为日志开关。"""
|
|
100
|
+
(tmp_path / "flowcraft.yaml").write_text(
|
|
101
|
+
"sessionlog:\n url: http://x\nother:\n local: false\n", encoding="utf-8"
|
|
102
|
+
)
|
|
103
|
+
assert flowcraft_env.sessionlog_local_enabled(tmp_path) is True
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ---------- R1: user-prompt-submit hook gating ----------
|
|
107
|
+
|
|
108
|
+
class TestUserPromptSubmitSwitch:
|
|
109
|
+
def test_default_writes(self, tmp_path):
|
|
110
|
+
make_project(tmp_path)
|
|
111
|
+
run_hook("user-prompt-submit.py", "hi", tmp_path)
|
|
112
|
+
assert marker(tmp_path).exists()
|
|
113
|
+
|
|
114
|
+
def test_local_false_skips(self, tmp_path):
|
|
115
|
+
make_project(tmp_path, local=False)
|
|
116
|
+
p = run_hook("user-prompt-submit.py", "hi", tmp_path)
|
|
117
|
+
assert p.returncode == 0
|
|
118
|
+
assert not marker(tmp_path).exists()
|
|
119
|
+
|
|
120
|
+
def test_local_true_writes(self, tmp_path):
|
|
121
|
+
make_project(tmp_path, local=True)
|
|
122
|
+
run_hook("user-prompt-submit.py", "hi", tmp_path)
|
|
123
|
+
assert marker(tmp_path).exists()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# ---------- R1: stop-check hook gating ----------
|
|
127
|
+
|
|
128
|
+
class TestStopCheckSwitch:
|
|
129
|
+
def test_default_writes(self, tmp_path):
|
|
130
|
+
make_project(tmp_path)
|
|
131
|
+
run_hook("stop-check.py", json.dumps({"last_assistant_message": "hi"}), tmp_path)
|
|
132
|
+
assert marker(tmp_path).exists()
|
|
133
|
+
|
|
134
|
+
def test_local_false_skips(self, tmp_path):
|
|
135
|
+
make_project(tmp_path, local=False)
|
|
136
|
+
p = run_hook("stop-check.py", json.dumps({"last_assistant_message": "hi"}), tmp_path)
|
|
137
|
+
assert p.returncode == 0
|
|
138
|
+
assert not marker(tmp_path).exists()
|
|
139
|
+
|
|
140
|
+
def test_local_true_writes(self, tmp_path):
|
|
141
|
+
make_project(tmp_path, local=True)
|
|
142
|
+
run_hook("stop-check.py", json.dumps({"last_assistant_message": "hi"}), tmp_path)
|
|
143
|
+
assert marker(tmp_path).exists()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# ---------- R2: settings template has no enabled plugins ----------
|
|
147
|
+
|
|
148
|
+
class TestSettingsTemplateNoPlugins:
|
|
149
|
+
def test_no_enabled_plugins(self):
|
|
150
|
+
"""PRD R2: 模板不再默认启用未安装插件(消除启动期网络解析)。"""
|
|
151
|
+
text = SETTINGS_TEMPLATE.read_text(encoding="utf-8")
|
|
152
|
+
assert "enabledPlugins" not in text
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# ---------- R4: permission-request root fallback ----------
|
|
156
|
+
|
|
157
|
+
def run_permission_request(cwd, payload):
|
|
158
|
+
"""Run permission-request.py without CLAUDE_PROJECT_DIR (subdir session)."""
|
|
159
|
+
env = os.environ.copy()
|
|
160
|
+
env.pop("CLAUDE_PROJECT_DIR", None)
|
|
161
|
+
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
162
|
+
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
163
|
+
return subprocess.run(
|
|
164
|
+
[sys.executable, str(HOOKS / "permission-request.py")],
|
|
165
|
+
input=payload,
|
|
166
|
+
capture_output=True,
|
|
167
|
+
encoding="utf-8",
|
|
168
|
+
errors="replace",
|
|
169
|
+
cwd=str(cwd),
|
|
170
|
+
env=env,
|
|
171
|
+
timeout=60,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def write_payload(path):
|
|
176
|
+
"""Build a Write-tool payload for a .py target."""
|
|
177
|
+
return json.dumps({"tool_name": "Write", "tool_input": {"file_path": str(path)}})
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class TestPermissionRequestRootFallback:
|
|
181
|
+
def test_subdir_session_resolves_parent_state(self, tmp_path):
|
|
182
|
+
"""R4: 子目录启动会话经 walk-up 解析到根状态(P2)→代码写入放行。"""
|
|
183
|
+
root = tmp_path / "proj"
|
|
184
|
+
sub = root / "sub"
|
|
185
|
+
sub.mkdir(parents=True)
|
|
186
|
+
(root / ".claude").mkdir()
|
|
187
|
+
(root / ".claude" / "project-state.md").write_text(
|
|
188
|
+
'current_phase: P2\ntask_description: "t"\n', encoding="utf-8"
|
|
189
|
+
)
|
|
190
|
+
p = run_permission_request(sub, write_payload(sub / "x.py"))
|
|
191
|
+
out = json.loads(p.stdout)
|
|
192
|
+
assert out["hookSpecificOutput"]["decision"]["behavior"] == "allow"
|
|
193
|
+
|
|
194
|
+
def test_no_state_keeps_p0_semantics(self, tmp_path):
|
|
195
|
+
"""R4: 无状态文件项目保持 P0 语义(代码写入拒绝)。"""
|
|
196
|
+
p = run_permission_request(tmp_path, write_payload(tmp_path / "x.py"))
|
|
197
|
+
out = json.loads(p.stdout)
|
|
198
|
+
assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
|
|
199
|
+
assert "P0" in out["hookSpecificOutput"]["decision"]["message"]
|