@furongjun1999/dsh-memory 0.9.9 → 0.9.12
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 +181 -150
- package/lib/hooks.d.ts +16 -1
- package/lib/hooks.js +53 -2
- package/lib/index.d.ts +3 -0
- package/lib/index.js +9 -1
- package/lib/tools.d.ts +8 -0
- package/lib/tools.js +32 -5
- package/md_cg/config_registry_bulk.py +488 -483
- package/md_cg/config_validate.py +5 -0
- package/md_cg/mcp_server.py +5446 -5324
- package/md_cg/mdcg.py +62 -4
- package/md_cg/mdcos.py +7259 -7159
- package/md_cg/refindex.py +11 -4
- package/md_cg/test_c3_transient_read_negative.py +797 -797
- package/md_cg/test_c8_search_rrf_gates.py +511 -502
- package/md_cg/test_domain_granularity.py +68 -0
- package/md_cg/test_exact_text_cache.py +194 -194
- package/md_cg/test_hotcache_tool.py +121 -121
- package/md_cg/test_index_snapshot_fastpath.py +72 -0
- package/md_cg/test_issue274_read_node_id_none.py +364 -364
- package/md_cg/test_issue623_fullwidth_symmetry.py +66 -0
- package/md_cg/test_p28_refcheck.py +7 -7
- package/md_cg/test_p3_legacy_closure.py +441 -441
- package/md_cg/test_retr_gates_prodpath.py +11 -1
- package/md_cg/test_search_async.py +84 -0
- package/md_cg/test_search_bm25_default.py +60 -60
- package/md_cg/test_search_prefilter.py +85 -0
- package/md_cg/test_untrusted_audit.py +55 -55
- package/md_cg/test_untrusted_classifier.py +42 -42
- package/md_cg/test_untrusted_enforcement.py +66 -66
- package/md_cg/tokens.py +5 -1
- package/md_cg/untrusted.py +45 -45
- package/md_cg/untrusted_audit.py +87 -87
- package/package.json +113 -113
- package/scripts/workspace_index.py +2 -0
- package/src/hooks.ts +1043 -986
- package/src/index.ts +12 -1
- package/src/tools.ts +37 -6
package/src/index.ts
CHANGED
|
@@ -95,6 +95,9 @@ export const inject = ['tools']
|
|
|
95
95
|
export interface Config {
|
|
96
96
|
/** 内部标识(provider/日志用;**不再用于工具名前缀**,工具名与 MCP 服务同名)。 */
|
|
97
97
|
serverName: string
|
|
98
|
+
/** issue #634:是否同时注册 lingshu_* 兼容别名(缺省 true)。
|
|
99
|
+
* 0.9.9 起工具名去前缀,旧会话/旧脚本硬编码旧名会 unknown tool。 */
|
|
100
|
+
toolAliases: boolean
|
|
98
101
|
/** Python 可执行文件(或 md_cg-mcp console script)。
|
|
99
102
|
* 缺省 = 平台感知(issue #19):Windows `python` / Linux·macOS `python3`,
|
|
100
103
|
* 可用 env `MDCG_PYTHON` 覆盖;显式配置本项优先级最高。 */
|
|
@@ -149,6 +152,9 @@ export interface Config {
|
|
|
149
152
|
|
|
150
153
|
export const Config: z<Config> = z.object({
|
|
151
154
|
serverName: z.string().default('lingshu'),
|
|
155
|
+
/** issue #634:0.9.9 起工具名去前缀(lingshu_cg -> cg)。
|
|
156
|
+
* 缺省 true = 同时注册 lingshu_* 兼容别名;设 false 则只注册裸名。 */
|
|
157
|
+
toolAliases: z.boolean().default(true),
|
|
152
158
|
// issue #19:默认值按平台解析(Windows: python / 其它: python3;env MDCG_PYTHON 可覆盖)。
|
|
153
159
|
// 写死 'python' 时 Linux/macOS 首装即 spawn ENOENT(PEP 394 只有 python3),
|
|
154
160
|
// 且表现为「装好了但记忆永远为空」——最难定位的失效形态。
|
|
@@ -168,6 +174,8 @@ export const Config: z<Config> = z.object({
|
|
|
168
174
|
importance: z.number().default(0.6),
|
|
169
175
|
autoRecall: z.boolean().default(true),
|
|
170
176
|
autoRecallLimit: z.number().default(4),
|
|
177
|
+
/** issue #635:self/anchor 层单列「身份锚点」块(默认 false = 维持既有行为)。 */
|
|
178
|
+
autoRecallIdentity: z.boolean().default(false),
|
|
171
179
|
desensitize: z.boolean().default(true),
|
|
172
180
|
/** **短期会话窗口**(滑动窗口,2026-10-06)——「短期保留近 N 条对话记录」
|
|
173
181
|
* 的机制实现(长期记忆仍走灵枢的显式调用)。
|
|
@@ -191,7 +199,7 @@ export const Config: z<Config> = z.object({
|
|
|
191
199
|
})
|
|
192
200
|
.default({ enabled: true, turns: 10 }),
|
|
193
201
|
})
|
|
194
|
-
.default({ userMessage: true, assistantMessage: false, toolResult: false, importance: 0.6, autoRecall: true, autoRecallLimit: 4, desensitize: true, contextWindow: { enabled: true, turns: 10 } }),
|
|
202
|
+
.default({ userMessage: true, assistantMessage: false, toolResult: false, importance: 0.6, autoRecall: true, autoRecallLimit: 4, autoRecallIdentity: false, desensitize: true, contextWindow: { enabled: true, turns: 10 } }),
|
|
195
203
|
toolCallTimeoutMs: z.number().default(60_000),
|
|
196
204
|
maxRetryDelayMs: z.number().default(30_000),
|
|
197
205
|
failOnStartupError: z.boolean().default(false),
|
|
@@ -430,6 +438,9 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
430
438
|
// `cg` / `stg` / `mdcg_*`。此前按 `${config.serverName}_` 拼成 `cg`,造成「同一个
|
|
431
439
|
// MCP 服务、不同端看到不同工具名」的初次识别错误。serverName 仍用于内部 provider/日志标识。
|
|
432
440
|
toolPrefix: '',
|
|
441
|
+
// issue #634:默认补注册 lingshu_* 兼容别名(旧会话/旧脚本硬编码旧名时不至于 unknown tool)。
|
|
442
|
+
// 需要「只要裸名」的部署可设 tools.legacyAliases=false。
|
|
443
|
+
legacyAliases: config.toolAliases !== false,
|
|
433
444
|
})
|
|
434
445
|
disposers.push(dispose)
|
|
435
446
|
toolsRegistered = true
|
package/src/tools.ts
CHANGED
|
@@ -186,10 +186,26 @@ export function extractText(content: Array<{ type: string; text?: string; [key:
|
|
|
186
186
|
* import 本包」在模块求值前就失败。惰性导入后:不在 DSH 宿主内时包仍可加载,
|
|
187
187
|
* 只有真正注册工具才报错,且错误消息点名缺哪个包。
|
|
188
188
|
*/
|
|
189
|
+
/** 工具对外名(issue #634):正式名 + 可选兼容别名。
|
|
190
|
+
*
|
|
191
|
+
* 0.9.9 起去掉了 `${serverName}_` 前缀(lingshu_cg -> cg),升级瞬间
|
|
192
|
+
* 已存在会话里的旧名调用全部变成 unknown tool。这里给出「一个工具要注册哪些名字」的
|
|
193
|
+
* 纯函数,注册面与测试共用,避免两处各写一份判据。
|
|
194
|
+
*/
|
|
195
|
+
export function toolPublicNames(
|
|
196
|
+
toolName: string,
|
|
197
|
+
prefix: string,
|
|
198
|
+
legacyAliases = true,
|
|
199
|
+
): string[] {
|
|
200
|
+
const primary = `${prefix}${toolName}`
|
|
201
|
+
if (prefix || !legacyAliases || toolName.startsWith("lingshu_")) return [primary]
|
|
202
|
+
return [primary, `lingshu_${toolName}`]
|
|
203
|
+
}
|
|
204
|
+
|
|
189
205
|
export async function registerLingshuTools(
|
|
190
206
|
ctx: Context,
|
|
191
207
|
bridge: LingshuBridge,
|
|
192
|
-
opts: { selection: ToolSelection; toolPrefix: string },
|
|
208
|
+
opts: { selection: ToolSelection; toolPrefix: string; legacyAliases?: boolean },
|
|
193
209
|
): Promise<() => void> {
|
|
194
210
|
let defineTool: typeof import('@deepseek-ai/dsh-tools').defineTool
|
|
195
211
|
try {
|
|
@@ -205,12 +221,21 @@ export async function registerLingshuTools(
|
|
|
205
221
|
const disposers: Array<() => void> = []
|
|
206
222
|
const registered: string[] = []
|
|
207
223
|
try {
|
|
224
|
+
// issue #634(2026-10-22):0.9.9 起工具名去掉 serverName 前缀(lingshu_cg -> cg),
|
|
225
|
+
// 升级瞬间已存在的会话里旧名调用全变 unknown tool,宿主与插件都没有提示。
|
|
226
|
+
// 这里加兼容别名:裸名照常注册,同时补注册 lingshu_<name>(legacyAliases=false 可关)。
|
|
227
|
+
// 别名与正式名指向同一个 execute,语义不变;描述标注 deprecated 供模型与人识别。
|
|
208
228
|
for (const tool of tools) {
|
|
209
229
|
if (!wanted.has(tool.name)) continue
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
230
|
+
const names = toolPublicNames(tool.name, opts.toolPrefix, opts.legacyAliases !== false)
|
|
231
|
+
const publicName = names[0] as string
|
|
232
|
+
const aliasName = names[1] ?? ""
|
|
233
|
+
const makeDefinition = (registeredName: string, deprecated: boolean) => defineTool({
|
|
234
|
+
name: registeredName,
|
|
235
|
+
description: deprecated
|
|
236
|
+
? '【已弃用别名】旧版工具名(升级兼容用),请改用 ' + publicName + '。原始描述:'
|
|
237
|
+
+ (tool.description || '灵枢 ' + tool.name)
|
|
238
|
+
: (tool.description || '灵枢 ' + tool.name),
|
|
214
239
|
parameters: schemaToParameters(tool.inputSchema),
|
|
215
240
|
output: {
|
|
216
241
|
schema: { type: 'json' } as never,
|
|
@@ -253,8 +278,14 @@ export async function registerLingshuTools(
|
|
|
253
278
|
return { content: result.content } as never
|
|
254
279
|
},
|
|
255
280
|
})
|
|
256
|
-
disposers.push(ctx.tools.register(
|
|
281
|
+
disposers.push(ctx.tools.register(makeDefinition(publicName, false)))
|
|
257
282
|
registered.push(publicName)
|
|
283
|
+
if (aliasName) {
|
|
284
|
+
// 兼容别名:指向同一个 execute(makeDefinition 复用了同一份定义体),
|
|
285
|
+
// 标记 deprecated;下一轮 minor 再评估是否移除。
|
|
286
|
+
disposers.push(ctx.tools.register(makeDefinition(aliasName, true)))
|
|
287
|
+
registered.push(aliasName)
|
|
288
|
+
}
|
|
258
289
|
}
|
|
259
290
|
} catch (err) {
|
|
260
291
|
for (const dispose of disposers) dispose()
|