@sparkelf/dsh-knowledge-base 0.6.7 → 0.6.9

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/index.js CHANGED
@@ -18462,6 +18462,27 @@ var GuardianSessionStore = class {
18462
18462
  }
18463
18463
  return false;
18464
18464
  }
18465
+ /**
18466
+ * Every user's durable guardian session id, for the system-patrol seam.
18467
+ * A missing users root yields no guardians; an unreadable state file is skipped.
18468
+ * @returns the guardian session ids in directory order.
18469
+ */
18470
+ async listSessionIds() {
18471
+ let entries;
18472
+ try {
18473
+ entries = await readdir(this.usersRoot, { withFileTypes: true });
18474
+ } catch (error) {
18475
+ if (isErrno(error, "ENOENT")) return [];
18476
+ throw error;
18477
+ }
18478
+ const ids = [];
18479
+ for (const entry of entries) {
18480
+ if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
18481
+ const state = await this.read(entry.name).catch(() => void 0);
18482
+ if (state !== void 0) ids.push(state.sessionId);
18483
+ }
18484
+ return ids;
18485
+ }
18465
18486
  };
18466
18487
  /**
18467
18488
  * Resolve the user's guardian, creating it lazily when needed.
@@ -28350,30 +28371,59 @@ function apply(ctx, deploymentConfig) {
28350
28371
  })]),
28351
28372
  source: Object.freeze({ kind: "user" })
28352
28373
  });
28374
+ const guardianWorkspaceRegistry = ctx.workspaceRegistry;
28375
+ const guardianCwd = guardianWorkspaceRegistry?.list()[0]?.path ?? process.cwd();
28376
+ const guardianPersistence = ctx.sessionPersistence;
28377
+ const attachGuardianToWorkspace = async (agent) => {
28378
+ if (guardianWorkspaceRegistry === void 0) return;
28379
+ const sessionId = agent.session?.id ?? agent.id;
28380
+ try {
28381
+ await (await guardianWorkspaceRegistry.resolveByPath(guardianCwd))?.attachSession(sessionId);
28382
+ } catch (error) {
28383
+ ctx.logger.warn(`knowledge-base: guardian ${sessionId} did not join workspace at ${guardianCwd}: ${String(error)}`);
28384
+ }
28385
+ };
28353
28386
  const guardianSessionHost = {
28354
28387
  usersRoot: memoryUsersRoot,
28355
- cwd: process.cwd(),
28388
+ cwd: guardianCwd,
28356
28389
  timeoutMs: DEFAULT_GUARDIAN_TIMEOUT_MS,
28357
28390
  getAgent: (sessionId) => guardianRegistry?.get(sessionId),
28358
- createAgent: async ({ sessionId, cwd, title }) => {
28391
+ createAgent: async ({ sessionId, title }) => {
28359
28392
  if (guardianLoop === void 0) throw new Error("the DSH agent loop is not available");
28360
28393
  const handle = await guardianLoop.createAgent(ctx, {
28361
28394
  sessionId,
28362
- meta: { cwd },
28395
+ meta: { cwd: guardianCwd },
28363
28396
  ...guardianAgentOptions === void 0 ? {} : { agentOptions: guardianAgentOptions }
28364
28397
  });
28365
28398
  try {
28366
28399
  const session = handle.agent.session;
28367
28400
  if (session !== void 0) guardianTitles?.rename(session, title);
28368
28401
  } catch {}
28402
+ await attachGuardianToWorkspace(handle.agent);
28369
28403
  return handle.agent;
28370
28404
  },
28371
28405
  resumeAgent: async ({ sessionId }) => {
28372
28406
  if (guardianLoop === void 0) throw new Error("the DSH agent loop is not available");
28373
- return (await guardianLoop.resume(ctx, {
28407
+ if (guardianPersistence !== void 0) {
28408
+ let persistedCwd;
28409
+ try {
28410
+ const handle = await guardianPersistence.open(sessionId, "read");
28411
+ try {
28412
+ persistedCwd = handle.header.cwd;
28413
+ } finally {
28414
+ await handle.close();
28415
+ }
28416
+ } catch {
28417
+ persistedCwd = void 0;
28418
+ }
28419
+ if (persistedCwd !== void 0 && persistedCwd !== guardianCwd) throw new Error(`guardian ${sessionId} cwd ${persistedCwd} differs from workspace ${guardianCwd}; recreating`);
28420
+ }
28421
+ const handle = await guardianLoop.resume(ctx, {
28374
28422
  resumeSessionId: sessionId,
28375
28423
  ...guardianAgentOptions === void 0 ? {} : { agentOptions: guardianAgentOptions }
28376
- })).agent;
28424
+ });
28425
+ await attachGuardianToWorkspace(handle.agent);
28426
+ return handle.agent;
28377
28427
  },
28378
28428
  deliverText: (agent, text) => {
28379
28429
  const runtime = agent;
@@ -28386,6 +28436,7 @@ function apply(ctx, deploymentConfig) {
28386
28436
  }
28387
28437
  };
28388
28438
  const guardianSessions = new GuardianSessionStore(memoryUsersRoot);
28439
+ ctx.provide("memoryGuardianSessions", { listSessionIds: () => guardianSessions.listSessionIds() });
28389
28440
  const memoryGuardianToolHost = {
28390
28441
  resolveCaller: async () => {
28391
28442
  return { userId: (await fetchCaller(host, config)).userId };
@@ -142,6 +142,12 @@ export declare class GuardianSessionStore {
142
142
  * are, so the common turn-event path stays cheap.
143
143
  */
144
144
  isGuardianSession(sessionId: string): Promise<boolean>;
145
+ /**
146
+ * Every user's durable guardian session id, for the system-patrol seam.
147
+ * A missing users root yields no guardians; an unreadable state file is skipped.
148
+ * @returns the guardian session ids in directory order.
149
+ */
150
+ listSessionIds(): Promise<string[]>;
145
151
  }
146
152
  /**
147
153
  * Resolve the user's guardian, creating it lazily when needed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
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",