@kenz1117/dsh-engram 0.13.5 → 0.13.7
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/CHANGELOG.md +19 -0
- package/README.md +23 -1
- package/i18n/ru.txt +7 -0
- package/lib/client.js +1 -1
- package/lib/client.js.map +1 -1
- package/lib/index.js +271 -6
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { cpSync, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
5
5
|
import { homedir } from "node:os";
|
|
@@ -196,6 +196,7 @@ const zh$5 = {
|
|
|
196
196
|
"core.observationsHeader": "Consolidated beliefs (distilled from multiple stored memories; verify against sources before high-stakes use):",
|
|
197
197
|
"core.observationItem": "- {belief} ({count} sources)",
|
|
198
198
|
"core.reviewDue": "\nPalace review due today: {count}{plus} memories. Use engram_review_queue for active recall (recall beats re-reading).",
|
|
199
|
+
"core.reflectPending": "\n巩固待处理:有 {count} 组会话登记的记忆还没蒸馏。调用 engram_reflect 整理——只摄取不整理,记忆就是散的。",
|
|
199
200
|
"core.compressSystem": "把记忆条目压缩为更短的一句话表述(每条不超过 40 个字符),保留可跨会话复用的关键信息(事实、偏好、决策、方法)。\n只输出一个 JSON 数组,每项形如 {\"id\": \"原样返回的id\", \"content\": \"压缩后表述\"},条目数量与 id 必须与输入一一对应。\n不要输出 JSON 以外的任何内容。",
|
|
200
201
|
"core.rationaleHeader": "本轮画像共 {count} 条记忆,挑选理由如下:",
|
|
201
202
|
"core.rationaleFooter": "如果某条理由错误,请通过 engram_report 反馈,越准的画像越能帮你。",
|
|
@@ -231,6 +232,7 @@ const zh$5 = {
|
|
|
231
232
|
"core.warnDisposeFinalFailed": "[dsh-engram] 会话结束的收尾处理异常(不影响对话):",
|
|
232
233
|
"core.warnInjectionSnapshotFailed": "[dsh-engram] 注入快照落库失败(不影响对话):",
|
|
233
234
|
"core.warnReflectFailed": "[dsh-engram] 会话结束的信念巩固异常({scope},不影响对话):",
|
|
235
|
+
"core.warnIngestWithoutReflect": "[dsh-engram] ingest 开启但 reflect 为 off:记忆只摄取不整理(读起来就是散的)。建议 reflect: auto(或 suggest,靠会话提醒驱动),或定期运行 engram_reflect。",
|
|
234
236
|
"core.warnReflectBatchDropped": "[dsh-engram] 信念巩固丢弃 {count} 条候选(输出预算/解析失败;未被巩固、下次巩固继续取材)",
|
|
235
237
|
"core.warnDecayStartupFailed": "[dsh-engram] 启动衰减调度失败(跳过):",
|
|
236
238
|
"core.warnDecayPeriodicFailed": "[dsh-engram] 周期衰减调度失败(跳过):",
|
|
@@ -254,6 +256,8 @@ const en$5 = {
|
|
|
254
256
|
"core.observationsHeader": "Consolidated beliefs (distilled from multiple stored memories; verify against sources before high-stakes use):",
|
|
255
257
|
"core.observationItem": "- {belief} ({count} sources)",
|
|
256
258
|
"core.reviewDue": "\nPalace review due today: {count}{plus} memories. Use engram_review_queue for active recall (recall beats re-reading).",
|
|
259
|
+
"core.reflectPending": "\nConsolidation pending: {count} session registration(s) hold memories not yet distilled. Call engram_reflect to consolidate them — ingested memories stay scattered until reflected.",
|
|
260
|
+
"core.warnIngestWithoutReflect": "[dsh-engram] ingest is on but reflect is off — memories accumulate without consolidation (they read scattered). Set reflect: auto (or suggest), or run engram_reflect regularly.",
|
|
257
261
|
"core.compressSystem": "Compress each memory entry into a shorter single-sentence wording (at most 40 characters per entry), keeping the key information that can be reused across sessions (facts, preferences, decisions, methods).\nOutput only one JSON array, each item shaped like {\"id\": \"the id returned verbatim\", \"content\": \"the compressed wording\"}; the number of items and the ids must correspond one-to-one with the input.\nDo not output anything other than JSON.",
|
|
258
262
|
"core.rationaleHeader": "This profile holds {count} memories in total; they were picked for the following reasons:",
|
|
259
263
|
"core.rationaleFooter": "If any reason is wrong, report it via engram_report — the more accurate the profile, the better it helps you.",
|
|
@@ -540,6 +544,11 @@ const zh$2 = {
|
|
|
540
544
|
"store.migrationDbNames": "旧库 {legacy};新库 {next}",
|
|
541
545
|
"store.migrationManualGuidance": "人工处理前请停止相关宿主并备份所有数据库及 sidecar;新库可能已写入记忆,请勿直接覆盖,先用 engram_review / engram_export 审核并人工重新归属",
|
|
542
546
|
"store.migrationRenamed": "[dsh-engram] 项目记忆库已迁移({names}),已记录 .migrated-to;旧库可能包含同前缀目录的记忆。{manual}",
|
|
547
|
+
"store.homeAdoptionMoved": "[dsh-engram] 数据目录已随宿主数据根搬到 {to}(原 {from})。记忆库、词典与模型缓存一并搬走。",
|
|
548
|
+
"store.homeAdoptionCopied": "[dsh-engram] 数据目录已复制到 {to}(原 {from},跨盘无法直接改名);旧目录已在校验后删除。",
|
|
549
|
+
"store.homeAdoptionDeferred": "[dsh-engram] conservative 模式暂缓收编:数据仍在 {from},本次继续使用旧目录。",
|
|
550
|
+
"store.homeAdoptionKeptBoth": "[dsh-engram] 两处都有记忆库({from} 与 {to}):未自动合并,本次继续使用旧目录 {from},请人工确认后清理。",
|
|
551
|
+
"store.homeAdoptionFailed": "[dsh-engram] 数据目录收编失败({from} → {to}):{detail};本次继续使用旧目录,数据未丢失。",
|
|
543
552
|
"store.migrationKeptBoth": "[dsh-engram] 新旧项目记忆库并存,未合并或移动({names})。{manual}",
|
|
544
553
|
"store.migrationDeferred": "[dsh-engram] conservative 模式暂缓旧库迁移({names});旧库保持不变,将打开新的空库。{manual}",
|
|
545
554
|
"store.migrationAlreadyMigrated": "[dsh-engram] 旧库已有迁移记录({names},先前归属 {cwd}):{pointer};先前迁移的库可能含有当前目录的记忆。{manual}",
|
|
@@ -587,6 +596,11 @@ const en$2 = {
|
|
|
587
596
|
"store.migrationDbNames": "old database {legacy}; new database {next}",
|
|
588
597
|
"store.migrationManualGuidance": "before handling this manually, stop the affected hosts and back up every database and sidecar; the new database may already contain memories, so do not overwrite it — review it with engram_review / engram_export and re-assign ownership by hand",
|
|
589
598
|
"store.migrationRenamed": "[dsh-engram] the project memory database was migrated ({names}) and .migrated-to was recorded; the old database may hold memories of directories sharing the same prefix. {manual}",
|
|
599
|
+
"store.homeAdoptionMoved": "[dsh-engram] the data directory moved with the harness home to {to} (was {from}); memories, dictionaries and the model cache moved along.",
|
|
600
|
+
"store.homeAdoptionCopied": "[dsh-engram] the data directory was copied to {to} (was {from}; a cross-device move cannot be a rename); the old directory was removed after verification.",
|
|
601
|
+
"store.homeAdoptionDeferred": "[dsh-engram] conservative mode deferred the adoption: the data is still in {from}, and that directory is used for now.",
|
|
602
|
+
"store.homeAdoptionKeptBoth": "[dsh-engram] both locations hold memory databases ({from} and {to}); nothing was merged automatically, the old directory {from} is used for now — confirm and clean up by hand.",
|
|
603
|
+
"store.homeAdoptionFailed": "[dsh-engram] the data directory adoption failed ({from} → {to}): {detail}; the old directory is used for now and no data was lost.",
|
|
590
604
|
"store.migrationKeptBoth": "[dsh-engram] old and new project memory databases coexist; neither was merged nor moved ({names}). {manual}",
|
|
591
605
|
"store.migrationDeferred": "[dsh-engram] conservative mode deferred the legacy database migration ({names}); the old database is left untouched and a new empty one will be opened. {manual}",
|
|
592
606
|
"store.migrationAlreadyMigrated": "[dsh-engram] the legacy database already has a migration record ({names}, claimed earlier by {cwd}): {pointer}; the database migrated earlier may hold memories of the current directory. {manual}",
|
|
@@ -1460,6 +1474,20 @@ function noteLegacyJevFields(where, fields) {
|
|
|
1460
1474
|
* 插件 Config:所有部署可变项集中于此,禁止在实现里内嵌默认值。
|
|
1461
1475
|
* @module @kenz1117/dsh-engram/config
|
|
1462
1476
|
*/
|
|
1477
|
+
/**
|
|
1478
|
+
* 宿主数据根目录:`$DSH_HOME`,缺省 `~/.dsh`。
|
|
1479
|
+
*
|
|
1480
|
+
* 契约抄自宿主的 `@deepseek-ai/dsh-home-paths`(resolveDshHome):显式值 > `$DSH_HOME`
|
|
1481
|
+
* > `~/.dsh`;空白或只有空格的 `$DSH_HOME` 视同未设置(否则 home 会被解析成当前目录)。
|
|
1482
|
+
* 插件不直接依赖那个包——它是可选 peer,缺了不能让插件起不来;语义保持一致即可。
|
|
1483
|
+
* @param env - 环境变量映射(默认 `process.env`)。
|
|
1484
|
+
* @returns 绝对路径形式的数据根目录。
|
|
1485
|
+
*/
|
|
1486
|
+
function resolveDshHome(env = process.env) {
|
|
1487
|
+
const fromEnv = env.DSH_HOME;
|
|
1488
|
+
const home = fromEnv !== void 0 && fromEnv.trim() !== "" ? fromEnv : join(homedir(), ".dsh");
|
|
1489
|
+
return resolve(home);
|
|
1490
|
+
}
|
|
1463
1491
|
/** 合法配置键集合(未知键 loud 失败)。 */
|
|
1464
1492
|
const CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1465
1493
|
"legacyMigration",
|
|
@@ -1484,6 +1512,7 @@ const CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
1484
1512
|
"autoSlot",
|
|
1485
1513
|
"reviewScheduling",
|
|
1486
1514
|
"assessReminder",
|
|
1515
|
+
"reflectReminder",
|
|
1487
1516
|
"palaceChangeWindowSec",
|
|
1488
1517
|
"panelAccess",
|
|
1489
1518
|
"historyBackfillDays",
|
|
@@ -1545,6 +1574,7 @@ const Config = z.object({
|
|
|
1545
1574
|
panelAccess: z.string(),
|
|
1546
1575
|
palaceChangeWindowSec: z.number().step(1).min(5).max(600),
|
|
1547
1576
|
assessReminder: z.boolean(),
|
|
1577
|
+
reflectReminder: z.boolean(),
|
|
1548
1578
|
historyBackfillDays: z.number().step(1).min(0).max(3650),
|
|
1549
1579
|
historyBackfillMaxTurnsPerSession: z.number().step(1).min(1).max(500),
|
|
1550
1580
|
historyBackfillMaxTotalTurns: z.number().step(1).min(1).max(5e3),
|
|
@@ -1660,9 +1690,14 @@ function resolveConfig(config = {}) {
|
|
|
1660
1690
|
if (baseUrl === void 0 || baseUrl === "") throw new Error("dsh-engram: embedder.kind=remote requires embedder.baseUrl");
|
|
1661
1691
|
}
|
|
1662
1692
|
}
|
|
1663
|
-
const
|
|
1693
|
+
const dshHome = resolveDshHome();
|
|
1694
|
+
const legacyDbDir = join(homedir(), ".dsh", "engram");
|
|
1695
|
+
const dbDir = config.dbDir ?? join(dshHome, "engram");
|
|
1664
1696
|
return {
|
|
1665
1697
|
dbDir,
|
|
1698
|
+
dshHome,
|
|
1699
|
+
dbDirExplicit: config.dbDir !== void 0,
|
|
1700
|
+
legacyDbDir,
|
|
1666
1701
|
legacyMigration: config.legacyMigration ?? "eager",
|
|
1667
1702
|
injectProfile: config.injectProfile ?? true,
|
|
1668
1703
|
profileTopN: config.profileTopN ?? 8,
|
|
@@ -1684,6 +1719,7 @@ function resolveConfig(config = {}) {
|
|
|
1684
1719
|
injectItemBudgetDecay: config.injectItemBudgetDecay ?? .9,
|
|
1685
1720
|
injectItemBudgetFloor: config.injectItemBudgetFloor ?? 24,
|
|
1686
1721
|
assessReminder: config.assessReminder ?? true,
|
|
1722
|
+
reflectReminder: config.reflectReminder ?? true,
|
|
1687
1723
|
rankRecencyWeight: config.rankRecencyWeight ?? .2,
|
|
1688
1724
|
rankProofWeight: config.rankProofWeight ?? .1,
|
|
1689
1725
|
queryRewrite: config.queryRewrite ?? true,
|
|
@@ -2483,6 +2519,7 @@ const en = {
|
|
|
2483
2519
|
governanceConflicts: "Conflicts",
|
|
2484
2520
|
governanceBeliefs: "Beliefs",
|
|
2485
2521
|
systemRuntime: "Runtime",
|
|
2522
|
+
systemGuardIngestNoReflect: "Ingest is on but consolidation (reflect) is off: memories are collected but never distilled — they read scattered. Set reflect: auto or suggest in the config.",
|
|
2486
2523
|
systemStorage: "Storage",
|
|
2487
2524
|
systemModels: "Models & language",
|
|
2488
2525
|
pageHeaderRuntimeSubtitle: "Plugin and panel versions, the durable job queue, embedding model status.",
|
|
@@ -2504,6 +2541,8 @@ const en = {
|
|
|
2504
2541
|
systemJobEmpty: "The queue is empty: nothing pending and nothing failed.",
|
|
2505
2542
|
systemStorageTotal: "Total",
|
|
2506
2543
|
systemStorageScope: "Store",
|
|
2544
|
+
systemStorageHome: "Harness home",
|
|
2545
|
+
systemStorageOutsideHome: "The data directory sits outside the harness home: the memory database stays where it is and will not follow a relocated home.",
|
|
2507
2546
|
systemStorageActive: "Active",
|
|
2508
2547
|
systemStorageArchived: "Archived",
|
|
2509
2548
|
systemStorageForgotten: "Forgotten",
|
|
@@ -3139,6 +3178,7 @@ const ru = {
|
|
|
3139
3178
|
governanceConflicts: "Противоречия",
|
|
3140
3179
|
governanceBeliefs: "Убеждения",
|
|
3141
3180
|
systemRuntime: "Время выполнения",
|
|
3181
|
+
systemGuardIngestNoReflect: "Ingest включён, но обобщение (reflect) выключено: воспоминания собираются, но не перегоняются — и читаются разрозненно. Задайте reflect: auto или suggest в конфигурации.",
|
|
3142
3182
|
systemStorage: "Хранилище",
|
|
3143
3183
|
systemModels: "Модели и язык",
|
|
3144
3184
|
pageHeaderRuntimeSubtitle: "Версии плагина и панели, очередь устойчивых заданий, состояние модели эмбеддинга.",
|
|
@@ -3160,6 +3200,8 @@ const ru = {
|
|
|
3160
3200
|
systemJobEmpty: "Очередь пуста: ни ждущих, ни упавших заданий.",
|
|
3161
3201
|
systemStorageTotal: "Всего",
|
|
3162
3202
|
systemStorageScope: "База",
|
|
3203
|
+
systemStorageHome: "Дом Harness",
|
|
3204
|
+
systemStorageOutsideHome: "Каталог данных лежит вне дома Harness: база памяти остаётся на месте и не переедёт вместе с домом.",
|
|
3163
3205
|
systemStorageActive: "Активные",
|
|
3164
3206
|
systemStorageArchived: "В архиве",
|
|
3165
3207
|
systemStorageForgotten: "Забытые",
|
|
@@ -3793,6 +3835,7 @@ const zh = {
|
|
|
3793
3835
|
governanceConflicts: "矛盾",
|
|
3794
3836
|
governanceBeliefs: "信念",
|
|
3795
3837
|
systemRuntime: "运行时",
|
|
3838
|
+
systemGuardIngestNoReflect: "摄取已开启但整理(reflect)为关闭:记忆只收集不蒸馏,读起来会是散的。建议在配置里设置 reflect: auto 或 suggest。",
|
|
3796
3839
|
systemStorage: "存储",
|
|
3797
3840
|
systemModels: "模型与词典",
|
|
3798
3841
|
pageHeaderRuntimeSubtitle: "插件与面板版本、持久作业队列、嵌入模型状态。",
|
|
@@ -3814,6 +3857,8 @@ const zh = {
|
|
|
3814
3857
|
systemJobEmpty: "队列为空:没有待处理、也没有失败的作业。",
|
|
3815
3858
|
systemStorageTotal: "总条数",
|
|
3816
3859
|
systemStorageScope: "库",
|
|
3860
|
+
systemStorageHome: "宿主数据根",
|
|
3861
|
+
systemStorageOutsideHome: "数据目录不在宿主数据根之下:记忆库落在别处,迁移 home 时不会跟着走。",
|
|
3817
3862
|
systemStorageActive: "活跃",
|
|
3818
3863
|
systemStorageArchived: "归档",
|
|
3819
3864
|
systemStorageForgotten: "已遗忘",
|
|
@@ -10731,6 +10776,19 @@ var UnknownProjectError = class extends Error {
|
|
|
10731
10776
|
this.name = "UnknownProjectError";
|
|
10732
10777
|
}
|
|
10733
10778
|
};
|
|
10779
|
+
/** 管理面板的路由依赖。 */
|
|
10780
|
+
/**
|
|
10781
|
+
* 路径是否位于某个根之下(用于「数据目录在不在 home 之下」这类判断)。
|
|
10782
|
+
* @param child - 待判断的路径。
|
|
10783
|
+
* @param root - 根目录。
|
|
10784
|
+
* @returns true 表示 child 位于 root 之内(含 root 自身)。
|
|
10785
|
+
*/
|
|
10786
|
+
function isInside(child, root) {
|
|
10787
|
+
const from = resolve(root);
|
|
10788
|
+
const to = resolve(child);
|
|
10789
|
+
if (to === from) return true;
|
|
10790
|
+
return to.startsWith(from.endsWith(sep) ? from : `${from}${sep}`);
|
|
10791
|
+
}
|
|
10734
10792
|
/**
|
|
10735
10793
|
* 注册 /engram 页面与 /api/engram/* 接口(effect 由调用方持有,disposer 可逆)。
|
|
10736
10794
|
* @param ctx - 携带 webServer 服务的宿主上下文。
|
|
@@ -11165,6 +11223,8 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
11165
11223
|
const allTrue = (key) => parts.length > 0 && parts.every((part) => part[key] === true);
|
|
11166
11224
|
json(res, 200, {
|
|
11167
11225
|
dir: deps.dbDir,
|
|
11226
|
+
home: deps.dshHome,
|
|
11227
|
+
outsideHome: !isInside(deps.dbDir, deps.dshHome),
|
|
11168
11228
|
keepOps: LOG_KEEP_OPS,
|
|
11169
11229
|
parts,
|
|
11170
11230
|
totals: {
|
|
@@ -11495,7 +11555,11 @@ function registerEngramRoutes(ctx, deps) {
|
|
|
11495
11555
|
return;
|
|
11496
11556
|
}
|
|
11497
11557
|
if (req.method === "GET" && route === "version") {
|
|
11498
|
-
json(res, 200, {
|
|
11558
|
+
json(res, 200, {
|
|
11559
|
+
pluginVersion: deps.pluginVersion,
|
|
11560
|
+
ingest: deps.ingest,
|
|
11561
|
+
reflect: deps.reflect
|
|
11562
|
+
});
|
|
11499
11563
|
return;
|
|
11500
11564
|
}
|
|
11501
11565
|
if (req.method === "GET" && route === "registry") {
|
|
@@ -12962,6 +13026,157 @@ function findProjectPalace(palaces, selector) {
|
|
|
12962
13026
|
}
|
|
12963
13027
|
return palaces.find((palace) => palace.kind === "process") ?? palaces[0];
|
|
12964
13028
|
}
|
|
13029
|
+
// src/store/home-adoption.ts
|
|
13030
|
+
/**
|
|
13031
|
+
* 旧数据目录的收编(#51):DSH_HOME 迁移之后,别让记忆库分裂成两份。
|
|
13032
|
+
*
|
|
13033
|
+
* 背景:数据目录默认值此前写死 `~/.dsh/engram`,不看宿主的 `$DSH_HOME`。把 home
|
|
13034
|
+
* 搬到别的盘之后,插件的数据仍然静默留在旧盘上;人以为在用新盘,其实读的是旧盘。
|
|
13035
|
+
* 默认值改成跟 `$DSH_HOME` 之后又来一个坑:旧盘上的库会被留在原地,插件却开始读
|
|
13036
|
+
* 新盘——于是「库不见了」。这里做的就是把那一份搬到新盘去。
|
|
13037
|
+
*
|
|
13038
|
+
* 规矩:
|
|
13039
|
+
* - 显式配置了 `dbDir` 的人自己说了算,这里一个字都不动;
|
|
13040
|
+
* - 目标目录已经有库 → 两边都有数据,不自动合并,保留旧目录继续用(人的记忆在那儿),
|
|
13041
|
+
* 并明确报出两个路径让人处理;
|
|
13042
|
+
* - 搬运失败 → 仍然用旧目录。数据看不见比数据待在新盘上更糟;
|
|
13043
|
+
* - 跨盘(EXDEV)先复制到临时目录、逐个文件核对大小,确认无误才改名并删旧,
|
|
13044
|
+
* 任何一步出错都不删旧目录。
|
|
13045
|
+
*
|
|
13046
|
+
* @module @kenz1117/dsh-engram/store/home-adoption
|
|
13047
|
+
*/
|
|
13048
|
+
/** 目录里是否有数据库文件(记忆库本体;只有字典/模型不算“有库”)。 */
|
|
13049
|
+
function hasDatabase(dir) {
|
|
13050
|
+
if (!existsSync(dir)) return false;
|
|
13051
|
+
let entries;
|
|
13052
|
+
try {
|
|
13053
|
+
entries = readdirSync(dir);
|
|
13054
|
+
} catch {
|
|
13055
|
+
return false;
|
|
13056
|
+
}
|
|
13057
|
+
return entries.some((name) => name.endsWith(".db"));
|
|
13058
|
+
}
|
|
13059
|
+
/** 目录是否为空(没有任何条目)。 */
|
|
13060
|
+
function isEmptyDir(dir) {
|
|
13061
|
+
if (!existsSync(dir)) return true;
|
|
13062
|
+
try {
|
|
13063
|
+
return readdirSync(dir).length === 0;
|
|
13064
|
+
} catch {
|
|
13065
|
+
return false;
|
|
13066
|
+
}
|
|
13067
|
+
}
|
|
13068
|
+
/** 递归列出相对路径与字节数(复制后的核对依据)。 */
|
|
13069
|
+
function fileSizes(dir) {
|
|
13070
|
+
const out = /* @__PURE__ */ new Map();
|
|
13071
|
+
const walk = (current, prefix) => {
|
|
13072
|
+
for (const name of readdirSync(current)) {
|
|
13073
|
+
const full = join(current, name);
|
|
13074
|
+
const rel = prefix === "" ? name : `${prefix}/${name}`;
|
|
13075
|
+
const stat = statSync(full);
|
|
13076
|
+
if (stat.isDirectory()) walk(full, rel);
|
|
13077
|
+
else out.set(rel, stat.size);
|
|
13078
|
+
}
|
|
13079
|
+
};
|
|
13080
|
+
walk(dir, "");
|
|
13081
|
+
return out;
|
|
13082
|
+
}
|
|
13083
|
+
/** 两份目录的文件清单与大小是否一致。 */
|
|
13084
|
+
function sameContent(a, b) {
|
|
13085
|
+
const left = fileSizes(a);
|
|
13086
|
+
const right = fileSizes(b);
|
|
13087
|
+
if (left.size !== right.size) return false;
|
|
13088
|
+
for (const [name, size] of left) if (right.get(name) !== size) return false;
|
|
13089
|
+
return true;
|
|
13090
|
+
}
|
|
13091
|
+
/**
|
|
13092
|
+
* 决定并(必要时)执行旧目录收编。
|
|
13093
|
+
* @param target - 新数据目录(`$DSH_HOME/engram` 或显式配置)。
|
|
13094
|
+
* @param legacy - 旧默认目录(`~/.dsh/engram`)。
|
|
13095
|
+
* @param policy - 迁移策略:`eager` 自动搬,`conservative` 只报不动。
|
|
13096
|
+
* @returns 实际应使用的目录与搬运结果。
|
|
13097
|
+
*/
|
|
13098
|
+
function adoptLegacyDbDir(options) {
|
|
13099
|
+
const { target, legacy, policy } = options;
|
|
13100
|
+
const base = { legacyDbDir: legacy };
|
|
13101
|
+
if (target === legacy) return {
|
|
13102
|
+
...base,
|
|
13103
|
+
dbDir: target,
|
|
13104
|
+
outcome: "none"
|
|
13105
|
+
};
|
|
13106
|
+
if (!hasDatabase(legacy)) return {
|
|
13107
|
+
...base,
|
|
13108
|
+
dbDir: target,
|
|
13109
|
+
outcome: "none"
|
|
13110
|
+
};
|
|
13111
|
+
if (hasDatabase(target)) return {
|
|
13112
|
+
...base,
|
|
13113
|
+
dbDir: legacy,
|
|
13114
|
+
outcome: "kept-both"
|
|
13115
|
+
};
|
|
13116
|
+
if (policy === "conservative") return {
|
|
13117
|
+
...base,
|
|
13118
|
+
dbDir: legacy,
|
|
13119
|
+
outcome: "deferred"
|
|
13120
|
+
};
|
|
13121
|
+
try {
|
|
13122
|
+
if (isEmptyDir(target) && existsSync(target)) rmSync(target, {
|
|
13123
|
+
recursive: true,
|
|
13124
|
+
force: true
|
|
13125
|
+
});
|
|
13126
|
+
renameSync(legacy, target);
|
|
13127
|
+
return {
|
|
13128
|
+
...base,
|
|
13129
|
+
dbDir: target,
|
|
13130
|
+
outcome: "moved"
|
|
13131
|
+
};
|
|
13132
|
+
} catch (error) {
|
|
13133
|
+
if (error.code !== "EXDEV") return {
|
|
13134
|
+
...base,
|
|
13135
|
+
dbDir: legacy,
|
|
13136
|
+
outcome: "failed",
|
|
13137
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
13138
|
+
};
|
|
13139
|
+
}
|
|
13140
|
+
const staging = `${target}.adopting`;
|
|
13141
|
+
try {
|
|
13142
|
+
rmSync(staging, {
|
|
13143
|
+
recursive: true,
|
|
13144
|
+
force: true
|
|
13145
|
+
});
|
|
13146
|
+
mkdirSync(join(staging, ".."), { recursive: true });
|
|
13147
|
+
cpSync(legacy, staging, {
|
|
13148
|
+
recursive: true,
|
|
13149
|
+
errorOnExist: true,
|
|
13150
|
+
force: false
|
|
13151
|
+
});
|
|
13152
|
+
if (!sameContent(legacy, staging)) throw new Error("copied tree differs from the source (file list or size mismatch)");
|
|
13153
|
+
rmSync(target, {
|
|
13154
|
+
recursive: true,
|
|
13155
|
+
force: true
|
|
13156
|
+
});
|
|
13157
|
+
renameSync(staging, target);
|
|
13158
|
+
rmSync(legacy, {
|
|
13159
|
+
recursive: true,
|
|
13160
|
+
force: true
|
|
13161
|
+
});
|
|
13162
|
+
return {
|
|
13163
|
+
...base,
|
|
13164
|
+
dbDir: target,
|
|
13165
|
+
outcome: "copied"
|
|
13166
|
+
};
|
|
13167
|
+
} catch (error) {
|
|
13168
|
+
rmSync(staging, {
|
|
13169
|
+
recursive: true,
|
|
13170
|
+
force: true
|
|
13171
|
+
});
|
|
13172
|
+
return {
|
|
13173
|
+
...base,
|
|
13174
|
+
dbDir: legacy,
|
|
13175
|
+
outcome: "failed",
|
|
13176
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
13177
|
+
};
|
|
13178
|
+
}
|
|
13179
|
+
}
|
|
12965
13180
|
/** kind → базовый идентификатор комнаты. Фиксированное соответствие: однотипные
|
|
12966
13181
|
* записи всегда попадают в одну комнату. Идентификатор — это ДАННЫЕ, он пишется
|
|
12967
13182
|
* в память (slot_room) и не зависит от языка интерфейса; отображаемое имя берётся
|
|
@@ -18567,7 +18782,7 @@ function estimateTokens(text) {
|
|
|
18567
18782
|
return Math.ceil(wide * WIDE_TOKENS_PER_CHAR + narrow / 4);
|
|
18568
18783
|
}
|
|
18569
18784
|
// package.json
|
|
18570
|
-
var version = "0.13.
|
|
18785
|
+
var version = "0.13.7";
|
|
18571
18786
|
// src/index.ts
|
|
18572
18787
|
/**
|
|
18573
18788
|
* dsh-engram:DeepSeek Harness 跨会话长期记忆插件(host 半)。
|
|
@@ -18839,6 +19054,16 @@ async function preStep(ctx, openStore, openStoreForProjectCwd, resolved, embedde
|
|
|
18839
19054
|
const top = await store.topActive("user", resolved.profileTopN);
|
|
18840
19055
|
if (top.length === 0 && curated === void 0) return decision;
|
|
18841
19056
|
const dueTotal = resolved.reviewScheduling ? (await Promise.all(["user", "project"].map(async (scope) => (await openStore(scope)).dueReviews(Date.now(), 50)))).reduce((sum, rows) => sum + rows.length, 0) : 0;
|
|
19057
|
+
let reflectPending = 0;
|
|
19058
|
+
if (resolved.reflect === "suggest" && resolved.reflectReminder) reflectPending = (await Promise.all(["user", "project"].map(async (scope) => {
|
|
19059
|
+
return (await (await openStore(scope)).listAuditDetails("reflect-pending")).reduce((total, detail) => {
|
|
19060
|
+
try {
|
|
19061
|
+
return JSON.parse(detail).scope === scope ? total + 1 : total;
|
|
19062
|
+
} catch {
|
|
19063
|
+
return total;
|
|
19064
|
+
}
|
|
19065
|
+
}, 0);
|
|
19066
|
+
}))).reduce((sum, count) => sum + count, 0);
|
|
18842
19067
|
const itemBudget = {
|
|
18843
19068
|
start: resolved.injectItemBudgetStart,
|
|
18844
19069
|
decay: resolved.injectItemBudgetDecay,
|
|
@@ -18875,7 +19100,8 @@ async function preStep(ctx, openStore, openStoreForProjectCwd, resolved, embedde
|
|
|
18875
19100
|
count: dueTotal,
|
|
18876
19101
|
plus: dueTotal >= 50 ? "+" : ""
|
|
18877
19102
|
});
|
|
18878
|
-
const
|
|
19103
|
+
const reflectPendingLine = reflectPending === 0 ? "" : message("core.reflectPending", { count: reflectPending });
|
|
19104
|
+
const textWithRationale = wrapWithRationale(text, top) + dueLine + reflectPendingLine;
|
|
18879
19105
|
const hash = createHash("sha256").update(`${parts.curated ?? ""}\n${textWithRationale}`).digest("hex");
|
|
18880
19106
|
if (!compacted && hash === sessionState.lastProfileHash) return decision;
|
|
18881
19107
|
sessionState.lastProfileHash = hash;
|
|
@@ -19075,6 +19301,41 @@ function persistPalaceLanguage(ctx, language) {
|
|
|
19075
19301
|
*/
|
|
19076
19302
|
async function apply(ctx, config = {}) {
|
|
19077
19303
|
const resolvedConfig = resolveConfig(config);
|
|
19304
|
+
const adoption = resolvedConfig.dbDirExplicit ? {
|
|
19305
|
+
dbDir: resolvedConfig.dbDir,
|
|
19306
|
+
legacyDbDir: resolvedConfig.legacyDbDir,
|
|
19307
|
+
outcome: "none"
|
|
19308
|
+
} : adoptLegacyDbDir({
|
|
19309
|
+
target: resolvedConfig.dbDir,
|
|
19310
|
+
legacy: resolvedConfig.legacyDbDir,
|
|
19311
|
+
policy: resolvedConfig.legacyMigration
|
|
19312
|
+
});
|
|
19313
|
+
if (adoption.outcome === "moved") console.warn(message("store.homeAdoptionMoved", {
|
|
19314
|
+
from: adoption.legacyDbDir,
|
|
19315
|
+
to: adoption.dbDir
|
|
19316
|
+
}));
|
|
19317
|
+
if (adoption.outcome === "copied") console.warn(message("store.homeAdoptionCopied", {
|
|
19318
|
+
from: adoption.legacyDbDir,
|
|
19319
|
+
to: adoption.dbDir
|
|
19320
|
+
}));
|
|
19321
|
+
if (adoption.outcome === "deferred") console.warn(message("store.homeAdoptionDeferred", {
|
|
19322
|
+
from: adoption.legacyDbDir,
|
|
19323
|
+
to: adoption.dbDir
|
|
19324
|
+
}));
|
|
19325
|
+
if (adoption.outcome === "kept-both") console.warn(message("store.homeAdoptionKeptBoth", {
|
|
19326
|
+
from: adoption.legacyDbDir,
|
|
19327
|
+
to: adoption.dbDir
|
|
19328
|
+
}));
|
|
19329
|
+
if (adoption.outcome === "failed") console.warn(message("store.homeAdoptionFailed", {
|
|
19330
|
+
from: adoption.legacyDbDir,
|
|
19331
|
+
to: adoption.dbDir,
|
|
19332
|
+
detail: adoption.detail ?? ""
|
|
19333
|
+
}));
|
|
19334
|
+
const effectiveConfig = adoption.dbDir === resolvedConfig.dbDir ? resolvedConfig : {
|
|
19335
|
+
...resolvedConfig,
|
|
19336
|
+
dbDir: adoption.dbDir,
|
|
19337
|
+
...config.modelCacheDir === void 0 ? { modelCacheDir: join(adoption.dbDir, "models") } : {}
|
|
19338
|
+
};
|
|
19078
19339
|
const registry = loadRegistry({ dbDir: resolvedConfig.dbDir });
|
|
19079
19340
|
/** Что записано в настройке: `auto` — решения о языке дворца ещё нет. */
|
|
19080
19341
|
const languageSetting = readLanguageSetting(config.language);
|
|
@@ -19088,7 +19349,7 @@ async function apply(ctx, config = {}) {
|
|
|
19088
19349
|
if (!determination.decision.conflict) language = determination.decision.language;
|
|
19089
19350
|
}
|
|
19090
19351
|
const resolved = {
|
|
19091
|
-
...
|
|
19352
|
+
...effectiveConfig,
|
|
19092
19353
|
language,
|
|
19093
19354
|
languageSetting
|
|
19094
19355
|
};
|
|
@@ -19217,6 +19478,7 @@ async function apply(ctx, config = {}) {
|
|
|
19217
19478
|
/** Ожидание базы под текущий язык: пересчитывается, а не берётся из сборки плагина. */
|
|
19218
19479
|
const baseTargetNow = () => resolveBaseTarget(registry, basesLanguage, resolved.embedder);
|
|
19219
19480
|
setExtraRedactWords(resolved.redactWords);
|
|
19481
|
+
if (resolved.ingest !== "off" && resolved.reflect === "off") console.warn(message("core.warnIngestWithoutReflect"));
|
|
19220
19482
|
mkdirSync(resolved.dbDir, {
|
|
19221
19483
|
recursive: true,
|
|
19222
19484
|
mode: 448
|
|
@@ -20003,6 +20265,9 @@ async function apply(ctx, config = {}) {
|
|
|
20003
20265
|
exportDir: `${resolved.dbDir}/exports`,
|
|
20004
20266
|
mirrorDir: `${resolved.dbDir}/palaces`,
|
|
20005
20267
|
dbDir: resolved.dbDir,
|
|
20268
|
+
dshHome: resolved.dshHome,
|
|
20269
|
+
ingest: resolved.ingest,
|
|
20270
|
+
reflect: resolved.reflect,
|
|
20006
20271
|
pluginVersion: VERSION,
|
|
20007
20272
|
language: resolved.language,
|
|
20008
20273
|
panelAccess: resolved.panelAccess,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-engram",
|
|
3
3
|
"description": "Local-first cross-session long-term memory for DeepSeek Harness: dual-scope SQLite stores, hybrid FTS5 + local-vector retrieval with RRF, an evidence gate, provenance audit and SM-2 spaced repetition. 23 narrow tools, zero external services, zero API keys.",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.7",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"logo": "icon-256.svg",
|
|
7
7
|
"publishConfig": {
|