@mycodemap/mycodemap 0.1.0 → 0.1.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/CHANGELOG.md +86 -6
- package/README.md +172 -80
- package/dist/cli/commands/cycles.d.ts.map +1 -1
- package/dist/cli/commands/cycles.js +2 -0
- package/dist/cli/commands/cycles.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +3 -1
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/logs.d.ts +5 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +189 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/report.d.ts +12 -0
- package/dist/cli/commands/report.d.ts.map +1 -0
- package/dist/cli/commands/report.js +158 -0
- package/dist/cli/commands/report.js.map +1 -0
- package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
- package/dist/cli/commands/watch-foreground.js +2 -0
- package/dist/cli/commands/watch-foreground.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +2 -0
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/first-run-guide.d.ts +23 -0
- package/dist/cli/first-run-guide.d.ts.map +1 -0
- package/dist/cli/first-run-guide.js +83 -0
- package/dist/cli/first-run-guide.js.map +1 -0
- package/dist/cli/index.js +63 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/platform-check.d.ts +21 -0
- package/dist/cli/platform-check.d.ts.map +1 -0
- package/dist/cli/platform-check.js +94 -0
- package/dist/cli/platform-check.js.map +1 -0
- package/dist/cli/tree-sitter-check.d.ts +35 -0
- package/dist/cli/tree-sitter-check.d.ts.map +1 -0
- package/dist/cli/tree-sitter-check.js +133 -0
- package/dist/cli/tree-sitter-check.js.map +1 -0
- package/dist/cli/utils/sanitize.d.ts +54 -0
- package/dist/cli/utils/sanitize.d.ts.map +1 -0
- package/dist/cli/utils/sanitize.js +131 -0
- package/dist/cli/utils/sanitize.js.map +1 -0
- package/docs/AI_ASSISTANT_SETUP.md +743 -0
- package/docs/CI_GATEWAY_DESIGN.md +784 -0
- package/docs/OMC_TEAM_DEBUG_REPORT.md +285 -0
- package/docs/PUBLISH_NPM_DESIGN_FINAL.md +485 -0
- package/docs/REFACTOR_ARCHITECTURE_OVERVIEW.md +552 -0
- package/docs/REFACTOR_CONFIDENCE_DESIGN.md +244 -0
- package/docs/REFACTOR_GIT_ANALYZER_DESIGN.md +785 -0
- package/docs/REFACTOR_ORCHESTRATOR_DESIGN.md +1065 -0
- package/docs/REFACTOR_REQUIREMENTS.md +970 -0
- package/docs/REFACTOR_RESULT_FUSION_DESIGN.md +315 -0
- package/docs/REFACTOR_TEST_LINKER_DESIGN.md +311 -0
- package/docs/SETUP_GUIDE.md +407 -0
- package/docs/archive/AI_INTEGRATION_GUIDE_ARCHIVED.md +385 -0
- package/docs/archive/PUBLISH_NPM_DESIGN_V1.md +1693 -0
- package/docs/archive/PUBLISH_NPM_DESIGN_V2.md +390 -0
- package/docs/archive/TASK_DESIGN_COVERAGE_REPORT.md +314 -0
- package/docs/plans/POST_TASK_PLAN.md +129 -0
- package/docs/plans/archive/2026-03-03-deps-path-extension-fix.md +186 -0
- package/examples/README.md +61 -0
- package/examples/claude/codemap-skill.md +94 -0
- package/examples/codex/codemap-agent.md +66 -0
- package/examples/copilot/copilot-instructions.md +24 -0
- package/examples/kimi/codemap-skill.md +92 -0
- package/package.json +5 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# 置信度机制详细设计
|
|
2
|
+
|
|
3
|
+
> 版本: 2.4
|
|
4
|
+
> 所属模块: 编排层 - 置信度计算
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. 设计原则
|
|
9
|
+
|
|
10
|
+
**核心思路**:不预测置信度,而是基于结果质量反推置信度。
|
|
11
|
+
|
|
12
|
+
借鉴搜索引擎的 Quality Score 模式,用结果数量、质量、场景匹配度三个维度计算置信度。
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 2. 数据结构设计
|
|
17
|
+
|
|
18
|
+
### 2.1 统一结果接口
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// src/orchestrator/confidence.ts
|
|
22
|
+
|
|
23
|
+
interface SearchResult {
|
|
24
|
+
file: string;
|
|
25
|
+
line?: number;
|
|
26
|
+
content: string;
|
|
27
|
+
score?: number; // SearchResult 原始分数
|
|
28
|
+
toolScore?: number; // UnifiedResult 原始分数
|
|
29
|
+
relevance?: number; // UnifiedResult 归一化分数
|
|
30
|
+
matches?: number; // 匹配次数(仅 SearchResult)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2.2 置信度结果
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
interface ConfidenceResult {
|
|
38
|
+
score: number; // 综合置信度 0-1
|
|
39
|
+
level: 'high' | 'medium' | 'low';
|
|
40
|
+
reasons: string[]; // 置信度判断的原因
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. 接口设计
|
|
47
|
+
|
|
48
|
+
### 3.1 辅助函数
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
/**
|
|
52
|
+
* 获取结果的相关度分数
|
|
53
|
+
* 兼容 SearchResult 和 UnifiedResult 格式
|
|
54
|
+
*/
|
|
55
|
+
function getRelevance(result: SearchResult): number {
|
|
56
|
+
// 优先使用 UnifiedResult 字段
|
|
57
|
+
if (result.relevance !== undefined) return result.relevance;
|
|
58
|
+
if (result.toolScore !== undefined) return result.toolScore;
|
|
59
|
+
// 回退到 SearchResult 字段
|
|
60
|
+
return result.score || 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 获取结果的匹配次数
|
|
65
|
+
*/
|
|
66
|
+
function getMatchCount(result: SearchResult): number {
|
|
67
|
+
return result.matches || 0;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3.2 置信度计算函数
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
/**
|
|
75
|
+
* 基于搜索结果质量计算置信度
|
|
76
|
+
* - 结果数量评分 (40%): 有结果比少好,结果多比少好
|
|
77
|
+
* - 结果质量评分 (40%): 高相关度结果占比
|
|
78
|
+
* - 场景匹配评分 (20%): 特定场景的额外验证
|
|
79
|
+
*/
|
|
80
|
+
function calculateConfidence(
|
|
81
|
+
results: SearchResult[],
|
|
82
|
+
intent: IntentType
|
|
83
|
+
): ConfidenceResult {
|
|
84
|
+
const reasons: string[] = [];
|
|
85
|
+
|
|
86
|
+
// 1. 结果数量评分 (40%)
|
|
87
|
+
const countScore = Math.min(results.length / 5, 1) * 0.4;
|
|
88
|
+
if (results.length === 0) {
|
|
89
|
+
reasons.push('无搜索结果');
|
|
90
|
+
} else if (results.length >= 3) {
|
|
91
|
+
reasons.push(`找到 ${results.length} 个相关结果`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 2. 结果质量评分 (40%)
|
|
95
|
+
const qualityScore = results.length > 0
|
|
96
|
+
? (results.reduce((sum, r) => sum + getRelevance(r), 0) / results.length) * 0.4
|
|
97
|
+
: 0;
|
|
98
|
+
const topRelevance = results.length > 0 ? getRelevance(results[0]) : 0;
|
|
99
|
+
if (results.length > 0 && topRelevance > 0.8) {
|
|
100
|
+
reasons.push(`最高相关度 ${(topRelevance * 100).toFixed(0)}%`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 3. 场景特定评分 (20%)
|
|
104
|
+
let scenarioScore = 0;
|
|
105
|
+
switch (intent) {
|
|
106
|
+
case 'impact':
|
|
107
|
+
// 影响分析:需要找到依赖关系
|
|
108
|
+
scenarioScore = results.some(r => getMatchCount(r) > 1) ? 0.2 : 0;
|
|
109
|
+
if (scenarioScore > 0) reasons.push('发现多处引用');
|
|
110
|
+
break;
|
|
111
|
+
case 'search':
|
|
112
|
+
// 搜索:高质量结果给予额外加分
|
|
113
|
+
scenarioScore = topRelevance > 0.9 ? 0.2 : 0;
|
|
114
|
+
break;
|
|
115
|
+
case 'dependency':
|
|
116
|
+
// 依赖:需要结构化依赖数据
|
|
117
|
+
scenarioScore = results.length > 0 ? 0.2 : 0;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const totalScore = countScore + qualityScore + scenarioScore;
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
score: totalScore,
|
|
125
|
+
level: totalScore >= 0.6 ? 'high' : totalScore >= 0.3 ? 'medium' : 'low',
|
|
126
|
+
reasons
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 4. 阈值配置
|
|
134
|
+
|
|
135
|
+
### 4.1 意图类型定义
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
type IntentType = 'impact' | 'dependency' | 'search' | 'documentation' |
|
|
139
|
+
'complexity' | 'overview' | 'refactor' | 'reference';
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 4.2 置信度阈值
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// 置信度阈值(按 intent 区分)
|
|
146
|
+
const CONFIDENCE_THRESHOLDS: Record<IntentType, { high: number; medium: number }> = {
|
|
147
|
+
impact: { high: 0.7, medium: 0.4 }, // 结构化数据,要求高
|
|
148
|
+
dependency: { high: 0.7, medium: 0.4 }, // 结构化数据,要求高
|
|
149
|
+
search: { high: 0.5, medium: 0.25 }, // 文本搜索,容忍度较高
|
|
150
|
+
documentation: { high: 0.5, medium: 0.25 }, // 文档搜索,容忍度较高
|
|
151
|
+
complexity: { high: 0.6, medium: 0.3 },
|
|
152
|
+
overview: { high: 0.6, medium: 0.3 },
|
|
153
|
+
refactor: { high: 0.6, medium: 0.3 },
|
|
154
|
+
reference: { high: 0.5, medium: 0.25 } // 参考实现,容忍度较高
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 获取指定 intent 的阈值
|
|
159
|
+
*/
|
|
160
|
+
function getThreshold(intent: IntentType, level: 'high' | 'medium'): number {
|
|
161
|
+
return CONFIDENCE_THRESHOLDS[intent]?.[level] ?? 0.5;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 5. 模块依赖
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
置信度模块 (confidence.ts)
|
|
171
|
+
│
|
|
172
|
+
├── 依赖类型: SearchResult (输入)
|
|
173
|
+
├── 依赖类型: IntentType (配置)
|
|
174
|
+
├── 输出类型: ConfidenceResult
|
|
175
|
+
│
|
|
176
|
+
└── 被以下模块使用:
|
|
177
|
+
└── ToolOrchestrator (tool-orchestrator.ts)
|
|
178
|
+
└── WorkflowOrchestrator (workflow-orchestrator.ts) (v2.5 新增)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 6. 工作流阶段的置信度指导 (v2.5 规划)
|
|
184
|
+
|
|
185
|
+
### 6.1 置信度与阶段推进
|
|
186
|
+
|
|
187
|
+
在编排层工作流中,置信度用于决定阶段推进策略:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
// 工作流阶段的置信度要求
|
|
191
|
+
|
|
192
|
+
const PHASE_CONFIDENCE_REQUIREMENTS: Record<string, { min: number; auto: boolean; autoThreshold?: number }> = {
|
|
193
|
+
reference: { min: 0.3, auto: true, autoThreshold: 0.7 }, // >=0.7 自动推进
|
|
194
|
+
impact: { min: 0.4, auto: true, autoThreshold: 0.7 }, // >=0.7 自动推进
|
|
195
|
+
risk: { min: 0, auto: false }, // 风险评估:始终需要用户确认
|
|
196
|
+
implementation: { min: 0, auto: false }, // 代码实现:需要用户触发
|
|
197
|
+
commit: { min: 0, auto: false }, // 提交:需要用户触发
|
|
198
|
+
ci: { min: 0, auto: false } // CI:自动执行
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 6.2 置信度事件
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
// 置信度触发的工作流事件
|
|
206
|
+
|
|
207
|
+
interface ConfidenceEvent {
|
|
208
|
+
phase: string;
|
|
209
|
+
confidence: ConfidenceResult;
|
|
210
|
+
event: 'high-confidence' | 'medium-confidence' | 'low-confidence' | 'fallback-triggered';
|
|
211
|
+
recommendation: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 事件处理
|
|
215
|
+
function handleConfidenceEvent(event: ConfidenceEvent): void {
|
|
216
|
+
switch (event.event) {
|
|
217
|
+
case 'high-confidence':
|
|
218
|
+
// 自动推进到下一阶段
|
|
219
|
+
workflow.proceedToNextPhase();
|
|
220
|
+
break;
|
|
221
|
+
case 'medium-confidence':
|
|
222
|
+
// 提示用户确认
|
|
223
|
+
console.log(`[WARNING] Medium confidence: ${event.confidence.reasons.join(', ')}`);
|
|
224
|
+
break;
|
|
225
|
+
case 'low-confidence':
|
|
226
|
+
// 阻止推进,要求更多分析
|
|
227
|
+
console.log(`[ERROR] Low confidence, cannot proceed: ${event.recommendation}`);
|
|
228
|
+
break;
|
|
229
|
+
case 'fallback-triggered':
|
|
230
|
+
// 记录回退事件
|
|
231
|
+
logFallbackEvent(event);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 7. 风险与缓解
|
|
240
|
+
|
|
241
|
+
| 风险 | 影响 | 缓解措施 |
|
|
242
|
+
|------|------|----------|
|
|
243
|
+
| 置信度计算不准确 | 过度回退或回退不足 | 基于实际结果迭代调参 |
|
|
244
|
+
| 场景评分权重不合理 | 某些场景效果差 | 支持配置化权重 |
|