@boyingliu01/xp-gate 0.5.2 → 0.6.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/lib/ui-review.ts CHANGED
@@ -15,9 +15,9 @@ interface UiReviewResult {
15
15
  }
16
16
 
17
17
  function main(): void {
18
- // eslint-disable-next-line no-console
18
+
19
19
  console.log('═══ xp-gate ui-review ═══');
20
- // eslint-disable-next-line no-console
20
+
21
21
  console.log('');
22
22
 
23
23
  // Get staged + modified files
@@ -25,7 +25,7 @@ function main(): void {
25
25
  try {
26
26
  files = execSync('git diff --cached --name-only && git diff --name-only', { encoding: 'utf8' }).trim();
27
27
  } catch {
28
- // eslint-disable-next-line no-console
28
+
29
29
  console.log('⚠️ No git repo or no changes. Running in current directory.');
30
30
  }
31
31
 
@@ -35,7 +35,7 @@ function main(): void {
35
35
  .filter(f => f.length > 0);
36
36
 
37
37
  if (fileList.length === 0) {
38
- // eslint-disable-next-line no-console
38
+
39
39
  console.log('No files staged or modified. Checking all tracked files.');
40
40
  try {
41
41
  files = execSync('git ls-files', { encoding: 'utf8' }).trim();
@@ -48,28 +48,28 @@ function main(): void {
48
48
  const result = collectUiMatches(fileList);
49
49
 
50
50
  if (!result.isUiSprint) {
51
- // eslint-disable-next-line no-console
51
+
52
52
  console.log('ℹ️ No UI changes detected in staged/modified files.');
53
- // eslint-disable-next-line no-console
53
+
54
54
  console.log(' Nothing to review. Exiting.');
55
55
  process.exit(0);
56
56
  }
57
57
 
58
- // eslint-disable-next-line no-console
58
+
59
59
  console.log(`🎨 UI changes detected (${result.matchedFiles.length} files):`);
60
60
  result.matchedFiles.forEach(f => console.log(` - ${f}`));
61
- // eslint-disable-next-line no-console
61
+
62
62
  console.log('');
63
63
 
64
- // eslint-disable-next-line no-console
64
+
65
65
  console.log('Next steps required before push:');
66
- // eslint-disable-next-line no-console
66
+
67
67
  console.log(' 1. Run /design-review in your AI agent session');
68
- // eslint-disable-next-line no-console
68
+
69
69
  console.log(' 2. Run /qa or /qa-only in your AI agent session');
70
- // eslint-disable-next-line no-console
70
+
71
71
  console.log(' 3. Ensure you have .delphi-config.json configured for Delphi review');
72
- // eslint-disable-next-line no-console
72
+
73
73
  console.log('');
74
74
 
75
75
  const commit = execSync('git rev-parse HEAD 2>/dev/null || echo "no-commit"', { encoding: 'utf8' }).trim();
@@ -86,23 +86,23 @@ function main(): void {
86
86
 
87
87
  writeFileSync(join(process.cwd(), RESULT_FILE), JSON.stringify(uiResult, null, 2) + '\n', 'utf8');
88
88
 
89
- // eslint-disable-next-line no-console
89
+
90
90
  console.log(`✅ Generated ${RESULT_FILE} with APPROVED verdict (template)`);
91
- // eslint-disable-next-line no-console
91
+
92
92
  console.log(` Commit: ${commit}`);
93
- // eslint-disable-next-line no-console
93
+
94
94
  console.log(` Expires: ${expires}`);
95
- // eslint-disable-next-line no-console
95
+
96
96
  console.log('');
97
- // eslint-disable-next-line no-console
97
+
98
98
  console.log('⚠️ REVIEW THIS FILE before push:');
99
- // eslint-disable-next-line no-console
99
+
100
100
  console.log(' - Ensure design_review and browser_qa are actually APPROVED');
101
- // eslint-disable-next-line no-console
101
+
102
102
  console.log(' - Edit verdict to REJECTED if issues found');
103
- // eslint-disable-next-line no-console
103
+
104
104
  console.log('');
105
- // eslint-disable-next-line no-console
105
+
106
106
  console.log('Then: git push (pre-push will validate this file)');
107
107
  }
108
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "./bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 6 quality gates, Sprint Flow, and Delphi multi-expert review.",
6
6
  "author": {
@@ -53,6 +53,10 @@ maturity: beta
53
53
  ```
54
54
  Phase -1: ISOLATE → ⚠️ 检测保护分支(main/master/develop/trunk/mainline) → 强制创建 git worktree
55
55
  → 已在 worktree 中 → 跳过 → 项目 setup → .gitignore 校验 → sprint-state isolation 记录
56
+ Phase -0.5: AUTO-ESTIMATE → 自动评估需求规模 → ⚠️ 展示评估结果,用户确认
57
+ → 轻量:跳过 brainstorming + delphi-review,直接 Phase 2 BUILD
58
+ → 标准:正常流程 Phase 0-4
59
+ → 复杂:完整流程 Phase 0-8 + 风险警告
56
60
  Phase 0: THINK → brainstorming → ⚠️ HARD-GATE: 设计未批准 → 不可进入实现 → Design Document (AI编辑行为约束: 原则3 Surgical Changes, 验证循环要求: 原则4 Goal-Driven Execution - 见 AGENTS.md "## AI CODING DISCIPLINE (Karpathy Principles)")
57
61
  Phase 1: PLAN → autoplan → ⚠️ (如有taste_decisions,暂停等用户确认)
58
62
  → delphi-review → ⚠️ (等待 APPROVED)
@@ -82,6 +86,7 @@ Phase 8: CLEANUP → git worktree remove + sprint-state.json update → status:
82
86
  | 暂停点位置 | 触发条件 | 用户操作 | 自动恢复条件 |
83
87
  |-----------|---------|---------|-------------|
84
88
  | **Phase -1** | ⚠️ **保护分支强制隔离 / --no-isolate 跳过** | 输出 ⚠️ 警告或自动创建 worktree | 自动创建或用户确认后继续 |
89
+ | **Phase -0.5** | **AUTO-ESTIMATE 结果展示** | 接受建议 / 修改流程 / 取消 | 用户确认后按路由继续 |
85
90
  | **Phase 0** | ⚠️ **设计未 APPROVED (HARD-GATE)** | 根据反馈修改设计 | 设计 APPROVED 后继续 |
86
91
  | Phase 1 | autoplan surfacing taste_decisions | 用户确认每个决策 | 确认后自动继续 |
87
92
  | Phase 1 | delphi-review 未 APPROVED | 修复并重新评审 | APPROVED 后自动继续 |
@@ -155,6 +160,68 @@ Phase 8: CLEANUP → git worktree remove + sprint-state.json update → status:
155
160
 
156
161
  > **清理提示**: Sprint 完成(Phase 6 SHIP)后,执行 `git worktree remove <worktree_path>` 清理 worktree 目录,同时保留 `.sprint-state/` 中的历史记录。
157
162
 
163
+ ### Phase -0.5: AUTO-ESTIMATE(自动化规模评估与流程路由)
164
+
165
+ **执行时机**: Phase -1 ISOLATE 完成后、Phase 0 THINK 之前。**自动执行**。
166
+
167
+ **目的**: 自动评估需求规模,匹配适度流程,避免小需求走重量级流程造成资源浪费。不依赖人/AI 主观判断,而是通过代码结构分析提供客观指标。
168
+
169
+ **详细指令**: 参见 `references/phase-minus-0-5-auto-estimate.md`
170
+
171
+ #### 快速参考
172
+
173
+ **步骤**:
174
+ 1. **识别需求类型** — 删除/修改已存在代码 → 立即分析;新增功能 → brainstorming 后分析
175
+ 2. **收集指标** — 引用计数 (`grep -rn`)、跨模块依赖 (目录分布)、循环依赖、Public API 暴露、测试文件数
176
+ 3. **汇总评估** — 综合打分 → 轻量 / 标准 / 复杂
177
+ 4. **输出结果** — 使用 `templates/auto-estimate-output-template.md` 标准格式
178
+ 5. **用户确认** — 接受建议 / 修改流程 / 取消
179
+ 6. **路由执行** — 按最终级别进入对应 Phase
180
+
181
+ **路由决策表**:
182
+
183
+ | 评估结果 | 路由 | 说明 |
184
+ |---------|------|------|
185
+ | **轻量** (引用 ≤3, 同模块,无循环依赖) | 跳过 Phase 0 brainstorming + Phase 1 delphi-review → 直接进入 Phase 2 BUILD | 小改动不需要完整流程 |
186
+ | **标准** (引用 4-10, 跨 1-2 模块) | 正常流程 Phase 0-4 | 标准 sprint |
187
+ | **复杂** (引用 >10 或 循环依赖 或 跨 3+ 模块) | 完整 Phase 0-8 + 风险警告 | 高风险需求 |
188
+
189
+ **输出模板**: `templates/auto-estimate-output-template.md`
190
+ **学习日志**: `templates/auto-estimate-learning-log.md`(记录用户 override,用于阈值优化)
191
+
192
+ **输出格式**:
193
+ ```
194
+ +-------------------------------------------------------------+
195
+ | AUTO-ESTIMATE 评估结果 |
196
+ +-------------------------------------------------------------+
197
+ | 需求:{task_description} |
198
+ | 类型:{change_type} |
199
+ | |
200
+ | [{impact_level}] Impact: {impact_label} |
201
+ | |
202
+ | 引用:{ref_count} 处 |
203
+ | 跨模块:{cross_module_count} 个 ({module_list}) |
204
+ | 循环依赖:{circular_dep_status} |
205
+ | Public API:{public_api_count} 个 |
206
+ | |
207
+ | 建议流程:{recommended_flow} |
208
+ | |
209
+ | {risk_warning} |
210
+ | |
211
+ | [接受建议] [修改流程] [取消] |
212
+ +-------------------------------------------------------------+
213
+ ```
214
+
215
+ **纠偏机制**:
216
+ - **接受建议**: 按推荐流程执行,记录 `user_decision: "accepted"`
217
+ - **修改流程**: 用户选择其他级别,记录 `override_reason` 到 `.sprint-state/auto-estimate-learning.json`
218
+ - **取消**: 停止本次 sprint
219
+
220
+ **⚠️ 轻量路由的特殊处理**:
221
+ - 轻量路由跳过 Phase 0 brainstorming 和 Phase 1 delphi-review
222
+ - 但仍然执行 Phase 1→2 的 GITHOOKS-GATE 检查
223
+ - Phase 2 BUILD 仍然执行完整 TDD + 盲评 + 验证
224
+
158
225
  ### Phase 0: THINK(需求探索与设计)
159
226
  - **Subagent dispatch**: orchestrator 通过 `task(category="deep", load_skills=["brainstorming"])` 启动独立 session
160
227
  - 输入: Phase -1 summary(worktree 路径)+ 用户原始需求
@@ -318,11 +385,36 @@ Phase 2 第一步必须执行 DELPHI-GATE 检查。没有 delphi-review APPROVED
318
385
 
319
386
  ## 编排层规则(Orchestration Rules)
320
387
 
388
+ ### Agent Dispatch Rules
389
+
390
+ | Agent Type | 适用场景 | 不适用场景 | 超时处理 |
391
+ |-----------|---------|-----------|---------|
392
+ | `explore` (bare) | **窄搜索**:单个关键词/pattern,已知文件位置 | 多角度宽泛搜索,读取大文件,3+ search angles | >5min → cancel + 用 `deep` 重试 |
393
+ | `librarian` (bare) | **外部参考**:API 文档、OSS 示例 | 内部代码库宽泛探索 | >5min → cancel + 用 `deep` 重试 |
394
+ | `task(category="deep")` | **复杂研究**:多模块分析,架构决策 | 单文件 trivial fix | 无限制 |
395
+ | `task(category="unspecified-high")` | **高 effort 实现**:新模块、重构 | 单行修改 | 无限制 |
396
+
397
+ **关键规则**:
398
+
399
+ 1. Bare `explore` agent 本质是 contextual grep,**不是研究 agent**。如果任务涉及:
400
+ - 3+ 个独立搜索角度
401
+ - 读取多个大文件(>200 行)
402
+ - 需要跨层分析(如"查 ralph-loop + .sprint-state/ + token 阈值 + phase transition")
403
+
404
+ → **必须用 `task(category="deep", load_skills=[...])` 替代**
405
+
406
+ 2. 如果 `explore` agent >5 分钟未返回 → cancel 并立即用 `task(category="deep")` 重试。不要等待。
407
+
408
+ 3. **并行 explore 仍然是正确模式**。2-4 个窄搜索 explore agent 并行执行是高效且推荐的。问题在于给单一 explore agent 分配宽泛任务。
409
+
410
+ **issue #83 根因**:`bg_1abf2ed9` 被分配了 4 个独立搜索角度的宽泛任务(ralph-loop context + .sprint-state/ + token threshold + phase transition),bare explore agent 超时丢失 session。同批的 `bg_5ecf590d`(窄搜索 OpenCode compaction API)3m35s 正常完成。
411
+
321
412
  ### Phase Subagent Dispatch Matrix
322
413
 
323
414
  | Phase | 名称 | Subagent? | Category | load_skills | 执行者 |
324
415
  |-------|------|:---------:|----------|-------------|--------|
325
416
  | -1 | ISOLATE | ❌ | Bash(直接执行) | 无 | orchestrator |
417
+ | -0.5 | AUTO-ESTIMATE | ❌ | Bash(直接执行) | 无 | orchestrator |
326
418
  | 0 | THINK | ✅ | `deep` | `["brainstorming"]` | subagent |
327
419
  | 1 | PLAN | ✅ | `deep` | `["autoplan", "delphi-review", "to-issues"]` | subagent |
328
420
  | 2 | BUILD | ✅(已有) | ralph-loop | `["test-driven-development"]` | subagent |
@@ -446,6 +538,22 @@ Sprint state is persisted as JSON in `.sprint-state/sprint-state.json`:
446
538
  "created_from": "main",
447
539
  "created_from_commit": "abc123def..."
448
540
  },
541
+ "auto_estimate": {
542
+ "change_type": "删除已存在代码|修改已存在代码|新增功能|Bug修复",
543
+ "metrics": {
544
+ "ref_count": 12,
545
+ "cross_module_count": 3,
546
+ "modules": ["auth", "user", "admin"],
547
+ "circular_dep": true,
548
+ "public_api_count": 5,
549
+ "test_file_count": 4
550
+ },
551
+ "estimated_level": "轻量|标准|复杂",
552
+ "recommended_flow": "轻量流程 (Phase 2-3)|标准流程 (Phase 0-4)|完整 Sprint Flow (Phase 0-8)",
553
+ "risk_warnings": ["循环依赖: user ↔ plane"],
554
+ "user_decision": "accepted|overridden|cancelled",
555
+ "override_reason": null
556
+ },
449
557
  "outputs": {
450
558
  "pain_document": "docs/pain-document.md",
451
559
  "specification": "specification.yaml",
@@ -0,0 +1,238 @@
1
+ # Phase -0.5: AUTO-ESTIMATE(自动化规模评估与流程路由)
2
+
3
+ **执行时机**: Phase -1 ISOLATE 完成后、Phase 0 THINK 之前。**自动执行**。
4
+
5
+ **目的**: 自动评估需求规模,匹配适度流程,避免小需求走重量级流程造成资源浪费。
6
+
7
+ **核心原则**:
8
+ - **客观指标 > 主观判断**:依赖代码结构分析,不依赖人/AI 的主观直觉
9
+ - **显式告知**:用户看到客观指标,不是 AI 主观结论
10
+ - **可纠偏**:用户可接受/修改/取消
11
+ - **学习闭环**:记录用户 override,优化阈值
12
+
13
+ ---
14
+
15
+ ## 执行流程
16
+
17
+ ### 步骤 1: 识别需求类型
18
+
19
+ 分析用户输入的需求描述,判定变更类型:
20
+
21
+ | 关键词模式 | 变更类型 | AUTO-ESTIMATE 时机 |
22
+ |-----------|---------|-------------------|
23
+ | 删除、移除、去掉、砍掉、清理 + 已有模块名 | 删除已存在代码 | 立即执行 |
24
+ | 修改、改、调整、重构、优化 + 已有模块名 | 修改已存在代码 | 立即执行 |
25
+ | 新增、添加、开发、实现、创建 + 新模块名 | 新增功能 | brainstorming 后执行 |
26
+ | 修复、fix、bug | Bug 修复 | 立即执行 |
27
+ | 无法判断 | 询问用户 | — |
28
+
29
+ **IF 新增功能**: 跳过当前 AUTO-ESTIMATE,先执行 Phase 0 brainstorming,brainstorming 完成后以设计文档为输入重新执行 AUTO-ESTIMATE。
30
+
31
+ **IF 删除/修改/Bug 修复**: 继续执行以下步骤。
32
+
33
+ ### 步骤 2: 收集指标
34
+
35
+ #### 2.1 引用计数
36
+
37
+ ```bash
38
+ # 从用户输入中提取目标关键词(模块名、函数名、类名)
39
+ # 示例:删除平面维护界面 → target="plane", "平面"
40
+ grep -rn "{target_pattern}" --include="*.{ext}" . | grep -v node_modules | grep -v .git | wc -l
41
+ ```
42
+
43
+ **阈值**:
44
+ - ≤3: 轻量
45
+ - 4-10: 标准
46
+ - >10: 复杂
47
+
48
+ #### 2.2 跨模块依赖
49
+
50
+ 分析引用出现的目录分布:
51
+
52
+ ```bash
53
+ # 提取引用所在的目录(取前两级目录)
54
+ grep -rn "{target_pattern}" --include="*.{ext}" . | grep -v node_modules | grep -v .git | \
55
+ awk -F: '{print $1}' | sed 's|/[^/]*$||' | sort -u
56
+ ```
57
+
58
+ **阈值**:
59
+ - 1 个目录: 轻量
60
+ - 2 个目录: 标准
61
+ - 3+ 个目录: 复杂
62
+
63
+ #### 2.3 循环依赖检测
64
+
65
+ 简单检查:如果 A 引用 B 且 B 引用 A,则存在循环依赖。
66
+
67
+ ```bash
68
+ # 简化检测:检查目标是否导入其调用者
69
+ # 这需要根据具体语言调整。对于 TS/JS:
70
+ grep -rn "import.*{target}" --include="*.ts" --include="*.tsx" .
71
+ grep -rn "import.*{caller}" --include="*.ts" --include="*.tsx" {target_dir}/
72
+ ```
73
+
74
+ **阈值**:
75
+ - 无: 正常
76
+ - 存在: 高风险 → 无论如何输出风险警告
77
+
78
+ #### 2.4 Public API 暴露
79
+
80
+ ```bash
81
+ # 统计目标模块中 export 的数量
82
+ grep -rn "^export " {target_dir}/ --include="*.ts" | wc -l
83
+ ```
84
+
85
+ **阈值**:
86
+ - ≤2: 低影响
87
+ - 3-5: 中影响
88
+ - >5: 高影响 → 输出风险警告
89
+
90
+ #### 2.5 相关测试文件
91
+
92
+ ```bash
93
+ # 统计与目标相关的测试文件数
94
+ find . -name "*{target}*.test.*" -o -name "*{target}*.spec.*" | grep -v node_modules | wc -l
95
+ ```
96
+
97
+ **阈值**:
98
+ - 0: 无测试覆盖(风险提示)
99
+ - 1-2: 正常
100
+ - >3: 重构工作量大 → 提示
101
+
102
+ ### 步骤 3: 汇总评估
103
+
104
+ 根据各指标得分,汇总整体评估结果:
105
+
106
+ ```
107
+ 总分计算:
108
+ - 引用计数:轻量=1, 标准=2, 复杂=3
109
+ - 跨模块:轻量=1, 标准=2, 复杂=3
110
+ - 循环依赖:无=0, 存在=5(强制复杂)
111
+ - Public API:低=0, 中=1, 高=2
112
+ - 测试文件:正常=0, 多=1
113
+
114
+ 总分:1-3 = 轻量 | 4-6 = 标准 | 7+ 或 循环依赖存在 = 复杂
115
+ ```
116
+
117
+ ### 步骤 4: 输出评估结果
118
+
119
+ 使用 `templates/auto-estimate-output-template.md` 的标准格式向用户展示评估结果。
120
+
121
+ **MUST** 遵循模板格式,包含:
122
+ - 需求描述 + 变更类型
123
+ - 影响级别标识
124
+ - 各项指标的具体数值
125
+ - 建议流程
126
+ - 风险警告(如有)
127
+ - 用户操作选项
128
+
129
+ ### 步骤 5: 处理用户选择
130
+
131
+ #### 用户选择「接受建议」
132
+
133
+ > 按推荐流程执行。保存评估结果到 sprint-state.json。
134
+
135
+ ```json
136
+ {
137
+ "auto_estimate": {
138
+ "change_type": "删除已存在代码",
139
+ "metrics": {
140
+ "ref_count": 12,
141
+ "cross_module_count": 3,
142
+ "modules": ["auth", "user", "admin"],
143
+ "circular_dep": true,
144
+ "public_api_count": 5,
145
+ "test_file_count": 4
146
+ },
147
+ "estimated_level": "复杂",
148
+ "recommended_flow": "完整 Sprint Flow (Phase 0-8)",
149
+ "risk_warnings": ["循环依赖: user ↔ plane"],
150
+ "user_decision": "accepted"
151
+ }
152
+ }
153
+ ```
154
+
155
+ #### 用户选择「修改流程」
156
+
157
+ > 展示修改流程子菜单(3 个选项:轻量/标准/完整)。
158
+ > 要求用户输入修改原因(必填)。
159
+
160
+ 记录到学习日志:
161
+ ```json
162
+ {
163
+ "sprint_id": "{sprint_id}",
164
+ "task_description": "{需求描述}",
165
+ "estimated_level": "标准",
166
+ "user_override_level": "轻量",
167
+ "override_reason": "{用户输入原因}",
168
+ "timestamp": "{当前时间}"
169
+ }
170
+ ```
171
+
172
+ 数据写入 `.sprint-state/auto-estimate-learning.json`(追加模式)。
173
+
174
+ #### 用户选择「取消」
175
+
176
+ > 停止本次 sprint。
177
+ > 输出:`[CANCELLED] 用户取消 Sprint,AUTO-ESTIMATE 评估结果为 {estimated_level}`。
178
+
179
+ ### 步骤 6: 路由执行
180
+
181
+ 根据最终确定的流程级别,进入对应 Phase:
182
+
183
+ | 流程级别 | 路由 |
184
+ |---------|------|
185
+ | **轻量** | → Phase 2 BUILD(跳过 Phase 0 brainstorming、Phase 1 delphi-review) |
186
+ | **标准** | → Phase 0 THINK(正常流程) |
187
+ | **复杂** | → Phase 0 THINK(完整流程 + 风险警告提示) |
188
+
189
+ ---
190
+
191
+ ## 特殊场景处理
192
+
193
+ ### 场景 1: 小改动(总计 < 20 行新增/删除代码)
194
+
195
+ ```bash
196
+ # 检查预估改动量
197
+ git diff --stat HEAD 2>/dev/null # 如果有局部修改
198
+ ```
199
+
200
+ **处理**: 如果预估改动 < 20 行且涉及 ≤ 2 个文件,自动判定为「轻量」并告知用户,不强制展示完整 AUTO-ESTIMATE 面板。
201
+
202
+ ### 场景 2: 无法提取目标关键词
203
+
204
+ **处理**: 询问用户「无法自动识别目标模块,请指定要分析的关键词(函数名/类名/模块名):」
205
+
206
+ ### 场景 3: 用户输入包含多个独立需求
207
+
208
+ **处理**: 提示用户「检测到多个独立需求,建议分别执行 sprint。是否拆分?」→ 等待确认
209
+
210
+ ---
211
+
212
+ ## 与学习循环的集成
213
+
214
+ ### 数据收集
215
+
216
+ 每次 sprint 完成(Phase 8 CLEANUP)后,将以下数据记录到 `.sprint-state/auto-estimate-learning.json`:
217
+
218
+ ```json
219
+ {
220
+ "entries": [
221
+ {
222
+ "sprint_id": "sprint-YYYY-MM-DD-NN",
223
+ "estimated_level": "标准",
224
+ "user_decision": "accepted",
225
+ "actual_effort_phase_count": 5,
226
+ "actual_duration_minutes": 45,
227
+ "was_accurate": true
228
+ }
229
+ ]
230
+ }
231
+ ```
232
+
233
+ ### 阈值优化
234
+
235
+ 当积累 ≥ 20 条记录后,提示用户可以运行阈值分析:
236
+
237
+ > 已积累 {n} 条 AUTO-ESTIMATE 记录。是否运行阈值优化分析?
238
+ > 分析会检查:过度估计(建议标准但实际轻量)、低估(建议轻量但实际复杂),并推荐阈值调整。
@@ -0,0 +1,136 @@
1
+ # AUTO-ESTIMATE 学习日志
2
+
3
+ 本文件记录 AUTO-ESTIMATE 的用户纠偏历史和完成数据,用于阈值迭代优化。
4
+
5
+ ## 文件位置
6
+
7
+ `.sprint-state/auto-estimate-learning.json`
8
+
9
+ ## JSON Schema
10
+
11
+ ```json
12
+ {
13
+ "entries": [
14
+ {
15
+ "sprint_id": "sprint-2026-06-01-14",
16
+ "task_description": "实现issue92 auto-estimate",
17
+ "change_type": "新增功能",
18
+ "estimated_level": "标准",
19
+ "estimated_metrics": {
20
+ "ref_count": null,
21
+ "cross_module_count": 2,
22
+ "circular_dep": false,
23
+ "public_api_count": 0,
24
+ "test_file_count": 0
25
+ },
26
+ "user_decision": "accepted",
27
+ "override_reason": null,
28
+ "actual_outcome": {
29
+ "phase_count": 3,
30
+ "duration_estimate": "30-45min",
31
+ "was_accurate": true,
32
+ "notes": "纯文档修改,实际确实为标准级别"
33
+ },
34
+ "timestamp": "2026-06-01T23:35:00+08:00"
35
+ }
36
+ ],
37
+ "summary": {
38
+ "total_entries": 1,
39
+ "accepted_count": 1,
40
+ "overridden_count": 0,
41
+ "accurate_count": 1,
42
+ "over_estimate_count": 0,
43
+ "under_estimate_count": 0,
44
+ "last_updated": "2026-06-01T23:35:00+08:00"
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## 字段说明
50
+
51
+ ### Entry 级别
52
+
53
+ | 字段 | 类型 | 必填 | 说明 |
54
+ |------|------|------|------|
55
+ | `sprint_id` | string | ✅ | Sprint 标识符 |
56
+ | `task_description` | string | ✅ | 需求描述 |
57
+ | `change_type` | string | ✅ | 变更类型:`删除已存在代码` / `修改已存在代码` / `新增功能` / `Bug修复` |
58
+ | `estimated_level` | string | ✅ | 评估级别:`轻量` / `标准` / `复杂` |
59
+ | `estimated_metrics` | object | ✅ | 评估时的指标数据 |
60
+ | `user_decision` | string | ✅ | 用户决定:`accepted` / `overridden` / `cancelled` |
61
+ | `override_reason` | string | 条件 | 当 `user_decision` 为 `overridden` 时必填 |
62
+ | `actual_outcome` | object | 条件 | Sprint 完成后回填 |
63
+ | `timestamp` | string | ✅ | ISO 8601 时间戳 |
64
+
65
+ ### actual_outcome 级别
66
+
67
+ | 字段 | 类型 | 必填 | 说明 |
68
+ |------|------|------|------|
69
+ | `phase_count` | number | ✅ | 实际执行的 phase 数 |
70
+ | `duration_estimate` | string | 推荐 | 实际耗时估算 |
71
+ | `was_accurate` | boolean | ✅ | 评估是否准确 |
72
+ | `notes` | string | 推荐 | 备注说明 |
73
+
74
+ ### summary 级别
75
+
76
+ | 字段 | 类型 | 说明 |
77
+ |------|------|------|
78
+ | `total_entries` | number | 总条目数 |
79
+ | `accepted_count` | number | 接受建议数 |
80
+ | `overridden_count` | number | 用户修改数 |
81
+ | `accurate_count` | number | 评估准确数 |
82
+ | `over_estimate_count` | number | 高估数(建议标准但实际轻量) |
83
+ | `under_estimate_count` | number | 低估数(建议轻量但实际复杂) |
84
+
85
+ ## 初始化
86
+
87
+ 新 sprint 创建时,自动创建 `.sprint-state/auto-estimate-learning.json`:
88
+
89
+ ```json
90
+ {
91
+ "entries": [],
92
+ "summary": {
93
+ "total_entries": 0,
94
+ "accepted_count": 0,
95
+ "overridden_count": 0,
96
+ "accurate_count": 0,
97
+ "over_estimate_count": 0,
98
+ "under_estimate_count": 0,
99
+ "last_updated": null
100
+ }
101
+ }
102
+ ```
103
+
104
+ ## 阈值优化触发
105
+
106
+ 当 `total_entries >= 20` 时,在 Phase 8 CLEANUP 阶段提示用户:
107
+
108
+ ```
109
+ 已积累 20 条 AUTO-ESTIMATE 记录。是否运行阈值优化分析?
110
+
111
+ 当前准确率:{accurate_count / total_entries * 100}%
112
+ 高估率:{over_estimate_count / total_entries * 100}%
113
+ 低估率:{under_estimate_count / total_entries * 100}%
114
+
115
+ [运行分析] [跳过]
116
+ ```
117
+
118
+ ## 阈值优化规则
119
+
120
+ ### 高估模式检测
121
+
122
+ IF `over_estimate_count / total_entries > 30%`:
123
+ → 建议降低「标准」→「复杂」的引用计数阈值(当前 >10)
124
+ → 分析高估的共性:是否某个指标权重过高?
125
+
126
+ ### 低估模式检测
127
+
128
+ IF `under_estimate_count / total_entries > 20%`:
129
+ → 建议增加额外检查项(如循环依赖、测试文件数)
130
+ → 分析低估的共性:是否遗漏了关键复杂度信号?
131
+
132
+ ### 纠偏频率检测
133
+
134
+ IF `overridden_count / total_entries > 30%`:
135
+ → 用户频繁修改建议 → 阈值体系可能有问题
136
+ → 建议全面阈值校准