@leocm/flowcraft 2.0.0 → 2.1.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 CHANGED
@@ -1,4 +1,4 @@
1
- # SDLC框架
1
+ # FLowCraft框架
2
2
 
3
3
  > Claude Code 开发流程框架 - 标准化需求→设计→编码→测试→审查→交付
4
4
 
@@ -19,7 +19,7 @@
19
19
 
20
20
  ## 项目简介
21
21
 
22
- SDLC(Software Development Life Cycle)框架是一套基于 Claude Code 的智能开发流程管理系统。它通过自动化 hooks、标准化流程和 AI 辅助技能,帮助开发者实现从需求分析到交付的全流程规范化管理。
22
+ FLowCraft框架是一套基于 Claude Code 的智能开发流程管理系统。它通过自动化 hooks、标准化流程和 AI 辅助技能,帮助开发者实现从需求分析到交付的全流程规范化管理。
23
23
 
24
24
  ### 核心价值
25
25
 
@@ -104,17 +104,21 @@ SDLC(Software Development Life Cycle)框架是一套基于 Claude Code 的
104
104
  ### 方式零:npm 包安装(跨平台,无 bash 依赖)
105
105
 
106
106
  ```bash
107
- # 打包(仓库内执行,产出 leocm-flowcraft-2.0.0.tgz)
107
+ # 打包(仓库内执行,产出 leocm-flowcraft-2.1.0.tgz)
108
108
  npm pack ./flowcraft
109
109
 
110
110
  # 全局安装后提供 flowcraft 命令
111
- npm i -g leocm-flowcraft-2.0.0.tgz
111
+ npm i -g leocm-flowcraft-2.1.0.tgz
112
112
 
113
113
  # 常用命令(与 install.sh 参数面等价)
114
114
  flowcraft install --quick # 项目安装
115
115
  flowcraft install --global # 用户级全局安装
116
116
  flowcraft init # 当前目录最小化初始化
117
117
  flowcraft install --preset backend # 应用预设
118
+
119
+ # Sessionlog 分发(默认关闭,明确启用才分发)
120
+ flowcraft install --sessionlog # 分发默认 http://127.0.0.1:8181/api/logs
121
+ flowcraft install --sessionlog http://host:8181/api/logs # 分发指定地址
118
122
  ```
119
123
 
120
124
  ### 方式一:自动安装(推荐)
@@ -126,7 +130,7 @@ flowcraft install --preset backend # 应用预设
126
130
 
127
131
  ### claude (推荐)
128
132
  ```bash
129
- 安装 sdlc install.sh
133
+ 安装 FLowCraft install.sh
130
134
 
131
135
  chmod +x ~/.flowcraft/hooks/*.py
132
136
 
@@ -171,7 +175,7 @@ cd your-project
171
175
 
172
176
  ### 方式二:通过 Claude Code 重新安装
173
177
 
174
- 适用于已安装过 SDLC 框架的项目,用于升级或修复。
178
+ 适用于已安装过 FLowCraft 框架的项目,用于升级或修复。
175
179
 
176
180
  #### 前置条件
177
181
 
@@ -182,7 +186,7 @@ cd your-project
182
186
  在 Claude Code 中执行:
183
187
 
184
188
  ```
185
- 重新安装sdlc
189
+ 重新安装FLowCraft
186
190
  ```
187
191
 
188
192
  #### 说明
@@ -258,7 +262,7 @@ Claude 会自动:
258
262
 
259
263
  ```
260
264
  ┌─────────────────────────────────────────────────────────────┐
261
- │ SDLC 工作流程 │
265
+ │ FLowCraft 工作流程 │
262
266
  ├─────────────────────────────────────────────────────────────┤
263
267
  │ │
264
268
  │ P0 等待任务 │
@@ -637,7 +641,7 @@ completed_tasks:
637
641
 
