@sparkelf/dsh-knowledge-base 0.6.12 → 0.6.13

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 (3) hide show
  1. package/lib/client.js +659 -659
  2. package/lib/index.js +70 -5
  3. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -28515,19 +28515,84 @@ 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 eagerGuardian = async (attempt) => {
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
- await resolveOrCreateGuardian(guardianSessionHost, LOCAL_USER_ID);
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.kind === "session" && item.target.sessionId !== void 0);
28538
+ let taskId;
28539
+ let sessionId;
28540
+ if (existing !== void 0 && existing.target.sessionId !== void 0) {
28541
+ taskId = existing.id;
28542
+ sessionId = existing.target.sessionId;
28543
+ } else {
28544
+ const entry = await schedule.create({
28545
+ title: GUARDIAN_SESSION_TITLE,
28546
+ prompt: guardianTaskPrompt,
28547
+ timing: {
28548
+ kind: "daily",
28549
+ daily: {
28550
+ time: "03:00:00",
28551
+ time_zone: "Asia/Shanghai"
28552
+ }
28553
+ },
28554
+ target: {
28555
+ kind: "new_once",
28556
+ create: { cwd }
28557
+ }
28558
+ });
28559
+ taskId = entry.id;
28560
+ if (entry.target.sessionId === void 0) throw new Error("schedule new_once did not reserve a session id");
28561
+ sessionId = entry.target.sessionId;
28562
+ }
28563
+ const store = new GuardianSessionStore(memoryUsersRoot);
28564
+ const prior = await store.read(LOCAL_USER_ID).catch(() => void 0);
28565
+ if (prior?.sessionId !== sessionId) {
28566
+ const now = (/* @__PURE__ */ new Date()).toISOString();
28567
+ await store.write({
28568
+ version: 1,
28569
+ userId: LOCAL_USER_ID,
28570
+ sessionId,
28571
+ title: GUARDIAN_SESSION_TITLE,
28572
+ createdAt: prior?.createdAt ?? now,
28573
+ updatedAt: now
28574
+ });
28575
+ }
28576
+ await schedule.run({ id: taskId });
28577
+ const pinGuardian = async (tries) => {
28578
+ try {
28579
+ await registry.pinSession(sessionId);
28580
+ } catch {
28581
+ if (tries < 8) setTimeout(() => {
28582
+ pinGuardian(tries + 1);
28583
+ }, 2e3);
28584
+ }
28585
+ };
28586
+ pinGuardian(0);
28522
28587
  } catch (error) {
28523
28588
  if (attempt < 15) setTimeout(() => {
28524
- eagerGuardian(attempt + 1);
28589
+ setupGuardianSchedule(attempt + 1);
28525
28590
  }, 2e3);
28526
- else host.logger?.warn?.(`knowledge-base: eager guardian creation failed after retries: ${String(error)}`);
28591
+ else host.logger?.warn?.(`knowledge-base: guardian schedule setup failed after retries: ${String(error)}`);
28527
28592
  }
28528
28593
  };
28529
28594
  setTimeout(() => {
28530
- eagerGuardian(0);
28595
+ setupGuardianSchedule(0);
28531
28596
  }, 3e3);
28532
28597
  }
28533
28598
  const memoryGuardianToolHost = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
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",