@leocm/flowcraft 0.0.0-stage → 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 +855 -3
- package/bin/cli.js +108 -0
- package/flowcraft.yaml +30 -0
- package/install.sh +24 -0
- package/lib/args.js +38 -0
- package/lib/config.js +20 -0
- package/lib/copy.js +131 -0
- package/lib/fix.js +110 -0
- package/lib/fsutil.js +104 -0
- package/lib/global.js +229 -0
- package/lib/init.js +43 -0
- package/lib/runtime.js +84 -0
- package/lib/version.js +55 -0
- package/lib/wizard.js +125 -0
- package/package.json +31 -4
- package/presets/backend.yaml +20 -0
- package/presets/default.yaml +15 -0
- package/presets/frontend.yaml +20 -0
- package/presets/quick-fix.yaml +15 -0
- package/setup/.claude/commands/P0.5.md +1 -0
- package/setup/.claude/commands/P0.md +1 -0
- package/setup/.claude/commands/P1.md +1 -0
- package/setup/.claude/commands/P2.md +1 -0
- package/setup/.claude/commands/P3.md +1 -0
- package/setup/.claude/commands/P4.md +1 -0
- package/setup/.claude/commands/P5.md +1 -0
- package/setup/.claude/commands/code-analysis-init.md +1 -0
- package/setup/.claude/commands/code-analysis-rebuild.md +1 -0
- package/setup/.claude/commands/code-analysis-show-memory.md +1 -0
- package/setup/.claude/commands/code-analysis-update.md +1 -0
- package/setup/.claude/hooks/check-phase-advancement.py +180 -0
- package/setup/.claude/hooks/check-phase-test.py +152 -0
- package/setup/.claude/hooks/check-phase-write.py +235 -0
- package/setup/.claude/hooks/dispatch.py +67 -0
- package/setup/.claude/hooks/file-suggestion.py +45 -0
- package/setup/.claude/hooks/flowcraft_env.py +137 -0
- package/setup/.claude/hooks/log_session.py +93 -0
- package/setup/.claude/hooks/permission-request.py +125 -0
- package/setup/.claude/hooks/post-tool-failure.py +36 -0
- package/setup/.claude/hooks/pre-compact.py +66 -0
- package/setup/.claude/hooks/review-runner.py +846 -0
- package/setup/.claude/hooks/session-end.py +184 -0
- package/setup/.claude/hooks/session-start.py +188 -0
- package/setup/.claude/hooks/settings.json +0 -0
- package/setup/.claude/hooks/setup-keys.py +282 -0
- package/setup/.claude/hooks/statusline.py +63 -0
- package/setup/.claude/hooks/stop-check.py +171 -0
- package/setup/.claude/hooks/subagent-start.py +50 -0
- package/setup/.claude/hooks/subagent-stop.py +63 -0
- package/setup/.claude/hooks/task-completed.py +57 -0
- package/setup/.claude/hooks/task_manager.py +592 -0
- package/setup/.claude/hooks/user-prompt-submit.py +85 -0
- package/setup/.claude/project-state.md +109 -0
- package/setup/.claude/settings.json +237 -0
- package/setup/.claude/settings.local.json +13 -0
- package/setup/.claude/skills/P5report/SKILL.md +77 -0
- package/setup/.claude/skills/Pstatus/SKILL.md +68 -0
- package/setup/.claude/skills/archive/SKILL.md +196 -0
- package/setup/.claude/skills/brainstorming/SKILL.md +155 -0
- package/setup/.claude/skills/brainstorming/scripts/frame-template.html +213 -0
- package/setup/.claude/skills/brainstorming/scripts/helper.js +167 -0
- package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -0
- package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -0
- package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -0
- package/setup/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/setup/.claude/skills/brainstorming/visual-companion.md +298 -0
- package/setup/.claude/skills/checkpoint/SKILL.md +42 -0
- package/setup/.claude/skills/chrome-integration/SKILL.md +67 -0
- package/setup/.claude/skills/code-analysis/SKILL.md +1243 -0
- package/setup/.claude/skills/code-review/SKILL.md +265 -0
- package/setup/.claude/skills/cross-review/SKILL.md +41 -0
- package/setup/.claude/skills/executing-plans/SKILL.md +64 -0
- package/setup/.claude/skills/git-prep/SKILL.md +50 -0
- package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
- package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
- package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
- package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
- package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
- package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
- package/setup/.claude/skills/graphify/SKILL.md +49 -0
- package/setup/.claude/skills/openspec-apply-change/SKILL.md +185 -0
- package/setup/.claude/skills/openspec-archive-change/SKILL.md +182 -0
- package/setup/.claude/skills/openspec-bulk-archive-change/SKILL.md +339 -0
- package/setup/.claude/skills/openspec-continue-change/SKILL.md +118 -0
- package/setup/.claude/skills/openspec-explore/SKILL.md +311 -0
- package/setup/.claude/skills/openspec-ff-change/SKILL.md +113 -0
- package/setup/.claude/skills/openspec-new-change/SKILL.md +77 -0
- package/setup/.claude/skills/openspec-onboard/SKILL.md +573 -0
- package/setup/.claude/skills/openspec-propose/SKILL.md +149 -0
- package/setup/.claude/skills/openspec-sync-specs/SKILL.md +262 -0
- package/setup/.claude/skills/openspec-update-change/SKILL.md +91 -0
- package/setup/.claude/skills/openspec-verify-change/SKILL.md +175 -0
- package/setup/.claude/skills/oss-version-check/SKILL.md +71 -0
- package/setup/.claude/skills/oss-version-check/check_oss_version.py +205 -0
- package/setup/.claude/skills/phase/SKILL.md +63 -0
- package/setup/.claude/skills/playwright/SKILL.md +86 -0
- package/setup/.claude/skills/playwright-cli/SKILL.md +420 -0
- package/setup/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
- package/setup/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/setup/.claude/skills/playwright-cli/references/references/element-attributes.md +23 -0
- package/setup/.claude/skills/playwright-cli/references/references/playwright-tests.md +39 -0
- package/setup/.claude/skills/playwright-cli/references/references/request-mocking.md +87 -0
- package/setup/.claude/skills/playwright-cli/references/references/running-code.md +241 -0
- package/setup/.claude/skills/playwright-cli/references/references/session-management.md +225 -0
- package/setup/.claude/skills/playwright-cli/references/references/storage-state.md +275 -0
- package/setup/.claude/skills/playwright-cli/references/references/test-generation.md +433 -0
- package/setup/.claude/skills/playwright-cli/references/references/tracing.md +139 -0
- package/setup/.claude/skills/playwright-cli/references/references/video-recording.md +143 -0
- package/setup/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/setup/.claude/skills/playwright-cli/references/running-code.md +241 -0
- package/setup/.claude/skills/playwright-cli/references/session-management.md +225 -0
- package/setup/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/setup/.claude/skills/playwright-cli/references/test-generation.md +433 -0
- package/setup/.claude/skills/playwright-cli/references/tracing.md +139 -0
- package/setup/.claude/skills/playwright-cli/references/video-recording.md +143 -0
- package/setup/.claude/skills/review/SKILL.md +98 -0
- package/setup/.claude/skills/review-tools/SKILL.md +76 -0
- package/setup/.claude/skills/subagent-driven-development/SKILL.md +94 -0
- package/setup/.claude/skills/task/SKILL.md +26 -0
- package/setup/.claude/skills/test-driven-development/SKILL.md +320 -0
- package/setup/.claude/skills/test-driven-development/writing-good-tests.md +198 -0
- package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +377 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/setup/.claude/skills/ui-ux-standards/SKILL.md +154 -0
- package/setup/.claude/skills/verification-before-completion/SKILL.md +120 -0
- package/setup/.claude/skills/wiki-read/SKILL.md +190 -0
- package/setup/.claude/skills/writing-plans/SKILL.md +168 -0
- package/setup/.claude/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/setup/.claude/tasks/.last-session +1 -0
- package/setup/.codex/.agents/skills/P5report/SKILL.md +77 -0
- package/setup/.codex/.agents/skills/Pstatus/SKILL.md +30 -0
- package/setup/.codex/.agents/skills/archive/SKILL.md +196 -0
- package/setup/.codex/.agents/skills/brainstorming/SKILL.md +155 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/frame-template.html +213 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/helper.js +167 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -0
- package/setup/.codex/.agents/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -0
- package/setup/.codex/.agents/skills/checkpoint/SKILL.md +42 -0
- package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +67 -0
- package/setup/.codex/.agents/skills/code-analysis/SKILL.md +1243 -0
- package/setup/.codex/.agents/skills/code-review/SKILL.md +265 -0
- package/setup/.codex/.agents/skills/cross-review/SKILL.md +42 -0
- package/setup/.codex/.agents/skills/executing-plans/SKILL.md +64 -0
- package/setup/.codex/.agents/skills/git-prep/SKILL.md +50 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
- package/setup/.codex/.agents/skills/graphify/SKILL.md +49 -0
- package/setup/.codex/.agents/skills/openspec-apply-change/SKILL.md +185 -0
- package/setup/.codex/.agents/skills/openspec-archive-change/SKILL.md +182 -0
- package/setup/.codex/.agents/skills/openspec-bulk-archive-change/SKILL.md +339 -0
- package/setup/.codex/.agents/skills/openspec-continue-change/SKILL.md +118 -0
- package/setup/.codex/.agents/skills/openspec-explore/SKILL.md +311 -0
- package/setup/.codex/.agents/skills/openspec-ff-change/SKILL.md +113 -0
- package/setup/.codex/.agents/skills/openspec-new-change/SKILL.md +77 -0
- package/setup/.codex/.agents/skills/openspec-onboard/SKILL.md +573 -0
- package/setup/.codex/.agents/skills/openspec-propose/SKILL.md +149 -0
- package/setup/.codex/.agents/skills/openspec-sync-specs/SKILL.md +262 -0
- package/setup/.codex/.agents/skills/openspec-update-change/SKILL.md +91 -0
- package/setup/.codex/.agents/skills/openspec-verify-change/SKILL.md +175 -0
- package/setup/.codex/.agents/skills/oss-version-check/SKILL.md +71 -0
- package/setup/.codex/.agents/skills/oss-version-check/check_oss_version.py +205 -0
- package/setup/.codex/.agents/skills/phase/SKILL.md +63 -0
- package/setup/.codex/.agents/skills/playwright/SKILL.md +86 -0
- package/setup/.codex/.agents/skills/playwright-cli/SKILL.md +420 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/element-attributes.md +23 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/element-attributes.md +23 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/playwright-tests.md +39 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/request-mocking.md +87 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/running-code.md +241 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/session-management.md +225 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/storage-state.md +275 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/test-generation.md +433 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/tracing.md +139 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/video-recording.md +143 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/request-mocking.md +87 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/running-code.md +241 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/session-management.md +225 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/storage-state.md +275 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/test-generation.md +433 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/tracing.md +139 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/video-recording.md +143 -0
- package/setup/.codex/.agents/skills/review/SKILL.md +98 -0
- package/setup/.codex/.agents/skills/review-tools/SKILL.md +76 -0
- package/setup/.codex/.agents/skills/subagent-driven-development/SKILL.md +94 -0
- package/setup/.codex/.agents/skills/task/SKILL.md +27 -0
- package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +320 -0
- package/setup/.codex/.agents/skills/test-driven-development/writing-good-tests.md +198 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +377 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/setup/.codex/.agents/skills/ui-ux-standards/SKILL.md +154 -0
- package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +120 -0
- package/setup/.codex/.agents/skills/wiki-read/SKILL.md +190 -0
- package/setup/.codex/.agents/skills/writing-plans/SKILL.md +168 -0
- package/setup/.codex/.agents/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/setup/.codex/config.toml +10 -0
- package/setup/.codex/hooks/log_session.py +92 -0
- package/setup/.codex/hooks/review-runner.py +851 -0
- package/setup/.codex/hooks/sdlc-codex-hook.cjs +1039 -0
- package/setup/.codex/hooks/setup-keys.py +287 -0
- package/setup/.codex/hooks.json +121 -0
- package/setup/.codex/model-catalog.json +154 -0
- package/setup/.codex/project-state.md +103 -0
- package/setup/AGENTS.md +722 -0
- package/setup/CLAUDE.md +717 -0
- package/setup/install.sh +24 -0
- package/setup/tests/test_decision_timeout.py +241 -0
- package/setup/tests/test_hook_guards.py +357 -0
- package/setup/tests/test_sdlc_bootstrap.py +167 -0
- package/setup/tests/test_task_manager.py +148 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
智能代码分析技能。执行 /code-analysis init — 初始化 Wiki 目录结构并分析所有模块代码。详细阅读 SKILL.md 中的完整说明。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
智能代码分析技能。执行 /code-analysis rebuild — 全量对比优化,对比现有文档进行优化、补全、矫正,展示变更清单让你确认。详细阅读 SKILL.md 中的完整说明。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
智能代码分析技能。执行 /code-analysis show-memory — 查看当前变更记忆内容。详细阅读 SKILL.md 中的完整说明。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
智能代码分析技能。执行 /code-analysis update [模块名] — 增量更新指定模块的文档。详细阅读 SKILL.md 中的完整说明。
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""check-phase-advancement - verify phase deliverables before advancing.
|
|
3
|
+
|
|
4
|
+
Reads the deliverable_checklist from project-state.md and enforces the SDLC
|
|
5
|
+
phase ordering rules before a phase transition is written.
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
import urllib.request
|
|
13
|
+
import uuid
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from flowcraft_env import extract_nested
|
|
18
|
+
|
|
19
|
+
MCP_URL = "http://127.0.0.1:8181/api/logs"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def deny(message: str) -> int:
|
|
23
|
+
out = {
|
|
24
|
+
"hookSpecificOutput": {
|
|
25
|
+
"hookEventName": "PhaseAdvancementCheck",
|
|
26
|
+
"decision": {"behavior": "deny", "message": message},
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
30
|
+
return 1
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main() -> int:
|
|
34
|
+
raw = sys.stdin.read()
|
|
35
|
+
|
|
36
|
+
tool_name = extract_nested(raw, "tool_name")
|
|
37
|
+
if not tool_name:
|
|
38
|
+
return 0
|
|
39
|
+
|
|
40
|
+
file_path = extract_nested(raw, "file_path")
|
|
41
|
+
basename = os.path.basename(file_path or "")
|
|
42
|
+
if basename != "project-state.md":
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
state_file = Path(os.environ.get("CLAUDE_PROJECT_DIR") or ".") / ".claude" / "project-state.md"
|
|
46
|
+
if not state_file.is_file():
|
|
47
|
+
return 0
|
|
48
|
+
state_content = state_file.read_text(encoding="utf-8")
|
|
49
|
+
|
|
50
|
+
# Old phase (value before the edit); P0.5 supported (R4)
|
|
51
|
+
m = re.search(r"^current_phase:\s*P(\d+(?:\.\d+)?)", state_content, re.M)
|
|
52
|
+
old_phase = m.group(1) if m else "0"
|
|
53
|
+
|
|
54
|
+
# New phase from the input's new_string; P0.5 supported (R4)
|
|
55
|
+
new_phase = ""
|
|
56
|
+
m = re.search(r'"new_string[^}]*current_phase:\s*P(\d+(?:\.\d+)?)', raw)
|
|
57
|
+
if m:
|
|
58
|
+
new_phase = m.group(1)
|
|
59
|
+
if not new_phase:
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
# Only check on actual phase changes
|
|
63
|
+
if old_phase == new_phase:
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
project_dir = os.environ.get("CLAUDE_PROJECT_DIR") or "."
|
|
67
|
+
|
|
68
|
+
# ---- log sync: mirror session_log.json to the MCP service ----
|
|
69
|
+
session_log = Path(project_dir) / ".claude" / "session_log.json"
|
|
70
|
+
has_logs = False
|
|
71
|
+
if session_log.is_file() and session_log.stat().st_size > 0:
|
|
72
|
+
try:
|
|
73
|
+
first_char = session_log.read_text(encoding="utf-8")[:1]
|
|
74
|
+
except Exception:
|
|
75
|
+
first_char = ""
|
|
76
|
+
if first_char == "[":
|
|
77
|
+
if session_log.stat().st_size > 3:
|
|
78
|
+
has_logs = True
|
|
79
|
+
|
|
80
|
+
# Generate a phase-change summary when the log is empty
|
|
81
|
+
if not has_logs:
|
|
82
|
+
git_user = "unknown"
|
|
83
|
+
try:
|
|
84
|
+
r = subprocess.run(["git", "config", "user.name"], capture_output=True, text=True, timeout=3)
|
|
85
|
+
if r.returncode == 0 and r.stdout.strip():
|
|
86
|
+
git_user = r.stdout.strip()
|
|
87
|
+
except Exception:
|
|
88
|
+
pass
|
|
89
|
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
90
|
+
summary = f"阶段变更 P{old_phase} -> P{new_phase}"
|
|
91
|
+
session_id = str(uuid.uuid4())
|
|
92
|
+
entry = [{
|
|
93
|
+
"sessionId": session_id,
|
|
94
|
+
"userName": git_user,
|
|
95
|
+
"date": timestamp,
|
|
96
|
+
"role": "assistant",
|
|
97
|
+
"content": summary,
|
|
98
|
+
}]
|
|
99
|
+
session_log.write_text(json.dumps(entry, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
100
|
+
has_logs = True
|
|
101
|
+
|
|
102
|
+
if has_logs:
|
|
103
|
+
try:
|
|
104
|
+
payload = session_log.read_bytes()
|
|
105
|
+
req = urllib.request.Request(
|
|
106
|
+
MCP_URL,
|
|
107
|
+
data=payload,
|
|
108
|
+
headers={"Content-Type": "application/json"},
|
|
109
|
+
method="POST",
|
|
110
|
+
)
|
|
111
|
+
with urllib.request.urlopen(req, timeout=5) as resp:
|
|
112
|
+
code = resp.status
|
|
113
|
+
if 200 <= code < 300:
|
|
114
|
+
session_log.write_text("[]", encoding="utf-8")
|
|
115
|
+
except Exception:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
# P0.5 rollback: exempt from all forced-transition rules (R4)
|
|
119
|
+
if new_phase == "0.5" or old_phase == "0.5":
|
|
120
|
+
return 0
|
|
121
|
+
|
|
122
|
+
# ---- P1 must complete requirement-method selection before P2 ----
|
|
123
|
+
if old_phase == "1" and new_phase == "2":
|
|
124
|
+
if "requirement_method_selected: true" not in state_content:
|
|
125
|
+
return deny(
|
|
126
|
+
"【SDLC 违规】P1→P2 前必须先完成「需求澄清方式选择」(A brainstorming / B openspec)"
|
|
127
|
+
"并记录 requirement_method_selected = true。"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# ---- P2 must advance to P3, cannot skip ----
|
|
131
|
+
if old_phase == "2" and new_phase != "3":
|
|
132
|
+
return deny(
|
|
133
|
+
"【SDLC 违规】P2(编码阶段)完成后必须推进到 P3(测试阶段),不能跳过或直接切到其他阶段。请按顺序推进。"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# ---- P2→P3 triggers the AI code review ----
|
|
137
|
+
if old_phase == "2" and new_phase == "3":
|
|
138
|
+
m = re.search(r"modified_files:.*?\n((?:\s+-\s+[^\n]*?\n)*)", state_content, re.DOTALL)
|
|
139
|
+
if m and "-" in m.group(1):
|
|
140
|
+
out = {
|
|
141
|
+
"hookSpecificOutput": {
|
|
142
|
+
"hookEventName": "CodeReviewRequired",
|
|
143
|
+
"decision": {"behavior": "allow", "message": "P2 完成,触发 AI 代码审查"},
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
147
|
+
|
|
148
|
+
# ---- P3 must advance to P4, cannot skip ----
|
|
149
|
+
if old_phase == "3" and new_phase != "4":
|
|
150
|
+
return deny(
|
|
151
|
+
"【SDLC 违规】P3(测试阶段)完成后必须推进到 P4(审查阶段),不能跳过或直接切到其他阶段。请按顺序推进。"
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# ---- P4 must advance to P5, cannot skip ----
|
|
155
|
+
if old_phase == "4" and new_phase != "5":
|
|
156
|
+
return deny(
|
|
157
|
+
"【SDLC 违规】P4(审查阶段)完成后必须推进到 P5(交付阶段),不能跳过或直接切到其他阶段。请按顺序推进。"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# ---- deliverable checklist for the old phase ----
|
|
161
|
+
pattern = r"P" + old_phase + r":.*?\n((?:\s+-\s+[^\n]+?\n)*)"
|
|
162
|
+
m = re.search(pattern, state_content, re.DOTALL)
|
|
163
|
+
if m and m.group(1).strip():
|
|
164
|
+
project_root = Path(project_dir)
|
|
165
|
+
missing = []
|
|
166
|
+
for line in m.group(1).strip().split("\n"):
|
|
167
|
+
m2 = re.match(r'\s*-\s+"([^"]+)"', line)
|
|
168
|
+
if m2:
|
|
169
|
+
path = m2.group(1)
|
|
170
|
+
if not (project_root / path).exists():
|
|
171
|
+
missing.append(path)
|
|
172
|
+
if missing:
|
|
173
|
+
return deny(
|
|
174
|
+
f"P{old_phase}→P{new_phase} 产出物检查失败,缺少: {'; '.join(missing)} 请先补充完整后再推进。"
|
|
175
|
+
)
|
|
176
|
+
return 0
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
if __name__ == "__main__":
|
|
180
|
+
sys.exit(main())
|
|
@@ -0,0 +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())
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""check-phase-write - PreToolUse hook for Write/Edit operations.
|
|
3
|
+
|
|
4
|
+
Guards SDLC framework files and enforces phase-based code-edit restrictions.
|
|
5
|
+
Reads flowcraft.yaml for stage configuration and complexity-based skipping.
|
|
6
|
+
|
|
7
|
+
Auto-transition: P0 + code write → auto-enter P1 (no user prompt).
|
|
8
|
+
"""
|
|
9
|
+
import re
|
|
10
|
+
import sys
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from flowcraft_env import extract_nested, get_project_root, is_under_root
|
|
15
|
+
from task_manager import get_task_state
|
|
16
|
+
|
|
17
|
+
CODE_EXTS = {
|
|
18
|
+
"java", "js", "ts", "jsx", "tsx", "py", "go", "rs", "c", "cpp", "h",
|
|
19
|
+
"cs", "rb", "php", "swift", "kt", "dart", "vue", "svelte", "html", "css",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# Phases that can be skipped based on complexity
|
|
23
|
+
SKIPPABLE_PHASES = {"P1", "P3", "P5"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def auto_transition_to_p1(state_file: Path) -> bool:
|
|
27
|
+
"""Auto-transition from P0 to P1 when code write is attempted.
|
|
28
|
+
|
|
29
|
+
Updates project-state.md: current_phase → P1, adds phase_history entry.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
state_file: Task/project state file to update.
|
|
33
|
+
Returns:
|
|
34
|
+
True when the state file was updated successfully.
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
content = state_file.read_text(encoding="utf-8")
|
|
38
|
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
39
|
+
|
|
40
|
+
# Update current_phase
|
|
41
|
+
content = re.sub(
|
|
42
|
+
r"^current_phase:\s*\S+",
|
|
43
|
+
"current_phase: P1",
|
|
44
|
+
content,
|
|
45
|
+
count=1,
|
|
46
|
+
flags=re.M,
|
|
47
|
+
)
|
|
48
|
+
# Update last_updated
|
|
49
|
+
content = re.sub(
|
|
50
|
+
r"^last_updated:\s*\S+",
|
|
51
|
+
f"last_updated: \"{now}\"",
|
|
52
|
+
content,
|
|
53
|
+
count=1,
|
|
54
|
+
flags=re.M,
|
|
55
|
+
)
|
|
56
|
+
# Add phase_history entry (insert after "phase_history:")
|
|
57
|
+
content = re.sub(
|
|
58
|
+
r"(phase_history:\s*\n)",
|
|
59
|
+
f'\\1 - phase: P1\n action: "auto-enter: code write detected"\n at: "{now}"\n',
|
|
60
|
+
content,
|
|
61
|
+
count=1,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
state_file.write_text(content, encoding="utf-8")
|
|
65
|
+
print(f"[FlowCraft] 检测到代码写入,自动进入 P1 需求阶段", file=sys.stderr)
|
|
66
|
+
return True
|
|
67
|
+
except Exception as e:
|
|
68
|
+
print(f"[FlowCraft] 自动切换P1失败: {e}", file=sys.stderr)
|
|
69
|
+
return False
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def load_flowcraft_config(project_root: Path) -> dict:
|
|
73
|
+
"""Load flowcraft.yaml configuration."""
|
|
74
|
+
config_path = project_root / "flowcraft.yaml"
|
|
75
|
+
if not config_path.is_file():
|
|
76
|
+
return {}
|
|
77
|
+
try:
|
|
78
|
+
import yaml
|
|
79
|
+
with open(config_path, "r", encoding="utf-8") as f:
|
|
80
|
+
return yaml.safe_load(f) or {}
|
|
81
|
+
except ImportError:
|
|
82
|
+
# Fallback: parse simple YAML manually
|
|
83
|
+
return _parse_yaml_simple(config_path)
|
|
84
|
+
except Exception:
|
|
85
|
+
return {}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _parse_yaml_simple(path: Path) -> dict:
|
|
89
|
+
"""Minimal YAML parser for flowcraft.yaml (no external dependency)."""
|
|
90
|
+
config = {"stages": {}}
|
|
91
|
+
try:
|
|
92
|
+
for line in path.read_text(encoding="utf-8").splitlines():
|
|
93
|
+
line = line.strip()
|
|
94
|
+
if line.startswith("#") or not line or ":" not in line:
|
|
95
|
+
continue
|
|
96
|
+
# Handle stages section
|
|
97
|
+
if re.match(r"^P\d+\.?\d*:", line):
|
|
98
|
+
key, val = line.split(":", 1)
|
|
99
|
+
config["stages"][key.strip()] = val.strip().strip('"').strip("'")
|
|
100
|
+
except Exception:
|
|
101
|
+
pass
|
|
102
|
+
return config
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def get_complexity_level(state_file: Path) -> str:
|
|
106
|
+
"""Read complexity_level from the given state file."""
|
|
107
|
+
if not state_file.is_file():
|
|
108
|
+
return "medium"
|
|
109
|
+
try:
|
|
110
|
+
content = state_file.read_text(encoding="utf-8")
|
|
111
|
+
m = re.search(r"^complexity_level:\s*(\S+)", content, re.M)
|
|
112
|
+
if m:
|
|
113
|
+
level = m.group(1).strip().lower()
|
|
114
|
+
if level in ("low", "medium", "high"):
|
|
115
|
+
return level
|
|
116
|
+
except Exception:
|
|
117
|
+
pass
|
|
118
|
+
return "medium"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def is_phase_skippable(phase: str, config: dict, complexity: str) -> bool:
|
|
122
|
+
"""Check if a phase should be skipped based on config and complexity."""
|
|
123
|
+
stages = config.get("stages", {})
|
|
124
|
+
phase_setting = stages.get(phase, "true")
|
|
125
|
+
|
|
126
|
+
if phase_setting == "true":
|
|
127
|
+
return False
|
|
128
|
+
if phase_setting == "false":
|
|
129
|
+
return True
|
|
130
|
+
if phase_setting == "auto":
|
|
131
|
+
# Auto mode: skip based on complexity
|
|
132
|
+
if complexity == "low":
|
|
133
|
+
return phase in SKIPPABLE_PHASES
|
|
134
|
+
# medium and high: don't skip
|
|
135
|
+
return False
|
|
136
|
+
return False
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def main() -> int:
|
|
140
|
+
raw = sys.stdin.read()
|
|
141
|
+
# R1: real PreToolUse payloads nest the path under tool_input
|
|
142
|
+
file_path = extract_nested(raw, "file_path")
|
|
143
|
+
if not file_path:
|
|
144
|
+
return 0
|
|
145
|
+
|
|
146
|
+
# Windows path compatibility
|
|
147
|
+
file_path = file_path.replace("\\", "/").replace("//", "/")
|
|
148
|
+
|
|
149
|
+
project_root = get_project_root(__file__)
|
|
150
|
+
state_file = get_task_state(__file__)
|
|
151
|
+
current_phase = "P0"
|
|
152
|
+
if state_file.is_file():
|
|
153
|
+
try:
|
|
154
|
+
m = re.search(r"^current_phase:\s*(\S+)", state_file.read_text(encoding="utf-8"), re.M)
|
|
155
|
+
if m:
|
|
156
|
+
current_phase = m.group(1).strip()
|
|
157
|
+
except Exception:
|
|
158
|
+
pass
|
|
159
|
+
|
|
160
|
+
# No state file → non-SDLC project, allow everything (R3)
|
|
161
|
+
if not state_file.is_file():
|
|
162
|
+
return 0
|
|
163
|
+
|
|
164
|
+
m = re.search(r"\.([^.\\/]+)$", file_path)
|
|
165
|
+
ext = m.group(1).lower() if m else ""
|
|
166
|
+
|
|
167
|
+
# Protect SDLC framework files (flowcraft/ paths continue to phase checks)
|
|
168
|
+
if "flowcraft/" in file_path:
|
|
169
|
+
pass
|
|
170
|
+
elif re.search(
|
|
171
|
+
r"/\.claude/(project-state\.md|session_log\.json|prd\.md|code-review-report\.md|"
|
|
172
|
+
r"reports/.*|hooks/.*|skills/.*|memory/.*|docs/.*|plans/.*|tasks/[^/]+\.md)|/plan/",
|
|
173
|
+
file_path,
|
|
174
|
+
):
|
|
175
|
+
return 0
|
|
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
|
|
180
|
+
print(f"[FlowCraft 守卫] 禁止修改框架文件: {file_path}", file=sys.stderr)
|
|
181
|
+
print("[FlowCraft 守卫] 如需修改框架文件,请手动编辑。", file=sys.stderr)
|
|
182
|
+
return 2
|
|
183
|
+
|
|
184
|
+
# Load flowcraft.yaml config and complexity
|
|
185
|
+
config = load_flowcraft_config(project_root)
|
|
186
|
+
complexity = get_complexity_level(state_file)
|
|
187
|
+
|
|
188
|
+
# Check if current phase is skippable
|
|
189
|
+
if is_phase_skippable(current_phase, config, complexity):
|
|
190
|
+
return 0
|
|
191
|
+
|
|
192
|
+
# P0: block the write and auto-enter P1 (R2)
|
|
193
|
+
if current_phase == "P0" and ext in CODE_EXTS:
|
|
194
|
+
ok = auto_transition_to_p1(state_file)
|
|
195
|
+
print(f"[FlowCraft] P0阶段禁止直接修改代码: {file_path}", file=sys.stderr)
|
|
196
|
+
print("", file=sys.stderr)
|
|
197
|
+
if ok:
|
|
198
|
+
print(" 已自动切换至 P1 需求阶段。", file=sys.stderr)
|
|
199
|
+
print(" → 请先完成 P1 需求澄清与 PRD 确认后再编码", file=sys.stderr)
|
|
200
|
+
return 2
|
|
201
|
+
|
|
202
|
+
# P0.5: block code modifications (problem rollback mode)
|
|
203
|
+
if current_phase == "P0.5" and ext in CODE_EXTS:
|
|
204
|
+
print(f"[FlowCraft] P0.5问题回溯阶段,禁止修改代码: {file_path}", file=sys.stderr)
|
|
205
|
+
print("", file=sys.stderr)
|
|
206
|
+
print(" 请选择:", file=sys.stderr)
|
|
207
|
+
print(" A. 优化原方案 → 运行 /P1", file=sys.stderr)
|
|
208
|
+
print(" B. 重做需求 → 运行 /P1", file=sys.stderr)
|
|
209
|
+
print(" C. 直接修复 → 需用户确认", file=sys.stderr)
|
|
210
|
+
return 2
|
|
211
|
+
|
|
212
|
+
# P1: only PRD and plan files
|
|
213
|
+
if current_phase == "P1" and ext in CODE_EXTS:
|
|
214
|
+
if re.search(r"/plan/|/\.claude/prd\.md", file_path):
|
|
215
|
+
return 0
|
|
216
|
+
print(f"[FlowCraft] P1阶段禁止修改代码文件: {file_path}", file=sys.stderr)
|
|
217
|
+
print("", file=sys.stderr)
|
|
218
|
+
print(" P1是需求设计阶段,只允许修改PRD和计划文件。", file=sys.stderr)
|
|
219
|
+
print(" → 完成P1后自动进入P2编码阶段", file=sys.stderr)
|
|
220
|
+
print(" → 或运行 /P2 强制跳转", file=sys.stderr)
|
|
221
|
+
return 2
|
|
222
|
+
|
|
223
|
+
# P5: code is frozen
|
|
224
|
+
if current_phase == "P5" and ext in CODE_EXTS:
|
|
225
|
+
print(f"[FlowCraft] P5交付阶段,代码已冻结: {file_path}", file=sys.stderr)
|
|
226
|
+
print("", file=sys.stderr)
|
|
227
|
+
print(" 代码已冻结,如需修改:", file=sys.stderr)
|
|
228
|
+
print(" → 运行 /P0.5 进入问题回溯", file=sys.stderr)
|
|
229
|
+
return 2
|
|
230
|
+
|
|
231
|
+
return 0
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
if __name__ == "__main__":
|
|
235
|
+
sys.exit(main())
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Cross-platform hook dispatcher - Mac/Linux/Windows.
|
|
3
|
+
|
|
4
|
+
Usage: dispatch.py <hook-name> [args...]
|
|
5
|
+
|
|
6
|
+
Routes to the sibling ``<hook-name>.py`` script, forwarding stdin and the
|
|
7
|
+
exit code. Extracts ``session_id`` from the hook payload and exposes it as
|
|
8
|
+
FLOWCRAFT_SESSION_ID so task_manager can resolve per-session task bindings (R2).
|
|
9
|
+
Supports both project-level (.claude/hooks/) and global (~/.flowcraft/hooks/)
|
|
10
|
+
installations.
|
|
11
|
+
"""
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def extract_session_id(raw: bytes) -> str:
|
|
21
|
+
"""Extract session_id from the hook payload without altering it.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
raw: Raw stdin bytes from the hook event.
|
|
25
|
+
Returns:
|
|
26
|
+
Session ID string, or empty when absent/unparseable.
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
text = raw.decode("utf-8", errors="replace")
|
|
30
|
+
data = json.loads(text) if text.strip() else {}
|
|
31
|
+
if isinstance(data, dict):
|
|
32
|
+
return str(data.get("session_id") or "").strip()
|
|
33
|
+
except Exception:
|
|
34
|
+
pass
|
|
35
|
+
m = re.search(rb'"session_id"\s*:\s*"([^"]+)"', raw)
|
|
36
|
+
return m.group(1).decode("utf-8", errors="replace").strip() if m else ""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main() -> int:
|
|
40
|
+
"""Route the hook event to the target script with session context.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
The target script's exit code.
|
|
44
|
+
"""
|
|
45
|
+
if len(sys.argv) < 2:
|
|
46
|
+
print("Usage: dispatch.py <hook-name>", file=sys.stderr)
|
|
47
|
+
return 1
|
|
48
|
+
hook_name = sys.argv[1]
|
|
49
|
+
script_dir = Path(__file__).resolve().parent
|
|
50
|
+
target = script_dir / (hook_name + ".py")
|
|
51
|
+
if not target.is_file():
|
|
52
|
+
print(f"dispatch.py: hook not found: {target}", file=sys.stderr)
|
|
53
|
+
return 0
|
|
54
|
+
raw = sys.stdin.buffer.read()
|
|
55
|
+
env = os.environ.copy()
|
|
56
|
+
# R2 保险2:子钩子输出固定 UTF-8(消除 Windows GBK 乱码)
|
|
57
|
+
env["PYTHONIOENCODING"] = "utf-8"
|
|
58
|
+
env["PYTHONUTF8"] = "1"
|
|
59
|
+
session_id = extract_session_id(raw)
|
|
60
|
+
if session_id:
|
|
61
|
+
env["FLOWCRAFT_SESSION_ID"] = session_id
|
|
62
|
+
proc = subprocess.run([sys.executable, str(target), *sys.argv[2:]], input=raw, env=env)
|
|
63
|
+
return proc.returncode
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
sys.exit(main())
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""fileSuggestion - @ file completion, prioritising Superpowers project files.
|
|
3
|
+
|
|
4
|
+
Receives stdin JSON: {"query": "..."}
|
|
5
|
+
Outputs: one file path per line (core files + rules + up to 10 skills).
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> int:
|
|
13
|
+
project_dir = os.environ.get("CLAUDE_PROJECT_DIR") or "."
|
|
14
|
+
root = Path(project_dir)
|
|
15
|
+
|
|
16
|
+
# Superpowers project core files (always shown first)
|
|
17
|
+
core_files = [
|
|
18
|
+
".claude/project-state.md",
|
|
19
|
+
"CLAUDE.md",
|
|
20
|
+
".claude/settings.json",
|
|
21
|
+
]
|
|
22
|
+
for f in core_files:
|
|
23
|
+
if (root / f).is_file():
|
|
24
|
+
print(f)
|
|
25
|
+
|
|
26
|
+
# Superpowers rule files
|
|
27
|
+
rules_dir = root / ".claude" / "sdlc" / "rules"
|
|
28
|
+
if rules_dir.is_dir():
|
|
29
|
+
for f in sorted(rules_dir.glob("*.md")):
|
|
30
|
+
print(f".claude/sdlc/rules/{f.name}")
|
|
31
|
+
|
|
32
|
+
# Skills files (max 10)
|
|
33
|
+
skills_dir = root / ".claude" / "skills"
|
|
34
|
+
if skills_dir.is_dir():
|
|
35
|
+
count = 0
|
|
36
|
+
for f in sorted(skills_dir.glob("*/SKILL.md")):
|
|
37
|
+
if count >= 10:
|
|
38
|
+
break
|
|
39
|
+
print(f".claude/skills/{f.parent.name}/SKILL.md")
|
|
40
|
+
count += 1
|
|
41
|
+
return 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
sys.exit(main())
|