638
642
  ```
639
643
  your-project/
640
- ├── CLAUDE.md # SDLC 流程定义(核心)
644
+ ├── CLAUDE.md # FLowCraft 流程定义(核心)
641
645
  └── .claude/
642
646
  ├── project-state.md # 项目状态(活文档)
643
647
  ├── prd.md # PRD 文档
@@ -666,7 +670,7 @@ your-project/
666
670
  │ ├── gitnexus/
667
671
  │ ├── playwright/
668
672
  │ └── ...
669
- ├── sdlc/ # SDLC 规则文档
673
+ ├── FLowCraft/ # FLowCraft 规则文档
670
674
  │ └── rules/
671
675
  │ ├── 01-lifecycle-phases.md
672
676
  │ ├── 02-coding-standards.md
@@ -694,7 +698,7 @@ your-project/
694
698
  ### 核心文件说明
695
699
 
696
700
  #### `CLAUDE.md`
697
- SDLC 流程定义文件,包含:
701
+ FLowCraft 流程定义文件,包含:
698
702
  - 启动指令
699
703
  - 核心规则
700
704
  - 阶段流程
@@ -810,7 +814,7 @@ Hooks 在 `settings.json` 中配置,支持以下事件:
810
814
  ## 技术支持
811
815
 
812
816
  - **问题反馈**:提交 GitHub Issue
813
- - **文档更新**:查看 `.claude/sdlc/rules/` 目录
817
+ - **文档更新**:查看 `.claude/FLowCraft/rules/` 目录
814
818
  - **技能说明**:查看 `.claude/skills/` 目录
815
819
 
816
820
  ---
@@ -823,6 +827,11 @@ MIT License
823
827
 
824
828
  ## 更新日志
825
829
 
830
+ ### v2.1.0 (2026-10-12)
831
+ - Sessionlog 分发改为明确启用:`--sessionlog [url]`(默认不分发;裸旗标分发 `http://127.0.0.1:8181/api/logs`);默认地址 `192.168.2.99`→`127.0.0.1`
832
+ - 守卫修复:`.claude/` 拦截锚定 project_root,用户级 `~/.claude/**`(如计划草稿)放行;白名单补 `plans/`
833
+ - 钩子输出 UTF-8 双保险:消除 Windows GBK 乱码(进程内 reconfigure + dispatch 子进程 UTF-8)
834
+
826
835
  ### v2.0.0 (2026-09-24)
827
836
  - `--global` 补全用户级安装:skills/commands 分发(Claude + Codex 全局兜底)、Codex 全局 hooks 注册(`~/.codex/hooks.json` 绝对路径)、config.toml `[features]` 特性开关合并
828
837
  - 项目级安装不再复制 hooks/skills/commands(仅建空目录,统一由用户级提供)
package/bin/cli.js CHANGED
@@ -59,9 +59,15 @@ async function runInstall(opts) {
59
59
  addPathToHooks(target);
60
60
  const fixCount = fixLineEndings(target);
61
61
  const replaceCount = replacePythonCommands(target, py);
62
- const urlCount = replaceSessionlogUrl(SESSIONLOG_URL, target, path.join(PKG_ROOT, 'setup', '.claude'));
62
+ // R1/R2:仅 --sessionlog 明确启用才分发(null=未给不分发,''=裸旗标用默认URL)
63
+ let urlCount = 0;
64
+ let sessionlogUrl = null;
65
+ if (opts.sessionlog !== null) {
66
+ sessionlogUrl = opts.sessionlog || SESSIONLOG_URL;
67
+ urlCount = replaceSessionlogUrl(sessionlogUrl, target, path.join(PKG_ROOT, 'setup', '.claude'));
68
+ }
63
69
  writeVersionFile(target, process.cwd(), presetMode || 'default');
64
- showStats({ copyCount, fixCount, replaceCount, urlCount }, process.cwd(), SESSIONLOG_URL);
70
+ showStats({ copyCount, fixCount, replaceCount, urlCount }, process.cwd(), sessionlogUrl);
65
71
  showNextSteps();
66
72
  }
67
73
 
package/lib/args.js CHANGED
@@ -6,10 +6,10 @@
6
6
  /**
7
7
  * 解析命令行参数
8
8
  * @param {string[]} argv 进程参数(不含 node 与脚本路径)
9
- * @returns {{mode:string,presetArg:string|null,presetMode:string,quick:boolean,interactive:boolean,unknown:string[]}} 解析结果
9
+ * @returns {{mode:string,presetArg:string|null,presetMode:string,quick:boolean,interactive:boolean,sessionlog:string|null,unknown:string[]}} 解析结果
10
10
  */
