dsh-verbatim 0.1.0 → 0.1.1

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +1 -1
  3. package/README.en.md +24 -22
  4. package/README.md +24 -22
  5. package/bin/cli.mjs +2 -1
  6. package/bin/mcp-memory.mjs +130 -62
  7. package/client.js +8880 -8857
  8. package/cordis.patch.yml +1 -1
  9. package/docs/ARCHITECTURE.md +1 -1
  10. package/icon.svg +1 -1
  11. package/index.js +613 -2558
  12. package/locale/en.json +1 -1
  13. package/locale/zh.json +1 -1
  14. package/package.json +2 -3
  15. package/src/config/exclude-range.js +1 -1
  16. package/src/config/global-config.js +3 -1
  17. package/src/config/session-config.js +12 -10
  18. package/src/config/session-config.test.js +375 -375
  19. package/src/derive/fact.js +6 -6
  20. package/src/derive/gist.js +2 -1
  21. package/src/host/config-views.js +2 -0
  22. package/src/host/db-admin.js +78 -15
  23. package/src/host/panel-api.js +1109 -0
  24. package/src/host/panel-http.js +322 -0
  25. package/src/host/panel-search.js +236 -0
  26. package/src/host/panel-session-store.js +411 -0
  27. package/src/host/rebuild.js +11 -3
  28. package/src/host/scene-ops.js +75 -6
  29. package/src/host/session-sync.js +91 -0
  30. package/src/index.js +2 -1
  31. package/src/ingest/cli.js +8 -7
  32. package/src/ingest/export.js +28 -18
  33. package/src/ingest/package.json +1 -1
  34. package/src/ingest/reader.js +181 -7
  35. package/src/model/embedding.js +3 -2
  36. package/src/model/llm.js +3 -2
  37. package/src/model/rerank.js +7 -4
  38. package/src/pipeline.js +159 -763
  39. package/src/scene/link.js +4 -4
  40. package/src/scene/package.json +1 -1
  41. package/src/scene/split.js +11 -11
  42. package/src/search/_fixtures.js +1 -0
  43. package/src/search/bench.js +4 -2
  44. package/src/search/chunk.js +6 -4
  45. package/src/search/dedupe.js +8 -8
  46. package/src/search/indexer.js +889 -879
  47. package/src/search/note-rank.js +64 -12
  48. package/src/search/regression.test.js +2 -1
  49. package/src/search/rrf.js +11 -11
  50. package/src/search/session-shape.js +3 -1
  51. package/src/search/thread.js +8 -8
  52. package/src/search/vector-fallback.js +509 -0
  53. package/src/search/vector-hydrate.js +309 -0
  54. package/src/search/vector-math.js +125 -0
  55. package/src/search/vector-store.js +1065 -1598
  56. package/src/search/vector-store.test.js +30 -0
  57. package/src/search/window.js +8 -8
  58. package/src/store/db.js +803 -715
  59. package/src/store/repo-extras-meta.js +430 -0
  60. package/src/store/repo-extras-search.js +580 -0
  61. package/src/store/repo.js +1024 -2133
  62. package/src/store/repo.test.js +39 -1
  63. package/src/store/schema.sql +15 -1
  64. package/src/tools/format.js +594 -503
  65. package/src/tools/index.js +7 -15
  66. package/src/tools/memory-forget.js +43 -32
  67. package/src/tools/memory-remember.js +11 -7
  68. package/src/tools/memory-search.js +721 -2206
  69. package/src/tools/remember-forget.test.js +19 -0
  70. package/src/tools/scope.js +7 -6
  71. package/src/tools/search-render.js +502 -0
  72. package/src/tools/time-route.js +71 -66
  73. package/src/tools/vector-route.js +655 -0
  74. package/sessions/qqb-p-0000000000-00000000000000000000000000000000.json +0 -12
package/locale/en.json CHANGED
@@ -4,4 +4,4 @@
4
4
  "description": "Long-term memory for a companion agent: every message is kept word for word, and the agent can look it up later.",
5
5
  "detail": "README.md"
6
6
  }
7
- }
7
+ }
package/locale/zh.json CHANGED
@@ -4,4 +4,4 @@
4
4
  "description": "给陪伴型 Agent 的长期记忆:你们说过的每一句话都原样存下来,TA想翻的时候能查到。",
5
5
  "detail": "README.md"
6
6
  }
7
- }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-verbatim",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "一字不改的长期记忆 —— 给陪伴型 Agent 记住你们说过的每一句话",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,8 +55,7 @@
55
55
  "icon.svg",
56
56
  "README.md",
57
57
  "CHANGELOG.md",
58
- "LICENSE",
59
- "sessions/qqb-p-0000000000-00000000000000000000000000000000.json"
58
+ "LICENSE"
60
59
  ],
