@sparkelf/dsh-knowledge-base 0.6.11 → 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.
- package/lib/client.js +655 -655
- package/lib/index.js +85 -17
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -28445,28 +28445,30 @@ function apply(ctx, deploymentConfig) {
|
|
|
28445
28445
|
})]),
|
|
28446
28446
|
source: Object.freeze({ kind: "user" })
|
|
28447
28447
|
});
|
|
28448
|
-
const
|
|
28449
|
-
const
|
|
28450
|
-
const guardianPersistence = ctx.sessionPersistence;
|
|
28448
|
+
const getGuardianWorkspaceRegistry = () => ctx.get("workspaceRegistry");
|
|
28449
|
+
const resolveGuardianCwd = () => getGuardianWorkspaceRegistry()?.list()[0]?.path ?? process.cwd();
|
|
28450
|
+
const guardianPersistence = ctx.get("sessionPersistence");
|
|
28451
28451
|
const attachGuardianToWorkspace = async (agent) => {
|
|
28452
|
-
|
|
28452
|
+
const registry = getGuardianWorkspaceRegistry();
|
|
28453
|
+
if (registry === void 0) return;
|
|
28453
28454
|
const sessionId = agent.session?.id ?? agent.id;
|
|
28455
|
+
const cwd = resolveGuardianCwd();
|
|
28454
28456
|
try {
|
|
28455
|
-
await (await
|
|
28457
|
+
await (await registry.resolveByPath(cwd))?.attachSession(sessionId);
|
|
28456
28458
|
} catch (error) {
|
|
28457
|
-
ctx.logger.warn(`knowledge-base: guardian ${sessionId} did not join workspace at ${
|
|
28459
|
+
ctx.logger.warn(`knowledge-base: guardian ${sessionId} did not join workspace at ${cwd}: ${String(error)}`);
|
|
28458
28460
|
}
|
|
28459
28461
|
};
|
|
28460
28462
|
const guardianSessionHost = {
|
|
28461
28463
|
usersRoot: memoryUsersRoot,
|
|
28462
|
-
cwd:
|
|
28464
|
+
cwd: process.cwd(),
|
|
28463
28465
|
timeoutMs: DEFAULT_GUARDIAN_TIMEOUT_MS,
|
|
28464
28466
|
getAgent: (sessionId) => guardianRegistry?.get(sessionId),
|
|
28465
28467
|
createAgent: async ({ sessionId, title }) => {
|
|
28466
28468
|
if (guardianLoop === void 0) throw new Error("the DSH agent loop is not available");
|
|
28467
28469
|
const handle = await guardianLoop.createAgent(ctx, {
|
|
28468
28470
|
sessionId,
|
|
28469
|
-
meta: { cwd:
|
|
28471
|
+
meta: { cwd: resolveGuardianCwd() },
|
|
28470
28472
|
...guardianAgentOptions === void 0 ? {} : { agentOptions: guardianAgentOptions }
|
|
28471
28473
|
});
|
|
28472
28474
|
try {
|
|
@@ -28490,7 +28492,8 @@ function apply(ctx, deploymentConfig) {
|
|
|
28490
28492
|
} catch {
|
|
28491
28493
|
persistedCwd = void 0;
|
|
28492
28494
|
}
|
|
28493
|
-
|
|
28495
|
+
const targetCwd = resolveGuardianCwd();
|
|
28496
|
+
if (persistedCwd !== void 0 && persistedCwd !== targetCwd) throw new Error(`guardian ${sessionId} cwd ${persistedCwd} differs from workspace ${targetCwd}; recreating`);
|
|
28494
28497
|
}
|
|
28495
28498
|
const handle = await guardianLoop.resume(ctx, {
|
|
28496
28499
|
resumeSessionId: sessionId,
|
|
@@ -28512,20 +28515,85 @@ function apply(ctx, deploymentConfig) {
|
|
|
28512
28515
|
const guardianSessions = new GuardianSessionStore(memoryUsersRoot);
|
|
28513
28516
|
ctx.provide("memoryGuardianSessions", { listSessionIds: () => guardianSessions.listSessionIds() });
|
|
28514
28517
|
if (!isTeamDeployment(config)) {
|
|
28515
|
-
const
|
|
28518
|
+
const guardianTaskPrompt = [
|
|
28519
|
+
"你是记忆守护会话,本任务即每日 dream 整理。",
|
|
28520
|
+
"第一步:阅读 memory 技能,再按指引读取 references/guardian.md,严格按该准则工作。",
|
|
28521
|
+
"本轮执行记忆整理:抽取 / 合并 / 纠偏 / 遗忘 / 晋升,写审计与 Git 恢复点。",
|
|
28522
|
+
"若收到存储报错告警,先按「存储报错自愈」诊断修复存储,再整理。",
|
|
28523
|
+
"只处理投递到本会话的消息,串行处理,不为单条消息新建会话。"
|
|
28524
|
+
].join("\n");
|
|
28525
|
+
const setupGuardianSchedule = async (attempt) => {
|
|
28516
28526
|
try {
|
|
28517
28527
|
if (!await memorySettings.isEnabled("local")) return;
|
|
28518
|
-
|
|
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);
|
|
28519
28587
|
} catch (error) {
|
|
28520
|
-
if (attempt <
|
|
28521
|
-
|
|
28522
|
-
},
|
|
28523
|
-
else host.logger?.warn?.(`knowledge-base:
|
|
28588
|
+
if (attempt < 15) setTimeout(() => {
|
|
28589
|
+
setupGuardianSchedule(attempt + 1);
|
|
28590
|
+
}, 2e3);
|
|
28591
|
+
else host.logger?.warn?.(`knowledge-base: guardian schedule setup failed after retries: ${String(error)}`);
|
|
28524
28592
|
}
|
|
28525
28593
|
};
|
|
28526
28594
|
setTimeout(() => {
|
|
28527
|
-
|
|
28528
|
-
},
|
|
28595
|
+
setupGuardianSchedule(0);
|
|
28596
|
+
}, 3e3);
|
|
28529
28597
|
}
|
|
28530
28598
|
const memoryGuardianToolHost = {
|
|
28531
28599
|
resolveCaller: async () => {
|
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.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",
|