11
11
  function parseArgs(argv) {
12
- const out = { mode: 'install', presetArg: null, presetMode: '', quick: false, interactive: false, unknown: [] };
12
+ const out = { mode: 'install', presetArg: null, presetMode: '', quick: false, interactive: false, sessionlog: null, unknown: [] };
13
13
  const rest = [...argv];
14
14
  while (rest.length > 0) {
15
15
  const a = rest.shift();
@@ -20,7 +20,11 @@ function parseArgs(argv) {
20
20
  out.quick = true;
21
21
  out.presetMode = 'default';
22
22
  } else if (a === '--interactive') out.interactive = true;
23
- else if (a === '--preset') {
23
+ else if (a === '--sessionlog') {
24
+ // 三态:null=未给(不分发)、''=裸旗标(默认URL)、字符串=指定URL;仅消费 http(s) 参数防吞旗标
25
+ const nxt = rest[0];
26
+ out.sessionlog = nxt && /^https?:\/\//.test(nxt) ? rest.shift() : '';
27
+ } else if (a === '--preset') {
24
28
  out.presetArg = rest.shift() || null;
25
29
  if (!out.presetArg) out.unknown.push('--preset(缺参数)');
26
30
  else out.presetMode = out.presetArg.replace(/\.yaml$/, '');
package/lib/config.js CHANGED
@@ -3,11 +3,11 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
- /** 默认 sessionlog MCP 地址(与 install.sh SESSIONLOG_URL 一致) */
7
- const SESSIONLOG_URL = 'http://192.168.2.99:8181/api/logs';
6
+ /** 默认 sessionlog MCP 地址(仅 --sessionlog 裸旗标启用分发时使用;默认不分发) */
7
+ const SESSIONLOG_URL = 'http://127.0.0.1:8181/api/logs';
8
8
 
9
- /** 框架版本(与 write_version_file / README 一致) */
10
- const FRAMEWORK_VERSION = '2.0.0';
9
+ /** 框架版本(与 package.json version / README 一致,发版时两处同步) */
10
+ const FRAMEWORK_VERSION = '2.1.0';
11
11
 
12
12
  /** 需要 PATH 注入的 hook 文件清单(对齐 install.sh add_path_to_hooks) */
13
13
  const HOOK_FILES = [
package/lib/wizard.js CHANGED
@@ -96,10 +96,10 @@ async function askConfig(rl, pkgRoot) {
96
96
  }
97
97
 
98
98
  /**
99
- * 显示安装统计(对齐 show_stats)
99
+ * 显示安装统计(对齐 show_stats;Sessionlog 行仅在启用分发时输出)
100
100
  * @param {object} stats 统计对象
101
101
  * @param {string} projectRoot 项目根
102
- * @param {string} url sessionlog URL
102
+ * @param {string|null} url 已启用分发的 sessionlog URL(null=未启用,不输出该行)
103
103
  * @returns {void}
104
104
  */
105
105
  function showStats(stats, projectRoot, url) {
@@ -109,7 +109,7 @@ function showStats(stats, projectRoot, url) {
109
109
  console.log(`Codex hooks: ${fs.existsSync(path.join(projectRoot, '.codex', 'hooks.json')) ? '已安装' : '未安装'}`);
110
110
  console.log(`修复行尾符: ${stats.fixCount} 个文件`);
111
111
  console.log(`替换 Python: ${stats.replaceCount} 个文件`);
112
- console.log(`Sessionlog URL: ${url}(已分发 ${stats.urlCount} 个文件)`);
112
+ if (url) console.log(`Sessionlog URL: ${url}(已分发 ${stats.urlCount} 个文件)`);
113
113
  }
114
114
 
115
115
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leocm/flowcraft",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "FlowCraft SDLC 框架安装 CLI(跨平台,行为与 install.sh 等价)",
5
5
  "bin": {
6
6
  "flowcraft": "bin/cli.js"
@@ -16,7 +16,7 @@ from pathlib import Path
16
16
 
17
17
  from flowcraft_env import extract_nested
18
18
 
19
- MCP_URL = "http://192.168.2.99:8181/api/logs"
19
+ MCP_URL = "http://127.0.0.1:8181/api/logs"
20
20
 
21
21
 
22
22
  def deny(message: str) -> int:
@@ -11,7 +11,7 @@ import sys
11
11
  from datetime import datetime
12
12
  from pathlib import Path
13
13
 
14
- from flowcraft_env import extract_nested, get_project_root
14
+ from flowcraft_env import extract_nested, get_project_root, is_under_root
15
15
  from task_manager import get_task_state
16
16
 
17
17
  CODE_EXTS = {
@@ -169,11 +169,14 @@ def main() -> int:
169
169
  pass
170
170
  elif re.search(
171
171
  r"/\.claude/(project-state\.md|session_log\.json|prd\.md|code-review-report\.md|"
172
- r"reports/.*|hooks/.*|skills/.*|memory/.*|docs/.*|tasks/[^/]+\.md)|/plan/",
172
+ r"reports/.*|hooks/.*|skills/.*|memory/.*|docs/.*|plans/.*|tasks/[^/]+\.md)|/plan/",
173
173
  file_path,
174
174
  ):
175
175
  return 0
176
176
  elif "/.claude/" in file_path:
177
+ # R1: 锚定 project_root——用户级 ~/.claude(如 Claude Code plans 草稿)不归守卫管
178
+ if not is_under_root(file_path, project_root):
179
+ return 0
177
180
  print(f"[FlowCraft 守卫] 禁止修改框架文件: {file_path}", file=sys.stderr)
178
181
  print("[FlowCraft 守卫] 如需修改框架文件,请手动编辑。", file=sys.stderr)
179
182
  return 2
@@ -53,6 +53,9 @@ def main() -> int:
53
53
  return 0
54
54
  raw = sys.stdin.buffer.read()
55
55
  env = os.environ.copy()
56
+ # R2 保险2:子钩子输出固定 UTF-8(消除 Windows GBK 乱码)
57
+ env["PYTHONIOENCODING"] = "utf-8"
58
+ env["PYTHONUTF8"] = "1"
56
59
  session_id = extract_session_id(raw)
57
60
  if session_id:
58
61
  env["FLOWCRAFT_SESSION_ID"] = session_id
@@ -8,6 +8,7 @@ extract_nested() for unified hook payload field extraction (R5).
8
8
  import json
9
9
  import os
10
10
  import re
11
+ import sys
11
12
  from pathlib import Path
12
13
 
13
14
 
@@ -67,6 +68,43 @@ def get_claude_dir(script_path: str = None) -> Path:
67
68
  return get_project_root(script_path) / ".claude"
68
69
 
69
70
 
71
+ def force_utf8_stdio() -> None:
72
+ """把 stdout/stderr 固定为 UTF-8(R2: 消除 Windows GBK 乱码双保险之进程内保险).
73
+
74
+ hook 失败须静默放行,因此任何异常都不外抛。
75
+ """
76
+ for stream in (sys.stdout, sys.stderr):
77
+ try:
78
+ stream.reconfigure(encoding="utf-8", errors="replace")
79
+ except Exception:
80
+ pass
81
+
82
+
83
+ # 导入即生效:所有 import flowcraft_env 的钩子自动获得 UTF-8 stdio
84
+ force_utf8_stdio()
85
+
86
+
87
+ def is_under_root(file_path: str, root: Path) -> bool:
88
+ """判断目标路径是否位于 root 之下(R1: 守卫只管项目内文件).
89
+
90
+ Windows 路径按 normcase 归一(大小写/分隔符不敏感)后比较,避免
91
+ 项目根解析与载荷路径书写形式不同导致误判。
92
+
93
+ Args:
94
+ file_path: 目标文件路径(任意分隔符)
95
+ root: 项目根目录
96
+ Returns:
97
+ True 表示目标在 root 之下(含 root 自身)
98
+ """
99
+ try:
100
+ target = os.path.normcase(os.path.abspath(str(file_path)))
101
+ base = os.path.normcase(os.path.abspath(str(root)))
102
+ return target == base or target.startswith(base + os.sep)
103
+ except Exception:
104
+ # 解析失败按"项目内"处理:守卫失败须保守(保持拦截),不静默放行
105
+ return True
106
+
107
+
70
108
  def extract_nested(raw, key):
71
109
  """Extract a string field from a hook payload (R5 unified extraction).
72
110
 
@@ -12,6 +12,8 @@ import tempfile
12
12
  from datetime import datetime
13
13
  from pathlib import Path
14
14
 
15
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
16
+
15
17
 
16
18
  def _sanitize(text: str) -> str:
17
19
  """Strip UTF-16 surrogates that json.loads may preserve on Windows."""
@@ -4,6 +4,8 @@ import json
4
4
  import re
5
5
  import sys
6
6
 
7
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
8
+
7
9
 
8
10
  def main() -> int:
9
11
  raw = sys.stdin.read()
@@ -6,6 +6,8 @@ import sys
6
6
 
7
7
  from task_manager import get_task_state
8
8
 
9
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
10
+
9
11
 
10
12
  def count_modified_files(content: str) -> int:
11
13
  """Count list items under the modified_files: section."""
@@ -28,6 +28,8 @@ import sys
28
28
  import tempfile
29
29
  import time
30
30
  import urllib.request
31
+
32
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
31
33
  from datetime import datetime
32
34
  from pathlib import Path
33
35
 
@@ -8,8 +8,10 @@ import urllib.request
8
8
  from datetime import datetime
9
9
  from pathlib import Path
10
10
 
11
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
11
12
 
12
- MCP_URL = "http://192.168.2.99:8181/api/logs"
13
+
14
+ MCP_URL = "http://127.0.0.1:8181/api/logs"
13
15
 
14
16
 
15
17
  def generate_session_log(state_content: str, session_log: Path, jsonl_dir: str) -> list:
@@ -17,6 +17,8 @@ import sys
17
17
  import urllib.parse
18
18
  from pathlib import Path
19
19
 
20
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
21
+
20
22
  SCRIPT_DIR = Path(__file__).resolve().parent
21
23
  if SCRIPT_DIR.name == "hooks":
22
24
  REPO = SCRIPT_DIR.parent.parent
@@ -8,6 +8,8 @@ from pathlib import Path
8
8
 
9
9
  from task_manager import get_task_state_path, resolve_task_id
10
10
 
11
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
12
+
11
13
 
12
14
  def main() -> int:
13
15
  """Print the phase, task description and active task id for the status line.
@@ -9,6 +9,8 @@ import tempfile
9
9
  import time
10
10
  from pathlib import Path
11
11
 
12
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
13
+
12
14
 
13
15
  def _sanitize(text: str) -> str:
14
16
  """Strip UTF-16 surrogates that json.loads may preserve on Windows."""
@@ -6,6 +6,8 @@ import re
6
6
  import sys
7
7
  from pathlib import Path
8
8
 
9
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
10
+
9
11
 
10
12
  def _clean(value: str) -> str:
11
13
  value = re.sub(r"\s*#.*$", "", value)
@@ -6,6 +6,8 @@ import re
6
6
  import sys
7
7
  from pathlib import Path
8
8
 
9
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
10
+
9
11
 
10
12
  def _clean(value: str) -> str:
11
13
  value = re.sub(r"\s*#.*$", "", value)
@@ -6,6 +6,8 @@ import re
6
6
  import sys
7
7
  from pathlib import Path
8
8
 
9
+ import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
10
+
9
11
 
10
12
  def _clean(value: str) -> str:
11
13
  value = re.sub(r"\s*#.*$", "", value)
@@ -12,6 +12,13 @@ import tempfile
12
12
  from datetime import datetime
13
13
  from pathlib import Path
14
14
 
15
+ # R2 UTF-8 stdio 双保险(消除 Windows GBK 乱码)
16
+ for _s in (sys.stdout, sys.stderr):
17
+ try:
18
+ _s.reconfigure(encoding="utf-8", errors="replace")
19
+ except Exception:
20
+ pass
21
+
15
22
 
16
23
  def log_session(role: str, content: str) -> None:
17
24
  """
@@ -31,6 +31,13 @@ import urllib.request
31
31
  from datetime import datetime
32
32
  from pathlib import Path
33
33
 
34
+ # R2 UTF-8 stdio 双保险(消除 Windows GBK 乱码)
35
+ for _s in (sys.stdout, sys.stderr):
36
+ try:
37
+ _s.reconfigure(encoding="utf-8", errors="replace")
38
+ except Exception:
39
+ pass
40
+
34
41
 
35
42
  def parse_args(argv):
36
43
  args = {
@@ -40,6 +40,7 @@ const CLAUDE_ALLOWED_FRAGMENTS = [
40
40
  '/skills/',
41
41
  '/memory/',
42
42
  '/docs/',
43
+ '/plans/',
43
44
  '/plan/',
44
45
  ];
45
46
 
@@ -511,15 +512,33 @@ function getExtension(filePath) {
511
512
  }
512
513
 
513
514
  /**
514
- * 判断是否为受保护的 .claude 文件(非白名单路径)
515
+ * 判断目标路径是否位于 root 之下(R1: 守卫只管项目内文件)
516
+ *
517
+ * @param {string} filePath 规范化路径
518
+ * @param {string} root 项目根目录
519
+ * @returns {boolean} 是否位于 root 之下
520
+ */
521
+ function isUnderRoot(filePath, root) {
522
+ const target = path.resolve(filePath).toLowerCase().replace(/\\/g, '/');
523
+ const base = path.resolve(root).toLowerCase().replace(/\\/g, '/');
524
+ return target === base || target.startsWith(base + '/');
525
+ }
526
+
527
+ /**
528
+ * 判断是否为受保护的 .claude 文件(非白名单路径;仅项目内 .claude 受管)
515
529
  *
516
530
  * @param {string} normalized 规范化路径
531
+ * @param {string} root 项目根目录
517
532
  * @returns {boolean} 是否为受保护框架文件
518
533
  */
519
- function isProtectedClaudeFile(normalized) {
534
+ function isProtectedClaudeFile(normalized, root) {
520
535
  if (!normalized.includes('/.claude/') && !normalized.startsWith('.claude/')) {
521
536
  return false;
522
537
  }
538
+ // R1: 用户级 ~/.claude(如 Claude Code plans 草稿)不归守卫管
539
+ if (root && !isUnderRoot(normalized, root)) {
540
+ return false;
541
+ }
523
542
  return !CLAUDE_ALLOWED_FRAGMENTS.some((fragment) => normalized.includes(fragment));
524
543
  }
525
544
 
@@ -546,7 +565,7 @@ function checkPhaseWrite(input, root, stateText) {
546
565
  if (normalized.includes('flowcraft/')) {
547
566
  continue; // 框架自身文件允许修改
548
567
  }
549
- if (isProtectedClaudeFile(normalized)) {
568
+ if (isProtectedClaudeFile(normalized, root)) {
550
569
  emitDecision('deny', `【SDLC 守卫】禁止修改 SDLC 框架文件: ${rawFile},如需修改请手动编辑。`);
551
570
  return;
552
571
  }
@@ -17,6 +17,13 @@ import sys
17
17
  import urllib.parse
18
18
  from pathlib import Path
19
19
 
20
+ # R2 UTF-8 stdio 双保险(消除 Windows GBK 乱码)
21
+ for _s in (sys.stdout, sys.stderr):
22
+ try:
23
+ _s.reconfigure(encoding="utf-8", errors="replace")
24
+ except Exception:
25
+ pass
26
+
20
27
  SCRIPT_DIR = Path(__file__).resolve().parent
21
28
  if SCRIPT_DIR.name == "hooks":
22
29
  REPO = SCRIPT_DIR.parent.parent
@@ -128,10 +128,26 @@ class TestCheckPhaseWrite:
128
128
  assert p.returncode == 0
129
129
 
130
130
  def test_framework_file_blocked(self, tmp_path):
131
+ """R1: 项目内 .claude 框架文件仍拦(守卫只守本项目,项目内不放开)。"""
131
132
  make_state(tmp_path, "P2")
132
- p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/settings.json"), tmp_path)
133
+ target = tmp_path / ".claude" / "settings.json"
134
+ p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
133
135
  assert p.returncode == 2
134
136
 
137
+ def test_user_level_claude_allowed(self, tmp_path):
138
+ """R1: 非项目内的 .claude(如 ~/.claude/plans/ 计划草稿)不归守卫管,放行。"""
139
+ make_state(tmp_path, "P2")
140
+ outside = tmp_path.parent / "fake-home" / ".claude" / "plans" / "draft.md"
141
+ p = run_hook("check-phase-write.py", edit_payload(str(outside)), tmp_path)
142
+ assert p.returncode == 0
143
+
144
+ def test_project_claude_plans_allowed(self, tmp_path):
145
+ """R2: 白名单补 plans/,项目内计划草稿目录放行。"""
146
+ make_state(tmp_path, "P2")
147
+ target = tmp_path / ".claude" / "plans" / "x.md"
148
+ p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
149
+ assert p.returncode == 0
150
+
135
151
  def test_task_state_file_allowed(self, tmp_path):
136
152
  """R6: .claude/tasks/*.md editable (multi-task state files)."""
137
153
  make_state(tmp_path, "P2")