@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.
- package/README.md +7 -2
- package/bin/cli.js +108 -108
- package/flowcraft.yaml +30 -30
- package/install.sh +24 -24
- package/lib/args.js +38 -38
- package/lib/config.js +20 -20
- package/lib/copy.js +131 -131
- package/lib/fix.js +110 -110
- package/lib/fsutil.js +104 -104
- package/lib/global.js +229 -229
- package/lib/init.js +43 -43
- package/lib/runtime.js +84 -84
- package/lib/version.js +55 -55
- package/lib/wizard.js +125 -125
- package/package.json +33 -33
- package/presets/backend.yaml +20 -20
- package/presets/default.yaml +15 -15
- package/presets/frontend.yaml +20 -20
- package/presets/quick-fix.yaml +15 -15
- package/setup/.claude/hooks/check-phase-test.py +152 -152
- package/setup/.claude/hooks/check-phase-write.py +235 -235
- package/setup/.claude/hooks/dispatch.py +67 -67
- package/setup/.claude/hooks/file-suggestion.py +45 -45
- package/setup/.claude/hooks/flowcraft_env.py +162 -162
- package/setup/.claude/hooks/permission-request.py +132 -132
- package/setup/.claude/hooks/post-tool-failure.py +36 -36
- package/setup/.claude/hooks/pre-compact.py +66 -66
- package/setup/.claude/hooks/review-runner.py +846 -846
- package/setup/.claude/hooks/setup-keys.py +282 -282
- package/setup/.claude/hooks/statusline.py +63 -63
- package/setup/.claude/hooks/stop-check.py +186 -186
- package/setup/.claude/hooks/subagent-start.py +50 -50
- package/setup/.claude/hooks/subagent-stop.py +63 -63
- package/setup/.claude/hooks/task-completed.py +57 -57
- package/setup/.claude/hooks/task_manager.py +592 -592
- package/setup/.claude/hooks/user-prompt-submit.py +91 -91
- package/setup/.claude/settings.json +233 -233
- package/setup/.claude/skills/Pstatus/SKILL.md +68 -68
- package/setup/.claude/skills/archive/SKILL.md +195 -195
- package/setup/.claude/skills/brainstorming/SKILL.md +5 -5
- package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -723
- package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -245
- package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -178
- package/setup/.claude/skills/brainstorming/visual-companion.md +298 -298
- package/setup/.claude/skills/chrome-integration/SKILL.md +66 -66
- package/setup/.claude/skills/code-review/SKILL.md +264 -264
- package/setup/.claude/skills/executing-plans/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
- package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
- package/setup/.claude/skills/methodology/SKILL.md +124 -0
- package/setup/.claude/skills/phase/SKILL.md +62 -62
- package/setup/.claude/skills/playwright/SKILL.md +85 -85
- package/setup/.claude/skills/review/SKILL.md +97 -97
- package/setup/.claude/skills/task/SKILL.md +26 -26
- package/setup/.claude/skills/test-driven-development/SKILL.md +1 -1
- package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +1 -1
- package/setup/.claude/skills/verification-before-completion/SKILL.md +1 -1
- package/setup/.claude/skills/writing-plans/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/archive/SKILL.md +195 -195
- package/setup/.codex/.agents/skills/brainstorming/SKILL.md +5 -5
- package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -723
- package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -245
- package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -178
- package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -298
- package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +66 -66
- package/setup/.codex/.agents/skills/code-review/SKILL.md +264 -264
- package/setup/.codex/.agents/skills/executing-plans/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/methodology/SKILL.md +124 -0
- package/setup/.codex/.agents/skills/phase/SKILL.md +62 -62
- package/setup/.codex/.agents/skills/playwright/SKILL.md +85 -85
- package/setup/.codex/.agents/skills/review/SKILL.md +97 -97
- package/setup/.codex/.agents/skills/task/SKILL.md +27 -27
- package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/writing-plans/SKILL.md +1 -1
- package/setup/.codex/hooks/review-runner.py +851 -851
- package/setup/.codex/hooks/setup-keys.py +287 -287
- package/setup/AGENTS.md +11 -1
- package/setup/CLAUDE.md +11 -1
- package/setup/install.sh +24 -24
- package/setup/tests/test_decision_timeout.py +241 -241
- package/setup/tests/test_hook_guards.py +357 -357
- package/setup/tests/test_sdlc_bootstrap.py +167 -167
- package/setup/tests/test_sessionlog_switch.py +199 -199
- package/setup/tests/test_task_manager.py +148 -148
package/presets/default.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# FlowCraft 预设: 通用项目(默认)
|
|
2
|
-
preset_name: "通用项目"
|
|
3
|
-
preset_version: "1.0"
|
|
4
|
-
description: "完整六阶段流程,适合大多数项目"
|
|
5
|
-
|
|
6
|
-
stages:
|
|
7
|
-
P1: auto
|
|
8
|
-
P2: true
|
|
9
|
-
P3: auto
|
|
10
|
-
P4: true
|
|
11
|
-
P5: auto
|
|
12
|
-
|
|
13
|
-
review:
|
|
14
|
-
standard: alibaba
|
|
15
|
-
retry_limit: 3
|
|
1
|
+
# FlowCraft 预设: 通用项目(默认)
|
|
2
|
+
preset_name: "通用项目"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "完整六阶段流程,适合大多数项目"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: auto
|
|
8
|
+
P2: true
|
|
9
|
+
P3: auto
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 3
|
package/presets/frontend.yaml
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# FlowCraft 预设: 前端项目
|
|
2
|
-
preset_name: "前端项目"
|
|
3
|
-
preset_version: "1.0"
|
|
4
|
-
description: "前端项目专用,P3含视觉回归测试,UI/UX强制"
|
|
5
|
-
|
|
6
|
-
stages:
|
|
7
|
-
P1: true # 前端需要设计确认
|
|
8
|
-
P2: true
|
|
9
|
-
P3: true # 含视觉回归
|
|
10
|
-
P4: true
|
|
11
|
-
P5: auto
|
|
12
|
-
|
|
13
|
-
review:
|
|
14
|
-
standard: alibaba
|
|
15
|
-
retry_limit: 3
|
|
16
|
-
|
|
17
|
-
tech_defaults:
|
|
18
|
-
language: typescript
|
|
19
|
-
framework: nextjs
|
|
20
|
-
testing: jest
|
|
1
|
+
# FlowCraft 预设: 前端项目
|
|
2
|
+
preset_name: "前端项目"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "前端项目专用,P3含视觉回归测试,UI/UX强制"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: true # 前端需要设计确认
|
|
8
|
+
P2: true
|
|
9
|
+
P3: true # 含视觉回归
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 3
|
|
16
|
+
|
|
17
|
+
tech_defaults:
|
|
18
|
+
language: typescript
|
|
19
|
+
framework: nextjs
|
|
20
|
+
testing: jest
|
package/presets/quick-fix.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# FlowCraft 预设: 快速修复
|
|
2
|
-
preset_name: "快速修复"
|
|
3
|
-
preset_version: "1.0"
|
|
4
|
-
description: "Bug修复/小改动专用,P1/P3/P5可跳过,只保留编码和审查"
|
|
5
|
-
|
|
6
|
-
stages:
|
|
7
|
-
P1: auto # 小改动可跳过
|
|
8
|
-
P2: true
|
|
9
|
-
P3: auto # 简单修复可跳过
|
|
10
|
-
P4: true
|
|
11
|
-
P5: auto # 小改动可跳过
|
|
12
|
-
|
|
13
|
-
review:
|
|
14
|
-
standard: alibaba
|
|
15
|
-
retry_limit: 2
|
|
1
|
+
# FlowCraft 预设: 快速修复
|
|
2
|
+
preset_name: "快速修复"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "Bug修复/小改动专用,P1/P3/P5可跳过,只保留编码和审查"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: auto # 小改动可跳过
|
|
8
|
+
P2: true
|
|
9
|
+
P3: auto # 简单修复可跳过
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto # 小改动可跳过
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 2
|
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""check-phase-test - PreToolUse hook for Bash/PowerShell commands.
|
|
3
|
-
|
|
4
|
-
Detects file-writing commands that could bypass Write/Edit hooks:
|
|
5
|
-
- Shell redirects: > file, >> file
|
|
6
|
-
- tee, cp, mv to protected paths
|
|
7
|
-
- PowerShell: Set-Content, Out-File, Add-Content
|
|
8
|
-
- sed -i (in-place edit)
|
|
9
|
-
|
|
10
|
-
Auto-transition: P0 + code write → auto-enter P1 (no user prompt).
|
|
11
|
-
"""
|
|
12
|
-
import os
|
|
13
|
-
import re
|
|
14
|
-
import sys
|
|
15
|
-
from datetime import datetime
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
|
|
18
|
-
from flowcraft_env import extract_nested, get_project_root
|
|
19
|
-
from task_manager import get_task_state
|
|
20
|
-
|
|
21
|
-
# Code file extensions (same as check-phase-write.py)
|
|
22
|
-
CODE_EXTS = {
|
|
23
|
-
"java", "js", "ts", "jsx", "tsx", "py", "go", "rs", "c", "cpp", "h",
|
|
24
|
-
"cs", "rb", "php", "swift", "kt", "dart", "vue", "svelte", "html", "css",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
# Patterns that extract target file paths from shell commands
|
|
28
|
-
WRITE_PATTERNS = [
|
|
29
|
-
r">(?:>)?\s+(?!/dev/null|&\d)(\S+)",
|
|
30
|
-
r"\btee\s+(?:-\w+\s+)?(?!/dev/null)(\S+)",
|
|
31
|
-
r"\bsed\s+(?:-\w*\s+)*-i\w*\s+(\S+)",
|
|
32
|
-
r"\b(?:cp|mv)\s+(?:-\w+\s+)*\S+\s+(\S+)",
|
|
33
|
-
r"\b(?:Set-Content|Out-File|Add-Content)\s+(?:-\w+\s+)*['\"]?(\S+?)['\"]?\s*$",
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def extract_command(raw: str) -> str:
|
|
38
|
-
"""Extract the command from the hook input (R5: unified extraction)."""
|
|
39
|
-
return extract_nested(raw, "command")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def extract_target_files(command: str) -> list:
|
|
43
|
-
"""Extract potential target file paths from a shell command."""
|
|
44
|
-
targets = []
|
|
45
|
-
for pattern in WRITE_PATTERNS:
|
|
46
|
-
for m in re.finditer(pattern, command):
|
|
47
|
-
path = m.group(1)
|
|
48
|
-
if path.startswith("-") or path.startswith("$") or path.startswith("|"):
|
|
49
|
-
continue
|
|
50
|
-
path = path.strip("'\"")
|
|
51
|
-
if path:
|
|
52
|
-
targets.append(path)
|
|
53
|
-
return targets
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def get_current_phase_from_file(state_file: Path) -> str:
|
|
57
|
-
"""Read current_phase from the given state file."""
|
|
58
|
-
if not state_file.is_file():
|
|
59
|
-
return "P0"
|
|
60
|
-
try:
|
|
61
|
-
content = state_file.read_text(encoding="utf-8")
|
|
62
|
-
m = re.search(r"^current_phase:\s*(\S+)", content, re.M)
|
|
63
|
-
return m.group(1).strip() if m else "P0"
|
|
64
|
-
except Exception:
|
|
65
|
-
return "P0"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def auto_transition_to_p1(state_file: Path) -> bool:
|
|
69
|
-
"""Auto-transition from P0 to P1 when code write is attempted.
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
state_file: Task/project state file to update.
|
|
73
|
-
Returns:
|
|
74
|
-
True when the state file was updated successfully.
|
|
75
|
-
"""
|
|
76
|
-
try:
|
|
77
|
-
content = state_file.read_text(encoding="utf-8")
|
|
78
|
-
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
79
|
-
content = re.sub(r"^current_phase:\s*\S+", "current_phase: P1", content, count=1, flags=re.M)
|
|
80
|
-
content = re.sub(r"^last_updated:\s*\S+", f'last_updated: "{now}"', content, count=1, flags=re.M)
|
|
81
|
-
content = re.sub(
|
|
82
|
-
r"(phase_history:\s*\n)",
|
|
83
|
-
f'\\1 - phase: P1\n action: "auto-enter: code write detected"\n at: "{now}"\n',
|
|
84
|
-
content, count=1,
|
|
85
|
-
)
|
|
86
|
-
state_file.write_text(content, encoding="utf-8")
|
|
87
|
-
print(f"[FlowCraft] 检测到代码写入,自动进入 P1 需求阶段", file=sys.stderr)
|
|
88
|
-
return True
|
|
89
|
-
except Exception as e:
|
|
90
|
-
print(f"[FlowCraft] 自动切换P1失败: {e}", file=sys.stderr)
|
|
91
|
-
return False
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def main() -> int:
|
|
95
|
-
raw = sys.stdin.read()
|
|
96
|
-
command = extract_command(raw)
|
|
97
|
-
if not command:
|
|
98
|
-
return 0
|
|
99
|
-
|
|
100
|
-
project_root = get_project_root(__file__)
|
|
101
|
-
state_file = get_task_state(__file__)
|
|
102
|
-
phase = get_current_phase_from_file(state_file)
|
|
103
|
-
|
|
104
|
-
# No state file → no SDLC, allow everything
|
|
105
|
-
if not state_file.is_file():
|
|
106
|
-
return 0
|
|
107
|
-
|
|
108
|
-
targets = extract_target_files(command)
|
|
109
|
-
if not targets:
|
|
110
|
-
return 0
|
|
111
|
-
|
|
112
|
-
for target in targets:
|
|
113
|
-
if not os.path.isabs(target):
|
|
114
|
-
target = os.path.join(os.getcwd(), target)
|
|
115
|
-
target = target.replace("\\", "/")
|
|
116
|
-
|
|
117
|
-
# Check if it's a code file
|
|
118
|
-
m = re.search(r"\.([^.\\/]+)$", target)
|
|
119
|
-
ext = m.group(1).lower() if m else ""
|
|
120
|
-
|
|
121
|
-
# P0: block the write and auto-enter P1 (R2)
|
|
122
|
-
if phase == "P0" and ext in CODE_EXTS:
|
|
123
|
-
ok = auto_transition_to_p1(state_file)
|
|
124
|
-
print(f"[FlowCraft] P0阶段禁止通过 Bash 修改代码: {target}", file=sys.stderr)
|
|
125
|
-
if ok:
|
|
126
|
-
print(" 已自动切换至 P1 需求阶段。", file=sys.stderr)
|
|
127
|
-
return 2
|
|
128
|
-
|
|
129
|
-
# P0.5: block code modifications (problem rollback mode)
|
|
130
|
-
if phase == "P0.5" and ext in CODE_EXTS:
|
|
131
|
-
print(f"[FlowCraft] P0.5问题回溯阶段,禁止通过 Bash 修改代码: {target}", file=sys.stderr)
|
|
132
|
-
return 2
|
|
133
|
-
|
|
134
|
-
# P1+: block writes to protected framework paths
|
|
135
|
-
if phase not in ("P0", "P0.5"):
|
|
136
|
-
if re.search(
|
|
137
|
-
r"/\.claude/(project-state\.md|prd\.md|session_log|reports/|hooks/|skills/|memory/)"
|
|
138
|
-
r"|/\.codex/"
|
|
139
|
-
r"|/plan/"
|
|
140
|
-
r"|/flowcraft/"
|
|
141
|
-
r"|CLAUDE\.md$"
|
|
142
|
-
r"|AGENTS\.md$",
|
|
143
|
-
target,
|
|
144
|
-
):
|
|
145
|
-
print(f"[FlowCraft 守卫] {phase} 阶段禁止通过 Bash 写入框架文件: {target}", file=sys.stderr)
|
|
146
|
-
return 2
|
|
147
|
-
|
|
148
|
-
return 0
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if __name__ == "__main__":
|
|
152
|
-
sys.exit(main())
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""check-phase-test - PreToolUse hook for Bash/PowerShell commands.
|
|
3
|
+
|
|
4
|
+
Detects file-writing commands that could bypass Write/Edit hooks:
|
|
5
|
+
- Shell redirects: > file, >> file
|
|
6
|
+
- tee, cp, mv to protected paths
|
|
7
|
+
- PowerShell: Set-Content, Out-File, Add-Content
|
|
8
|
+
- sed -i (in-place edit)
|
|
9
|
+
|
|
10
|
+
Auto-transition: P0 + code write → auto-enter P1 (no user prompt).
|
|
11
|
+
"""
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import sys
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from flowcraft_env import extract_nested, get_project_root
|
|
19
|
+
from task_manager import get_task_state
|
|
20
|
+
|
|
21
|
+
# Code file extensions (same as check-phase-write.py)
|
|
22
|
+
CODE_EXTS = {
|
|
23
|
+
"java", "js", "ts", "jsx", "tsx", "py", "go", "rs", "c", "cpp", "h",
|
|
24
|
+
"cs", "rb", "php", "swift", "kt", "dart", "vue", "svelte", "html", "css",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Patterns that extract target file paths from shell commands
|
|
28
|
+
WRITE_PATTERNS = [
|
|
29
|
+
r">(?:>)?\s+(?!/dev/null|&\d)(\S+)",
|
|
30
|
+
r"\btee\s+(?:-\w+\s+)?(?!/dev/null)(\S+)",
|
|
31
|
+
r"\bsed\s+(?:-\w*\s+)*-i\w*\s+(\S+)",
|
|
32
|
+
r"\b(?:cp|mv)\s+(?:-\w+\s+)*\S+\s+(\S+)",
|
|
33
|
+
r"\b(?:Set-Content|Out-File|Add-Content)\s+(?:-\w+\s+)*['\"]?(\S+?)['\"]?\s*$",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def extract_command(raw: str) -> str:
|
|
38
|
+
"""Extract the command from the hook input (R5: unified extraction)."""
|
|
39
|
+
return extract_nested(raw, "command")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def extract_target_files(command: str) -> list:
|
|
43
|
+
"""Extract potential target file paths from a shell command."""
|
|
44
|
+
targets = []
|
|
45
|
+
for pattern in WRITE_PATTERNS:
|
|
46
|
+
for m in re.finditer(pattern, command):
|
|
47
|
+
path = m.group(1)
|
|
48
|
+
if path.startswith("-") or path.startswith("$") or path.startswith("|"):
|
|
49
|
+
continue
|
|
50
|
+
path = path.strip("'\"")
|
|
51
|
+
if path:
|
|
52
|
+
targets.append(path)
|
|
53
|
+
return targets
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_current_phase_from_file(state_file: Path) -> str:
|
|
57
|
+
"""Read current_phase from the given state file."""
|
|
58
|
+
if not state_file.is_file():
|
|
59
|
+
return "P0"
|
|
60
|
+
try:
|
|
61
|
+
content = state_file.read_text(encoding="utf-8")
|
|
62
|
+
m = re.search(r"^current_phase:\s*(\S+)", content, re.M)
|
|
63
|
+
return m.group(1).strip() if m else "P0"
|
|
64
|
+
except Exception:
|
|
65
|
+
return "P0"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def auto_transition_to_p1(state_file: Path) -> bool:
|
|
69
|
+
"""Auto-transition from P0 to P1 when code write is attempted.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
state_file: Task/project state file to update.
|
|
73
|
+
Returns:
|
|
74
|
+
True when the state file was updated successfully.
|
|
75
|
+
"""
|
|
76
|
+
try:
|
|
77
|
+
content = state_file.read_text(encoding="utf-8")
|
|
78
|
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
79
|
+
content = re.sub(r"^current_phase:\s*\S+", "current_phase: P1", content, count=1, flags=re.M)
|
|
80
|
+
content = re.sub(r"^last_updated:\s*\S+", f'last_updated: "{now}"', content, count=1, flags=re.M)
|
|
81
|
+
content = re.sub(
|
|
82
|
+
r"(phase_history:\s*\n)",
|
|
83
|
+
f'\\1 - phase: P1\n action: "auto-enter: code write detected"\n at: "{now}"\n',
|
|
84
|
+
content, count=1,
|
|
85
|
+
)
|
|
86
|
+
state_file.write_text(content, encoding="utf-8")
|
|
87
|
+
print(f"[FlowCraft] 检测到代码写入,自动进入 P1 需求阶段", file=sys.stderr)
|
|
88
|
+
return True
|
|
89
|
+
except Exception as e:
|
|
90
|
+
print(f"[FlowCraft] 自动切换P1失败: {e}", file=sys.stderr)
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def main() -> int:
|
|
95
|
+
raw = sys.stdin.read()
|
|
96
|
+
command = extract_command(raw)
|
|
97
|
+
if not command:
|
|
98
|
+
return 0
|
|
99
|
+
|
|
100
|
+
project_root = get_project_root(__file__)
|
|
101
|
+
state_file = get_task_state(__file__)
|
|
102
|
+
phase = get_current_phase_from_file(state_file)
|
|
103
|
+
|
|
104
|
+
# No state file → no SDLC, allow everything
|
|
105
|
+
if not state_file.is_file():
|
|
106
|
+
return 0
|
|
107
|
+
|
|
108
|
+
targets = extract_target_files(command)
|
|
109
|
+
if not targets:
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
for target in targets:
|
|
113
|
+
if not os.path.isabs(target):
|
|
114
|
+
target = os.path.join(os.getcwd(), target)
|
|
115
|
+
target = target.replace("\\", "/")
|
|
116
|
+
|
|
117
|
+
# Check if it's a code file
|
|
118
|
+
m = re.search(r"\.([^.\\/]+)$", target)
|
|
119
|
+
ext = m.group(1).lower() if m else ""
|
|
120
|
+
|
|
121
|
+
# P0: block the write and auto-enter P1 (R2)
|
|
122
|
+
if phase == "P0" and ext in CODE_EXTS:
|
|
123
|
+
ok = auto_transition_to_p1(state_file)
|
|
124
|
+
print(f"[FlowCraft] P0阶段禁止通过 Bash 修改代码: {target}", file=sys.stderr)
|
|
125
|
+
if ok:
|
|
126
|
+
print(" 已自动切换至 P1 需求阶段。", file=sys.stderr)
|
|
127
|
+
return 2
|
|
128
|
+
|
|
129
|
+
# P0.5: block code modifications (problem rollback mode)
|
|
130
|
+
if phase == "P0.5" and ext in CODE_EXTS:
|
|
131
|
+
print(f"[FlowCraft] P0.5问题回溯阶段,禁止通过 Bash 修改代码: {target}", file=sys.stderr)
|
|
132
|
+
return 2
|
|
133
|
+
|
|
134
|
+
# P1+: block writes to protected framework paths
|
|
135
|
+
if phase not in ("P0", "P0.5"):
|
|
136
|
+
if re.search(
|
|
137
|
+
r"/\.claude/(project-state\.md|prd\.md|session_log|reports/|hooks/|skills/|memory/)"
|
|
138
|
+
r"|/\.codex/"
|
|
139
|
+
r"|/plan/"
|
|
140
|
+
r"|/flowcraft/"
|
|
141
|
+
r"|CLAUDE\.md$"
|
|
142
|
+
r"|AGENTS\.md$",
|
|
143
|
+
target,
|
|
144
|
+
):
|
|
145
|
+
print(f"[FlowCraft 守卫] {phase} 阶段禁止通过 Bash 写入框架文件: {target}", file=sys.stderr)
|
|
146
|
+
return 2
|
|
147
|
+
|
|
148
|
+
return 0
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
sys.exit(main())
|