@leocm/flowcraft 2.2.0 → 2.3.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.
Files changed (96) hide show
  1. package/README.md +7 -2
  2. package/bin/cli.js +108 -108
  3. package/flowcraft.yaml +30 -30
  4. package/install.sh +24 -24
  5. package/lib/args.js +38 -38
  6. package/lib/config.js +20 -20
  7. package/lib/copy.js +131 -131
  8. package/lib/fix.js +110 -110
  9. package/lib/fsutil.js +104 -104
  10. package/lib/global.js +229 -229
  11. package/lib/init.js +43 -43
  12. package/lib/runtime.js +84 -84
  13. package/lib/version.js +55 -55
  14. package/lib/wizard.js +125 -125
  15. package/package.json +33 -33
  16. package/presets/backend.yaml +20 -20
  17. package/presets/default.yaml +15 -15
  18. package/presets/frontend.yaml +20 -20
  19. package/presets/quick-fix.yaml +15 -15
  20. package/setup/.claude/hooks/check-phase-test.py +152 -152
  21. package/setup/.claude/hooks/check-phase-write.py +235 -235
  22. package/setup/.claude/hooks/dispatch.py +67 -67
  23. package/setup/.claude/hooks/file-suggestion.py +45 -45
  24. package/setup/.claude/hooks/flowcraft_env.py +162 -162
  25. package/setup/.claude/hooks/permission-request.py +132 -132
  26. package/setup/.claude/hooks/post-tool-failure.py +36 -36
  27. package/setup/.claude/hooks/pre-compact.py +66 -66
  28. package/setup/.claude/hooks/review-runner.py +846 -846
  29. package/setup/.claude/hooks/setup-keys.py +282 -282
  30. package/setup/.claude/hooks/statusline.py +63 -63
  31. package/setup/.claude/hooks/stop-check.py +186 -186
  32. package/setup/.claude/hooks/subagent-start.py +50 -50
  33. package/setup/.claude/hooks/subagent-stop.py +63 -63
  34. package/setup/.claude/hooks/task-completed.py +57 -57
  35. package/setup/.claude/hooks/task_manager.py +592 -592
  36. package/setup/.claude/hooks/user-prompt-submit.py +91 -91
  37. package/setup/.claude/settings.json +233 -233
  38. package/setup/.claude/skills/Pstatus/SKILL.md +68 -68
  39. package/setup/.claude/skills/archive/SKILL.md +195 -195
  40. package/setup/.claude/skills/brainstorming/SKILL.md +5 -5
  41. package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -723
  42. package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -245
  43. package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -178
  44. package/setup/.claude/skills/brainstorming/visual-companion.md +298 -298
  45. package/setup/.claude/skills/chrome-integration/SKILL.md +66 -66
  46. package/setup/.claude/skills/code-review/SKILL.md +264 -264
  47. package/setup/.claude/skills/executing-plans/SKILL.md +1 -1
  48. package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  49. package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  50. package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  51. package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  52. package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  53. package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  54. package/setup/.claude/skills/methodology/SKILL.md +124 -0
  55. package/setup/.claude/skills/phase/SKILL.md +62 -62
  56. package/setup/.claude/skills/playwright/SKILL.md +85 -85
  57. package/setup/.claude/skills/review/SKILL.md +97 -97
  58. package/setup/.claude/skills/task/SKILL.md +26 -26
  59. package/setup/.claude/skills/test-driven-development/SKILL.md +1 -1
  60. package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +1 -1
  61. package/setup/.claude/skills/verification-before-completion/SKILL.md +1 -1
  62. package/setup/.claude/skills/writing-plans/SKILL.md +1 -1
  63. package/setup/.codex/.agents/skills/archive/SKILL.md +195 -195
  64. package/setup/.codex/.agents/skills/brainstorming/SKILL.md +5 -5
  65. package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -723
  66. package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -245
  67. package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -178
  68. package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -298
  69. package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +66 -66
  70. package/setup/.codex/.agents/skills/code-review/SKILL.md +264 -264
  71. package/setup/.codex/.agents/skills/executing-plans/SKILL.md +1 -1
  72. package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  73. package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  74. package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  75. package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  76. package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  77. package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  78. package/setup/.codex/.agents/skills/methodology/SKILL.md +124 -0
  79. package/setup/.codex/.agents/skills/phase/SKILL.md +62 -62
  80. package/setup/.codex/.agents/skills/playwright/SKILL.md +85 -85
  81. package/setup/.codex/.agents/skills/review/SKILL.md +97 -97
  82. package/setup/.codex/.agents/skills/task/SKILL.md +27 -27
  83. package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +1 -1
  84. package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +1 -1
  85. package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +1 -1
  86. package/setup/.codex/.agents/skills/writing-plans/SKILL.md +1 -1
  87. package/setup/.codex/hooks/review-runner.py +851 -851
  88. package/setup/.codex/hooks/setup-keys.py +287 -287
  89. package/setup/AGENTS.md +11 -1
  90. package/setup/CLAUDE.md +11 -1
  91. package/setup/install.sh +24 -24
  92. package/setup/tests/test_decision_timeout.py +241 -241
  93. package/setup/tests/test_hook_guards.py +357 -357
  94. package/setup/tests/test_sdlc_bootstrap.py +167 -167
  95. package/setup/tests/test_sessionlog_switch.py +199 -199
  96. package/setup/tests/test_task_manager.py +148 -148
@@ -1,199 +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"]
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"]