@deepmaid/maid-memory-local 0.1.0-alpha.1 → 0.1.0-alpha.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/lib/index.d.ts ADDED
@@ -0,0 +1,125 @@
1
+ //#region ../maid-memory/src/types.d.ts
2
+ interface ProviderCapabilities {
3
+ readonly forget: boolean;
4
+ readonly sharedScopes: boolean;
5
+ readonly supportsRecent: boolean;
6
+ }
7
+ type ProviderStatus = 'cold' | 'ready' | 'degraded';
8
+ /**
9
+ * 召回命中(M3b 任务 9 扩):scope/provenanceKind 透传 SLM 读面回显(docs/mslm-provenance-需求书
10
+ * §7 R4:'scope'/'provenance_kind' 两键,additive;缺席 = 个人记忆,渲染层按 scope==='global'
11
+ * 分流「背景事实」小节,不依赖 provenanceKind 做行为分支(v1)。
12
+ */
13
+ interface RecallHit {
14
+ readonly id: string;
15
+ readonly title: string;
16
+ readonly content: string;
17
+ readonly score: number;
18
+ readonly createdAt?: string;
19
+ readonly scope?: string;
20
+ readonly provenanceKind?: string;
21
+ }
22
+ /**
23
+ * 读通道滤镜参数(M3b 任务 9,任务 5 裁定移交;round 1 修订回规格 §3.1 原文语义):
24
+ * excludeTags = tag 命中条目**降权排尾**(稳定排序,不剔除——「命中集不做硬删」),与任务 6
25
+ * 降级链「自队尾向前逐命中降档」协同 → 被降权条目先降档先出预算;preferRecentDays =
26
+ * createdAt 窗口内排序靠前(排序加权不过滤);组合时降权强于时窗提升。local 假件忽略之;
27
+ * memory_search 工具面不走本通道。
28
+ */
29
+ interface RecallOpts {
30
+ readonly excludeTags?: readonly string[];
31
+ readonly preferRecentDays?: number;
32
+ }
33
+ interface RecentMemory {
34
+ readonly id: string;
35
+ readonly title: string;
36
+ readonly content: string;
37
+ readonly createdAt?: string;
38
+ }
39
+ /**
40
+ * 策展扫描条目(M3b 任务 10,三闸门之策展修订服务面):provider.scanUnsorted 的浅投影。
41
+ * scope/provenanceKind 词表语义同 RecallHit 回显(docs/mslm-provenance-需求书 §7:'world'/
42
+ * 'private'/'curated'/'legacy');扫描集固定 scope='global' 且未标注(provenance_kind=null),
43
+ * 故 provenanceKind 通常缺席——字段保留只为容读面回显毛边,不承担行为分支。
44
+ */
45
+ interface CuratorFact {
46
+ readonly id: string;
47
+ readonly content: string;
48
+ readonly scope: string;
49
+ readonly provenanceKind?: string;
50
+ }
51
+ interface MemoryRecord {
52
+ readonly title: string;
53
+ readonly content: string;
54
+ readonly tags: readonly string[];
55
+ readonly importance: number;
56
+ }
57
+ /**
58
+ * 写入门 opts(M3b 任务 8,规格 §3 闸门 1):scope=global 只在守卫放行后出现(降级路径/缺省
59
+ * 均 personal);provenanceKind 用 SLM 落地版受控词表(docs/mslm-provenance-需求书 §7:
60
+ * 'world'/'private'/'curated'/'legacy',非需求书原文的 world-fact/maid-private)。
61
+ */
62
+ interface WriteOpts {
63
+ readonly scope?: 'personal' | 'global';
64
+ readonly provenanceKind?: 'world' | 'private' | 'curated' | 'legacy';
65
+ }
66
+ interface WriteReceipt {
67
+ readonly id: string;
68
+ readonly deduped: boolean;
69
+ readonly scope?: string;
70
+ }
71
+ /**
72
+ * 原位修订 opts(M3b 任务 11,闸门三策展执行):键缺席 = 不变(fork update_memory 落地版
73
+ * 语义,docs/mslm-provenance-需求书 §7);scope/标注类修订 in-place(fact_id 不变迁);
74
+ * content 修订走 correction 链(fact_id 会变迁),仅确需改写正文时携带,语义调用方自担。
75
+ * MCP 面不能清标注、不能迁 scope='shared'(清标注走 daemon HTTP 预留面),故本面无
76
+ * provenanceKind:null 形态、shared 迁移不经此。
77
+ */
78
+ interface UpdateOpts {
79
+ readonly scope?: 'personal' | 'shared' | 'global';
80
+ readonly provenanceKind?: 'world' | 'private' | 'curated' | 'legacy';
81
+ readonly content?: string;
82
+ }
83
+ interface MaidMemoryProvider {
84
+ readonly id: string;
85
+ readonly capabilities: ProviderCapabilities;
86
+ status(): Promise<ProviderStatus>;
87
+ recall(ns: string, query: string, limit: number, opts?: RecallOpts): Promise<RecallHit[]>;
88
+ write(ns: string, records: MemoryRecord[], opts?: WriteOpts): Promise<WriteReceipt[]>;
89
+ forget?(ns: string, recordId: string): Promise<void>;
90
+ recent?(ns: string, limit: number): Promise<RecentMemory[]>;
91
+ /**
92
+ * 原位修订(M3b 任务 11):按 factId 精确修订既有事实的 scope/标注(/正文)。可选 =
93
+ * 能力声明(方法在场即能力,照 scanUnsorted 先例,不设独立 capabilities 位);缺席时
94
+ * 策展执行方逐条记错误不中断。mslm 实现 = MCP update_memory(remember 路由同款
95
+ * per-request profile_id 穿透);local 假件 = 内存态合成集同步。
96
+ */
97
+ update?(ns: string, factId: string, opts: UpdateOpts): Promise<void>;
98
+ /**
99
+ * 策展扫描(M3b 任务 10):该命名空间 scope='global' 且未标注(provenance_kind=null)的
100
+ * 待分拣集。可选 = 能力声明(方法在场即能力,不设独立 capabilities 位——策展是低频管理
101
+ * 面不是读写主路);缺席时调用方按 [] 优雅降级,不视作故障。mslm 实现 = MCP list_recent
102
+ * 策展筛选参数(fork 落地);local 假件 = 合成 canned 集。
103
+ */
104
+ scanUnsorted?(ns: string): Promise<CuratorFact[]>;
105
+ dispose(): Promise<void>;
106
+ }
107
+ //#endregion
108
+ //#region src/index.d.ts
109
+ declare const name = "maid-memory-local";
110
+ declare const inject: string[];
111
+ /**
112
+ * 策展扫描合成集(M3b 任务 10,铁律 7:只用 Doris/合成内容):global+null / global+已标注 /
113
+ * personal 混排的 canned 假件集,scanUnsorted 只回 global+null 子集(与 mslm 服务端显式筛选
114
+ * 同语义)。导出供契约测试推导期望集;ns 无关(local 是降级假件,无真实 global 层可盘)。
115
+ */
116
+ declare const SYNTHETIC_UNSORTED_SCAN: readonly CuratorFact[];
117
+ declare const apply: (ctx: any, config?: {
118
+ dataFile?: string;
119
+ }) => void;
120
+ /** local 降级假件:自包含 JSONL + 内存关键词打分(规格 §7.1;有意保持简单,不做向量/BM25)。 */
121
+ declare function createLocalMemoryProvider(config: {
122
+ dataFile: string;
123
+ }): MaidMemoryProvider;
124
+ //#endregion
125
+ export { SYNTHETIC_UNSORTED_SCAN, apply, createLocalMemoryProvider, inject, name };
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
+ import { managedPathsOf } from "@deepmaid/maid-identity/managed-paths";
4
5
  //#region src/index.ts
