@max-null/dsh-memory 0.7.3 → 0.8.0

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/README.md CHANGED
@@ -74,15 +74,18 @@ md 文件是唯一事实源(`~/.dsh/prompt-library/*.md` 为 global;`<worksp
74
74
 
75
75
  ```
76
76
  模型 memory_save → status: approved,立即生效;命中密钥/凭据规则则隔离(不进检索也不进注入)
77
+ 给 injected 则同时钉住常驻(0.8.0),不吃下面两条自动规则
77
78
  memory_search → 关键词/语义召回(只搜记忆;模板走 prompt_search 通道,不会混进候选池)
78
79
  命中累计 2 次 → injected: true(自动打开常驻:global + 当前会话工作区,摘要化 + 预算截断)
79
- 30 天未再命中 → 自动撤下常驻(只撤自动开的;人工动过的开关双向豁免)
80
+ 30 天未再命中 → 自动撤下常驻(只撤自动开的;人工或模型显式动过的开关双向豁免)
80
81
  人(面板 / 开关) → 钉住 / 删除 / 放行隔离记录 / 回滚
81
82
  memory_forget → 随时删除(删除始终是人的动作)
82
83
  ```
83
84
 
84
85
  两条自动规则撑起淘汰机制:**反复被检索命中**是它值得每轮付费的证据,**长期不再被命中**则自动退出常驻。两者都不删除任何内容——记忆不会无限累积,也不会被系统自行清空。
85
86
 
87
+ 自动规则对**低频但关键**的记忆(长期约定、判据、委托)够不着:它们不会被反复检索,够不到阈值;勉强够到也会被 30 天撤下。这类走显式路径——在 `memory_save` / `memory_update` 里给 `injected` 即钉住,写的是与面板开关同一套语义(`injectedAuto: false`),此后不受两条自动规则影响。未审核与已隔离的记录不接受注入。
88
+
86
89
  记忆还可声明**有效性锚点**(环境变量 / 工具清单 / 插件版本):所绑的值变化后,这条记忆被标记 `stale` 并撤下常驻,检索结果里也带出失效提示——环境变了,旧结论就不再被当成仍然正确。
87
90
 
88
91
  模型写入不需要人点头,但**人始终能看见并推翻**:面板按「隔离区 / 常驻 / 冷数据」分组,被隔离的记录必须由人放行才会重新进入检索。
package/dist/engine.d.ts CHANGED
@@ -94,6 +94,12 @@ export interface MemoryWrite {
94
94
  * 失效。只用于「随环境变化的事实」(某工具版本下的行为、某环境变量决定的配置)。
95
95
  */
96
96
  anchor?: MemoryAnchor;
97
+ /**
98
+ * 常驻注入(可选,2026-09-18):显式指定这条记忆是否每轮进上下文。**给值即接管**——
99
+ * 与 {@link MemoryEngine.setInjected} 同一套语义(写 `injectedAuto: false`,此后不受自动
100
+ * 升降影响)。省略则维持缺省行为:不注入,且**保留**「被反复命中即自动升常驻」的资格。
101
+ */
102
+ injected?: boolean;
97
103
  }
98
104
  export interface MemoryFilter {
99
105
  namespace?: MemoryNamespace;
@@ -104,6 +110,16 @@ export interface MemoryFilter {
104
110
  /** 记录类别过滤(0.6.0);缺省不过滤(工具层显式传 kind='fact' 保持旧行为)。 */
105
111
  kind?: MemoryKind;
106
112
  }
113
+ /** {@link MemoryEngine.update} 的补丁:省略的字段保持原值(`injected` 省略时连 `injectedAuto` 一起保持)。 */
114
+ export interface MemoryPatch {
115
+ content?: string;
116
+ keywords?: string[];
117
+ /**
118
+ * 常驻注入(2026-09-18):给值即接管,与 {@link MemoryEngine.setInjected} 同义(写
119
+ * `injectedAuto: false`,此后不受自动升降影响);省略则保持原值。
120
+ */
121
+ injected?: boolean;
122
+ }
107
123
  export interface MemoryHit {
108
124
  record: MemoryRecord;
109
125
  score: number;
@@ -426,21 +442,22 @@ export declare class MemoryEngine extends Service {
426
442
  /** {@link setStatus} 的实现体;必须经 `writeScope` 进入。 */
427
443
  private setStatusInner;
428
444
  /**
429
- * 注入维度开关(0.3.0):只改 injected,不动审核状态。供 UI 面板
430
- * 「常驻注入」开关调用(remote.setInjected)。
445
+ * 注入维度开关(0.3.0):只改 injected,不动审核状态。供 UI 面板「常驻注入」开关调用
446
+ * (remote.setInjected)。2026-09-18 起模型侧有等价路径——`memory_save` / `memory_update`
447
+ * 的 `injected` 参数,经 {@link remember} / {@link update} 写同一套 `injectedAuto: false`
448
+ * 语义。差异只在越界处理:本方法对隔离记录**抛错**(用户明确要开,该被告知),
449
+ * 而写入/更新路径**静默降级为不注入**(那是顺带设置,不该中断整次写入)。
431
450
  */
432
451
  setInjected(id: MemoryId, injected: boolean, projectCwd?: string): Promise<MemoryRecord>;
433
452
  /** {@link setInjected} 的实现体;必须经 `writeScope` 进入。 */
434
453
  private setInjectedInner;
435
454
  /**
436
- * 修改一条记忆的内容/关键词(0.3.1 整理记忆用)。2026-09-15 起:改动**不再**
437
- * 退回待审核——静默机制下记忆由系统与模型自行维护,更新即保持原有审核状态;
438
- * `injected` 保留原值。若新内容命中危险规则则转为隔离(与写入路径同一判定)。
455
+ * 修改一条记忆的内容/关键词/注入位(0.3.1 整理记忆用)。2026-09-15 起:改动**不再**
456
+ * 退回待审核——静默机制下记忆由系统与模型自行维护,更新即保持原有审核状态。2026-09-18
457
+ * 起可改 `injected`:**省略则保留原值**(连 `injectedAuto` 一起不动),给值即接管。若新
458
+ * 内容命中危险规则则转为隔离(与写入路径同一判定),并连带撤下注入。
439
459
  */
440
- update(id: MemoryId, patch: {
441
- content?: string;
442
- keywords?: string[];
443
- }, projectCwd?: string): Promise<MemoryRecord>;
460
+ update(id: MemoryId, patch: MemoryPatch, projectCwd?: string): Promise<MemoryRecord>;
444
461
  /** {@link update} 的实现体;必须经 `writeScope` 进入。 */
445
462
  private updateInner;
446
463
  /**
package/dist/engine.js CHANGED
@@ -417,13 +417,16 @@ export class MemoryEngine extends Service {
417
417
  const block = {
418
418
  namespace,
419
419
  status: verdict.quarantined ? 'suggested' : 'approved',
420
- injected: false,
420
+ // 常驻注入(2026-09-18):显式给值即接管;隔离内容一律不注入
421
+ injected: verdict.quarantined ? false : input.injected ?? false,
421
422
  content: input.content,
422
423
  keywords: (input.keywords ?? []).map(keyword => keyword.toLowerCase()),
423
424
  createdAt: now,
424
425
  updatedAt: now,
425
426
  // ⑧ 来源(2026-09-15):缺省 'agent'——写入这条记忆的就是主模型
426
427
  source: input.source ?? 'agent',
428
+ // 显式指定注入即接管:此后既不被自动降级,也不被自动升级(同 setInjected,2026-09-18)
429
+ ...input.injected === undefined ? {} : { injectedAuto: false },
427
430
  // 有效性锚点(可选):值变了这条记忆会被标 stale,不再被当成仍然正确
428
431
  ...input.anchor === undefined ? {} : { anchor: input.anchor },
429
432
  ...verdict.quarantined
@@ -980,8 +983,11 @@ export class MemoryEngine extends Service {
980
983
  throw new Error(`cannot set status of unknown memory '${id}'`);
981
984
  }
982
985
  /**
983
- * 注入维度开关(0.3.0):只改 injected,不动审核状态。供 UI 面板
984
- * 「常驻注入」开关调用(remote.setInjected)。
986
+ * 注入维度开关(0.3.0):只改 injected,不动审核状态。供 UI 面板「常驻注入」开关调用
987
+ * (remote.setInjected)。2026-09-18 起模型侧有等价路径——`memory_save` / `memory_update`
988
+ * 的 `injected` 参数,经 {@link remember} / {@link update} 写同一套 `injectedAuto: false`
989
+ * 语义。差异只在越界处理:本方法对隔离记录**抛错**(用户明确要开,该被告知),
990
+ * 而写入/更新路径**静默降级为不注入**(那是顺带设置,不该中断整次写入)。
985
991
  */
986
992
  async setInjected(id, injected, projectCwd) {
987
993
  return this.writeScope(projectCwd, () => this.setInjectedInner(id, injected, projectCwd));
@@ -1025,9 +1031,10 @@ export class MemoryEngine extends Service {
1025
1031
  return record;
1026
1032
  }
1027
1033
  /**
1028
- * 修改一条记忆的内容/关键词(0.3.1 整理记忆用)。2026-09-15 起:改动**不再**
1029
- * 退回待审核——静默机制下记忆由系统与模型自行维护,更新即保持原有审核状态;
1030
- * `injected` 保留原值。若新内容命中危险规则则转为隔离(与写入路径同一判定)。
1034
+ * 修改一条记忆的内容/关键词/注入位(0.3.1 整理记忆用)。2026-09-15 起:改动**不再**
1035
+ * 退回待审核——静默机制下记忆由系统与模型自行维护,更新即保持原有审核状态。2026-09-18
1036
+ * 起可改 `injected`:**省略则保留原值**(连 `injectedAuto` 一起不动),给值即接管。若新
1037
+ * 内容命中危险规则则转为隔离(与写入路径同一判定),并连带撤下注入。
1031
1038
  */
1032
1039
  async update(id, patch, projectCwd) {
1033
1040
  return this.writeScope(projectCwd, () => this.updateInner(id, patch, projectCwd));
@@ -1041,11 +1048,16 @@ export class MemoryEngine extends Service {
1041
1048
  ? block.keywords
1042
1049
  : patch.keywords.map(keyword => keyword.toLowerCase());
1043
1050
  const verdict = detectSensitive(content, ...keywords);
1051
+ // 命中危险规则:退回 suggested(不注入)+ 隔离(不检索)双保险;否则保持原状态
1052
+ const status = verdict.quarantined ? 'suggested' : normalized.status;
1053
+ // 常驻注入(2026-09-18):显式给值即接管;未审核或已隔离一律不注入(与自动升级同一门槛)
1054
+ const injected = status === 'approved' ? patch.injected ?? normalized.injected : false;
1044
1055
  return {
1045
1056
  ...block,
1046
- // 命中危险规则:退回 suggested(不注入)+ 隔离(不检索)双保险;否则保持原状态
1047
- status: verdict.quarantined ? 'suggested' : normalized.status,
1048
- injected: normalized.injected,
1057
+ status,
1058
+ injected,
1059
+ // 显式改注入即视为有意决定:此后不受自动升降影响(省略时连 injectedAuto 一起保持)
1060
+ ...patch.injected === undefined ? {} : { injectedAuto: false },
1049
1061
  ...verdict.quarantined
1050
1062
  ? { quarantined: true, ...verdict.reason === undefined ? {} : { quarantineReason: verdict.reason } }
1051
1063
  : { quarantined: false, quarantineReason: undefined },
@@ -1054,13 +1066,22 @@ export class MemoryEngine extends Service {
1054
1066
  updatedAt: Date.now(),
1055
1067
  };
1056
1068
  };
1069
+ // 注入位变化单独发一条事件:客户端与面板据此刷新「常驻」列,只发 status 会漏掉它
1070
+ const publish = (previous, updated) => {
1071
+ const record = toRecord(id, updated);
1072
+ this.ctx.emit('memory/changed', { operation: 'status', id, status: normalizeBlock(updated).status });
1073
+ const wasInjected = normalizeBlock(previous).injected;
1074
+ const isInjected = normalizeBlock(updated).injected;
1075
+ if (isInjected !== wasInjected) {
1076
+ this.ctx.emit('memory/changed', { operation: 'injected', id, injected: isInjected });
1077
+ }
1078
+ return record;
1079
+ };
1057
1080
  const global = this.requireTable('global').get(id);
1058
1081
  if (global !== undefined) {
1059
1082
  const updated = applyPatch(global);
1060
1083
  await this.requireTable('global').put(id, updated);
1061
- const record = toRecord(id, updated);
1062
- this.ctx.emit('memory/changed', { operation: 'status', id, status: normalizeBlock(updated).status });
1063
- return record;
1084
+ return publish(global, updated);
1064
1085
  }
1065
1086
  const project = await this.projectTableFor(projectCwd);
1066
1087
  if (project !== undefined) {
@@ -1068,9 +1089,7 @@ export class MemoryEngine extends Service {
1068
1089
  if (block !== undefined) {
1069
1090
  const updated = applyPatch(block);
1070
1091
  await project.put(id, updated);
1071
- const record = toRecord(id, updated);
1072
- this.ctx.emit('memory/changed', { operation: 'status', id, status: normalizeBlock(updated).status });
1073
- return record;
1092
+ return publish(block, updated);
1074
1093
  }
1075
1094
  }
1076
1095
  throw new Error(`cannot update unknown memory '${id}'`);
package/dist/index.js CHANGED
@@ -213,6 +213,7 @@ export async function apply(ctx, config) {
213
213
  content: { type: 'string', required: true, description: 'Plaintext memory content.' },
214
214
  namespace: { type: 'string', enum: ['global', 'project'], description: 'Where it applies; defaults to global.' },
215
215
  keywords: { type: 'array', items: { type: 'string' }, description: 'Explicit searchable anchors for memory_search. Give several angles (synonyms, abbreviations, zh/en) or it will not be found later. 多角度关键词(同义词、缩写、中英),否则将来检索不到它。' },
216
+ injected: { type: 'boolean', description: 'Set true to make this memory resident in every turn\'s context, as a deliberate decision that no longer auto-expires. Reserve it for rules, standing agreements and judgement criteria — the kind that must apply even when nobody thinks to search for them. Facts, references and case notes stay search-only (omit it). 设为 true 让这条记忆每轮常驻上下文,且视为有意决定、不再被自动淘汰。只用于规则、长期约定与判据——那些「没人想起来搜也必须生效」的记忆;事实、参考与案例留作按需检索(省略即可)。' },
216
217
  anchor: {
217
218
  type: 'object',
218
219
  additionalProperties: false,
@@ -233,6 +234,7 @@ export async function apply(ctx, config) {
233
234
  content: args.content,
234
235
  ...args.namespace === undefined ? {} : { namespace: args.namespace },
235
236
  ...args.keywords === undefined ? {} : { keywords: args.keywords },
237
+ ...args.injected === undefined ? {} : { injected: args.injected },
236
238
  // 参数已由 tool schema 校验,这里的窄化只为过类型
237
239
  ...args.anchor === undefined
238
240
  ? {}
@@ -431,11 +433,12 @@ export async function apply(ctx, config) {
431
433
  }));
432
434
  ctx.tools.register(defineTool({
433
435
  name: 'memory_update',
434
- description: 'Update the content or keywords of one stored memory (e.g. correcting stale facts). The record keeps its review status and injection switch; content that looks like a credential quarantines it instead. 修改一条记忆的内容或关键词(如修正过时信息)。改动后记忆保持原有审核状态与注入开关;若新内容命中危险规则则转为隔离。',
436
+ description: 'Update the content, keywords or persistent-injection switch of one stored memory (e.g. correcting stale facts). The record keeps its review status; content that looks like a credential quarantines it instead. 修改一条记忆的内容、关键词或常驻注入开关(如修正过时信息)。改动后记忆保持原有审核状态;若新内容命中危险规则则转为隔离。',
435
437
  parameters: {
436
438
  id: { type: 'string', required: true, description: 'Exact memory id from memory_list. 记忆 id(来自 memory_list).' },
437
439
  content: { type: 'string', description: 'New content; omit to keep current. 新内容;省略则保留现有内容.' },
438
440
  keywords: { type: 'array', items: { type: 'string' }, description: 'New keywords; omit to keep current. 新关键词;省略则保留现有.' },
441
+ injected: { type: 'boolean', description: 'Set or clear the persistent-injection switch; omit to keep the current value. Setting it records a deliberate decision — the memory stops being auto-promoted or auto-demoted. See memory_save for what deserves residency. 设置或清除常驻注入开关;省略则保持原值。给值即视为有意决定——此后不受自动升降影响。何时该常驻见 memory_save。' },
439
442
  },
440
443
  output: {
441
444
  schema: RECORD_SCHEMA,
@@ -445,6 +448,7 @@ export async function apply(ctx, config) {
445
448
  return memory.update(args.id, {
446
449
  ...args.content === undefined ? {} : { content: args.content },
447
450
  ...args.keywords === undefined ? {} : { keywords: args.keywords },
451
+ ...args.injected === undefined ? {} : { injected: args.injected },
448
452
  }, execProjectCwd(exec)).then(recordValue);
449
453
  },
450
454
  presentCall: args => present('Update memory', 'other', args.id),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@max-null/dsh-memory",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "Cross-session plaintext memory plugin for the DeepSeek Harness — deterministic BM25 recall, writes take effect immediately, signal-driven injection, no embeddings",
5
5
  "license": "MIT",
6
6
  "publishConfig": {