cc-devflow 2.4.6 → 4.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/.claude/CLAUDE.md +1065 -48
- package/.claude/agents/dev-implementer.md +195 -0
- package/.claude/commands/{flow-archive.md → flow/archive.md} +46 -11
- package/.claude/commands/flow/context.md +150 -0
- package/.claude/commands/flow/delta.md +245 -0
- package/.claude/commands/{flow-dev.md → flow/dev.md} +112 -11
- package/.claude/commands/flow/init.md +45 -0
- package/.claude/commands/flow/quality.md +159 -0
- package/.claude/commands/flow/spec.md +186 -0
- package/.claude/commands/flow/workspace.md +146 -0
- package/.claude/commands/{cancel-ralph.md → util/cancel-ralph.md} +1 -0
- package/.claude/config/quality-gates.yml +305 -0
- package/.claude/docs/guides/TEAM_MODE_GUIDE.md +313 -0
- package/.claude/docs/templates/DELTA_SPEC_TEMPLATE.md +91 -0
- package/.claude/docs/templates/DESIGN_DECISIONS_TEMPLATE.md +151 -0
- package/.claude/docs/templates/JOURNAL_TEMPLATE.md +75 -0
- package/.claude/docs/templates/_shared/CLAUDE.md +36 -0
- package/.claude/docs/templates/_shared/CONSTITUTION_CHECK.md +125 -0
- package/.claude/docs/templates/_shared/VALIDATION_CHECKLIST.md +187 -0
- package/.claude/docs/templates/_shared/YAML_FRONTMATTER.md +164 -0
- package/.claude/docs/templates/context/dev.jsonl.template +6 -0
- package/.claude/docs/templates/context/epic.jsonl.template +5 -0
- package/.claude/docs/templates/context/prd.jsonl.template +4 -0
- package/.claude/docs/templates/context/research.jsonl.template +4 -0
- package/.claude/docs/templates/context/review.jsonl.template +5 -0
- package/.claude/docs/templates/context/tech.jsonl.template +5 -0
- package/.claude/hooks/CLAUDE.md +342 -0
- package/.claude/hooks/inject-agent-context.ts +480 -0
- package/.claude/hooks/inject-skill-context.ts +359 -0
- package/.claude/hooks/ralph-loop.ts +931 -0
- package/.claude/hooks/task-completed-hook.ts +593 -0
- package/.claude/hooks/teammate-idle-hook.ts +690 -0
- package/.claude/hooks/types/team-types.d.ts +238 -0
- package/.claude/rules/devflow-conventions.md +82 -9
- package/.claude/scripts/archive-requirement.sh +44 -1
- package/.claude/scripts/common.sh +670 -3
- package/.claude/scripts/delta-parser.ts +527 -0
- package/.claude/scripts/detect-file-conflicts.sh +151 -0
- package/.claude/scripts/flow-context-add.sh +134 -0
- package/.claude/scripts/flow-context-init.sh +133 -0
- package/.claude/scripts/flow-context-validate.sh +144 -0
- package/.claude/scripts/flow-delta-apply.sh +297 -0
- package/.claude/scripts/flow-delta-archive.sh +71 -0
- package/.claude/scripts/flow-delta-create.sh +202 -0
- package/.claude/scripts/flow-delta-list.sh +142 -0
- package/.claude/scripts/flow-delta-status.sh +235 -0
- package/.claude/scripts/flow-quality-full.sh +184 -0
- package/.claude/scripts/flow-quality-quick.sh +64 -0
- package/.claude/scripts/flow-workspace-init.sh +117 -0
- package/.claude/scripts/flow-workspace-record.sh +164 -0
- package/.claude/scripts/flow-workspace-start.sh +88 -0
- package/.claude/scripts/get-workflow-status.sh +415 -0
- package/.claude/scripts/parse-task-dependencies.js +334 -0
- package/.claude/scripts/record-quality-error.sh +165 -0
- package/.claude/scripts/run-quality-gates.sh +242 -0
- package/.claude/scripts/team-dev-init.sh +319 -0
- package/.claude/scripts/team-state-recovery.sh +229 -0
- package/.claude/scripts/workflow-status.ts +433 -0
- package/.claude/settings.json +19 -0
- package/.claude/skills/cc-devflow-orchestrator/SKILL.md +85 -200
- package/.claude/skills/domain/using-git-worktrees/SKILL.md +252 -0
- package/.claude/skills/domain/using-git-worktrees/assets/SHELL_ALIASES.md +133 -0
- package/.claude/skills/domain/using-git-worktrees/context.jsonl +4 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-cleanup.sh +218 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-create.sh +232 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-list.sh +130 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-status.sh +140 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-switch.sh +70 -0
- package/.claude/skills/skill-rules.json +72 -1
- package/.claude/skills/utility/journey-checker/SKILL.md +199 -0
- package/.claude/skills/utility/journey-checker/pressure-scenarios.md +164 -0
- package/.claude/skills/utility/skill-creator/LICENSE.txt +202 -0
- package/.claude/skills/utility/skill-creator/SKILL.md +356 -0
- package/.claude/skills/utility/skill-creator/references/output-patterns.md +82 -0
- package/.claude/skills/utility/skill-creator/references/workflows.md +28 -0
- package/.claude/skills/utility/skill-creator/scripts/init_skill.py +303 -0
- package/.claude/skills/utility/skill-creator/scripts/package_skill.py +110 -0
- package/.claude/skills/utility/skill-creator/scripts/quick_validate.py +95 -0
- package/.claude/skills/workflow/flow-dev/CLAUDE.md +78 -0
- package/.claude/skills/workflow/flow-dev/SKILL.md +96 -0
- package/.claude/skills/workflow/flow-dev/assets/IMPLEMENTATION_PLAN_TEMPLATE.md +71 -0
- package/.claude/skills/workflow/flow-dev/context.jsonl +8 -0
- package/.claude/skills/workflow/flow-dev/dev-implementer.jsonl +8 -0
- package/.claude/skills/workflow/flow-dev/scripts/entry-gate.sh +116 -0
- package/.claude/skills/workflow/flow-dev/scripts/exit-gate.sh +101 -0
- package/.claude/skills/workflow/flow-dev/scripts/task-orchestrator.sh +106 -0
- package/.claude/skills/workflow/flow-fix/SKILL.md +105 -0
- package/.claude/skills/workflow/flow-fix/context.jsonl +6 -0
- package/.claude/skills/workflow/flow-fix/references/bug-analyzer.md +381 -0
- package/.claude/skills/workflow/flow-init/SKILL.md +211 -0
- package/.claude/skills/workflow/flow-init/assets/BRAINSTORM_TEMPLATE.md +148 -0
- package/.claude/skills/workflow/flow-init/assets/INIT_FLOW_TEMPLATE.md +198 -0
- package/.claude/skills/workflow/flow-init/assets/RESEARCH_TEMPLATE.md +276 -0
- package/.claude/skills/workflow/flow-init/context.jsonl +5 -0
- package/.claude/skills/workflow/flow-init/references/flow-researcher.md +132 -0
- package/.claude/skills/workflow/flow-init/scripts/check-prerequisites.sh +232 -0
- package/.claude/skills/workflow/flow-init/scripts/consolidate-research.sh +182 -0
- package/.claude/skills/workflow/flow-init/scripts/create-requirement.sh +515 -0
- package/.claude/skills/workflow/flow-init/scripts/generate-research-tasks.sh +157 -0
- package/.claude/skills/workflow/flow-init/scripts/populate-research-tasks.sh +284 -0
- package/.claude/skills/workflow/flow-init/scripts/validate-research.sh +332 -0
- package/.claude/skills/workflow/flow-quality/SKILL.md +94 -0
- package/.claude/skills/workflow/flow-quality/context.jsonl +6 -0
- package/.claude/skills/workflow/flow-quality/references/code-quality-reviewer.md +205 -0
- package/.claude/skills/workflow/flow-quality/references/qa-tester.md +313 -0
- package/.claude/skills/workflow/flow-quality/references/security-reviewer.md +314 -0
- package/.claude/skills/workflow/flow-quality/references/spec-reviewer.md +221 -0
- package/.claude/skills/workflow/flow-release/SKILL.md +126 -0
- package/.claude/skills/workflow/flow-release/context.jsonl +7 -0
- package/.claude/skills/workflow/flow-release/references/release-manager.md +295 -0
- package/.claude/skills/workflow/flow-spec/CLAUDE.md +103 -0
- package/.claude/skills/workflow/flow-spec/SKILL.md +545 -0
- package/.claude/skills/workflow/flow-spec/context.jsonl +7 -0
- package/.claude/skills/workflow/flow-spec/scripts/entry-gate.sh +194 -0
- package/.claude/skills/workflow/flow-spec/scripts/exit-gate.sh +244 -0
- package/.claude/skills/workflow/flow-spec/scripts/parallel-orchestrator.sh +205 -0
- package/.claude/skills/workflow/flow-spec/scripts/team-communication.sh +353 -0
- package/.claude/skills/workflow/flow-spec/scripts/team-init.sh +195 -0
- package/.claude/skills/workflow/flow-spec/scripts/test-team-mode.sh +496 -0
- package/.claude/skills/workflow/flow-spec/team-config.json +165 -0
- package/.claude/skills/workflow.yaml +417 -0
- package/CHANGELOG.md +254 -0
- package/README.md +193 -33
- package/README.zh-CN.md +206 -46
- package/lib/compiler/CLAUDE.md +77 -46
- package/lib/compiler/__tests__/multi-module-emitters.test.js +508 -0
- package/lib/compiler/context-expander.js +179 -0
- package/lib/compiler/emitters/antigravity-emitter.js +195 -5
- package/lib/compiler/emitters/base-emitter.js +217 -2
- package/lib/compiler/emitters/codex-emitter.js +200 -4
- package/lib/compiler/emitters/cursor-emitter.js +307 -3
- package/lib/compiler/emitters/qwen-emitter.js +196 -4
- package/lib/compiler/index.js +197 -2
- package/lib/compiler/platforms.js +270 -21
- package/package.json +1 -1
- package/.claude/commands/flow-epic.md +0 -183
- package/.claude/commands/flow-init.md +0 -370
- package/.claude/commands/flow-prd.md +0 -144
- package/.claude/commands/flow-qa.md +0 -93
- package/.claude/commands/flow-review.md +0 -257
- package/.claude/commands/flow-tech.md +0 -142
- package/.claude/commands/flow-ui.md +0 -189
- package/.claude/skills/file-header-guardian/SKILL.md +0 -56
- package/.claude/skills/skill-developer/ADVANCED.md +0 -197
- package/.claude/skills/skill-developer/HOOK_MECHANISMS.md +0 -306
- package/.claude/skills/skill-developer/PATTERNS_LIBRARY.md +0 -152
- package/.claude/skills/skill-developer/SKILL.md +0 -426
- package/.claude/skills/skill-developer/SKILL_RULES_REFERENCE.md +0 -315
- package/.claude/skills/skill-developer/TRIGGER_TYPES.md +0 -305
- package/.claude/skills/skill-developer/TROUBLESHOOTING.md +0 -514
- package/.claude/skills/writing-skills/SKILL.md +0 -655
- package/.claude/skills/writing-skills/anthropic-best-practices.md +0 -1150
- package/.claude/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +0 -189
- package/.claude/skills/writing-skills/graphviz-conventions.dot +0 -172
- package/.claude/skills/writing-skills/persuasion-principles.md +0 -187
- package/.claude/skills/writing-skills/render-graphs.js +0 -168
- package/.claude/skills/writing-skills/testing-skills-with-subagents.md +0 -384
- package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/affected-repos.txt +0 -1
- package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/affected-repos.txt +0 -1
- /package/.claude/commands/{core-architecture.md → core/architecture.md} +0 -0
- /package/.claude/commands/{core-guidelines.md → core/guidelines.md} +0 -0
- /package/.claude/commands/{core-roadmap.md → core/roadmap.md} +0 -0
- /package/.claude/commands/{core-style.md → core/style.md} +0 -0
- /package/.claude/commands/{flow-checklist.md → flow/checklist.md} +0 -0
- /package/.claude/commands/{flow-clarify.md → flow/clarify.md} +0 -0
- /package/.claude/commands/{flow-constitution.md → flow/constitution.md} +0 -0
- /package/.claude/commands/{flow-fix.md → flow/fix.md} +0 -0
- /package/.claude/commands/{flow-ideate.md → flow/ideate.md} +0 -0
- /package/.claude/commands/{flow-new.md → flow/new.md} +0 -0
- /package/.claude/commands/{flow-release.md → flow/release.md} +0 -0
- /package/.claude/commands/{flow-restart.md → flow/restart.md} +0 -0
- /package/.claude/commands/{flow-status.md → flow/status.md} +0 -0
- /package/.claude/commands/{flow-update.md → flow/update.md} +0 -0
- /package/.claude/commands/{flow-upgrade.md → flow/upgrade.md} +0 -0
- /package/.claude/commands/{flow-verify.md → flow/verify.md} +0 -0
- /package/.claude/commands/{code-review-high.md → util/code-review.md} +0 -0
- /package/.claude/commands/{git-commit.md → util/git-commit.md} +0 -0
- /package/.claude/commands/{problem-analyzer.md → util/problem-analyzer.md} +0 -0
- /package/.claude/skills/{flow-attention-refresh → domain/attention-refresh}/SKILL.md +0 -0
- /package/.claude/skills/{flow-brainstorming → domain/brainstorming}/SKILL.md +0 -0
- /package/.claude/skills/{flow-debugging → domain/debugging}/SKILL.md +0 -0
- /package/.claude/skills/{flow-finishing-branch → domain/finishing-branch}/SKILL.md +0 -0
- /package/.claude/skills/{flow-receiving-review → domain/receiving-review}/SKILL.md +0 -0
- /package/.claude/skills/{flow-tdd → domain/tdd}/SKILL.md +0 -0
- /package/.claude/skills/{verification-before-completion → domain/verification}/SKILL.md +0 -0
- /package/.claude/skills/{constitution-guardian → guardrail/constitution-guardian}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-tdd-enforcer → guardrail/tdd-enforcer}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-constitution-quick-ref → utility/constitution-quick-ref}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-file-standards → utility/file-standards}/SKILL.md +0 -0
- /package/.claude/skills/{fractal-docs-generator → utility/fractal-docs}/SKILL.md +0 -0
- /package/.claude/skills/{npm-release → utility/npm-release}/SKILL.md +0 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
#!/usr/bin/env npx ts-node
|
|
2
|
+
/**
|
|
3
|
+
* [INPUT]: 依赖 quality-gates.yml 的 task_completed.verify 配置,依赖 common.sh 的 mark_teammate_task_complete
|
|
4
|
+
* [OUTPUT]: 对外提供 TaskCompleted 钩子,验证任务完成质量并更新状态
|
|
5
|
+
* [POS]: hooks/ 的任务完成验证器,被 Claude Team 系统消费
|
|
6
|
+
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
|
|
7
|
+
*
|
|
8
|
+
* =============================================================================
|
|
9
|
+
* CC-DevFlow TaskCompleted Hook (v4.7)
|
|
10
|
+
* =============================================================================
|
|
11
|
+
*
|
|
12
|
+
* 核心设计哲学:
|
|
13
|
+
* - 任务标记完成时执行程序化验证
|
|
14
|
+
* - 验证失败且 block_on_failure=true 时阻止完成
|
|
15
|
+
* - 记录失败到 ERROR_LOG.md
|
|
16
|
+
* - 更新 Team 状态并检查阶段转换
|
|
17
|
+
*
|
|
18
|
+
* 触发条件:TaskCompleted 事件
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as fs from 'fs';
|
|
22
|
+
import * as path from 'path';
|
|
23
|
+
import { execSync } from 'child_process';
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// 类型定义 (复用 team-types.d.ts 中的定义)
|
|
27
|
+
// =============================================================================
|
|
28
|
+
|
|
29
|
+
interface TaskCompletedInput {
|
|
30
|
+
hook_event_name: 'TaskCompleted';
|
|
31
|
+
task_id: string;
|
|
32
|
+
task_subject: string;
|
|
33
|
+
completed_by: string;
|
|
34
|
+
completion_time: string;
|
|
35
|
+
cwd: string;
|
|
36
|
+
session_id: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface TaskCompletedOutput {
|
|
40
|
+
decision: 'accept' | 'reject';
|
|
41
|
+
reason: string;
|
|
42
|
+
next_actions?: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface VerifyCommand {
|
|
46
|
+
name?: string;
|
|
47
|
+
command: string;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface TaskCompletedConfig {
|
|
52
|
+
verify?: (string | VerifyCommand)[];
|
|
53
|
+
block_on_failure?: boolean;
|
|
54
|
+
max_retries?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface QualityGatesConfig {
|
|
58
|
+
task_completed?: TaskCompletedConfig;
|
|
59
|
+
verify?: (string | VerifyCommand)[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface FailureRecord {
|
|
63
|
+
command: string;
|
|
64
|
+
output: string;
|
|
65
|
+
timestamp: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// 配置常量
|
|
70
|
+
// =============================================================================
|
|
71
|
+
|
|
72
|
+
const CONFIG_FILE = '.claude/config/quality-gates.yml';
|
|
73
|
+
const COMMAND_TIMEOUT_MS = 120000; // 2 minutes per command
|
|
74
|
+
const SCRIPTS_DIR = '.claude/scripts';
|
|
75
|
+
|
|
76
|
+
// =============================================================================
|
|
77
|
+
// 工具函数
|
|
78
|
+
// =============================================================================
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 查找 Git 仓库根目录
|
|
82
|
+
*/
|
|
83
|
+
function findRepoRoot(startPath: string): string | null {
|
|
84
|
+
let current = path.resolve(startPath);
|
|
85
|
+
while (current !== path.dirname(current)) {
|
|
86
|
+
if (fs.existsSync(path.join(current, '.git'))) {
|
|
87
|
+
return current;
|
|
88
|
+
}
|
|
89
|
+
current = path.dirname(current);
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 简单 YAML 解析器 (无外部依赖)
|
|
96
|
+
* 解析 task_completed 和顶级 verify 配置
|
|
97
|
+
*/
|
|
98
|
+
function parseSimpleYaml(content: string): QualityGatesConfig {
|
|
99
|
+
const config: QualityGatesConfig = {};
|
|
100
|
+
const lines = content.split('\n');
|
|
101
|
+
|
|
102
|
+
let currentSection = '';
|
|
103
|
+
let inVerifySection = false;
|
|
104
|
+
let inTaskCompletedSection = false;
|
|
105
|
+
let inTaskCompletedVerify = false;
|
|
106
|
+
const topLevelVerify: (string | VerifyCommand)[] = [];
|
|
107
|
+
const taskCompletedVerify: (string | VerifyCommand)[] = [];
|
|
108
|
+
let blockOnFailure = true; // default
|
|
109
|
+
|
|
110
|
+
for (const line of lines) {
|
|
111
|
+
const trimmed = line.trim();
|
|
112
|
+
const indent = line.length - line.trimStart().length;
|
|
113
|
+
|
|
114
|
+
// 跳过注释和空行
|
|
115
|
+
if (trimmed.startsWith('#') || trimmed === '') continue;
|
|
116
|
+
|
|
117
|
+
// 检测顶级 section
|
|
118
|
+
if (indent === 0 && trimmed.endsWith(':')) {
|
|
119
|
+
currentSection = trimmed.slice(0, -1);
|
|
120
|
+
inVerifySection = false;
|
|
121
|
+
inTaskCompletedSection = currentSection === 'task_completed';
|
|
122
|
+
inTaskCompletedVerify = false;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 检测顶级 verify section
|
|
127
|
+
if (indent === 0 && trimmed === 'verify:') {
|
|
128
|
+
inVerifySection = true;
|
|
129
|
+
inTaskCompletedSection = false;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 解析顶级 verify 列表项
|
|
134
|
+
if (inVerifySection && trimmed.startsWith('- ')) {
|
|
135
|
+
const value = trimmed.slice(2).trim();
|
|
136
|
+
if (!value.startsWith('name:') && !value.includes(':')) {
|
|
137
|
+
topLevelVerify.push(value);
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 解析 task_completed section
|
|
143
|
+
if (inTaskCompletedSection) {
|
|
144
|
+
if (trimmed === 'verify:') {
|
|
145
|
+
inTaskCompletedVerify = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (trimmed.startsWith('block_on_failure:')) {
|
|
150
|
+
const val = trimmed.split(':')[1].trim().toLowerCase();
|
|
151
|
+
blockOnFailure = val === 'true';
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (inTaskCompletedVerify && trimmed.startsWith('- ')) {
|
|
156
|
+
const value = trimmed.slice(2).trim();
|
|
157
|
+
if (!value.startsWith('name:') && !value.includes(':')) {
|
|
158
|
+
taskCompletedVerify.push(value);
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 设置顶级 verify
|
|
166
|
+
if (topLevelVerify.length > 0) {
|
|
167
|
+
config.verify = topLevelVerify;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 设置 task_completed 配置
|
|
171
|
+
if (taskCompletedVerify.length > 0 || inTaskCompletedSection) {
|
|
172
|
+
config.task_completed = {
|
|
173
|
+
verify: taskCompletedVerify.length > 0 ? taskCompletedVerify : undefined,
|
|
174
|
+
block_on_failure: blockOnFailure
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 读取 quality-gates.yml 配置
|
|
183
|
+
*/
|
|
184
|
+
function loadConfig(repoRoot: string): QualityGatesConfig {
|
|
185
|
+
const configPath = path.join(repoRoot, CONFIG_FILE);
|
|
186
|
+
if (!fs.existsSync(configPath)) {
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
192
|
+
return parseSimpleYaml(content);
|
|
193
|
+
} catch {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 获取 verify 命令列表
|
|
200
|
+
* 优先使用 task_completed.verify,否则使用顶级 verify
|
|
201
|
+
*/
|
|
202
|
+
function getVerifyCommands(config: QualityGatesConfig): string[] {
|
|
203
|
+
const taskCompletedVerify = config.task_completed?.verify;
|
|
204
|
+
if (taskCompletedVerify && taskCompletedVerify.length > 0) {
|
|
205
|
+
return taskCompletedVerify.map(cmd => {
|
|
206
|
+
if (typeof cmd === 'string') return cmd;
|
|
207
|
+
return cmd.command;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (config.verify && config.verify.length > 0) {
|
|
212
|
+
return config.verify.map(cmd => {
|
|
213
|
+
if (typeof cmd === 'string') return cmd;
|
|
214
|
+
return cmd.command;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 默认验证命令
|
|
219
|
+
return [
|
|
220
|
+
'npm run lint --if-present',
|
|
221
|
+
'npm run typecheck --if-present',
|
|
222
|
+
'npm test -- --passWithNoTests'
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 获取 block_on_failure 配置
|
|
228
|
+
*/
|
|
229
|
+
function getBlockOnFailure(config: QualityGatesConfig): boolean {
|
|
230
|
+
return config.task_completed?.block_on_failure ?? true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 执行验证命令 (复用 ralph-loop.ts 逻辑)
|
|
235
|
+
*/
|
|
236
|
+
function runVerifyCommands(
|
|
237
|
+
repoRoot: string,
|
|
238
|
+
commands: string[]
|
|
239
|
+
): { passed: boolean; failures: FailureRecord[] } {
|
|
240
|
+
const failures: FailureRecord[] = [];
|
|
241
|
+
|
|
242
|
+
for (const cmd of commands) {
|
|
243
|
+
try {
|
|
244
|
+
execSync(cmd, {
|
|
245
|
+
cwd: repoRoot,
|
|
246
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
247
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
248
|
+
encoding: 'utf-8'
|
|
249
|
+
});
|
|
250
|
+
} catch (error: unknown) {
|
|
251
|
+
let output = '';
|
|
252
|
+
if (error && typeof error === 'object') {
|
|
253
|
+
const execError = error as { stderr?: string; stdout?: string; message?: string };
|
|
254
|
+
output = execError.stderr || execError.stdout || execError.message || 'Unknown error';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 截断过长输出
|
|
258
|
+
if (output.length > 500) {
|
|
259
|
+
output = output.slice(0, 500) + '...';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
failures.push({
|
|
263
|
+
command: cmd,
|
|
264
|
+
output,
|
|
265
|
+
timestamp: new Date().toISOString()
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
passed: failures.length === 0,
|
|
272
|
+
failures
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 格式化失败信息
|
|
278
|
+
*/
|
|
279
|
+
function formatFailures(failures: FailureRecord[]): string {
|
|
280
|
+
return failures.map(f => `Command: ${f.command}\nOutput: ${f.output}`).join('\n\n');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 记录错误到 ERROR_LOG.md
|
|
285
|
+
*/
|
|
286
|
+
function recordErrorToLog(
|
|
287
|
+
repoRoot: string,
|
|
288
|
+
taskId: string,
|
|
289
|
+
taskSubject: string,
|
|
290
|
+
failures: FailureRecord[]
|
|
291
|
+
): void {
|
|
292
|
+
// 尝试找到当前需求目录
|
|
293
|
+
const reqId = detectReqId(repoRoot);
|
|
294
|
+
if (!reqId) return;
|
|
295
|
+
|
|
296
|
+
const reqDir = path.join(repoRoot, 'devflow', 'requirements', reqId);
|
|
297
|
+
const errorLogPath = path.join(reqDir, 'ERROR_LOG.md');
|
|
298
|
+
|
|
299
|
+
const timestamp = new Date().toISOString();
|
|
300
|
+
const errorNumber = getNextErrorNumber(errorLogPath);
|
|
301
|
+
|
|
302
|
+
const entry = `
|
|
303
|
+
## [${timestamp}] E${errorNumber.toString().padStart(3, '0')}: Task ${taskId} Verification Failed
|
|
304
|
+
|
|
305
|
+
**Phase**: flow-dev / ${taskId}
|
|
306
|
+
**Task**: ${taskSubject}
|
|
307
|
+
**Error Type**: Verification Failure
|
|
308
|
+
**Error Message**:
|
|
309
|
+
\`\`\`
|
|
310
|
+
${formatFailures(failures)}
|
|
311
|
+
\`\`\`
|
|
312
|
+
**Root Cause**: [Pending analysis]
|
|
313
|
+
**Resolution**: [Pending fix]
|
|
314
|
+
**Prevention**: [Optional]
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
`;
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
if (fs.existsSync(errorLogPath)) {
|
|
321
|
+
fs.appendFileSync(errorLogPath, entry, 'utf-8');
|
|
322
|
+
} else {
|
|
323
|
+
const header = `# ERROR_LOG.md
|
|
324
|
+
|
|
325
|
+
> 执行错误日志 - 记录 flow-dev 阶段的所有错误
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
`;
|
|
329
|
+
fs.writeFileSync(errorLogPath, header + entry, 'utf-8');
|
|
330
|
+
}
|
|
331
|
+
} catch {
|
|
332
|
+
// 忽略写入错误
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 获取下一个错误编号
|
|
338
|
+
*/
|
|
339
|
+
function getNextErrorNumber(errorLogPath: string): number {
|
|
340
|
+
if (!fs.existsSync(errorLogPath)) return 1;
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
const content = fs.readFileSync(errorLogPath, 'utf-8');
|
|
344
|
+
const matches = content.match(/E(\d{3}):/g);
|
|
345
|
+
if (!matches || matches.length === 0) return 1;
|
|
346
|
+
|
|
347
|
+
const numbers = matches.map(m => parseInt(m.slice(1, 4), 10));
|
|
348
|
+
return Math.max(...numbers) + 1;
|
|
349
|
+
} catch {
|
|
350
|
+
return 1;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 检测当前需求 ID
|
|
356
|
+
*/
|
|
357
|
+
function detectReqId(repoRoot: string): string | null {
|
|
358
|
+
// 1. 从环境变量获取
|
|
359
|
+
const envReqId = process.env.CURRENT_REQ_ID;
|
|
360
|
+
if (envReqId) return envReqId;
|
|
361
|
+
|
|
362
|
+
// 2. 从 .current-task 文件获取
|
|
363
|
+
const currentTaskPath = path.join(repoRoot, '.current-task');
|
|
364
|
+
if (fs.existsSync(currentTaskPath)) {
|
|
365
|
+
try {
|
|
366
|
+
const content = fs.readFileSync(currentTaskPath, 'utf-8').trim();
|
|
367
|
+
const match = content.match(/REQ-\d+/);
|
|
368
|
+
if (match) return match[0];
|
|
369
|
+
} catch {
|
|
370
|
+
// 忽略
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 3. 从 Git 分支名获取
|
|
375
|
+
try {
|
|
376
|
+
const branch = execSync('git rev-parse --abbrev-ref HEAD', {
|
|
377
|
+
cwd: repoRoot,
|
|
378
|
+
encoding: 'utf-8',
|
|
379
|
+
timeout: 5000
|
|
380
|
+
}).trim();
|
|
381
|
+
const match = branch.match(/REQ-\d+/);
|
|
382
|
+
if (match) return match[0];
|
|
383
|
+
} catch {
|
|
384
|
+
// 忽略
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* 调用 common.sh 中的 mark_teammate_task_complete 函数
|
|
392
|
+
*/
|
|
393
|
+
function markTeammateTaskComplete(
|
|
394
|
+
repoRoot: string,
|
|
395
|
+
reqId: string,
|
|
396
|
+
teammateId: string,
|
|
397
|
+
taskId: string
|
|
398
|
+
): boolean {
|
|
399
|
+
const commonShPath = path.join(repoRoot, SCRIPTS_DIR, 'common.sh');
|
|
400
|
+
if (!fs.existsSync(commonShPath)) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
const script = `
|
|
406
|
+
source "${commonShPath}"
|
|
407
|
+
mark_teammate_task_complete "${repoRoot}" "${reqId}" "${teammateId}" "${taskId}"
|
|
408
|
+
`;
|
|
409
|
+
execSync(`bash -c '${script}'`, {
|
|
410
|
+
cwd: repoRoot,
|
|
411
|
+
timeout: 10000,
|
|
412
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
413
|
+
});
|
|
414
|
+
return true;
|
|
415
|
+
} catch {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 检查是否触发阶段转换
|
|
422
|
+
*/
|
|
423
|
+
function checkPhaseTransition(
|
|
424
|
+
repoRoot: string,
|
|
425
|
+
reqId: string
|
|
426
|
+
): string[] {
|
|
427
|
+
const nextActions: string[] = [];
|
|
428
|
+
|
|
429
|
+
// 读取 orchestration_status.json
|
|
430
|
+
const statusPath = path.join(repoRoot, 'devflow', 'requirements', reqId, 'orchestration_status.json');
|
|
431
|
+
if (!fs.existsSync(statusPath)) {
|
|
432
|
+
return nextActions;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
try {
|
|
436
|
+
const content = fs.readFileSync(statusPath, 'utf-8');
|
|
437
|
+
const status = JSON.parse(content);
|
|
438
|
+
|
|
439
|
+
// 检查是否所有任务都已完成
|
|
440
|
+
const team = status.team;
|
|
441
|
+
if (!team) return nextActions;
|
|
442
|
+
|
|
443
|
+
const allTasksCompleted = team.teammates.every(
|
|
444
|
+
(t: { completedTasks?: string[]; currentTask?: string | null }) =>
|
|
445
|
+
!t.currentTask && (t.completedTasks?.length ?? 0) > 0
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
if (allTasksCompleted) {
|
|
449
|
+
nextActions.push('All tasks completed. Consider running /flow:quality');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// 检查是否有空闲的 teammate 可以分配新任务
|
|
453
|
+
const idleTeammates = team.teammates.filter(
|
|
454
|
+
(t: { status: string }) => t.status === 'idle'
|
|
455
|
+
);
|
|
456
|
+
if (idleTeammates.length > 0) {
|
|
457
|
+
nextActions.push(`${idleTeammates.length} teammate(s) idle. Check for unassigned tasks.`);
|
|
458
|
+
}
|
|
459
|
+
} catch {
|
|
460
|
+
// 忽略解析错误
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return nextActions;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// =============================================================================
|
|
467
|
+
// 主函数
|
|
468
|
+
// =============================================================================
|
|
469
|
+
|
|
470
|
+
function main(): void {
|
|
471
|
+
let inputData: TaskCompletedInput;
|
|
472
|
+
|
|
473
|
+
try {
|
|
474
|
+
const stdin = fs.readFileSync(0, 'utf-8');
|
|
475
|
+
inputData = JSON.parse(stdin);
|
|
476
|
+
} catch {
|
|
477
|
+
// 无法解析输入,接受完成
|
|
478
|
+
const output: TaskCompletedOutput = {
|
|
479
|
+
decision: 'accept',
|
|
480
|
+
reason: 'Unable to parse input. Accepting task completion.'
|
|
481
|
+
};
|
|
482
|
+
console.log(JSON.stringify(output, null, 0));
|
|
483
|
+
process.exit(0);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const hookEvent = inputData.hook_event_name || '';
|
|
487
|
+
|
|
488
|
+
// 只处理 TaskCompleted 事件
|
|
489
|
+
if (hookEvent !== 'TaskCompleted') {
|
|
490
|
+
const output: TaskCompletedOutput = {
|
|
491
|
+
decision: 'accept',
|
|
492
|
+
reason: `Ignoring non-TaskCompleted event: ${hookEvent}`
|
|
493
|
+
};
|
|
494
|
+
console.log(JSON.stringify(output, null, 0));
|
|
495
|
+
process.exit(0);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const cwd = inputData.cwd || process.cwd();
|
|
499
|
+
const taskId = inputData.task_id;
|
|
500
|
+
const taskSubject = inputData.task_subject;
|
|
501
|
+
const completedBy = inputData.completed_by;
|
|
502
|
+
|
|
503
|
+
// 查找仓库根目录
|
|
504
|
+
const repoRoot = findRepoRoot(cwd);
|
|
505
|
+
if (!repoRoot) {
|
|
506
|
+
const output: TaskCompletedOutput = {
|
|
507
|
+
decision: 'accept',
|
|
508
|
+
reason: 'Not in a git repository. Accepting task completion.'
|
|
509
|
+
};
|
|
510
|
+
console.log(JSON.stringify(output, null, 0));
|
|
511
|
+
process.exit(0);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// 加载配置
|
|
515
|
+
const config = loadConfig(repoRoot);
|
|
516
|
+
const verifyCommands = getVerifyCommands(config);
|
|
517
|
+
const blockOnFailure = getBlockOnFailure(config);
|
|
518
|
+
|
|
519
|
+
// 执行验证命令
|
|
520
|
+
const { passed, failures } = runVerifyCommands(repoRoot, verifyCommands);
|
|
521
|
+
|
|
522
|
+
// 检测需求 ID
|
|
523
|
+
const reqId = detectReqId(repoRoot);
|
|
524
|
+
|
|
525
|
+
if (passed) {
|
|
526
|
+
// 所有验证通过
|
|
527
|
+
const nextActions: string[] = [];
|
|
528
|
+
|
|
529
|
+
// 更新 Team 状态
|
|
530
|
+
if (reqId && completedBy) {
|
|
531
|
+
const updated = markTeammateTaskComplete(repoRoot, reqId, completedBy, taskId);
|
|
532
|
+
if (updated) {
|
|
533
|
+
nextActions.push(`Updated team state for ${completedBy}`);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// 检查阶段转换
|
|
537
|
+
const phaseActions = checkPhaseTransition(repoRoot, reqId);
|
|
538
|
+
nextActions.push(...phaseActions);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const output: TaskCompletedOutput = {
|
|
542
|
+
decision: 'accept',
|
|
543
|
+
reason: `Task ${taskId} completed successfully. All verification passed.`,
|
|
544
|
+
next_actions: nextActions.length > 0 ? nextActions : undefined
|
|
545
|
+
};
|
|
546
|
+
console.log(JSON.stringify(output, null, 0));
|
|
547
|
+
process.exit(0);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// 验证失败
|
|
551
|
+
const failureDetails = formatFailures(failures);
|
|
552
|
+
|
|
553
|
+
// 记录错误到 ERROR_LOG.md
|
|
554
|
+
if (reqId) {
|
|
555
|
+
recordErrorToLog(repoRoot, taskId, taskSubject, failures);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (blockOnFailure) {
|
|
559
|
+
// 阻止任务完成
|
|
560
|
+
const output: TaskCompletedOutput = {
|
|
561
|
+
decision: 'reject',
|
|
562
|
+
reason: `Task ${taskId} verification failed:\n\n${failureDetails}\n\nPlease fix the issues before marking the task as complete.`,
|
|
563
|
+
next_actions: ['Fix verification errors', 'Re-run task completion']
|
|
564
|
+
};
|
|
565
|
+
console.log(JSON.stringify(output, null, 0));
|
|
566
|
+
process.exit(0);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// 不阻止,但记录警告
|
|
570
|
+
const nextActions: string[] = ['Warning: Verification failed but block_on_failure is false'];
|
|
571
|
+
|
|
572
|
+
// 更新 Team 状态
|
|
573
|
+
if (reqId && completedBy) {
|
|
574
|
+
const updated = markTeammateTaskComplete(repoRoot, reqId, completedBy, taskId);
|
|
575
|
+
if (updated) {
|
|
576
|
+
nextActions.push(`Updated team state for ${completedBy}`);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// 检查阶段转换
|
|
580
|
+
const phaseActions = checkPhaseTransition(repoRoot, reqId);
|
|
581
|
+
nextActions.push(...phaseActions);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const output: TaskCompletedOutput = {
|
|
585
|
+
decision: 'accept',
|
|
586
|
+
reason: `Task ${taskId} accepted with warnings. Verification failed:\n\n${failureDetails}`,
|
|
587
|
+
next_actions: nextActions
|
|
588
|
+
};
|
|
589
|
+
console.log(JSON.stringify(output, null, 0));
|
|
590
|
+
process.exit(0);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
main();
|