5
6
  const name = "maid-memory-local";
6
7
  const inject = ["maidMemory"];
@@ -32,9 +33,10 @@ const SYNTHETIC_UNSORTED_SCAN = [
32
33
  scope: "personal"
33
34
  }
34
35
  ];
35
- const apply = (ctx, config) => {
36
- if (!config?.dataFile) throw new Error("maid-memory-local: config.dataFile 必填");
37
- ctx.maidMemory.registerProvider(createLocalMemoryProvider(config));
36
+ const apply = (ctx, config = {}) => {
37
+ if (ctx.maidMemory?.hasBuiltInProvider?.("local") === true) return;
38
+ const dataFile = config.dataFile ?? managedPathsOf(ctx).memoryFile;
39
+ ctx.maidMemory.registerProvider(createLocalMemoryProvider({ dataFile }));
38
40
  };
39
41
  function tokenize(text) {
40
42
  const lower = text.toLowerCase();
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@deepmaid/maid-memory-local",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
8
- ".": "./lib/index.js"
8
+ ".": {
9
+ "types": "./lib/index.d.ts",
10
+ "default": "./lib/index.js"
11
+ }
9
12
  },
10
13
  "files": [
11
14
  "lib"
12
15
  ],
16
+ "dependencies": {
17
+ "@deepmaid/maid-identity": "0.1.0-alpha.2"
18
+ },
13
19
  "devDependencies": {
14
20
  "tsdown": "0.22.14",
15
21
  "typescript": "6.0.3"