lumencode 1.3.1 → 1.3.2
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/index.js +348 -343
- package/lib/aggregate.js +58 -3
- package/lib/config.js +21 -8
- package/lib/path-utils.js +18 -0
- package/lib/report.js +969 -53
- package/lib/scenario.js +29 -4
- package/lib/server.js +331 -316
- package/package.json +1 -1
- package/public/app.js +232 -17
- package/public/config.js +1 -0
- package/public/export.js +11 -7
- package/public/index.html +77 -16
- package/public/style.css +248 -1
- package/public/utils.js +218 -0
package/lib/scenario.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
// 基于工具调用 + 用户文本关键词的使用场景分类引擎
|
|
2
2
|
|
|
3
|
+
export function escapeRegExp(string) {
|
|
4
|
+
return string.replace(/[-.*+?^${}()|[\]\\]/g, '\\$&');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function matchesKeyword(text, keyword) {
|
|
8
|
+
if (!text || !keyword) return false;
|
|
9
|
+
const t = text.toLowerCase();
|
|
10
|
+
const k = keyword.trim().toLowerCase();
|
|
11
|
+
if (!k) return false;
|
|
12
|
+
|
|
13
|
+
// 中文关键词:使用包含匹配(中文无词分隔符,边界匹配会误杀正常匹配)
|
|
14
|
+
if (/\p{Script=Han}/u.test(k)) {
|
|
15
|
+
return t.includes(k);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 英文关键词:词边界匹配
|
|
19
|
+
// 处理以非单词字符开头/结尾的关键词(如 /review)
|
|
20
|
+
const escaped = escapeRegExp(k);
|
|
21
|
+
const prefix = /^\w/.test(k) ? '\\b' : '(?:^|\\s)';
|
|
22
|
+
const suffix = /\w$/.test(k) ? '\\b' : '(?:$|\\s)';
|
|
23
|
+
const regex = new RegExp(`${prefix}${escaped}${suffix}`);
|
|
24
|
+
return regex.test(t);
|
|
25
|
+
}
|
|
26
|
+
|
|
3
27
|
const TOOL_SCENARIO_MAP = {
|
|
4
28
|
// Claude Code
|
|
5
29
|
Write: 'coding',
|
|
@@ -101,12 +125,9 @@ export function classifyRecord(record, scenarioKeywords) {
|
|
|
101
125
|
const recordType = record.metadata?.type || record.type;
|
|
102
126
|
const recordText = record.metadata?.text || record.text;
|
|
103
127
|
if (recordType === 'user' && recordText && scenarioKeywords) {
|
|
104
|
-
const lowerText = recordText.toLowerCase();
|
|
105
128
|
for (const [scenario, keywords] of Object.entries(scenarioKeywords)) {
|
|
106
129
|
for (const kw of keywords) {
|
|
107
|
-
|
|
108
|
-
// 简化正则表达式,对于中文使用简单的包含匹配
|
|
109
|
-
if (lowerText.includes(lowerKw)) {
|
|
130
|
+
if (matchesKeyword(recordText, kw)) {
|
|
110
131
|
scenarios[scenario] = (scenarios[scenario] || 0) + 1;
|
|
111
132
|
break;
|
|
112
133
|
}
|
|
@@ -127,6 +148,7 @@ export function mapToDisplayScenarios(internalScenarios) {
|
|
|
127
148
|
'阅读/研究': 0,
|
|
128
149
|
'规划/设计': 0,
|
|
129
150
|
'代码审查': 0,
|
|
151
|
+
'重构': 0,
|
|
130
152
|
'其他': 0,
|
|
131
153
|
};
|
|
132
154
|
|
|
@@ -154,6 +176,9 @@ export function mapToDisplayScenarios(internalScenarios) {
|
|
|
154
176
|
case 'review':
|
|
155
177
|
display['代码审查'] += count;
|
|
156
178
|
break;
|
|
179
|
+
case 'refactoring':
|
|
180
|
+
display['重构'] += count;
|
|
181
|
+
break;
|
|
157
182
|
case 'execution':
|
|
158
183
|
display['编码'] += count;
|
|
159
184
|
break;
|