@hupan56/wlkj 2.2.5 → 2.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hupan56/wlkj",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "AI Product R&D Workflow - PRD/Prototype/Search/Task/Report",
5
5
  "bin": {
6
6
  "wlkj": "bin/cli.js"
@@ -64,6 +64,37 @@ CN_MAP = {
64
64
  '分类': 'category classify', '类型': 'type',
65
65
  '地区': 'region area', '区域': 'zone region',
66
66
  '时间': 'time date', '日期': 'date',
67
+ # 异常/品质/合规 (高频但之前缺失, 导致"异常记录"搜不到)
68
+ '异常': 'abnormal anomaly exception', '故障': 'fault error failure',
69
+ '报警': 'alarm alert warning', '违规': 'violation breach',
70
+ '合规': 'compliance', '风险': 'risk hazard',
71
+ '处理': 'handle process deal', '反馈': 'feedback',
72
+ # 筛选/查询 (PRD 高频, "新增筛选条件"类需求)
73
+ '筛选': 'filter search', '过滤': 'filter',
74
+ '搜索': 'search query', '查询': 'query search find',
75
+ '条件': 'condition filter criteria',
76
+ '排序': 'sort order', '分组': 'group',
77
+ # 页面/交互
78
+ '列表': 'list table', '详情': 'detail info',
79
+ '弹窗': 'modal dialog popup', '抽屉': 'drawer',
80
+ '表单': 'form', '表格': 'table grid',
81
+ '看板': 'dashboard board panel', '大屏': 'screen monitor dashboard',
82
+ '图表': 'chart graph', '柱状图': 'bar chart',
83
+ '饼图': 'pie chart', '折线图': 'line chart',
84
+ # 项目类型/业务对象 (本次需求触发)
85
+ '项目类型': 'projectType project type',
86
+ '业务对象': 'business object entity',
87
+ # 导入导出增强
88
+ '上传': 'upload import', '下载': 'download export',
89
+ '打印': 'print', '预览': 'preview',
90
+ # 人员/身份增强
91
+ '人员': 'person personnel staff user',
92
+ '负责人': 'owner manager charge',
93
+ '驾驶员': 'driver',
94
+ # 地图/位置
95
+ '地图': 'map gis',
96
+ '位置': 'location position gps',
97
+ '轨迹': 'track trajectory gps',
67
98
  }
68
99
 
69
100
  # Chinese business term -> code path/identifier patterns.
@@ -120,6 +151,15 @@ BUSINESS_PATH_MAP = {
120
151
  '消息': ['message', 'Message', 'notify', 'Notify'],
121
152
  '配置': ['config', 'Config', 'setting', 'Setting'],
122
153
  '字典': ['dict', 'Dict', 'dictionary', 'Dictionary'],
154
+ # 异常/品质/合规 (新增, 解决"异常记录"搜不到)
155
+ '异常': ['abnormal', 'Abnormal', 'anomaly', 'Anomaly', 'exception', 'Exception'],
156
+ '故障': ['fault', 'Fault', 'error', 'Error', 'failure', 'Failure'],
157
+ '合规': ['compliance', 'Compliance'],
158
+ '看板': ['dashboard', 'Dashboard', 'board', 'Board', 'panel', 'Panel'],
159
+ '大屏': ['screen', 'Screen', 'monitor', 'Monitor', 'dashboard'],
160
+ '地图': ['map', 'Map', 'gis', 'GIS'],
161
+ '轨迹': ['track', 'Track', 'trajectory', 'gps', 'GPS'],
162
+ '筛选': ['filter', 'Filter', 'search', 'Search'],
123
163
  }
124
164
 
125
165
  # Chinese term -> single primary English keyword (derived from CN_MAP).
@@ -178,8 +218,8 @@ PRD_STOP_WORDS = {
178
218
  '以及', '如果', '那么', '但是', '因为', '所以', '用户', '系统', '页面', '数据',
179
219
  '信息', '操作', '管理', '列表', '详情', '新增', '修改', '删除', '查询', '搜索',
180
220
  '筛选', '点击', '选择', '输入', '确认', '取消', '保存', '提交', '返回', '跳转',
181
- '当前', '前端', '后端', '影响', '范围', '下拉', '条件', '字段', '全部', '异常',
182
- '正常', '记录', '面板', '统计', '表页', '搜索表', '与其他', '表单', '背景',
221
+ '当前', '前端', '后端', '影响', '范围', '下拉', '条件', '字段', '全部',
222
+ '正常', '面板', '统计', '表页', '搜索表', '与其他', '表单', '背景',
183
223
  '一个', '这个', '那个', '通过', '根据', '按照', '同时', '并且',
184
224
  '要求', '需求', '描述', '说明', '备注', '注意', '重要', '优先', '级别',
185
225
  '方案', '设计', '开发', '测试', '上线', '版本', '迭代', '更新', '发布',
@@ -78,7 +78,82 @@ def _search_cache_key(query, platform):
78
78
  return hashlib.md5(raw.encode('utf-8')).hexdigest()[:16]
79
79
 
80
80
 
81
+ def _check_index_freshness():
82
+ """轻量检查索引是否过期 (代码改了但索引没更新)。
83
+
84
+ 抽样 data/code/ 下最新修改的文件, 与 .index-meta.json 的 last_sync 比。
85
+ 过期则打印提示 (不阻塞搜索)。
86
+ 用一个静默文件标记避免每次搜索都提示 (.runtime/.index-stale-warned)。
87
+ """
88
+ try:
89
+ import datetime as _dt
90
+ meta_path = os.path.join(BASE, 'data', 'index', '.index-meta.json')
91
+ if not os.path.isfile(meta_path):
92
+ return
93
+ with open(meta_path, encoding='utf-8') as f:
94
+ meta = json.load(f)
95
+ last_sync_str = meta.get('last_sync', '')
96
+ if not last_sync_str:
97
+ return
98
+ last_sync = _dt.datetime.strptime(last_sync_str, '%Y-%m-%d %H:%M')
99
+
100
+ # 抽样: 找 data/code/ 下最新修改的 .java/.vue/.js 文件 (只扫一层子目录的最近文件)
101
+ code_dir = os.path.join(BASE, 'data', 'code')
102
+ if not os.path.isdir(code_dir):
103
+ return
104
+ newest_mtime = 0
105
+ for proj in os.listdir(code_dir):
106
+ proj_dir = os.path.join(code_dir, proj)
107
+ if not os.path.isdir(proj_dir):
108
+ continue
109
+ # 只看 src 目录下的文件 (避免 .git 干扰)
110
+ src_dir = os.path.join(proj_dir, 'src')
111
+ if not os.path.isdir(src_dir):
112
+ continue
113
+ # 抽样: os.walk 只走一层 (限制深度), 找最新 mtime
114
+ for root, dirs, files in os.walk(src_dir):
115
+ # 限制深度: 只走 3 层 (够采样, 不全扫)
116
+ depth = root[len(src_dir):].count(os.sep)
117
+ if depth >= 3:
118
+ dirs[:] = []
119
+ continue
120
+ for fn in files:
121
+ if fn.endswith(('.java', '.vue', '.js', '.ts')):
122
+ try:
123
+ mt = os.path.getmtime(os.path.join(root, fn))
124
+ if mt > newest_mtime:
125
+ newest_mtime = mt
126
+ except OSError:
127
+ pass
128
+ if newest_mtime > 0:
129
+ break # 拿到一个项目的最新就够了
130
+
131
+ if newest_mtime <= 0:
132
+ return
133
+ newest_dt = _dt.datetime.fromtimestamp(newest_mtime)
134
+ # 过期判定: 代码文件比索引新超过 1 小时
135
+ if (newest_dt - last_sync).total_seconds() > 3600:
136
+ # 静默标记: 避免每次搜索都提示 (索引更新后标记自动失效)
137
+ warned_path = os.path.join(BASE, '.qoder', '.runtime', '.index-stale-warned')
138
+ warn_mtime = os.path.getmtime(warned_path) if os.path.isfile(warned_path) else 0
139
+ meta_mtime = os.path.getmtime(meta_path)
140
+ if warn_mtime > meta_mtime:
141
+ return # 已经提示过了 (在本次索引周期内)
142
+ print('[提示] 代码有更新但知识图谱未刷新 (上次索引: %s)' % last_sync_str)
143
+ print(' 刷新: python .qoder/scripts/git_sync.py --index-only')
144
+ try:
145
+ os.makedirs(os.path.dirname(warned_path), exist_ok=True)
146
+ open(warned_path, 'w').close()
147
+ except OSError:
148
+ pass
149
+ except Exception:
150
+ pass # 新鲜度检查失败不阻塞搜索
151
+
152
+
81
153
  def search_keywords(query, platform=None):
154
+ # 新鲜度检查 (代码改了但索引没更新 → 提示, 不阻塞)
155
+ _check_index_freshness()
156
+
82
157
  # 结果缓存: 同 query+platform+索引未变 → 直接返回缓存输出
83
158
  cache_key = _search_cache_key(query, platform)
84
159
  cache_path = os.path.join(BASE, '.qoder', '.runtime', 'search-cache-%s.txt' % cache_key)
@@ -114,6 +189,53 @@ def search_keywords(query, platform=None):
114
189
  pass
115
190
 
116
191
 
192
+ def _expand_chinese_query(query):
193
+ """把中文查询拆成英文搜索词。
194
+
195
+ 三级匹配:
196
+ 1. 精确匹配: "异常" 在 CN_MAP → 直接扩展
197
+ 2. 分词匹配: "异常记录" → 拆成 "异常" + "记录", 各自扩展
198
+ (贪心最长匹配: 从长到短扫 CN_MAP 的 key)
199
+ 3. 兜底: 拆不出来的部分, 原样小写 (让英文子串索引做匹配)
200
+
201
+ 同时合并 BUSINESS_PATH_MAP 的路径模式。
202
+ """
203
+ words = []
204
+ # 合并 CN_MAP + PRD 自动扩展
205
+ try:
206
+ from common.terms import get_cn_map_with_auto
207
+ cn_map = get_cn_map_with_auto()
208
+ except ImportError:
209
+ cn_map = CN_MAP
210
+
211
+ # 1. 精确匹配
212
+ if query in cn_map:
213
+ words.extend(cn_map[query].split())
214
+ if query in BUSINESS_PATH_MAP:
215
+ words.extend(p.strip('/-').lower() for p in BUSINESS_PATH_MAP[query])
216
+
217
+ # 2. 分词匹配 (查询比单个 CN_MAP key 长 → 需要拆词)
218
+ if not words and len(query) >= 3:
219
+ # 贪心最长匹配: 把 CN_MAP keys 按长度降序排, 逐个从 query 里找
220
+ remaining = query
221
+ matched_segments = []
222
+ for cn in sorted(cn_map.keys(), key=len, reverse=True):
223
+ if cn in remaining:
224
+ matched_segments.append(cn)
225
+ remaining = remaining.replace(cn, ' ')
226
+ if matched_segments:
227
+ for seg in matched_segments:
228
+ words.extend(cn_map[seg].split())
229
+ if seg in BUSINESS_PATH_MAP:
230
+ words.extend(p.strip('/-').lower() for p in BUSINESS_PATH_MAP[seg])
231
+ # 剩余的英文/数字片段也加进去 (兜底)
232
+ for frag in remaining.split():
233
+ if frag and frag.isascii():
234
+ words.append(frag.lower())
235
+
236
+ return words
237
+
238
+
117
239
  def _search_keywords_impl(query, platform=None):
118
240
  """实际的搜索逻辑 (原 search_keywords 内容)。"""
119
241
  ki = load_index('keyword-index.json', hint='Run: python git_sync.py')
@@ -121,11 +243,7 @@ def _search_keywords_impl(query, platform=None):
121
243
  return
122
244
 
123
245
  # Expand Chinese query via the shared term maps (same maps used at build time)
124
- words = []
125
- if query in CN_MAP:
126
- words.extend(CN_MAP[query].split())
127
- if query in BUSINESS_PATH_MAP:
128
- words.extend(p.strip('/-').lower() for p in BUSINESS_PATH_MAP[query])
246
+ words = _expand_chinese_query(query)
129
247
  if words:
130
248
  words = sorted(set(w.lower() for w in words))
131
249
  print('Chinese: {} -> English: {}'.format(query, ' '.join(words)))