dsh-mem0-memory 0.1.2 → 0.1.3

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 CHANGED
@@ -5,6 +5,11 @@
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ### 0.1.3(2026-08-22)
9
+
10
+ - **工作区排除(召回侧)**:排除工作区的会话不再召回/注入记忆——插件通过 `ctx.agents.requireInitiator()` 获取当前会话 cwd,判定与 G1 写入侧一致:cwd 路径段 `0_` 前缀(写死约定)+ 新增 `excludeWorkspaces` 配置(名单子串匹配,对应 G1 excluded-workspaces.json)。排除工作区对话省去召回延时(每轮 5-10s),内容本就不入库。
11
+ - 配置新增:`excludeWorkspaces: []`(默认空;如 `["财富密码"]`)。
12
+
8
13
  ### 0.1.2(2026-08-22)
9
14
 
10
15
  - **降级可见性**:embedding API 故障触发关键词降级时,召回注入块现在会带警告行「⚠️ 注意:embedding 服务超时/故障,以下为降级关键词搜索结果(语义通道暂不可用),召回覆盖度可能下降。」——插件此前丢弃了 server 响应的 `degraded/mode` 标记,降级期间会话对结果质量下降毫不知情;已透传并对齐 OpenClaw 侧 mem0-memory 的 recall.js 实现。
package/README.md CHANGED
@@ -209,6 +209,7 @@ dsh-mem0-search "关键词" --json # 原始 JS
209
209
  | `source` | (空) | 只召回指定来源(多源场景) |
210
210
  | `probePath` | (空=关) | 排障探针日志文件路径(设置后才写文件) |
211
211
  | `autoImport` | true | 会话结束自动增量导入(关 = 只用手动/定时) |
212
+ | `excludeWorkspaces` | `[]` | 不召回的工作区名单(子串匹配会话 cwd;另 `0_` 前缀工作区写死排除) |
212
213
 
213
214
  ## 工作原理
214
215
 
package/lib/index.js CHANGED
@@ -210,6 +210,16 @@ function extractLastUserText(messages) {
210
210
  export const name = "dsh-mem0-memory";
211
211
  export const inject = ["agents"];
212
212
 
213
+ // ─── 工作区排除(2026-08-22,与 G1 判定一致)────────────────────────────
214
+ // 排除工作区的会话:不召回也不注入(该区内容本就不入库,召回只会带来延时开销)。
215
+ // 判定:① cwd 路径任一段以 `0_` 开头(写死约定,与 G1 EXCLUDE_PREFIX 一致)
216
+ // ② config.excludeWorkspaces 名单子串匹配(对应 G1 excluded-workspaces.json)
217
+ function isExcludedWorkspace(cwd, list) {
218
+ if (!cwd) return false;
219
+ if (String(cwd).split(/[\\/]/).some((s) => s.startsWith("0_"))) return true;
220
+ return (list ?? []).some((e) => e && String(cwd).includes(String(e)));
221
+ }
222
+
213
223
  export async function apply(ctx, config = {}) {
214
224
  // 探针(排障用,默认关闭):设置 config.probePath 后,apply 执行即写文件——
215
225
  // 用于区分「插件未加载」vs「加载了但 pre-step 未触发」。默认不写任何文件。
@@ -232,6 +242,7 @@ export async function apply(ctx, config = {}) {
232
242
  timeoutMs: config.timeoutMs ?? MEM0_SEARCH_TIMEOUT_MS,
233
243
  source: config.source, // 可选
234
244
  autoImport: config.autoImport !== false, // 会话结束自动增量导入(默认开,三档机制①)
245
+ excludeWorkspaces: config.excludeWorkspaces ?? [], // 可选:工作区名单子串(对应 G1 excluded-workspaces.json)
235
246
  };
236
247
  if (!cfg.enabled) {
237
248
  ctx.logger?.info("[mem0-memory] disabled");
@@ -267,6 +278,20 @@ export async function apply(ctx, config = {}) {
267
278
 
268
279
  if (decision.kind !== "enter" || !Array.isArray(decision.messages)) return decision;
269
280
 
281
+ // 工作区排除(2026-08-22):当前会话 cwd 属于排除工作区 → 跳过召回(不注入)。
282
+ // 判定与 G1 一致(0_ 前缀 + excludeWorkspaces 名单子串);拿不到 cwd 则不排除。
283
+ let cwd = "";
284
+ try {
285
+ const agent = ctx.agents?.requireInitiator?.();
286
+ cwd = agent?.session?.cwd ?? "";
287
+ } catch (e) {}
288
+ await probe(`workspace cwd=${cwd || "unknown"}`);
289
+ if (isExcludedWorkspace(cwd, cfg.excludeWorkspaces)) {
290
+ ctx.logger?.info(`[mem0-memory] workspace excluded (skip recall): ${cwd || "(unknown)"}`);
291
+ await probe("workspace excluded, skip recall");
292
+ return decision;
293
+ }
294
+
270
295
  try {
271
296
  const query = extractLastUserText(decision.messages);
272
297
  await probe(`query extracted: ${query ? query.slice(0, 80) : "NULL"}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mem0-memory",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Thin bridge: recall Mem0 memories into DSH agent context via agent/pre-step injection.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",