@sparkelf/dsh-knowledge-base 0.6.12 → 0.6.14
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/client.js +660 -660
- package/lib/index.js +73 -5
- package/package.json +1 -1
- package/skills/memory/references/guardian.md +1 -1
package/lib/index.js
CHANGED
|
@@ -28515,19 +28515,87 @@ function apply(ctx, deploymentConfig) {
|
|
|
28515
28515
|
const guardianSessions = new GuardianSessionStore(memoryUsersRoot);
|
|
28516
28516
|
ctx.provide("memoryGuardianSessions", { listSessionIds: () => guardianSessions.listSessionIds() });
|
|
28517
28517
|
if (!isTeamDeployment(config)) {
|
|
28518
|
-
const
|
|
28518
|
+
const guardianTaskPrompt = [
|
|
28519
|
+
"你是记忆守护会话,本任务即每日 dream 整理。",
|
|
28520
|
+
"第一步:阅读 memory 技能,再按指引读取 references/guardian.md,严格按该准则工作。",
|
|
28521
|
+
"本轮执行记忆整理:抽取 / 合并 / 纠偏 / 遗忘 / 晋升,写审计与 Git 恢复点。",
|
|
28522
|
+
"若收到存储报错告警,先按「存储报错自愈」诊断修复存储,再整理。",
|
|
28523
|
+
"只处理投递到本会话的消息,串行处理,不为单条消息新建会话。"
|
|
28524
|
+
].join("\n");
|
|
28525
|
+
const setupGuardianSchedule = async (attempt) => {
|
|
28519
28526
|
try {
|
|
28520
28527
|
if (!await memorySettings.isEnabled("local")) return;
|
|
28521
|
-
|
|
28528
|
+
const schedule = ctx.get("schedule");
|
|
28529
|
+
const registry = getGuardianWorkspaceRegistry();
|
|
28530
|
+
if (schedule === void 0 || registry === void 0) {
|
|
28531
|
+
if (attempt < 15) setTimeout(() => {
|
|
28532
|
+
setupGuardianSchedule(attempt + 1);
|
|
28533
|
+
}, 2e3);
|
|
28534
|
+
return;
|
|
28535
|
+
}
|
|
28536
|
+
const cwd = registry.list()[0]?.path ?? process.cwd();
|
|
28537
|
+
const existing = (await schedule.list({ limit: 200 })).items.find((item) => item.title === "记忆守护会话" && item.target.sessionId !== void 0);
|
|
28538
|
+
let taskId;
|
|
28539
|
+
let sessionId;
|
|
28540
|
+
let sessionExists;
|
|
28541
|
+
if (existing !== void 0 && existing.target.sessionId !== void 0) {
|
|
28542
|
+
taskId = existing.id;
|
|
28543
|
+
sessionId = existing.target.sessionId;
|
|
28544
|
+
sessionExists = existing.target.kind === "session";
|
|
28545
|
+
} else {
|
|
28546
|
+
const entry = await schedule.create({
|
|
28547
|
+
title: GUARDIAN_SESSION_TITLE,
|
|
28548
|
+
prompt: guardianTaskPrompt,
|
|
28549
|
+
timing: {
|
|
28550
|
+
kind: "daily",
|
|
28551
|
+
daily: {
|
|
28552
|
+
time: "03:00:00",
|
|
28553
|
+
time_zone: "Asia/Shanghai"
|
|
28554
|
+
}
|
|
28555
|
+
},
|
|
28556
|
+
target: {
|
|
28557
|
+
kind: "new_once",
|
|
28558
|
+
create: { cwd }
|
|
28559
|
+
}
|
|
28560
|
+
});
|
|
28561
|
+
taskId = entry.id;
|
|
28562
|
+
if (entry.target.sessionId === void 0) throw new Error("schedule new_once did not reserve a session id");
|
|
28563
|
+
sessionId = entry.target.sessionId;
|
|
28564
|
+
sessionExists = false;
|
|
28565
|
+
}
|
|
28566
|
+
const store = new GuardianSessionStore(memoryUsersRoot);
|
|
28567
|
+
const prior = await store.read(LOCAL_USER_ID).catch(() => void 0);
|
|
28568
|
+
if (prior?.sessionId !== sessionId) {
|
|
28569
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
28570
|
+
await store.write({
|
|
28571
|
+
version: 1,
|
|
28572
|
+
userId: LOCAL_USER_ID,
|
|
28573
|
+
sessionId,
|
|
28574
|
+
title: GUARDIAN_SESSION_TITLE,
|
|
28575
|
+
createdAt: prior?.createdAt ?? now,
|
|
28576
|
+
updatedAt: now
|
|
28577
|
+
});
|
|
28578
|
+
}
|
|
28579
|
+
if (!sessionExists) await schedule.run({ id: taskId });
|
|
28580
|
+
const pinGuardian = async (tries) => {
|
|
28581
|
+
try {
|
|
28582
|
+
await registry.pinSession(sessionId);
|
|
28583
|
+
} catch {
|
|
28584
|
+
if (tries < 8) setTimeout(() => {
|
|
28585
|
+
pinGuardian(tries + 1);
|
|
28586
|
+
}, 2e3);
|
|
28587
|
+
}
|
|
28588
|
+
};
|
|
28589
|
+
pinGuardian(0);
|
|
28522
28590
|
} catch (error) {
|
|
28523
28591
|
if (attempt < 15) setTimeout(() => {
|
|
28524
|
-
|
|
28592
|
+
setupGuardianSchedule(attempt + 1);
|
|
28525
28593
|
}, 2e3);
|
|
28526
|
-
else host.logger?.warn?.(`knowledge-base:
|
|
28594
|
+
else host.logger?.warn?.(`knowledge-base: guardian schedule setup failed after retries: ${String(error)}`);
|
|
28527
28595
|
}
|
|
28528
28596
|
};
|
|
28529
28597
|
setTimeout(() => {
|
|
28530
|
-
|
|
28598
|
+
setupGuardianSchedule(0);
|
|
28531
28599
|
}, 3e3);
|
|
28532
28600
|
}
|
|
28533
28601
|
const memoryGuardianToolHost = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkelf/dsh-knowledge-base",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "DataOps-backed knowledge base for DeepSeek Harness: a left-sidebar destination, Settings configuration, and index tooling over a mounted NAS view.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- **空闲**:某个会话静默了一段时间,可能积累了值得记住的内容。
|
|
8
8
|
- **压缩**:某个会话开始压缩。原始消息仍然存在,压缩摘要会标出被遮蔽的范围;判断依据以原始轨迹为准。
|
|
9
|
-
- **dream
|
|
9
|
+
- **dream**:每日一次的整理与评估。守护会话本身就是承载 dream 的 schedule 任务(new_once,新建并复用),**不要另建 dream 任务**;执行时间以该自动化任务的设置为准。若发现重复的同名任务,按标题去重只保留一份。
|
|
10
10
|
- **存储报错**:记忆增删改查遇到存储访问错误(如未挂载盘、目录缺失、权限拒绝)。消息里带错误信息,按「存储报错自愈」处理。
|
|
11
11
|
|
|
12
12
|
四类消息按到达顺序串行处理。上一轮没有收尾时,不要开始下一轮;宁可晚一点整理,也不要把同一天的记忆写乱。存储报错优先处理——存储不可用时整理也写不进去。
|