@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
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""PermissionRequest - generic security permission check (no phase limit)."""
|
|
3
|
-
import json
|
|
4
|
-
import re
|
|
5
|
-
import sys
|
|
6
|
-
|
|
7
|
-
from flowcraft_env import extract_nested, get_project_root
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def phase_number() -> int:
|
|
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"
|
|
21
|
-
if not state_file.is_file():
|
|
22
|
-
return 0
|
|
23
|
-
try:
|
|
24
|
-
content = state_file.read_text(encoding="utf-8")
|
|
25
|
-
m = re.search(r"^current_phase:\s*P(\d+)", content, re.M)
|
|
26
|
-
if m:
|
|
27
|
-
return int(m.group(1))
|
|
28
|
-
except Exception:
|
|
29
|
-
pass
|
|
30
|
-
return 0
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def main() -> int:
|
|
34
|
-
raw = sys.stdin.read()
|
|
35
|
-
phase_num = phase_number()
|
|
36
|
-
|
|
37
|
-
try:
|
|
38
|
-
data = json.loads(raw) if raw.strip() else {}
|
|
39
|
-
if not isinstance(data, dict):
|
|
40
|
-
return 0
|
|
41
|
-
except Exception:
|
|
42
|
-
return 0
|
|
43
|
-
|
|
44
|
-
tool_name = data.get("tool_name") or ""
|
|
45
|
-
if not tool_name:
|
|
46
|
-
return 0
|
|
47
|
-
# R5: unified nested/flat extraction; "command" may be empty, so chain keys
|
|
48
|
-
tool_action = extract_nested(raw, "file_path") or extract_nested(raw, "command") or ""
|
|
49
|
-
|
|
50
|
-
behavior = "allow"
|
|
51
|
-
message = ""
|
|
52
|
-
|
|
53
|
-
if tool_name in ("Write", "Edit"):
|
|
54
|
-
m = re.search(r"\.([^.\\/]+)$", tool_action)
|
|
55
|
-
ext = m.group(1).lower() if m else ""
|
|
56
|
-
if ext in (
|
|
57
|
-
"md", "txt", "json", "yaml", "yml", "toml", "ini",
|
|
58
|
-
"cfg", "conf", "csv", "xml", "svg", "log",
|
|
59
|
-
):
|
|
60
|
-
behavior = "allow"
|
|
61
|
-
elif ext in ("html", "css"):
|
|
62
|
-
if phase_num >= 1:
|
|
63
|
-
behavior = "allow"
|
|
64
|
-
else:
|
|
65
|
-
behavior = "deny"
|
|
66
|
-
message = f"阶段 P{phase_num} 不允许修改文件"
|
|
67
|
-
else:
|
|
68
|
-
if phase_num >= 2:
|
|
69
|
-
behavior = "allow"
|
|
70
|
-
else:
|
|
71
|
-
behavior = "deny"
|
|
72
|
-
message = f"阶段 P{phase_num} 不允许修改代码文件(P2 起可用,P1 仅允许原型 HTML/CSS)"
|
|
73
|
-
elif tool_name == "Bash":
|
|
74
|
-
action = tool_action
|
|
75
|
-
if re.match(r"git\s+(status|diff|log|branch|stash)\b", action):
|
|
76
|
-
behavior = "allow"
|
|
77
|
-
elif re.search(r"rm\s+-rf|--force|reset\s+--hard", action):
|
|
78
|
-
return 0 # dangerous commands go to the user
|
|
79
|
-
elif re.match(r"git\s+(commit|push|tag|merge)\b", action):
|
|
80
|
-
if phase_num >= 5:
|
|
81
|
-
behavior = "allow"
|
|
82
|
-
else:
|
|
83
|
-
behavior = "deny"
|
|
84
|
-
message = "Git 提交操作仅 P5 允许"
|
|
85
|
-
elif re.match(
|
|
86
|
-
r"(npm\s+test|npx\s+(jest|vitest|mocha)|yarn\s+test|pnpm\s+test|"
|
|
87
|
-
r"pytest|go\s+test|cargo\s+test|mvn\s+test|mvnd\s+test|jest\s+|"
|
|
88
|
-
r"vitest\s+|mocha\s+)",
|
|
89
|
-
action,
|
|
90
|
-
):
|
|
91
|
-
if phase_num >= 3:
|
|
92
|
-
behavior = "allow"
|
|
93
|
-
else:
|
|
94
|
-
behavior = "deny"
|
|
95
|
-
message = "测试命令仅 P3 起允许"
|
|
96
|
-
elif re.match(r"npx\s+(eslint|tsc)|npm\s+run\s+(lint|build)", action):
|
|
97
|
-
behavior = "allow"
|
|
98
|
-
else:
|
|
99
|
-
if phase_num >= 2:
|
|
100
|
-
behavior = "allow"
|
|
101
|
-
elif tool_name == "Chrome":
|
|
102
|
-
if phase_num == 1 or phase_num >= 3:
|
|
103
|
-
behavior = "allow"
|
|
104
|
-
else:
|
|
105
|
-
behavior = "deny"
|
|
106
|
-
message = "Chrome 仅在 P1(原型展示)和 P3+(测试/审查)阶段允许"
|
|
107
|
-
elif tool_name in ("Read", "Glob", "Grep", "WebSearch", "WebFetch"):
|
|
108
|
-
behavior = "allow"
|
|
109
|
-
else:
|
|
110
|
-
return 0 # unknown tools are not intercepted
|
|
111
|
-
|
|
112
|
-
if behavior == "deny" and message:
|
|
113
|
-
out = {
|
|
114
|
-
"hookSpecificOutput": {
|
|
115
|
-
"hookEventName": "PermissionRequest",
|
|
116
|
-
"decision": {"behavior": "deny", "message": message},
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
print(json.dumps(out, ensure_ascii=False))
|
|
120
|
-
elif behavior == "allow":
|
|
121
|
-
out = {
|
|
122
|
-
"hookSpecificOutput": {
|
|
123
|
-
"hookEventName": "PermissionRequest",
|
|
124
|
-
"decision": {"behavior": "allow"},
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
print(json.dumps(out, ensure_ascii=False))
|
|
128
|
-
return 0
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if __name__ == "__main__":
|
|
132
|
-
sys.exit(main())
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PermissionRequest - generic security permission check (no phase limit)."""
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from flowcraft_env import extract_nested, get_project_root
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def phase_number() -> int:
|
|
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"
|
|
21
|
+
if not state_file.is_file():
|
|
22
|
+
return 0
|
|
23
|
+
try:
|
|
24
|
+
content = state_file.read_text(encoding="utf-8")
|
|
25
|
+
m = re.search(r"^current_phase:\s*P(\d+)", content, re.M)
|
|
26
|
+
if m:
|
|
27
|
+
return int(m.group(1))
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
return 0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main() -> int:
|
|
34
|
+
raw = sys.stdin.read()
|
|
35
|
+
phase_num = phase_number()
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
data = json.loads(raw) if raw.strip() else {}
|
|
39
|
+
if not isinstance(data, dict):
|
|
40
|
+
return 0
|
|
41
|
+
except Exception:
|
|
42
|
+
return 0
|
|
43
|
+
|
|
44
|
+
tool_name = data.get("tool_name") or ""
|
|
45
|
+
if not tool_name:
|
|
46
|
+
return 0
|
|
47
|
+
# R5: unified nested/flat extraction; "command" may be empty, so chain keys
|
|
48
|
+
tool_action = extract_nested(raw, "file_path") or extract_nested(raw, "command") or ""
|
|
49
|
+
|
|
50
|
+
behavior = "allow"
|
|
51
|
+
message = ""
|
|
52
|
+
|
|
53
|
+
if tool_name in ("Write", "Edit"):
|
|
54
|
+
m = re.search(r"\.([^.\\/]+)$", tool_action)
|
|
55
|
+
ext = m.group(1).lower() if m else ""
|
|
56
|
+
if ext in (
|
|
57
|
+
"md", "txt", "json", "yaml", "yml", "toml", "ini",
|
|
58
|
+
"cfg", "conf", "csv", "xml", "svg", "log",
|
|
59
|
+
):
|
|
60
|
+
behavior = "allow"
|
|
61
|
+
elif ext in ("html", "css"):
|
|
62
|
+
if phase_num >= 1:
|
|
63
|
+
behavior = "allow"
|
|
64
|
+
else:
|
|
65
|
+
behavior = "deny"
|
|
66
|
+
message = f"阶段 P{phase_num} 不允许修改文件"
|
|
67
|
+
else:
|
|
68
|
+
if phase_num >= 2:
|
|
69
|
+
behavior = "allow"
|
|
70
|
+
else:
|
|
71
|
+
behavior = "deny"
|
|
72
|
+
message = f"阶段 P{phase_num} 不允许修改代码文件(P2 起可用,P1 仅允许原型 HTML/CSS)"
|
|
73
|
+
elif tool_name == "Bash":
|
|
74
|
+
action = tool_action
|
|
75
|
+
if re.match(r"git\s+(status|diff|log|branch|stash)\b", action):
|
|
76
|
+
behavior = "allow"
|
|
77
|
+
elif re.search(r"rm\s+-rf|--force|reset\s+--hard", action):
|
|
78
|
+
return 0 # dangerous commands go to the user
|
|
79
|
+
elif re.match(r"git\s+(commit|push|tag|merge)\b", action):
|
|
80
|
+
if phase_num >= 5:
|
|
81
|
+
behavior = "allow"
|
|
82
|
+
else:
|
|
83
|
+
behavior = "deny"
|
|
84
|
+
message = "Git 提交操作仅 P5 允许"
|
|
85
|
+
elif re.match(
|
|
86
|
+
r"(npm\s+test|npx\s+(jest|vitest|mocha)|yarn\s+test|pnpm\s+test|"
|
|
87
|
+
r"pytest|go\s+test|cargo\s+test|mvn\s+test|mvnd\s+test|jest\s+|"
|
|
88
|
+
r"vitest\s+|mocha\s+)",
|
|
89
|
+
action,
|
|
90
|
+
):
|
|
91
|
+
if phase_num >= 3:
|
|
92
|
+
behavior = "allow"
|
|
93
|
+
else:
|
|
94
|
+
behavior = "deny"
|
|
95
|
+
message = "测试命令仅 P3 起允许"
|
|
96
|
+
elif re.match(r"npx\s+(eslint|tsc)|npm\s+run\s+(lint|build)", action):
|
|
97
|
+
behavior = "allow"
|
|
98
|
+
else:
|
|
99
|
+
if phase_num >= 2:
|
|
100
|
+
behavior = "allow"
|
|
101
|
+
elif tool_name == "Chrome":
|
|
102
|
+
if phase_num == 1 or phase_num >= 3:
|
|
103
|
+
behavior = "allow"
|
|
104
|
+
else:
|
|
105
|
+
behavior = "deny"
|
|
106
|
+
message = "Chrome 仅在 P1(原型展示)和 P3+(测试/审查)阶段允许"
|
|
107
|
+
elif tool_name in ("Read", "Glob", "Grep", "WebSearch", "WebFetch"):
|
|
108
|
+
behavior = "allow"
|
|
109
|
+
else:
|
|
110
|
+
return 0 # unknown tools are not intercepted
|
|
111
|
+
|
|
112
|
+
if behavior == "deny" and message:
|
|
113
|
+
out = {
|
|
114
|
+
"hookSpecificOutput": {
|
|
115
|
+
"hookEventName": "PermissionRequest",
|
|
116
|
+
"decision": {"behavior": "deny", "message": message},
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
120
|
+
elif behavior == "allow":
|
|
121
|
+
out = {
|
|
122
|
+
"hookSpecificOutput": {
|
|
123
|
+
"hookEventName": "PermissionRequest",
|
|
124
|
+
"decision": {"behavior": "allow"},
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
128
|
+
return 0
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
sys.exit(main())
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""PostToolUseFailure - generic advice when a tool fails."""
|
|
3
|
-
import json
|
|
4
|
-
import re
|
|
5
|
-
import sys
|
|
6
|
-
|
|
7
|
-
import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def main() -> int:
|
|
11
|
-
raw = sys.stdin.read()
|
|
12
|
-
tool_name = "unknown"
|
|
13
|
-
try:
|
|
14
|
-
data = json.loads(raw) if raw.strip() else {}
|
|
15
|
-
if isinstance(data, dict):
|
|
16
|
-
tool_name = data.get("tool_name") or "unknown"
|
|
17
|
-
except Exception:
|
|
18
|
-
m = re.search(r'"tool_name"\s*:\s*"((?:[^"\\]|\\.)*)"', raw)
|
|
19
|
-
if m:
|
|
20
|
-
tool_name = m.group(1)
|
|
21
|
-
context = (
|
|
22
|
-
f"[工具失败] 工具={tool_name}。建议:(1) 检查命令/路径是否正确 "
|
|
23
|
-
"(2) 检查权限配置 (3) 查看是否有语法错误。"
|
|
24
|
-
)
|
|
25
|
-
out = {
|
|
26
|
-
"hookSpecificOutput": {
|
|
27
|
-
"hookEventName": "PostToolUseFailure",
|
|
28
|
-
"additionalContext": context,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
print(json.dumps(out, ensure_ascii=False))
|
|
32
|
-
return 0
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if __name__ == "__main__":
|
|
36
|
-
sys.exit(main())
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PostToolUseFailure - generic advice when a tool fails."""
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> int:
|
|
11
|
+
raw = sys.stdin.read()
|
|
12
|
+
tool_name = "unknown"
|
|
13
|
+
try:
|
|
14
|
+
data = json.loads(raw) if raw.strip() else {}
|
|
15
|
+
if isinstance(data, dict):
|
|
16
|
+
tool_name = data.get("tool_name") or "unknown"
|
|
17
|
+
except Exception:
|
|
18
|
+
m = re.search(r'"tool_name"\s*:\s*"((?:[^"\\]|\\.)*)"', raw)
|
|
19
|
+
if m:
|
|
20
|
+
tool_name = m.group(1)
|
|
21
|
+
context = (
|
|
22
|
+
f"[工具失败] 工具={tool_name}。建议:(1) 检查命令/路径是否正确 "
|
|
23
|
+
"(2) 检查权限配置 (3) 查看是否有语法错误。"
|
|
24
|
+
)
|
|
25
|
+
out = {
|
|
26
|
+
"hookSpecificOutput": {
|
|
27
|
+
"hookEventName": "PostToolUseFailure",
|
|
28
|
+
"additionalContext": context,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
32
|
+
return 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
sys.exit(main())
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""PreCompact - state check before context compaction."""
|
|
3
|
-
import json
|
|
4
|
-
import re
|
|
5
|
-
import sys
|
|
6
|
-
|
|
7
|
-
from task_manager import get_task_state
|
|
8
|
-
|
|
9
|
-
import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def count_modified_files(content: str) -> int:
|
|
13
|
-
"""Count list items under the modified_files: section."""
|
|
14
|
-
lines = content.split("\n")
|
|
15
|
-
in_files = False
|
|
16
|
-
count = 0
|
|
17
|
-
for line in lines:
|
|
18
|
-
if line.startswith("modified_files:"):
|
|
19
|
-
in_files = True
|
|
20
|
-
continue
|
|
21
|
-
if in_files:
|
|
22
|
-
if line and not line[0].isspace():
|
|
23
|
-
break
|
|
24
|
-
if re.match(r"^\s*-\s+", line):
|
|
25
|
-
count += 1
|
|
26
|
-
return count
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def main() -> int:
|
|
30
|
-
"""Emit a pre-compaction state reminder from the routed task state file.
|
|
31
|
-
|
|
32
|
-
Returns:
|
|
33
|
-
Process exit code.
|
|
34
|
-
"""
|
|
35
|
-
state_file = get_task_state(__file__)
|
|
36
|
-
if not state_file.is_file():
|
|
37
|
-
return 0
|
|
38
|
-
content = state_file.read_text(encoding="utf-8")
|
|
39
|
-
|
|
40
|
-
task = ""
|
|
41
|
-
m = re.search(r'^task_description:\s*"?([^"]*)"?\s*$', content, re.M)
|
|
42
|
-
if m:
|
|
43
|
-
task = m.group(1).strip()
|
|
44
|
-
kc = ""
|
|
45
|
-
m = re.search(r'^key_context:\s*"?([^"]*)"?\s*$', content, re.M)
|
|
46
|
-
if m:
|
|
47
|
-
kc = m.group(1).strip()
|
|
48
|
-
files_count = count_modified_files(content)
|
|
49
|
-
|
|
50
|
-
warnings = ""
|
|
51
|
-
if not kc:
|
|
52
|
-
warnings = "key_context 为空!"
|
|
53
|
-
if files_count == 0:
|
|
54
|
-
warnings += " modified_files 为空!"
|
|
55
|
-
|
|
56
|
-
context = (
|
|
57
|
-
f"[压缩前] 任务={task},已修改{files_count}个文件。{warnings}"
|
|
58
|
-
"请用 Edit 更新 project-state.md:(1) 确认 modified_files 完整 "
|
|
59
|
-
"(2) 更新 key_context 工作摘要。"
|
|
60
|
-
)
|
|
61
|
-
print(json.dumps({"stopReason": context}, ensure_ascii=False))
|
|
62
|
-
return 0
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if __name__ == "__main__":
|
|
66
|
-
sys.exit(main())
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PreCompact - state check before context compaction."""
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from task_manager import get_task_state
|
|
8
|
+
|
|
9
|
+
import flowcraft_env # noqa: F401 — UTF-8 stdio 双保险(R2)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def count_modified_files(content: str) -> int:
|
|
13
|
+
"""Count list items under the modified_files: section."""
|
|
14
|
+
lines = content.split("\n")
|
|
15
|
+
in_files = False
|
|
16
|
+
count = 0
|
|
17
|
+
for line in lines:
|
|
18
|
+
if line.startswith("modified_files:"):
|
|
19
|
+
in_files = True
|
|
20
|
+
continue
|
|
21
|
+
if in_files:
|
|
22
|
+
if line and not line[0].isspace():
|
|
23
|
+
break
|
|
24
|
+
if re.match(r"^\s*-\s+", line):
|
|
25
|
+
count += 1
|
|
26
|
+
return count
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def main() -> int:
|
|
30
|
+
"""Emit a pre-compaction state reminder from the routed task state file.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Process exit code.
|
|
34
|
+
"""
|
|
35
|
+
state_file = get_task_state(__file__)
|
|
36
|
+
if not state_file.is_file():
|
|
37
|
+
return 0
|
|
38
|
+
content = state_file.read_text(encoding="utf-8")
|
|
39
|
+
|
|
40
|
+
task = ""
|
|
41
|
+
m = re.search(r'^task_description:\s*"?([^"]*)"?\s*$', content, re.M)
|
|
42
|
+
if m:
|
|
43
|
+
task = m.group(1).strip()
|
|
44
|
+
kc = ""
|
|
45
|
+
m = re.search(r'^key_context:\s*"?([^"]*)"?\s*$', content, re.M)
|
|
46
|
+
if m:
|
|
47
|
+
kc = m.group(1).strip()
|
|
48
|
+
files_count = count_modified_files(content)
|
|
49
|
+
|
|
50
|
+
warnings = ""
|
|
51
|
+
if not kc:
|
|
52
|
+
warnings = "key_context 为空!"
|
|
53
|
+
if files_count == 0:
|
|
54
|
+
warnings += " modified_files 为空!"
|
|
55
|
+
|
|
56
|
+
context = (
|
|
57
|
+
f"[压缩前] 任务={task},已修改{files_count}个文件。{warnings}"
|
|
58
|
+
"请用 Edit 更新 project-state.md:(1) 确认 modified_files 完整 "
|
|
59
|
+
"(2) 更新 key_context 工作摘要。"
|
|
60
|
+
)
|
|
61
|
+
print(json.dumps({"stopReason": context}, ensure_ascii=False))
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
sys.exit(main())
|