dsh-memento 0.4.2 → 0.4.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/ARCHITECTURE.md +177 -177
- package/CHANGELOG.md +111 -104
- package/client/client.js +241 -241
- package/index.mjs +1743 -1739
- package/lib/constants.mjs +68 -68
- package/lib/store.mjs +717 -717
- package/package.json +153 -153
- package/types.d.ts +238 -237
package/types.d.ts
CHANGED
|
@@ -1,237 +1,238 @@
|
|
|
1
|
-
// types.d.ts — dsh-memento 类型契约(声明合并)。
|
|
2
|
-
//
|
|
3
|
-
// 本插件入口是纯 ESM JavaScript;类型契约集中在本文件:
|
|
4
|
-
// - `declare module '@deepseek-ai/cordis'`:ctx.memory 服务(F1,三角色 seam 的
|
|
5
|
-
// Service Definition 面)。
|
|
6
|
-
// - `declare module '@deepseek-ai/dsh-session'`:memory/* 会话事件词汇(F7)。
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
id
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
workspaceKey
|
|
60
|
-
|
|
61
|
-
agentKey
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
agent
|
|
84
|
-
|
|
85
|
-
callId
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
language
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
id
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
1
|
+
// types.d.ts — dsh-memento 类型契约(声明合并)。
|
|
2
|
+
//
|
|
3
|
+
// 本插件入口是纯 ESM JavaScript;类型契约集中在本文件:
|
|
4
|
+
// - `declare module '@deepseek-ai/cordis'`:ctx.memory 服务(F1,三角色 seam 的
|
|
5
|
+
// Service Definition 面)。
|
|
6
|
+
// - `declare module '@deepseek-ai/dsh-session'`:memory/* 会话事件词汇(F7)。
|
|
7
|
+
// rc.8 复核(2026-08-21):harness 仍无插件事件注册面
|
|
8
|
+
// (KNOWN_SESSION_EVENT_TYPES 不含 memory/*,Session.append 写入面也仍不接受
|
|
9
|
+
// ignorable 标记),运行时按已知集合自适应派发——未被 harness 收录时跳过
|
|
10
|
+
// append,审计由审批审计对 + 插件审计表承担;词汇与载荷形状在本文件定死,
|
|
11
|
+
// harness 收录后即自动启用。
|
|
12
|
+
|
|
13
|
+
export type MemoryTrack = 'user' | 'agent'
|
|
14
|
+
|
|
15
|
+
export type MemoryScope = 'user-global' | 'workspace'
|
|
16
|
+
|
|
17
|
+
export type MemoryWritePolicy = 'ask' | 'auto' | 'off'
|
|
18
|
+
|
|
19
|
+
export type MemoryAction = 'add' | 'replace' | 'remove' | 'consolidate' | 'query' | 'seed'
|
|
20
|
+
|
|
21
|
+
/** 落盘条目(审计/会话事件的载荷形状)。 */
|
|
22
|
+
export interface MemoryEntry {
|
|
23
|
+
/** 条目 id(本插件生成,UUID v4,跨会话稳定)。 */
|
|
24
|
+
id: string
|
|
25
|
+
/** 轨道:user=用户画像,agent=环境事实/约定/教训。 */
|
|
26
|
+
track: MemoryTrack
|
|
27
|
+
/** 作用域:user-global 跨工作区,workspace 按会话 cwd。 */
|
|
28
|
+
scope: MemoryScope
|
|
29
|
+
/** workspace 条目的规范化 cwd 键;user-global 条目为空串。 */
|
|
30
|
+
workspaceKey: string
|
|
31
|
+
/** 规范化 agentPreset 键;'' = 共享层(所有 preset 可见)。 */
|
|
32
|
+
agentKey: string
|
|
33
|
+
/** 条目文本(预算计数字符 = JS 字符串长度)。 */
|
|
34
|
+
text: string
|
|
35
|
+
/** 来源标注(dsh-memento / memory-tool / claude 等)。 */
|
|
36
|
+
source: string
|
|
37
|
+
/** 短标签(协议 v1:最多 16 个、每个 ≤32 字符;顺序 = 首次出现序)。 */
|
|
38
|
+
tags: string[]
|
|
39
|
+
/** 条目版本(协议 v1:新条目 = 1;每次 replace 自增)。 */
|
|
40
|
+
version: number
|
|
41
|
+
/** 创建时间(epoch ms)。 */
|
|
42
|
+
createdAt: number
|
|
43
|
+
/** 最近更新时间(epoch ms)。 */
|
|
44
|
+
updatedAt: number
|
|
45
|
+
/** 最近召回时间(epoch ms);从未命中为 null。 */
|
|
46
|
+
lastRecalled: number | null
|
|
47
|
+
/** 召回次数(query 排序用:高频即重要)。 */
|
|
48
|
+
recallCount: number
|
|
49
|
+
/** 最近一次写它的会话 id;无则 null。 */
|
|
50
|
+
sessionId: string | null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 写入输入(add/seed 用)。 */
|
|
54
|
+
export interface MemoryEntryInput {
|
|
55
|
+
track: MemoryTrack
|
|
56
|
+
scope: MemoryScope
|
|
57
|
+
text: string
|
|
58
|
+
source?: string
|
|
59
|
+
/** 显式 workspaceKey;省略时取写方会话 cwd。 */
|
|
60
|
+
workspaceKey?: string
|
|
61
|
+
/** 显式 agentKey;省略时取写方会话 agentPreset。 */
|
|
62
|
+
agentKey?: string
|
|
63
|
+
/** 短标签(协议 v1 条目规范;缺省 = 无标签)。 */
|
|
64
|
+
tags?: string[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 会话最小形状(插件只读这些面;字段宽类型以兼容真实 Session/Agent)。 */
|
|
68
|
+
export interface MemorySessionLike {
|
|
69
|
+
id?: unknown
|
|
70
|
+
header?: { cwd?: unknown; agentPreset?: unknown }
|
|
71
|
+
append?: (type: string, data: unknown) => unknown
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 审批服务最小形状(插件消费的 seam 面)。 */
|
|
75
|
+
export interface MemoryApprovalLike {
|
|
76
|
+
request(req: { agent?: unknown; toolName?: string; reason?: string; callId?: unknown; signal?: AbortSignal }): Promise<string>
|
|
77
|
+
overrideOf?(session: unknown): string | undefined
|
|
78
|
+
config?: { policy?: string }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 写上下文:审批路由与审计归属所必需。agent 缺失时写失败封闭。 */
|
|
82
|
+
export interface MemoryWriteContext {
|
|
83
|
+
/** 发起写的 agent(其 session 承载审批审计对)。 */
|
|
84
|
+
agent: { session?: MemorySessionLike | null } | null | undefined
|
|
85
|
+
/** 发起写的工具 callId(供 UI answerer 挂靠已流式化的工具调用)。 */
|
|
86
|
+
callId?: unknown
|
|
87
|
+
/** 取消信号:中止即 cancelled,不写任何东西。 */
|
|
88
|
+
signal?: AbortSignal
|
|
89
|
+
/** 可选自定义审批传输(turn 外命令路径注入;payload 携带完整写载荷)。 */
|
|
90
|
+
gate?: (payload: { action: string; track: string; scope: string; text: string; count?: number }, write: MemoryWriteContext) => Promise<string>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** query 结果。 */
|
|
94
|
+
export interface MemoryQueryResult {
|
|
95
|
+
entries: MemoryEntry[]
|
|
96
|
+
total: number
|
|
97
|
+
truncated: boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 预算行。 */
|
|
101
|
+
export interface MemoryBudgetRow {
|
|
102
|
+
track: MemoryTrack
|
|
103
|
+
scope: MemoryScope
|
|
104
|
+
used: number
|
|
105
|
+
limit: number
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 写成功后的用量(模型据此整合/删除后重试)。 */
|
|
109
|
+
export interface MemoryUsage {
|
|
110
|
+
track: MemoryTrack
|
|
111
|
+
scope: MemoryScope
|
|
112
|
+
used: number
|
|
113
|
+
limit: number
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** ctx.memory 服务:写方法内部强制过审批门,读方法无审批。 */
|
|
117
|
+
export interface MemoryService {
|
|
118
|
+
/** 模型可见文案与命令输出的语言(Config.language,'en' | 'zh')。 */
|
|
119
|
+
language: 'en' | 'zh'
|
|
120
|
+
|
|
121
|
+
/** 每轨每层当前用量与上限。 */
|
|
122
|
+
budgets(): MemoryBudgetRow[]
|
|
123
|
+
|
|
124
|
+
/** 子串查询(无审批);带 sessionId 时记 recalled 审计,带 session 时按已知事件类型自适应派发 memory/recalled。
|
|
125
|
+
* opts.agentKey 给定时按会话可见集过滤(共享层 + 指定 agent 键);缺省不过滤(管理面全量视图)。 */
|
|
126
|
+
query(filter?: { track?: MemoryTrack; scope?: MemoryScope; text?: string; limit?: number }, opts?: { sessionId?: string; session?: MemorySessionLike | null; agentKey?: string }): MemoryQueryResult
|
|
127
|
+
|
|
128
|
+
/** 新增条目(审批门 + 预算门)。 */
|
|
129
|
+
add(input: MemoryEntryInput, write: MemoryWriteContext): Promise<{ entry: MemoryEntry; usage: MemoryUsage }>
|
|
130
|
+
|
|
131
|
+
/** 按唯一子串替换(审批门 + 预算门;零/多命中报错)。写定位 = 会话可见集:
|
|
132
|
+
* agentKey/workspaceKey 显式给定则覆盖写方会话的推导值。审批载荷携带将被改写的旧条目全文。 */
|
|
133
|
+
replace(input: { track: MemoryTrack; scope: MemoryScope; match: string; text: string; source?: string; agentKey?: string; workspaceKey?: string; tags?: string[] }, write: MemoryWriteContext): Promise<{ previous: MemoryEntry; entry: MemoryEntry; usage: MemoryUsage }>
|
|
134
|
+
|
|
135
|
+
/** 按唯一子串删除(审批门;零/多命中报错)。写定位 = 会话可见集;审批载荷携带将被删除的条目全文。 */
|
|
136
|
+
remove(input: { track: MemoryTrack; scope: MemoryScope; match: string; agentKey?: string; workspaceKey?: string }, write: MemoryWriteContext): Promise<{ entry: MemoryEntry; usage: MemoryUsage }>
|
|
137
|
+
|
|
138
|
+
/** 整合多条为一条(一次审批 + Provider 单事务原子执行;零/多命中或超预算响亮失败)。 */
|
|
139
|
+
consolidate(input: { track: MemoryTrack; scope: MemoryScope; matches: string[]; text: string; source?: string; workspaceKey?: string; agentKey?: string; tags?: string[] }, write: MemoryWriteContext): Promise<{ removed: MemoryEntry[]; entry: MemoryEntry; usage: MemoryUsage }>
|
|
140
|
+
|
|
141
|
+
/** 批量种子(一次 ask 审批整批;任一条超预算整批拒绝)。 */
|
|
142
|
+
seed(inputs: MemoryEntryInput[], write: MemoryWriteContext): Promise<{ added: number; entries: MemoryEntry[] }>
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** 适配器描述(/memory adapters 与接入指南展示面)。 */
|
|
146
|
+
export interface MemoryAdapterDescriptor {
|
|
147
|
+
/** 唯一适配器 id(小写 kebab-case)。 */
|
|
148
|
+
id: string
|
|
149
|
+
/** 人类可读名称。 */
|
|
150
|
+
name: string
|
|
151
|
+
/** 一句话说明转换方向与适用格式。 */
|
|
152
|
+
description: string
|
|
153
|
+
/** 适配器自身版本。 */
|
|
154
|
+
version: string
|
|
155
|
+
/** 可导入的外部格式标签。 */
|
|
156
|
+
importFormats: string[]
|
|
157
|
+
/** 导出产出的外部格式标签。 */
|
|
158
|
+
exportFormat: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 适配器契约(第三方记忆插件实现面):外部格式 ⇄ 协议条目。 */
|
|
162
|
+
export interface MemoryAdapter extends MemoryAdapterDescriptor {
|
|
163
|
+
/** 外部载荷 → 协议条目输入(只转换,绝不调模型抽取)。 */
|
|
164
|
+
adapt(payload: unknown): { entries: MemoryEntryInput[] }
|
|
165
|
+
/** 协议条目 → 外部载荷(JSON 安全,只读转换)。 */
|
|
166
|
+
export(entries: MemoryEntry[]): unknown
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** ctx.memoryAdapters 服务(dsh-memory-protocol v1 适配器注册表)。 */
|
|
170
|
+
export interface MemoryAdaptersService {
|
|
171
|
+
/** 注册适配器(返回 disposer;id 冲突响亮失败)。 */
|
|
172
|
+
register(adapter: MemoryAdapter): () => void
|
|
173
|
+
/** 已注册适配器描述(按 id 排序)。 */
|
|
174
|
+
list(): MemoryAdapterDescriptor[]
|
|
175
|
+
/** 外部载荷 → 协议条目输入(未知 id / 非法载荷结构化报错)。 */
|
|
176
|
+
adapt(adapterId: string, payload: unknown): { entries: MemoryEntryInput[] }
|
|
177
|
+
/** 协议条目 → 外部格式载荷(只读)。 */
|
|
178
|
+
export(adapterId: string, entries: MemoryEntry[]): unknown
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
declare module '@deepseek-ai/cordis' {
|
|
182
|
+
interface Context {
|
|
183
|
+
/** dsh-memento 记忆服务(本插件提供;其它插件可读写同一 store)。 */
|
|
184
|
+
memory: MemoryService
|
|
185
|
+
/** dsh-memory-protocol v1 适配器注册表(本插件提供;第三方记忆插件注册自己的适配器)。 */
|
|
186
|
+
memoryAdapters: MemoryAdaptersService
|
|
187
|
+
/** 审批 seam(本插件消费的最小面;由 DSH interaction 能力提供)。 */
|
|
188
|
+
approval: MemoryApprovalLike
|
|
189
|
+
}
|
|
190
|
+
interface Events {
|
|
191
|
+
/** 审批 waterfall(本插件 answerer 挂链)。 */
|
|
192
|
+
'approval/request'(req: unknown, next: () => Promise<string>): Promise<string>
|
|
193
|
+
/** 可选服务就绪通知(withService 用)。 */
|
|
194
|
+
'internal/service'(name: string): void
|
|
195
|
+
/** 会话事件桥(auto-capture 等观察面用)。 */
|
|
196
|
+
'session/event'(session: unknown, event: unknown): void
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare module '@deepseek-ai/dsh-session' {
|
|
201
|
+
interface SessionEventMap {
|
|
202
|
+
/**
|
|
203
|
+
* 一条记忆条目已落盘(审批通过后的写成功)。日志只读事件,非 surface;
|
|
204
|
+
* 审计链 = approval/asked + approval/decided + 本事件 + 插件审计表。
|
|
205
|
+
* rc.8 无插件事件注册面时运行时跳过 append(见 types.d.ts 头注)。
|
|
206
|
+
*/
|
|
207
|
+
'memory/added': {
|
|
208
|
+
entry: MemoryEntry
|
|
209
|
+
source: string
|
|
210
|
+
sessionId: string
|
|
211
|
+
}
|
|
212
|
+
/** 一条记忆条目被 replace 改写(previous 为改写前内容)。 */
|
|
213
|
+
'memory/updated': {
|
|
214
|
+
previous: MemoryEntry
|
|
215
|
+
entry: MemoryEntry
|
|
216
|
+
source: string
|
|
217
|
+
sessionId: string
|
|
218
|
+
}
|
|
219
|
+
/** 一条记忆条目被 remove 删除。 */
|
|
220
|
+
'memory/removed': {
|
|
221
|
+
entry: MemoryEntry
|
|
222
|
+
source: string
|
|
223
|
+
sessionId: string
|
|
224
|
+
}
|
|
225
|
+
/** 一次 query 召回(记录过滤条件与命中数)。 */
|
|
226
|
+
'memory/recalled': {
|
|
227
|
+
query: string
|
|
228
|
+
matches: number
|
|
229
|
+
sessionId: string
|
|
230
|
+
}
|
|
231
|
+
/** 会话启动时注入的冻结快照(text 与模型所见 systemPrompt 段逐字一致,S2)。 */
|
|
232
|
+
'memory/snapshot': {
|
|
233
|
+
text: string
|
|
234
|
+
workspaceKey: string
|
|
235
|
+
at: number
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|