61
60
  "keywords": [
62
61
  "dsh",
@@ -329,7 +329,7 @@ function toNormalized(ranges, opts) {
329
329
  * @param {Array<{from:unknown,to:unknown,reason?:string}>|Array<{from:number,to:number}>} ranges
330
330
  * 配置原样(字符串)或归一化后的都行
331
331
  * @param {{ path?: string }} [opts]
332
- * @returns {{from:number, to:number, reason:string|null}|null} 命中返回该区间,否则 null
332
+ * @returns {{from:number, to:number, reason?:string|null}|null} 命中返回该区间,否则 null
333
333
  * @throws {ConfigError} 区间非法时(配置错误必须抛,不能静默不排除)
334
334
  */
335
335
  export function findRange(at, ranges, opts = {}) {
@@ -76,7 +76,7 @@ export const DEFAULT_GLOBAL_CONFIG = Object.freeze({
76
76
  apiKey: '',
77
77
  /** 兼容从环境变量读 Key(apiKey 为空时才用) */
78
78
  apiKeyEnv: '',
79
- /** 参与精排的候选条数上限(默认 50:与粗排池 RERANK_POOL_SIZE 对齐,保证整池都排到) */
79
+ /** 参与精排的候选条数上限(默认 50,保证紧凑候选池全池重排) */
80
80
  topN: 50,
81
81
  /** 超时毫秒(超时自动降级回 RRF 原序) */
82
82
  timeoutMs: 8000,
@@ -88,6 +88,8 @@ export const DEFAULT_GLOBAL_CONFIG = Object.freeze({
88
88
  defaultLimit: 8,
89
89
  /** 单次最多返回几条 */
90
90
  maxLimit: 50,
91
+ /** 固定时区偏移(分钟,默认 480 = UTC+8 Asia/Shanghai;设为 null 回退默认 +480) */
92
+ timezoneOffsetMinutes: 480,
91
93
  }),
92
94
 
93
95
  /** 索引 */
@@ -194,20 +194,22 @@ export function validateSessionConfig(input, opts = {}) {
194
194
  out[key] = v;
195
195
  }
196
196
 
197
- out.excludeRanges = sanitizeExcludeRanges(input.excludeRanges, `${at}.excludeRanges`);
197
+ /** @type {any} */
198
+ const inputObj = input;
199
+ out.excludeRanges = sanitizeExcludeRanges(inputObj.excludeRanges, `${at}.excludeRanges`);
198
200
 
199
201
  // 未知字段原样保留(写回时不丢),只在需要时告警
200
202
  const unknown = [];
201
- for (const key of Object.keys(input)) {
203
+ for (const key of Object.keys(inputObj)) {
202
204
  if (CONFIG_KEYS.includes(key)) continue;
203
- out[key] = input[key];
205
+ out[key] = inputObj[key];
204
206
  unknown.push(key);
205
207
  }
206
208
  if (unknown.length && onWarn) {
207
209
  onWarn(`${at}:有未知配置项 ${unknown.map((k) => JSON.stringify(k)).join(', ')},已保留但不会被使用`);
208
210
  }
209
211
 
210
- return out;
212
+ return /** @type {{ record: boolean, tools: boolean, autoRecall: boolean, excludeRanges: any[] }} */ (out);
211
213
  }
212
214
 
213
215
  /**
@@ -222,8 +224,8 @@ export function validateSessionConfig(input, opts = {}) {
222
224
  function sanitizeExcludeRanges(raw, at) {
223
225
  if (raw === undefined || raw === null) return [];
224
226
  // 复用严格校验:抛错即配置非法;返回值只用于校验,不写回配置
225
- normalizeRanges(raw, { path: at });
226
- return raw.map((r) => {
227
+ normalizeRanges(/** @type {any} */ (raw), { path: at });
228
+ return /** @type {any[]} */ (raw).map((r) => {
227
229
  const item = { from: r.from, to: r.to };
228
230
  if (typeof r.reason === 'string' && r.reason.trim()) item.reason = r.reason.trim();
229
231
  return item;
@@ -240,7 +242,7 @@ function sanitizeExcludeRanges(raw, at) {
240
242
  */
241
243
  export function loadSessionConfig(sessionId, opts = {}) {
242
244
  const file = sessionConfigPath(sessionId, opts);
243
- const onWarn = typeof opts?.onWarn === 'function' ? opts.onWarn : undefined;
245
+ const onWarn = typeof opts === 'object' && opts !== null && typeof opts.onWarn === 'function' ? opts.onWarn : undefined;
244
246
 
245
247
  if (!fs.existsSync(file)) return defaultSessionConfig();
246
248
 
@@ -286,7 +288,7 @@ export function loadSessionConfig(sessionId, opts = {}) {
286
288
  */
287
289
  export function saveSessionConfig(sessionId, patch, opts = {}) {
288
290
  const file = sessionConfigPath(sessionId, opts);
289
- const onWarn = typeof opts?.onWarn === 'function' ? opts.onWarn : undefined;
291
+ const onWarn = typeof opts === 'object' && opts !== null && typeof opts.onWarn === 'function' ? opts.onWarn : undefined;
290
292
 
291
293
  if (patch !== undefined && patch !== null && (typeof patch !== 'object' || Array.isArray(patch))) {
292
294
  throw new ConfigError(`saveSessionConfig 的 patch 必须是对象,实际是 ${typeName(patch)}`, {
@@ -370,7 +372,7 @@ export function setSessionExcludeRanges(sessionId, ranges, opts = {}) {
370
372
  */
371
373
  export function loadSessionExcludeRanges(sessionId, opts = {}) {
372
374
  const cfg = loadSessionConfig(sessionId, opts);
373
- return normalizeRanges(cfg.excludeRanges, { path: `${sessionConfigPath(sessionId, opts)}.excludeRanges` });
375
+ return normalizeRanges(/** @type {any} */ (cfg.excludeRanges), { path: `${sessionConfigPath(sessionId, opts)}.excludeRanges` });
374
376
  }
375
377
 
376
378
  /**
@@ -398,7 +400,7 @@ export function ensureSessionConfig(sessionId, opts = {}) {
398
400
  * 面板 `panel.status → enabled` 的形状(PANEL.md §5)。
399
401
  * `autoRecall` 恒带在返回值里(协议稳定),但面板不渲染开关(D-166)。
400
402
  *
401
- * @param {object} cfg
403
+ * @param {any} cfg
402
404
  * @returns {{ record: boolean, tools: boolean, autoRecall: boolean }}
403
405
  */
404
406
  export function enabledOf(cfg) {