cc-devflow 1.0.1
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/.claude/CLAUDE.md +83 -0
- package/.claude/agents/architecture-designer.md +443 -0
- package/.claude/agents/bug-analyzer.md +382 -0
- package/.claude/agents/checklist-agent.md +175 -0
- package/.claude/agents/clarify-analyst.md +50 -0
- package/.claude/agents/code-reviewer.md +71 -0
- package/.claude/agents/codex-analyzer.md +39 -0
- package/.claude/agents/compatibility-checker.md +580 -0
- package/.claude/agents/consistency-checker.md +532 -0
- package/.claude/agents/impact-analyzer.md +441 -0
- package/.claude/agents/planner.md +230 -0
- package/.claude/agents/prd-writer.md +320 -0
- package/.claude/agents/project-guidelines-generator.md +1329 -0
- package/.claude/agents/qa-tester.md +313 -0
- package/.claude/agents/release-manager.md +295 -0
- package/.claude/agents/security-reviewer.md +314 -0
- package/.claude/agents/style-guide-generator.md +458 -0
- package/.claude/agents/tech-architect.md +516 -0
- package/.claude/agents/ui-designer.md +485 -0
- package/.claude/commands/code-review-high.md +58 -0
- package/.claude/commands/core-architecture.md +429 -0
- package/.claude/commands/core-guidelines.md +486 -0
- package/.claude/commands/core-roadmap.md +439 -0
- package/.claude/commands/core-style.md +293 -0
- package/.claude/commands/flow-archive.md +245 -0
- package/.claude/commands/flow-checklist.md +260 -0
- package/.claude/commands/flow-clarify.md +136 -0
- package/.claude/commands/flow-constitution.md +82 -0
- package/.claude/commands/flow-dev.md +134 -0
- package/.claude/commands/flow-epic.md +150 -0
- package/.claude/commands/flow-fix.md +104 -0
- package/.claude/commands/flow-ideate.md +214 -0
- package/.claude/commands/flow-init.md +313 -0
- package/.claude/commands/flow-new.md +394 -0
- package/.claude/commands/flow-prd.md +131 -0
- package/.claude/commands/flow-qa.md +93 -0
- package/.claude/commands/flow-release.md +92 -0
- package/.claude/commands/flow-restart.md +98 -0
- package/.claude/commands/flow-status.md +64 -0
- package/.claude/commands/flow-tech.md +142 -0
- package/.claude/commands/flow-ui.md +189 -0
- package/.claude/commands/flow-update.md +111 -0
- package/.claude/commands/flow-upgrade.md +115 -0
- package/.claude/commands/flow-verify.md +96 -0
- package/.claude/commands/problem-analyzer.md +60 -0
- package/.claude/config/quality-rules.yml +161 -0
- package/.claude/docs/SPEC_KIT_CONSTITUTION_ANALYSIS.md +426 -0
- package/.claude/docs/design/consistency-conflict-detection-algorithms.md +658 -0
- package/.claude/docs/design/intent-driven-input-design.md +380 -0
- package/.claude/docs/design/prd-version-management-design.md +437 -0
- package/.claude/docs/guides/INIT_TROUBLESHOOTING.md +117 -0
- package/.claude/docs/guides/NEW_TROUBLESHOOTING.md +151 -0
- package/.claude/docs/guides/ROADMAP_TROUBLESHOOTING.md +188 -0
- package/.claude/docs/guides/TASK_COMPLETION_MARKING.md +338 -0
- package/.claude/docs/templates/ARCHITECTURE_TEMPLATE.md +633 -0
- package/.claude/docs/templates/BACKLOG_TEMPLATE.md +261 -0
- package/.claude/docs/templates/CHECKLIST_TEMPLATE.md +52 -0
- package/.claude/docs/templates/CLARIFICATION_REPORT_TEMPLATE.md +206 -0
- package/.claude/docs/templates/CODE_REVIEW_TEMPLATE.md +71 -0
- package/.claude/docs/templates/EPIC_TEMPLATE.md +805 -0
- package/.claude/docs/templates/INIT_FLOW_TEMPLATE.md +213 -0
- package/.claude/docs/templates/INTENT_CLARIFICATION_TEMPLATE.md +57 -0
- package/.claude/docs/templates/NEW_ORCHESTRATION_TEMPLATE.md +148 -0
- package/.claude/docs/templates/PRD_TEMPLATE.md +562 -0
- package/.claude/docs/templates/RESEARCH_TEMPLATE.md +276 -0
- package/.claude/docs/templates/REVIEW-HIGH.md +57 -0
- package/.claude/docs/templates/ROADMAP_DIALOGUE_TEMPLATE.md +198 -0
- package/.claude/docs/templates/ROADMAP_TEMPLATE.md +310 -0
- package/.claude/docs/templates/STYLE_TEMPLATE.md +1266 -0
- package/.claude/docs/templates/TASKS_TEMPLATE.md +523 -0
- package/.claude/docs/templates/TECH_DESIGN_TEMPLATE.md +1019 -0
- package/.claude/docs/templates/UI_PROTOTYPE_TEMPLATE.md +1436 -0
- package/.claude/guides/agent-guides/agent-coordination-guide.md +459 -0
- package/.claude/guides/project-guidelines-system.md +463 -0
- package/.claude/guides/technical-guides/datetime-handling-guide.md +563 -0
- package/.claude/guides/technical-guides/git-github-guide.md +642 -0
- package/.claude/guides/technical-guides/test-execution-guide.md +618 -0
- package/.claude/guides/workflow-guides/bug-fix-orchestrator.md +217 -0
- package/.claude/guides/workflow-guides/flow-orchestrator.md +282 -0
- package/.claude/hooks/checklist-gate.js +397 -0
- package/.claude/hooks/error-handling-reminder.sh +12 -0
- package/.claude/hooks/error-handling-reminder.ts +459 -0
- package/.claude/hooks/post-tool-use-tracker.sh +280 -0
- package/.claude/hooks/pre-tool-use-guardrail.sh +36 -0
- package/.claude/hooks/pre-tool-use-guardrail.ts +342 -0
- package/.claude/hooks/skill-activation-prompt.sh +36 -0
- package/.claude/hooks/skill-activation-prompt.ts +214 -0
- package/.claude/hooks/state/skills-used-test-guard.json +3 -0
- package/.claude/rules/devflow-conventions.md +305 -0
- package/.claude/rules/project-constitution.md +748 -0
- package/.claude/schemas/constitution.schema.json +43 -0
- package/.claude/scripts/analyze-upgrade-impact.sh +200 -0
- package/.claude/scripts/archive-requirement.sh +351 -0
- package/.claude/scripts/calculate-checklist-completion.sh +243 -0
- package/.claude/scripts/calculate-quarter.sh +206 -0
- package/.claude/scripts/check-dependencies.sh +409 -0
- package/.claude/scripts/check-prerequisites.sh +232 -0
- package/.claude/scripts/check-task-status.sh +264 -0
- package/.claude/scripts/checklist-errors.sh +131 -0
- package/.claude/scripts/common.sh +570 -0
- package/.claude/scripts/consolidate-research.sh +182 -0
- package/.claude/scripts/create-requirement.sh +426 -0
- package/.claude/scripts/export-contracts.sh +117 -0
- package/.claude/scripts/extract-data-model.sh +78 -0
- package/.claude/scripts/generate-clarification-questions.sh +377 -0
- package/.claude/scripts/generate-clarification-report.sh +463 -0
- package/.claude/scripts/generate-quickstart.sh +146 -0
- package/.claude/scripts/generate-research-tasks.sh +157 -0
- package/.claude/scripts/generate-status-report.sh +523 -0
- package/.claude/scripts/generate-tech-analysis.sh +46 -0
- package/.claude/scripts/locate-requirement-in-roadmap.sh +233 -0
- package/.claude/scripts/manage-constitution.sh +602 -0
- package/.claude/scripts/mark-task-complete.sh +198 -0
- package/.claude/scripts/populate-research-tasks.sh +259 -0
- package/.claude/scripts/recover-workflow.sh +460 -0
- package/.claude/scripts/run-clarify-scan.sh +601 -0
- package/.claude/scripts/run-high-review.sh +62 -0
- package/.claude/scripts/run-problem-analysis.sh +68 -0
- package/.claude/scripts/setup-epic.sh +173 -0
- package/.claude/scripts/sync-roadmap-progress.sh +300 -0
- package/.claude/scripts/sync-task-marks.sh +199 -0
- package/.claude/scripts/test-clarify-scan.sh +515 -0
- package/.claude/scripts/update-agent-context.sh +806 -0
- package/.claude/scripts/validate-constitution.sh +567 -0
- package/.claude/scripts/validate-hooks.sh +487 -0
- package/.claude/scripts/validate-research.sh +332 -0
- package/.claude/scripts/validate-scope-boundary.sh +493 -0
- package/.claude/scripts/verify-setup.sh +37 -0
- package/.claude/settings.json +76 -0
- package/.claude/skills/_reference-implementations/README.md +96 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/SKILL.md +302 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/architecture-overview.md +451 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/async-and-errors.md +307 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/complete-examples.md +638 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/configuration.md +275 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/database-patterns.md +224 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/middleware-guide.md +213 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/routing-and-controllers.md +756 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/sentry-and-monitoring.md +336 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/services-and-repositories.md +789 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/testing-guide.md +235 -0
- package/.claude/skills/_reference-implementations/backend-express-prisma/resources/validation-patterns.md +754 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/SKILL.md +399 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/common-patterns.md +331 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/complete-examples.md +872 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/component-patterns.md +502 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/data-fetching.md +767 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/file-organization.md +502 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/loading-and-error-states.md +501 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/performance.md +406 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/routing-guide.md +364 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/styling-guide.md +428 -0
- package/.claude/skills/_reference-implementations/frontend-react-mui/resources/typescript-standards.md +418 -0
- package/.claude/skills/cc-devflow-orchestrator/SKILL.md +229 -0
- package/.claude/skills/constitution-guardian/SKILL.md +306 -0
- package/.claude/skills/devflow-constitution-quick-ref/SKILL.md +374 -0
- package/.claude/skills/devflow-file-standards/SKILL.md +353 -0
- package/.claude/skills/devflow-tdd-enforcer/SKILL.md +192 -0
- package/.claude/skills/skill-developer/ADVANCED.md +197 -0
- package/.claude/skills/skill-developer/HOOK_MECHANISMS.md +306 -0
- package/.claude/skills/skill-developer/PATTERNS_LIBRARY.md +152 -0
- package/.claude/skills/skill-developer/SKILL.md +426 -0
- package/.claude/skills/skill-developer/SKILL_RULES_REFERENCE.md +315 -0
- package/.claude/skills/skill-developer/TRIGGER_TYPES.md +305 -0
- package/.claude/skills/skill-developer/TROUBLESHOOTING.md +514 -0
- package/.claude/skills/skill-rules.json +213 -0
- package/.claude/tests/README.md +300 -0
- package/.claude/tests/TODO.md +69 -0
- package/.claude/tests/__pycache__/test_analyze_upgrade_impact.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/__pycache__/test_consolidate_research.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/__pycache__/test_export_contracts.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/__pycache__/test_extract_data_model.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/__pycache__/test_generate_quickstart.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/__pycache__/test_generate_research_tasks.cpython-311-pytest-7.2.2.pyc +0 -0
- package/.claude/tests/constitution/run_all_constitution_tests.sh +111 -0
- package/.claude/tests/constitution/test_agent_assignment.sh +207 -0
- package/.claude/tests/constitution/test_article_coverage.sh +201 -0
- package/.claude/tests/constitution/test_template_completeness.sh +150 -0
- package/.claude/tests/constitution/test_version_consistency.sh +120 -0
- package/.claude/tests/fixtures/spec_delta_full.md +16 -0
- package/.claude/tests/fixtures/tasks_progress_sample.md +5 -0
- package/.claude/tests/run-all-tests.sh +229 -0
- package/.claude/tests/scripts/run.sh +30 -0
- package/.claude/tests/scripts/test-framework.sh +128 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh +511 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh.bak +504 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh.bak2 +505 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh.bak3 +506 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh.bak4 +507 -0
- package/.claude/tests/scripts/test_check_prerequisites.sh.bak5 +508 -0
- package/.claude/tests/scripts/test_check_task_status.sh +499 -0
- package/.claude/tests/scripts/test_common.sh +244 -0
- package/.claude/tests/scripts/test_generate_status_report.sh +71 -0
- package/.claude/tests/scripts/test_mark_task_complete.sh +441 -0
- package/.claude/tests/scripts/test_mark_task_complete.sh.backup +410 -0
- package/.claude/tests/scripts/test_recover_workflow.sh +304 -0
- package/.claude/tests/scripts/test_setup_epic.sh +437 -0
- package/.claude/tests/scripts/test_sync_task_marks.sh +196 -0
- package/.claude/tests/scripts/test_validate_constitution.sh +74 -0
- package/.claude/tests/scripts/test_validate_research.sh +462 -0
- package/.claude/tests/slugify.bats +82 -0
- package/.claude/tests/test-framework.sh +732 -0
- package/.claude/tests/test_analyze_upgrade_impact.py +34 -0
- package/.claude/tests/test_consolidate_research.py +48 -0
- package/.claude/tests/test_export_contracts.py +43 -0
- package/.claude/tests/test_extract_data_model.py +33 -0
- package/.claude/tests/test_generate_quickstart.py +50 -0
- package/.claude/tests/test_generate_research_tasks.py +52 -0
- package/.claude/tsc-cache/6e64f818-6398-49ca-8623-581a9af85c44/edited-files.log +1 -0
- package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/affected-repos.txt +1 -0
- package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/edited-files.log +1 -0
- package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/affected-repos.txt +1 -0
- package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/edited-files.log +1 -0
- package/CHANGELOG.md +507 -0
- package/LICENSE +21 -0
- package/README.md +534 -0
- package/README.zh-CN.md +530 -0
- package/bin/adapt.js +240 -0
- package/bin/cc-devflow-cli.js +185 -0
- package/bin/cc-devflow.js +78 -0
- package/config/adapters.yml +5 -0
- package/config/schema/adapters.schema.json +44 -0
- package/docs/CLAUDE.md +26 -0
- package/docs/commands/README.md +61 -0
- package/docs/commands/README.zh-CN.md +55 -0
- package/docs/commands/core-roadmap.md +106 -0
- package/docs/commands/core-roadmap.zh-CN.md +102 -0
- package/docs/commands/core-style.md +405 -0
- package/docs/commands/core-style.zh-CN.md +405 -0
- package/docs/commands/flow-init.md +134 -0
- package/docs/commands/flow-init.zh-CN.md +163 -0
- package/docs/commands/flow-new.md +274 -0
- package/docs/commands/flow-new.zh-CN.md +270 -0
- package/docs/guides/getting-started.md +204 -0
- package/docs/guides/getting-started.zh-CN.md +152 -0
- package/lib/adapters/adapter-interface.js +57 -0
- package/lib/adapters/claude-adapter.js +74 -0
- package/lib/adapters/codex-adapter.js +40 -0
- package/lib/adapters/config-validator.js +68 -0
- package/lib/adapters/logger.js +42 -0
- package/lib/adapters/registry.js +153 -0
- package/lib/compiler/CLAUDE.md +92 -0
- package/lib/compiler/__tests__/drift.test.js +215 -0
- package/lib/compiler/__tests__/errors.test.js +184 -0
- package/lib/compiler/__tests__/incremental.test.js +174 -0
- package/lib/compiler/__tests__/integration.test.js +174 -0
- package/lib/compiler/__tests__/manifest.test.js +233 -0
- package/lib/compiler/__tests__/parser.test.js +456 -0
- package/lib/compiler/__tests__/schemas.test.js +301 -0
- package/lib/compiler/__tests__/skills-registry.test.js +125 -0
- package/lib/compiler/__tests__/transformer.test.js +286 -0
- package/lib/compiler/emitters/antigravity-emitter.js +171 -0
- package/lib/compiler/emitters/base-emitter.js +73 -0
- package/lib/compiler/emitters/codex-emitter.js +52 -0
- package/lib/compiler/emitters/cursor-emitter.js +31 -0
- package/lib/compiler/emitters/index.js +50 -0
- package/lib/compiler/emitters/qwen-emitter.js +39 -0
- package/lib/compiler/errors.js +119 -0
- package/lib/compiler/index.js +256 -0
- package/lib/compiler/manifest.js +242 -0
- package/lib/compiler/parser.js +258 -0
- package/lib/compiler/platforms.js +113 -0
- package/lib/compiler/resource-copier.js +320 -0
- package/lib/compiler/rules-emitters/__tests__/antigravity-rules-emitter.test.js +191 -0
- package/lib/compiler/rules-emitters/__tests__/codex-rules-emitter.test.js +109 -0
- package/lib/compiler/rules-emitters/__tests__/cursor-rules-emitter.test.js +123 -0
- package/lib/compiler/rules-emitters/__tests__/qwen-rules-emitter.test.js +123 -0
- package/lib/compiler/rules-emitters/antigravity-rules-emitter.js +253 -0
- package/lib/compiler/rules-emitters/base-rules-emitter.js +83 -0
- package/lib/compiler/rules-emitters/codex-rules-emitter.js +116 -0
- package/lib/compiler/rules-emitters/cursor-rules-emitter.js +98 -0
- package/lib/compiler/rules-emitters/index.js +71 -0
- package/lib/compiler/rules-emitters/qwen-rules-emitter.js +70 -0
- package/lib/compiler/schemas.js +144 -0
- package/lib/compiler/skills-registry.js +225 -0
- package/lib/compiler/transformer.js +236 -0
- package/package.json +50 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
4
|
+
# CC-DevFlow Hooks 健康检查脚本
|
|
5
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
6
|
+
#
|
|
7
|
+
# 【核心功能】
|
|
8
|
+
# 1. 检查 hooks 文件的执行权限
|
|
9
|
+
# 2. 验证数据文件格式的正确性
|
|
10
|
+
# 3. 检查依赖组件的存在性
|
|
11
|
+
# 4. 清理过期的 session 数据
|
|
12
|
+
#
|
|
13
|
+
# 【使用方式】
|
|
14
|
+
# ./validate-hooks.sh # 完整健康检查
|
|
15
|
+
# ./validate-hooks.sh --check-all # 同上
|
|
16
|
+
# ./validate-hooks.sh --session <id> # 检查特定 session
|
|
17
|
+
# ./validate-hooks.sh --cleanup # 清理过期数据
|
|
18
|
+
# ./validate-hooks.sh --fix # 自动修复权限问题
|
|
19
|
+
#
|
|
20
|
+
# 【设计哲学】
|
|
21
|
+
# "检查要严格,修复要保守"
|
|
22
|
+
# 发现所有问题,但只自动修复确定安全的问题(如权限)
|
|
23
|
+
#
|
|
24
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
25
|
+
|
|
26
|
+
set -e
|
|
27
|
+
|
|
28
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
# 颜色定义(用于输出美化)
|
|
30
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
RED='\033[0;31m'
|
|
32
|
+
GREEN='\033[0;32m'
|
|
33
|
+
YELLOW='\033[1;33m'
|
|
34
|
+
BLUE='\033[0;34m'
|
|
35
|
+
NC='\033[0m' # No Color
|
|
36
|
+
|
|
37
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
38
|
+
# 工具函数:输出格式化消息
|
|
39
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
log_success() {
|
|
42
|
+
echo -e "${GREEN}✅ $1${NC}"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
log_warning() {
|
|
46
|
+
echo -e "${YELLOW}⚠️ $1${NC}"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
log_error() {
|
|
50
|
+
echo -e "${RED}❌ $1${NC}"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
log_info() {
|
|
54
|
+
echo -e "${BLUE}ℹ️ $1${NC}"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
log_section() {
|
|
58
|
+
echo ""
|
|
59
|
+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
60
|
+
echo -e "${BLUE}$1${NC}"
|
|
61
|
+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
65
|
+
# 全局变量
|
|
66
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
67
|
+
PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
|
68
|
+
HOOKS_DIR="$PROJECT_ROOT/.claude/hooks"
|
|
69
|
+
SKILLS_DIR="$PROJECT_ROOT/.claude/skills"
|
|
70
|
+
TSC_CACHE_DIR="$PROJECT_ROOT/.claude/tsc-cache"
|
|
71
|
+
HOOKS_STATE_DIR="$HOOKS_DIR/state"
|
|
72
|
+
|
|
73
|
+
ERROR_COUNT=0
|
|
74
|
+
WARNING_COUNT=0
|
|
75
|
+
|
|
76
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
77
|
+
# 检查 1: Hooks 文件执行权限
|
|
78
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
79
|
+
check_hook_permissions() {
|
|
80
|
+
log_section "📋 检查 Hooks 执行权限"
|
|
81
|
+
|
|
82
|
+
local hooks=(
|
|
83
|
+
"pre-tool-use-guardrail.ts"
|
|
84
|
+
"post-tool-use-tracker.sh"
|
|
85
|
+
"error-handling-reminder.ts"
|
|
86
|
+
"skill-activation-prompt.ts"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
for hook in "${hooks[@]}"; do
|
|
90
|
+
local hook_path="$HOOKS_DIR/$hook"
|
|
91
|
+
|
|
92
|
+
if [[ ! -f "$hook_path" ]]; then
|
|
93
|
+
log_error "Hook 文件不存在: $hook"
|
|
94
|
+
((ERROR_COUNT++))
|
|
95
|
+
continue
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
if [[ -x "$hook_path" ]]; then
|
|
99
|
+
log_success "$hook 有执行权限"
|
|
100
|
+
else
|
|
101
|
+
log_error "$hook 缺少执行权限"
|
|
102
|
+
((ERROR_COUNT++))
|
|
103
|
+
|
|
104
|
+
if [[ "$FIX_MODE" == "true" ]]; then
|
|
105
|
+
chmod +x "$hook_path"
|
|
106
|
+
log_success "已自动修复: $hook"
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
109
|
+
done
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
113
|
+
# 检查 2: Hooks 配置(settings.json)
|
|
114
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
115
|
+
check_hooks_config() {
|
|
116
|
+
log_section "⚙️ 检查 Hooks 配置"
|
|
117
|
+
|
|
118
|
+
local settings_file="$PROJECT_ROOT/.claude/settings.json"
|
|
119
|
+
|
|
120
|
+
if [[ ! -f "$settings_file" ]]; then
|
|
121
|
+
log_error "settings.json 不存在"
|
|
122
|
+
((ERROR_COUNT++))
|
|
123
|
+
return
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
# 检查 JSON 格式
|
|
127
|
+
if ! jq empty "$settings_file" 2>/dev/null; then
|
|
128
|
+
log_error "settings.json 格式无效(不是有效的 JSON)"
|
|
129
|
+
((ERROR_COUNT++))
|
|
130
|
+
return
|
|
131
|
+
fi
|
|
132
|
+
|
|
133
|
+
log_success "settings.json 格式正确"
|
|
134
|
+
|
|
135
|
+
# 检查是否有 hooks 配置
|
|
136
|
+
if jq -e '.hooks' "$settings_file" > /dev/null 2>&1; then
|
|
137
|
+
log_success "hooks 配置存在"
|
|
138
|
+
|
|
139
|
+
# 检查各个事件类型
|
|
140
|
+
local events=("UserPromptSubmit" "PreToolUse" "PostToolUse" "Stop")
|
|
141
|
+
for event in "${events[@]}"; do
|
|
142
|
+
if jq -e ".hooks[\"$event\"]" "$settings_file" > /dev/null 2>&1; then
|
|
143
|
+
local hook_count=$(jq ".hooks[\"$event\"] | length" "$settings_file")
|
|
144
|
+
log_success "$event: $hook_count 个 hook(s) 已配置"
|
|
145
|
+
else
|
|
146
|
+
log_info "$event: 未配置(可选)"
|
|
147
|
+
fi
|
|
148
|
+
done
|
|
149
|
+
else
|
|
150
|
+
log_error "settings.json 缺少 hooks 配置"
|
|
151
|
+
log_info "Hooks 必须在 settings.json 中显式配置才能自动触发"
|
|
152
|
+
log_info "参考: .claude/hooks/HOOKS_CONFIGURATION_GUIDE.md"
|
|
153
|
+
((ERROR_COUNT++))
|
|
154
|
+
fi
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
158
|
+
# 检查 3: Skill Rules 配置
|
|
159
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
160
|
+
check_skill_rules() {
|
|
161
|
+
log_section "📚 检查 Skill Rules 配置"
|
|
162
|
+
|
|
163
|
+
local rules_file="$SKILLS_DIR/skill-rules.json"
|
|
164
|
+
|
|
165
|
+
if [[ ! -f "$rules_file" ]]; then
|
|
166
|
+
log_error "skill-rules.json 不存在"
|
|
167
|
+
((ERROR_COUNT++))
|
|
168
|
+
return
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
# 检查 JSON 格式是否有效
|
|
172
|
+
if ! jq empty "$rules_file" 2>/dev/null; then
|
|
173
|
+
log_error "skill-rules.json 格式无效(不是有效的 JSON)"
|
|
174
|
+
((ERROR_COUNT++))
|
|
175
|
+
return
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
log_success "skill-rules.json 格式正确"
|
|
179
|
+
|
|
180
|
+
# 检查必需的 skills
|
|
181
|
+
local required_skills=("devflow-tdd-enforcer" "constitution-guardian" "cc-devflow-orchestrator")
|
|
182
|
+
|
|
183
|
+
for skill in "${required_skills[@]}"; do
|
|
184
|
+
if jq -e ".skills[\"$skill\"]" "$rules_file" > /dev/null 2>&1; then
|
|
185
|
+
log_success "Skill '$skill' 已配置"
|
|
186
|
+
else
|
|
187
|
+
log_warning "Skill '$skill' 未在 skill-rules.json 中找到"
|
|
188
|
+
((WARNING_COUNT++))
|
|
189
|
+
fi
|
|
190
|
+
done
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
194
|
+
# 检查 3: 数据文件格式
|
|
195
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
196
|
+
check_data_files() {
|
|
197
|
+
log_section "📂 检查数据文件格式"
|
|
198
|
+
|
|
199
|
+
if [[ ! -d "$TSC_CACHE_DIR" ]]; then
|
|
200
|
+
log_info "TSC cache 目录不存在(正常,首次运行时会创建)"
|
|
201
|
+
return
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
local session_count=0
|
|
205
|
+
local invalid_count=0
|
|
206
|
+
|
|
207
|
+
# 遍历所有 session 目录
|
|
208
|
+
for session_dir in "$TSC_CACHE_DIR"/*; do
|
|
209
|
+
if [[ ! -d "$session_dir" ]]; then
|
|
210
|
+
continue
|
|
211
|
+
fi
|
|
212
|
+
|
|
213
|
+
((session_count++))
|
|
214
|
+
local session_id=$(basename "$session_dir")
|
|
215
|
+
|
|
216
|
+
# 检查 edited-files.log
|
|
217
|
+
local log_file="$session_dir/edited-files.log"
|
|
218
|
+
if [[ -f "$log_file" ]]; then
|
|
219
|
+
# 验证格式:每行应该有 4 个 tab 分隔的字段
|
|
220
|
+
while IFS= read -r line; do
|
|
221
|
+
local field_count=$(echo "$line" | awk -F'\t' '{print NF}')
|
|
222
|
+
if [[ $field_count -ne 4 ]]; then
|
|
223
|
+
log_warning "Session $session_id: edited-files.log 格式错误(期望 4 个字段,实际 $field_count)"
|
|
224
|
+
log_info " 行内容: $line"
|
|
225
|
+
((invalid_count++))
|
|
226
|
+
break
|
|
227
|
+
fi
|
|
228
|
+
done < "$log_file"
|
|
229
|
+
fi
|
|
230
|
+
done
|
|
231
|
+
|
|
232
|
+
if [[ $session_count -eq 0 ]]; then
|
|
233
|
+
log_info "未找到任何 session 数据"
|
|
234
|
+
elif [[ $invalid_count -eq 0 ]]; then
|
|
235
|
+
log_success "检查了 $session_count 个 session,数据格式全部正确"
|
|
236
|
+
else
|
|
237
|
+
log_error "发现 $invalid_count 个格式错误"
|
|
238
|
+
((ERROR_COUNT += invalid_count))
|
|
239
|
+
fi
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
# 检查 4: Session 状态文件
|
|
244
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
245
|
+
check_session_state() {
|
|
246
|
+
log_section "🔐 检查 Session 状态文件"
|
|
247
|
+
|
|
248
|
+
if [[ ! -d "$HOOKS_STATE_DIR" ]]; then
|
|
249
|
+
log_info "Hooks state 目录不存在,将在首次触发时创建"
|
|
250
|
+
return
|
|
251
|
+
fi
|
|
252
|
+
|
|
253
|
+
local state_count=0
|
|
254
|
+
local invalid_count=0
|
|
255
|
+
|
|
256
|
+
for state_file in "$HOOKS_STATE_DIR"/skills-used-*.json; do
|
|
257
|
+
if [[ ! -f "$state_file" ]]; then
|
|
258
|
+
continue
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
((state_count++))
|
|
262
|
+
local filename=$(basename "$state_file")
|
|
263
|
+
|
|
264
|
+
# 检查 JSON 格式
|
|
265
|
+
if ! jq empty "$state_file" 2>/dev/null; then
|
|
266
|
+
log_error "$filename 格式无效(不是有效的 JSON)"
|
|
267
|
+
((invalid_count++))
|
|
268
|
+
((ERROR_COUNT++))
|
|
269
|
+
continue
|
|
270
|
+
fi
|
|
271
|
+
|
|
272
|
+
# 检查是否是字符串数组
|
|
273
|
+
if ! jq -e 'type == "array"' "$state_file" > /dev/null 2>&1; then
|
|
274
|
+
log_error "$filename 格式错误(应该是数组)"
|
|
275
|
+
((invalid_count++))
|
|
276
|
+
((ERROR_COUNT++))
|
|
277
|
+
continue
|
|
278
|
+
fi
|
|
279
|
+
|
|
280
|
+
log_success "$filename 格式正确"
|
|
281
|
+
done
|
|
282
|
+
|
|
283
|
+
if [[ $state_count -eq 0 ]]; then
|
|
284
|
+
log_info "未找到任何 session 状态文件"
|
|
285
|
+
elif [[ $invalid_count -eq 0 ]]; then
|
|
286
|
+
log_success "检查了 $state_count 个状态文件,格式全部正确"
|
|
287
|
+
fi
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
291
|
+
# 功能:清理过期 session 数据
|
|
292
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
293
|
+
cleanup_sessions() {
|
|
294
|
+
log_section "🧹 清理过期 Session 数据"
|
|
295
|
+
|
|
296
|
+
local cutoff_days=${1:-7} # 默认清理 7 天前的数据
|
|
297
|
+
local cutoff_seconds=$((cutoff_days * 86400))
|
|
298
|
+
local now=$(date +%s)
|
|
299
|
+
local deleted_count=0
|
|
300
|
+
|
|
301
|
+
# 清理 tsc-cache
|
|
302
|
+
if [[ -d "$TSC_CACHE_DIR" ]]; then
|
|
303
|
+
for session_dir in "$TSC_CACHE_DIR"/*; do
|
|
304
|
+
if [[ ! -d "$session_dir" ]]; then
|
|
305
|
+
continue
|
|
306
|
+
fi
|
|
307
|
+
|
|
308
|
+
local mtime=$(stat -f %m "$session_dir" 2>/dev/null || stat -c %Y "$session_dir" 2>/dev/null)
|
|
309
|
+
local age=$((now - mtime))
|
|
310
|
+
|
|
311
|
+
if [[ $age -gt $cutoff_seconds ]]; then
|
|
312
|
+
local session_id=$(basename "$session_dir")
|
|
313
|
+
log_info "删除过期 session: $session_id (${age}秒前)"
|
|
314
|
+
rm -rf "$session_dir"
|
|
315
|
+
((deleted_count++))
|
|
316
|
+
fi
|
|
317
|
+
done
|
|
318
|
+
fi
|
|
319
|
+
|
|
320
|
+
# 清理 hooks state
|
|
321
|
+
if [[ -d "$HOOKS_STATE_DIR" ]]; then
|
|
322
|
+
for state_file in "$HOOKS_STATE_DIR"/skills-used-*.json; do
|
|
323
|
+
if [[ ! -f "$state_file" ]]; then
|
|
324
|
+
continue
|
|
325
|
+
fi
|
|
326
|
+
|
|
327
|
+
local mtime=$(stat -f %m "$state_file" 2>/dev/null || stat -c %Y "$state_file" 2>/dev/null)
|
|
328
|
+
local age=$((now - mtime))
|
|
329
|
+
|
|
330
|
+
if [[ $age -gt $cutoff_seconds ]]; then
|
|
331
|
+
local filename=$(basename "$state_file")
|
|
332
|
+
log_info "删除过期状态: $filename (${age}秒前)"
|
|
333
|
+
rm -f "$state_file"
|
|
334
|
+
((deleted_count++))
|
|
335
|
+
fi
|
|
336
|
+
done
|
|
337
|
+
fi
|
|
338
|
+
|
|
339
|
+
if [[ $deleted_count -eq 0 ]]; then
|
|
340
|
+
log_success "无需清理(所有数据都在 $cutoff_days 天内)"
|
|
341
|
+
else
|
|
342
|
+
log_success "已清理 $deleted_count 个过期文件/目录"
|
|
343
|
+
fi
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
347
|
+
# 功能:检查特定 session
|
|
348
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
349
|
+
check_specific_session() {
|
|
350
|
+
local session_id="$1"
|
|
351
|
+
|
|
352
|
+
log_section "🔍 检查 Session: $session_id"
|
|
353
|
+
|
|
354
|
+
local session_dir="$TSC_CACHE_DIR/$session_id"
|
|
355
|
+
|
|
356
|
+
if [[ ! -d "$session_dir" ]]; then
|
|
357
|
+
log_error "Session 目录不存在: $session_id"
|
|
358
|
+
return 1
|
|
359
|
+
fi
|
|
360
|
+
|
|
361
|
+
# 检查 edited-files.log
|
|
362
|
+
if [[ -f "$session_dir/edited-files.log" ]]; then
|
|
363
|
+
local line_count=$(wc -l < "$session_dir/edited-files.log")
|
|
364
|
+
log_success "edited-files.log: $line_count 条记录"
|
|
365
|
+
else
|
|
366
|
+
log_warning "edited-files.log 不存在"
|
|
367
|
+
fi
|
|
368
|
+
|
|
369
|
+
# 检查 affected-repos.txt
|
|
370
|
+
if [[ -f "$session_dir/affected-repos.txt" ]]; then
|
|
371
|
+
local repo_count=$(wc -l < "$session_dir/affected-repos.txt")
|
|
372
|
+
log_success "affected-repos.txt: $repo_count 个仓库"
|
|
373
|
+
echo " 受影响的仓库:"
|
|
374
|
+
while IFS= read -r repo; do
|
|
375
|
+
echo " - $repo"
|
|
376
|
+
done < "$session_dir/affected-repos.txt"
|
|
377
|
+
else
|
|
378
|
+
log_warning "affected-repos.txt 不存在"
|
|
379
|
+
fi
|
|
380
|
+
|
|
381
|
+
# 检查 session 状态
|
|
382
|
+
local state_file="$HOOKS_STATE_DIR/skills-used-$session_id.json"
|
|
383
|
+
if [[ -f "$state_file" ]]; then
|
|
384
|
+
local skills=$(jq -r '.[]' "$state_file" | paste -sd ',' -)
|
|
385
|
+
log_success "已触发的 skills: $skills"
|
|
386
|
+
else
|
|
387
|
+
log_info "无 skill 状态记录"
|
|
388
|
+
fi
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
392
|
+
# 主函数
|
|
393
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
394
|
+
main() {
|
|
395
|
+
echo ""
|
|
396
|
+
echo "╔════════════════════════════════════════════════════════════╗"
|
|
397
|
+
echo "║ CC-DevFlow Hooks 健康检查工具 ║"
|
|
398
|
+
echo "╚════════════════════════════════════════════════════════════╝"
|
|
399
|
+
echo ""
|
|
400
|
+
|
|
401
|
+
# 解析参数
|
|
402
|
+
local mode="check-all"
|
|
403
|
+
local session_id=""
|
|
404
|
+
FIX_MODE="false"
|
|
405
|
+
|
|
406
|
+
while [[ $# -gt 0 ]]; do
|
|
407
|
+
case $1 in
|
|
408
|
+
--check-all)
|
|
409
|
+
mode="check-all"
|
|
410
|
+
shift
|
|
411
|
+
;;
|
|
412
|
+
--session)
|
|
413
|
+
mode="check-session"
|
|
414
|
+
session_id="$2"
|
|
415
|
+
shift 2
|
|
416
|
+
;;
|
|
417
|
+
--cleanup)
|
|
418
|
+
mode="cleanup"
|
|
419
|
+
shift
|
|
420
|
+
;;
|
|
421
|
+
--fix)
|
|
422
|
+
FIX_MODE="true"
|
|
423
|
+
shift
|
|
424
|
+
;;
|
|
425
|
+
--help)
|
|
426
|
+
echo "使用方式:"
|
|
427
|
+
echo " $0 完整健康检查"
|
|
428
|
+
echo " $0 --check-all 同上"
|
|
429
|
+
echo " $0 --session <id> 检查特定 session"
|
|
430
|
+
echo " $0 --cleanup 清理过期数据(默认 7 天)"
|
|
431
|
+
echo " $0 --fix 自动修复权限问题"
|
|
432
|
+
exit 0
|
|
433
|
+
;;
|
|
434
|
+
*)
|
|
435
|
+
log_error "未知参数: $1"
|
|
436
|
+
exit 1
|
|
437
|
+
;;
|
|
438
|
+
esac
|
|
439
|
+
done
|
|
440
|
+
|
|
441
|
+
# 执行对应模式
|
|
442
|
+
case $mode in
|
|
443
|
+
check-all)
|
|
444
|
+
check_hook_permissions
|
|
445
|
+
check_hooks_config
|
|
446
|
+
check_skill_rules
|
|
447
|
+
check_data_files
|
|
448
|
+
check_session_state
|
|
449
|
+
;;
|
|
450
|
+
check-session)
|
|
451
|
+
if [[ -z "$session_id" ]]; then
|
|
452
|
+
log_error "请提供 session ID: --session <id>"
|
|
453
|
+
exit 1
|
|
454
|
+
fi
|
|
455
|
+
check_specific_session "$session_id"
|
|
456
|
+
;;
|
|
457
|
+
cleanup)
|
|
458
|
+
cleanup_sessions 7
|
|
459
|
+
;;
|
|
460
|
+
esac
|
|
461
|
+
|
|
462
|
+
# 总结
|
|
463
|
+
echo ""
|
|
464
|
+
log_section "📊 检查总结"
|
|
465
|
+
|
|
466
|
+
if [[ $ERROR_COUNT -eq 0 ]] && [[ $WARNING_COUNT -eq 0 ]]; then
|
|
467
|
+
log_success "所有检查通过!Hooks 系统运行正常。"
|
|
468
|
+
exit 0
|
|
469
|
+
elif [[ $ERROR_COUNT -eq 0 ]]; then
|
|
470
|
+
log_warning "发现 $WARNING_COUNT 个警告"
|
|
471
|
+
echo ""
|
|
472
|
+
log_info "警告不会影响系统运行,但建议关注"
|
|
473
|
+
exit 0
|
|
474
|
+
else
|
|
475
|
+
log_error "发现 $ERROR_COUNT 个错误,$WARNING_COUNT 个警告"
|
|
476
|
+
echo ""
|
|
477
|
+
if [[ "$FIX_MODE" != "true" ]]; then
|
|
478
|
+
log_info "提示: 使用 --fix 参数自动修复权限问题"
|
|
479
|
+
fi
|
|
480
|
+
exit 1
|
|
481
|
+
fi
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
485
|
+
# 入口
|
|
486
|
+
# ───────────────────────────────────────────────────────────────────────────────
|
|
487
|
+
main "$@"
|