@a9i5k4/dsh-auto-memory 0.1.19 → 0.1.20

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/cordis.patch.yml CHANGED
@@ -5,5 +5,5 @@
5
5
  # the `dsh.client` declaration in package.json makes the browser half
6
6
  # (exports "./client", served at /plugins/<id>/client.js) load in the web GUI.
7
7
  - insert:
8
- - id: auto-memory-dev
9
- name: '@deepseek-ai/dsh-auto-memory'
8
+ - id: auto-memory
9
+ name: '@a9i5k4/dsh-auto-memory'
package/lib/index.js CHANGED
@@ -842,6 +842,8 @@ class MemoryEngine {
842
842
  async recall(query, limit = 8, agent) {
843
843
  const q = String(query || '').toLowerCase().trim()
844
844
  if (!q) return 'memory_recall: query 为空。'
845
+ // 多词查询:按空白/中文标点分词,任一词命中即算命中(OR),按命中词数排序取相关度最高的
846
+ const terms = q.split(/[\s,,、;;。::]+/).filter((t) => t.length > 0)
845
847
  const p = await this.resolvePaths(agent)
846
848
  const out = []
847
849
  const hits = []
@@ -850,12 +852,17 @@ class MemoryEngine {
850
852
  if (!text) return
851
853
  const matched = []
852
854
  for (const line of text.split('\n')) {
853
- if (line.toLowerCase().includes(q)) {
854
- matched.push(line.trim().slice(0, 200))
855
- if (matched.length >= maxMatches) break
855
+ const low = line.toLowerCase()
856
+ const score = terms.reduce((a, t) => a + (low.includes(t) ? 1 : 0), 0)
857
+ if (score > 0) {
858
+ matched.push({ line: line.trim().slice(0, 200), score })
859
+ if (matched.length >= maxMatches * 4) break
856
860
  }
857
861
  }
858
- if (matched.length) target.push({ where: label, matches: matched })
862
+ if (matched.length) {
863
+ matched.sort((a, b) => b.score - a.score)
864
+ target.push({ where: label, matches: matched.slice(0, maxMatches).map((m) => m.line) })
865
+ }
859
866
  }
860
867
  // 读取顺序:progress(日志/反思)先行,再读 memory(用户级/项目笔记)
861
868
  const logs = await this.listDailyLogs(p.projectDir, 40)
@@ -2136,6 +2143,12 @@ class ExternalMemory {
2136
2143
  async search(query, limit = 6) {
2137
2144
  const q = String(query || '').toLowerCase().trim()
2138
2145
  if (!q) return []
2146
+ // 多词查询:任一词命中即算命中(OR),按命中词数排序取相关度最高的
2147
+ const terms = q.split(/[\s,,、;;。::]+/).filter((t) => t.length > 0)
2148
+ const scoreLine = (line) => {
2149
+ const low = line.toLowerCase()
2150
+ return terms.reduce((a, t) => a + (low.includes(t) ? 1 : 0), 0)
2151
+ }
2139
2152
  const srcs = await this.discover(false)
2140
2153
  const out = []
2141
2154
  for (const s of srcs) {
@@ -2147,22 +2160,28 @@ class ExternalMemory {
2147
2160
  if (hits.length >= 3 || scanned >= 8 || out.length >= limit) break
2148
2161
  scanned++
2149
2162
  const text = await this.extractSessionText(f.path)
2163
+ const matched = []
2150
2164
  for (const line of text.split('\n')) {
2151
- if (line.toLowerCase().includes(q)) {
2152
- hits.push('(' + path.basename(f.path).slice(0, 20) + ') ' + line.trim().slice(0, 200))
2153
- if (hits.length >= 3) break
2165
+ const score = scoreLine(line)
2166
+ if (score > 0) {
2167
+ matched.push({ line: '(' + path.basename(f.path).slice(0, 20) + ') ' + line.trim().slice(0, 200), score })
2168
+ if (matched.length >= 6) break
2154
2169
  }
2155
2170
  }
2171
+ matched.sort((a, b) => b.score - a.score)
2172
+ hits.push(...matched.slice(0, 3).map((m) => m.line))
2156
2173
  }
2157
2174
  } else {
2158
2175
  const matched = []
2159
2176
  for (const line of s.content.split('\n')) {
2160
- if (line.toLowerCase().includes(q)) {
2161
- matched.push(line.trim().slice(0, 200))
2162
- if (matched.length >= 3) break
2177
+ const score = scoreLine(line)
2178
+ if (score > 0) {
2179
+ matched.push({ line: line.trim().slice(0, 200), score })
2180
+ if (matched.length >= 9) break
2163
2181
  }
2164
2182
  }
2165
- hits.push(...matched)
2183
+ matched.sort((a, b) => b.score - a.score)
2184
+ hits.push(...matched.slice(0, 3).map((m) => m.line))
2166
2185
  }
2167
2186
  if (hits.length) out.push({ source: s.name, tool: s.tool, kind: s.kind, lines: hits })
2168
2187
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@a9i5k4/dsh-auto-memory",
3
3
  "description": "DSH 自动记忆插件:三层记忆(用户级/项目笔记/每日日志)自动注入与检索、每轮对话自动沉淀、每日反思、可视化面板与设置页,支持继承其他 AI 工具的记忆。",
4
- "version": "0.1.19",
4
+ "version": "0.1.20",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {