@sparkelf/dsh-knowledge-base 0.6.14 → 0.6.15

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
@@ -17633,7 +17633,8 @@ const MEMORY_CONSOLIDATION_INTERVAL_MAX = 1440;
17633
17633
  const DEFAULT_MEMORY_SETTINGS = Object.freeze({
17634
17634
  version: 2,
17635
17635
  memoryEnabled: false,
17636
- consolidationIntervalMinutes: 60
17636
+ consolidationIntervalMinutes: 60,
17637
+ guardianMaxSubagents: 4
17637
17638
  });
17638
17639
  /** A malformed interval or write patch; the route maps this to HTTP 400. */
17639
17640
  var MemorySettingsError = class extends Error {
@@ -17669,6 +17670,25 @@ function readStoredInterval(value) {
17669
17670
  }
17670
17671
  }
17671
17672
  /**
17673
+ * Validate one guardian subagent limit.
17674
+ * @param value - raw value from an API body or a hand-edited file.
17675
+ * @returns the accepted integer.
17676
+ * @throws {MemorySettingsError} when the value is not an integer in range.
17677
+ */
17678
+ function normalizeGuardianSubagents(value) {
17679
+ if (typeof value !== "number" || !Number.isInteger(value)) throw new MemorySettingsError("invalid-settings", "guardianMaxSubagents must be an integer");
17680
+ if (value < 1 || value > 8) throw new MemorySettingsError("invalid-settings", `guardianMaxSubagents must be between ${String(1)} and ${String(8)}`);
17681
+ return value;
17682
+ }
17683
+ /** Read a stored guardian subagent limit leniently: an invalid/legacy value falls back to the default. */
17684
+ function readStoredGuardianSubagents(value) {
17685
+ try {
17686
+ return normalizeGuardianSubagents(value);
17687
+ } catch {
17688
+ return 4;
17689
+ }
17690
+ }
17691
+ /**
17672
17692
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
17673
17693
  *
17674
17694
  * `read()` tolerates a corrupt file by returning the paused default; the next
@@ -17733,7 +17753,8 @@ var MemorySettingsStore = class {
17733
17753
  return {
17734
17754
  version: 2,
17735
17755
  memoryEnabled,
17736
- consolidationIntervalMinutes: readStoredInterval(parsed.consolidationIntervalMinutes)
17756
+ consolidationIntervalMinutes: readStoredInterval(parsed.consolidationIntervalMinutes),
17757
+ guardianMaxSubagents: readStoredGuardianSubagents(parsed.guardianMaxSubagents)
17737
17758
  };
17738
17759
  }
17739
17760
  /** Whether learning is enabled for this user (default `false`). */
@@ -17750,14 +17771,16 @@ var MemorySettingsStore = class {
17750
17771
  * @returns the normalized settings actually written.
17751
17772
  */
17752
17773
  async save(userId, patch, options = {}) {
17753
- if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0) throw new MemorySettingsError("invalid-settings", "at least one memory setting must be supplied");
17774
+ if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0 && patch.guardianMaxSubagents === void 0) throw new MemorySettingsError("invalid-settings", "at least one memory setting must be supplied");
17754
17775
  if (patch.memoryEnabled !== void 0 && typeof patch.memoryEnabled !== "boolean") throw new MemorySettingsError("invalid-settings", "memoryEnabled must be a boolean");
17755
17776
  const interval = patch.consolidationIntervalMinutes === void 0 ? void 0 : normalizeConsolidationInterval(patch.consolidationIntervalMinutes);
17777
+ const subagents = patch.guardianMaxSubagents === void 0 ? void 0 : normalizeGuardianSubagents(patch.guardianMaxSubagents);
17756
17778
  const current = await this.read(userId, options);
17757
17779
  const settings = {
17758
17780
  version: 2,
17759
17781
  memoryEnabled: patch.memoryEnabled ?? current.memoryEnabled,
17760
- consolidationIntervalMinutes: interval ?? current.consolidationIntervalMinutes
17782
+ consolidationIntervalMinutes: interval ?? current.consolidationIntervalMinutes,
17783
+ guardianMaxSubagents: subagents ?? current.guardianMaxSubagents
17761
17784
  };
17762
17785
  await writeFileAtomic(this.filePath(userId), `${JSON.stringify(settings, null, 2)}\n`, { mode: 384 });
17763
17786
  return settings;
@@ -17818,7 +17841,11 @@ function settingsPayload(settings) {
17818
17841
  consolidationIntervalMinutes: settings.consolidationIntervalMinutes,
17819
17842
  intervalMin: 15,
17820
17843
  intervalMax: MEMORY_CONSOLIDATION_INTERVAL_MAX,
17821
- intervalDefault: 60
17844
+ intervalDefault: 60,
17845
+ guardianMaxSubagents: settings.guardianMaxSubagents,
17846
+ subagentsMin: 1,
17847
+ subagentsMax: 8,
17848
+ subagentsDefault: 4
17822
17849
  };
17823
17850
  }
17824
17851
  /** Options for a settings read that already knows the caller's first-read default. */
@@ -17917,7 +17944,7 @@ function readUpdatePatch(body, entry) {
17917
17944
  /** Extract and validate the settings write, translating `enabled` to the stored field. */
17918
17945
  function readSettingsPatch(body, options) {
17919
17946
  if (Object.prototype.hasOwnProperty.call(body, "userId")) return { error: fail$1(400, "userId must not be supplied; the caller is resolved from the request", "invalid") };
17920
- const unknown = Object.keys(body).filter((key) => key !== "enabled" && key !== "consolidationIntervalMinutes");
17947
+ const unknown = Object.keys(body).filter((key) => key !== "enabled" && key !== "consolidationIntervalMinutes" && key !== "guardianMaxSubagents");
17921
17948
  if (unknown.length > 0) return { error: fail$1(400, `unsupported settings field(s): ${unknown.join(", ")}`, "invalid") };
17922
17949
  if (options.requireEnabled && body.enabled === void 0) return { error: fail$1(400, "enabled must be a boolean", "invalid") };
17923
17950
  const patch = {};
@@ -17934,7 +17961,16 @@ function readSettingsPatch(body, options) {
17934
17961
  }) };
17935
17962
  throw error;
17936
17963
  }
17937
- if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0) return { error: fail$1(400, "at least one memory setting must be supplied", "invalid") };
17964
+ if (body.guardianMaxSubagents !== void 0) try {
17965
+ patch.guardianMaxSubagents = normalizeGuardianSubagents(body.guardianMaxSubagents);
17966
+ } catch (error) {
17967
+ if (error instanceof MemorySettingsError) return { error: fail$1(400, error.message, error.code, {
17968
+ min: 1,
17969
+ max: 8
17970
+ }) };
17971
+ throw error;
17972
+ }
17973
+ if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0 && patch.guardianMaxSubagents === void 0) return { error: fail$1(400, "at least one memory setting must be supplied", "invalid") };
17938
17974
  return { patch };
17939
17975
  }
17940
17976
  /** Reconcile the personal-memory graph; a derived failure must not undo the write. */
@@ -18028,6 +18064,46 @@ async function handleMemoryRoute(input) {
18028
18064
  }
18029
18065
  }
18030
18066
  //#endregion
18067
+ //#region src/guardianSubagentLimit.ts
18068
+ /**
18069
+ * Apply the guardian's per-user subagent concurrency to the runtime limit.
18070
+ *
18071
+ * The guardian is one subagent tree, and `ctx.subagents` caps every tree with the
18072
+ * same `maxActiveSubagents` value. Setting that value to the user's
18073
+ * `guardianMaxSubagents` therefore bounds the guardian's concurrent children.
18074
+ *
18075
+ * The limit is a cordis *volatile* config reference: a stable object whose current
18076
+ * value the owning runtime commits through the shared `cosmokit.volatile.write`
18077
+ * symbol (the same mechanism `updateVolatile` uses). There is no public setter on
18078
+ * the reference, and the subagent service lives in the base, so this module reaches
18079
+ * the reference through the optionally-resolved service and commits the validated
18080
+ * value directly. It never throws into guardian setup: a missing or differently
18081
+ * shaped service simply means "not applied yet", and a later setup attempt retries.
18082
+ *
18083
+ * @module @sparkelf/dsh-knowledge-base/guardian-subagent-limit
18084
+ */
18085
+ /** The cosmokit volatile commit symbol, shared by every config reference. */
18086
+ const VOLATILE_WRITE = Symbol.for("cosmokit.volatile.write");
18087
+ /**
18088
+ * Commit one guardian concurrency limit onto the subagent service's volatile config.
18089
+ *
18090
+ * @param subagents - the optionally-resolved `ctx.get('subagents')` service; may be undefined.
18091
+ * @param limit - the validated `guardianMaxSubagents` (an integer >= 1).
18092
+ * @returns whether the limit is now in effect (already equal, or freshly committed).
18093
+ */
18094
+ function applyGuardianSubagentLimit(subagents, limit) {
18095
+ if (!Number.isInteger(limit) || limit < 1) return false;
18096
+ const ref = subagents?.config?.maxActiveSubagents;
18097
+ if (typeof ref !== "object" || ref === null) return false;
18098
+ const get = Reflect.get(ref, "get");
18099
+ if (typeof get !== "function") return false;
18100
+ if (get.call(ref) === limit) return true;
18101
+ const write = Reflect.get(ref, VOLATILE_WRITE);
18102
+ if (typeof write !== "function") return false;
18103
+ write.call(ref, limit);
18104
+ return true;
18105
+ }
18106
+ //#endregion
18031
18107
  //#region src/memoryHeal.ts
18032
18108
  /**
18033
18109
  * Storage-error alerting for personal memory: notify the guardian session.
@@ -28524,7 +28600,9 @@ function apply(ctx, deploymentConfig) {
28524
28600
  ].join("\n");
28525
28601
  const setupGuardianSchedule = async (attempt) => {
28526
28602
  try {
28527
- if (!await memorySettings.isEnabled("local")) return;
28603
+ const settings = await memorySettings.read(LOCAL_USER_ID);
28604
+ if (!settings.memoryEnabled) return;
28605
+ applyGuardianSubagentLimit(ctx.get("subagents"), settings.guardianMaxSubagents);
28528
28606
  const schedule = ctx.get("schedule");
28529
28607
  const registry = getGuardianWorkspaceRegistry();
28530
28608
  if (schedule === void 0 || registry === void 0) {
@@ -137,6 +137,19 @@ export interface KnowledgeMemoryViewProps {
137
137
  intervalSaved: boolean;
138
138
  onIntervalDraftChange: (value: string) => void;
139
139
  onSaveInterval: () => void;
140
+ /** Saved guardian subagent concurrency. */
141
+ guardianMaxSubagents: number;
142
+ /** Allowed subagent bounds; reported by the host so the page never guesses. */
143
+ subagentsMin: number;
144
+ subagentsMax: number;
145
+ /** The number currently typed in the subagents field. */
146
+ subagentsDraft: string;
147
+ subagentsBusy: boolean;
148
+ subagentsError?: string;
149
+ /** True after a successful save until the field changes again. */
150
+ subagentsSaved: boolean;
151
+ onSubagentsDraftChange: (value: string) => void;
152
+ onSaveSubagents: () => void;
140
153
  list: MemoryListSnapshot;
141
154
  query: string;
142
155
  typeFilter: string;
@@ -685,6 +685,11 @@ export declare const en: {
685
685
  readonly memorySaveInterval: "Save";
686
686
  readonly memoryIntervalSaved: "Saved";
687
687
  readonly memoryIntervalInvalid: "Enter a whole number between 15 and 1440 minutes.";
688
+ readonly memorySubagentsLabel: "Guardian subagents";
689
+ readonly memorySubagentsHint: "{min}–{max} concurrent subagents. The guardian runs at most this many children at once while consolidating memory.";
690
+ readonly memorySaveSubagents: "Save";
691
+ readonly memorySubagentsSaved: "Saved";
692
+ readonly memorySubagentsInvalid: "Enter a whole number between {min} and {max}.";
688
693
  readonly memorySettingsFailed: "Could not read the memory setting.";
689
694
  readonly memoryEnableTitle: "Turn on memory";
690
695
  readonly memoryEnableBody: "When memory is on, the assistant learns preferences, facts, pitfalls and methods from your conversations, and they may affect later answers and actions. Existing memories are kept, and you can pause or forget any single memory at any time.";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Apply the guardian's per-user subagent concurrency to the runtime limit.
3
+ *
4
+ * The guardian is one subagent tree, and `ctx.subagents` caps every tree with the
5
+ * same `maxActiveSubagents` value. Setting that value to the user's
6
+ * `guardianMaxSubagents` therefore bounds the guardian's concurrent children.
7
+ *
8
+ * The limit is a cordis *volatile* config reference: a stable object whose current
9
+ * value the owning runtime commits through the shared `cosmokit.volatile.write`
10
+ * symbol (the same mechanism `updateVolatile` uses). There is no public setter on
11
+ * the reference, and the subagent service lives in the base, so this module reaches
12
+ * the reference through the optionally-resolved service and commits the validated
13
+ * value directly. It never throws into guardian setup: a missing or differently
14
+ * shaped service simply means "not applied yet", and a later setup attempt retries.
15
+ *
16
+ * @module @sparkelf/dsh-knowledge-base/guardian-subagent-limit
17
+ */
18
+ /**
19
+ * Commit one guardian concurrency limit onto the subagent service's volatile config.
20
+ *
21
+ * @param subagents - the optionally-resolved `ctx.get('subagents')` service; may be undefined.
22
+ * @param limit - the validated `guardianMaxSubagents` (an integer >= 1).
23
+ * @returns whether the limit is now in effect (already equal, or freshly committed).
24
+ */
25
+ export declare function applyGuardianSubagentLimit(subagents: unknown, limit: number): boolean;
@@ -8,6 +8,12 @@ export declare const MEMORY_CONSOLIDATION_INTERVAL_MIN = 15;
8
8
  export declare const MEMORY_CONSOLIDATION_INTERVAL_MAX = 1440;
9
9
  /** Default consolidation interval, in minutes. */
10
10
  export declare const MEMORY_CONSOLIDATION_INTERVAL_DEFAULT = 60;
11
+ /** Fewest concurrent guardian subagents allowed. */
12
+ export declare const MEMORY_GUARDIAN_SUBAGENTS_MIN = 1;
13
+ /** Most concurrent guardian subagents allowed. */
14
+ export declare const MEMORY_GUARDIAN_SUBAGENTS_MAX = 8;
15
+ /** Default concurrent guardian subagents. */
16
+ export declare const MEMORY_GUARDIAN_SUBAGENTS_DEFAULT = 4;
11
17
  /** Persisted settings shape. */
12
18
  export interface MemorySettings {
13
19
  version: typeof MEMORY_SETTINGS_VERSION;
@@ -15,6 +21,8 @@ export interface MemorySettings {
15
21
  memoryEnabled: boolean;
16
22
  /** How often the guardian consolidates memory, in minutes (15–1440). */
17
23
  consolidationIntervalMinutes: number;
24
+ /** Maximum concurrent subagents the guardian may run (1–8). */
25
+ guardianMaxSubagents: number;
18
26
  }
19
27
  /** The paused default for a user who has never confirmed the enable dialog. */
20
28
  export declare const DEFAULT_MEMORY_SETTINGS: Readonly<MemorySettings>;
@@ -50,6 +58,7 @@ export interface MemorySettingsReadOptions {
50
58
  export interface MemorySettingsPatch {
51
59
  memoryEnabled?: boolean;
52
60
  consolidationIntervalMinutes?: number;
61
+ guardianMaxSubagents?: number;
53
62
  }
54
63
  /**
55
64
  * Validate one consolidation interval.
@@ -63,6 +72,13 @@ export interface MemorySettingsPatch {
63
72
  * @throws {MemorySettingsError} when the value is not an integer in range.
64
73
  */
65
74
  export declare function normalizeConsolidationInterval(value: unknown): number;
75
+ /**
76
+ * Validate one guardian subagent limit.
77
+ * @param value - raw value from an API body or a hand-edited file.
78
+ * @returns the accepted integer.
79
+ * @throws {MemorySettingsError} when the value is not an integer in range.
80
+ */
81
+ export declare function normalizeGuardianSubagents(value: unknown): number;
66
82
  /**
67
83
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
68
84
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.6.14",
3
+ "version": "0.6.15",
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",