@sparkelf/dsh-knowledge-base 0.6.14 → 0.6.16

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
@@ -17618,6 +17618,9 @@ async function ensurePersonalMemoryGraph(options) {
17618
17618
  * Version 1 files (only `memoryEnabled`, or even a hand-written bare boolean) are
17619
17619
  * still read: a missing interval falls back to 60 minutes, and a malformed
17620
17620
  * interval never turns a remembered enable/disable decision into a different one.
17621
+ * Later fields (`guardianMaxSubagents`, `gitRemoteEnabled`) join the same version:
17622
+ * a file written before they existed reads them as their defaults, and a malformed
17623
+ * value never changes the remembered enable/disable decision.
17621
17624
  *
17622
17625
  * The route/UI layer reads `read()` or `isEnabled()` and writes through
17623
17626
  * `save()`; every write is atomic (tmp + rename) and persists both fields in one
@@ -17633,7 +17636,9 @@ const MEMORY_CONSOLIDATION_INTERVAL_MAX = 1440;
17633
17636
  const DEFAULT_MEMORY_SETTINGS = Object.freeze({
17634
17637
  version: 2,
17635
17638
  memoryEnabled: false,
17636
- consolidationIntervalMinutes: 60
17639
+ consolidationIntervalMinutes: 60,
17640
+ guardianMaxSubagents: 4,
17641
+ gitRemoteEnabled: false
17637
17642
  });
17638
17643
  /** A malformed interval or write patch; the route maps this to HTTP 400. */
17639
17644
  var MemorySettingsError = class extends Error {
@@ -17669,6 +17674,48 @@ function readStoredInterval(value) {
17669
17674
  }
17670
17675
  }
17671
17676
  /**
17677
+ * Validate one guardian subagent limit.
17678
+ * @param value - raw value from an API body or a hand-edited file.
17679
+ * @returns the accepted integer.
17680
+ * @throws {MemorySettingsError} when the value is not an integer in range.
17681
+ */
17682
+ function normalizeGuardianSubagents(value) {
17683
+ if (typeof value !== "number" || !Number.isInteger(value)) throw new MemorySettingsError("invalid-settings", "guardianMaxSubagents must be an integer");
17684
+ if (value < 1 || value > 8) throw new MemorySettingsError("invalid-settings", `guardianMaxSubagents must be between ${String(1)} and ${String(8)}`);
17685
+ return value;
17686
+ }
17687
+ /** Read a stored guardian subagent limit leniently: an invalid/legacy value falls back to the default. */
17688
+ function readStoredGuardianSubagents(value) {
17689
+ try {
17690
+ return normalizeGuardianSubagents(value);
17691
+ } catch {
17692
+ return 4;
17693
+ }
17694
+ }
17695
+ /**
17696
+ * Validate the Git remote backup switch.
17697
+ *
17698
+ * A boolean carries no range, so the only guard is the type itself; the route
17699
+ * turns a refusal into a 400.
17700
+ *
17701
+ * @param value - raw value from an API body or a hand-edited file.
17702
+ * @returns the accepted boolean.
17703
+ * @throws {MemorySettingsError} when the value is not a boolean.
17704
+ */
17705
+ function normalizeGitRemoteEnabled(value) {
17706
+ if (typeof value !== "boolean") throw new MemorySettingsError("invalid-settings", "gitRemoteEnabled must be a boolean");
17707
+ return value;
17708
+ }
17709
+ /**
17710
+ * Read a stored Git remote switch leniently: only an explicit `true` enables it.
17711
+ *
17712
+ * A missing field (a file written before backups existed) or a malformed value
17713
+ * reads as OFF, so a corrupt file can never start pushing personal memory.
17714
+ */
17715
+ function readStoredGitRemoteEnabled(value) {
17716
+ return value === true;
17717
+ }
17718
+ /**
17672
17719
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
17673
17720
  *
17674
17721
  * `read()` tolerates a corrupt file by returning the paused default; the next
@@ -17733,7 +17780,9 @@ var MemorySettingsStore = class {
17733
17780
  return {
17734
17781
  version: 2,
17735
17782
  memoryEnabled,
17736
- consolidationIntervalMinutes: readStoredInterval(parsed.consolidationIntervalMinutes)
17783
+ consolidationIntervalMinutes: readStoredInterval(parsed.consolidationIntervalMinutes),
17784
+ guardianMaxSubagents: readStoredGuardianSubagents(parsed.guardianMaxSubagents),
17785
+ gitRemoteEnabled: readStoredGitRemoteEnabled(parsed.gitRemoteEnabled)
17737
17786
  };
17738
17787
  }
17739
17788
  /** Whether learning is enabled for this user (default `false`). */
@@ -17750,14 +17799,18 @@ var MemorySettingsStore = class {
17750
17799
  * @returns the normalized settings actually written.
17751
17800
  */
17752
17801
  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");
17802
+ if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0 && patch.guardianMaxSubagents === void 0 && patch.gitRemoteEnabled === void 0) throw new MemorySettingsError("invalid-settings", "at least one memory setting must be supplied");
17754
17803
  if (patch.memoryEnabled !== void 0 && typeof patch.memoryEnabled !== "boolean") throw new MemorySettingsError("invalid-settings", "memoryEnabled must be a boolean");
17755
17804
  const interval = patch.consolidationIntervalMinutes === void 0 ? void 0 : normalizeConsolidationInterval(patch.consolidationIntervalMinutes);
17805
+ const subagents = patch.guardianMaxSubagents === void 0 ? void 0 : normalizeGuardianSubagents(patch.guardianMaxSubagents);
17806
+ const gitRemote = patch.gitRemoteEnabled === void 0 ? void 0 : normalizeGitRemoteEnabled(patch.gitRemoteEnabled);
17756
17807
  const current = await this.read(userId, options);
17757
17808
  const settings = {
17758
17809
  version: 2,
17759
17810
  memoryEnabled: patch.memoryEnabled ?? current.memoryEnabled,
17760
- consolidationIntervalMinutes: interval ?? current.consolidationIntervalMinutes
17811
+ consolidationIntervalMinutes: interval ?? current.consolidationIntervalMinutes,
17812
+ guardianMaxSubagents: subagents ?? current.guardianMaxSubagents,
17813
+ gitRemoteEnabled: gitRemote ?? current.gitRemoteEnabled
17761
17814
  };
17762
17815
  await writeFileAtomic(this.filePath(userId), `${JSON.stringify(settings, null, 2)}\n`, { mode: 384 });
17763
17816
  return settings;
@@ -17818,7 +17871,12 @@ function settingsPayload(settings) {
17818
17871
  consolidationIntervalMinutes: settings.consolidationIntervalMinutes,
17819
17872
  intervalMin: 15,
17820
17873
  intervalMax: MEMORY_CONSOLIDATION_INTERVAL_MAX,
17821
- intervalDefault: 60
17874
+ intervalDefault: 60,
17875
+ guardianMaxSubagents: settings.guardianMaxSubagents,
17876
+ subagentsMin: 1,
17877
+ subagentsMax: 8,
17878
+ subagentsDefault: 4,
17879
+ gitRemoteEnabled: settings.gitRemoteEnabled
17822
17880
  };
17823
17881
  }
17824
17882
  /** Options for a settings read that already knows the caller's first-read default. */
@@ -17917,7 +17975,7 @@ function readUpdatePatch(body, entry) {
17917
17975
  /** Extract and validate the settings write, translating `enabled` to the stored field. */
17918
17976
  function readSettingsPatch(body, options) {
17919
17977
  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");
17978
+ const unknown = Object.keys(body).filter((key) => key !== "enabled" && key !== "consolidationIntervalMinutes" && key !== "guardianMaxSubagents" && key !== "gitRemoteEnabled");
17921
17979
  if (unknown.length > 0) return { error: fail$1(400, `unsupported settings field(s): ${unknown.join(", ")}`, "invalid") };
17922
17980
  if (options.requireEnabled && body.enabled === void 0) return { error: fail$1(400, "enabled must be a boolean", "invalid") };
17923
17981
  const patch = {};
@@ -17934,7 +17992,22 @@ function readSettingsPatch(body, options) {
17934
17992
  }) };
17935
17993
  throw error;
17936
17994
  }
17937
- if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0) return { error: fail$1(400, "at least one memory setting must be supplied", "invalid") };
17995
+ if (body.guardianMaxSubagents !== void 0) try {
17996
+ patch.guardianMaxSubagents = normalizeGuardianSubagents(body.guardianMaxSubagents);
17997
+ } catch (error) {
17998
+ if (error instanceof MemorySettingsError) return { error: fail$1(400, error.message, error.code, {
17999
+ min: 1,
18000
+ max: 8
18001
+ }) };
18002
+ throw error;
18003
+ }
18004
+ if (body.gitRemoteEnabled !== void 0) try {
18005
+ patch.gitRemoteEnabled = normalizeGitRemoteEnabled(body.gitRemoteEnabled);
18006
+ } catch (error) {
18007
+ if (error instanceof MemorySettingsError) return { error: fail$1(400, error.message, error.code) };
18008
+ throw error;
18009
+ }
18010
+ if (patch.memoryEnabled === void 0 && patch.consolidationIntervalMinutes === void 0 && patch.guardianMaxSubagents === void 0 && patch.gitRemoteEnabled === void 0) return { error: fail$1(400, "at least one memory setting must be supplied", "invalid") };
17938
18011
  return { patch };
17939
18012
  }
17940
18013
  /** Reconcile the personal-memory graph; a derived failure must not undo the write. */
@@ -18028,6 +18101,46 @@ async function handleMemoryRoute(input) {
18028
18101
  }
18029
18102
  }
18030
18103
  //#endregion
18104
+ //#region src/guardianSubagentLimit.ts
18105
+ /**
18106
+ * Apply the guardian's per-user subagent concurrency to the runtime limit.
18107
+ *
18108
+ * The guardian is one subagent tree, and `ctx.subagents` caps every tree with the
18109
+ * same `maxActiveSubagents` value. Setting that value to the user's
18110
+ * `guardianMaxSubagents` therefore bounds the guardian's concurrent children.
18111
+ *
18112
+ * The limit is a cordis *volatile* config reference: a stable object whose current
18113
+ * value the owning runtime commits through the shared `cosmokit.volatile.write`
18114
+ * symbol (the same mechanism `updateVolatile` uses). There is no public setter on
18115
+ * the reference, and the subagent service lives in the base, so this module reaches
18116
+ * the reference through the optionally-resolved service and commits the validated
18117
+ * value directly. It never throws into guardian setup: a missing or differently
18118
+ * shaped service simply means "not applied yet", and a later setup attempt retries.
18119
+ *
18120
+ * @module @sparkelf/dsh-knowledge-base/guardian-subagent-limit
18121
+ */
18122
+ /** The cosmokit volatile commit symbol, shared by every config reference. */
18123
+ const VOLATILE_WRITE = Symbol.for("cosmokit.volatile.write");
18124
+ /**
18125
+ * Commit one guardian concurrency limit onto the subagent service's volatile config.
18126
+ *
18127
+ * @param subagents - the optionally-resolved `ctx.get('subagents')` service; may be undefined.
18128
+ * @param limit - the validated `guardianMaxSubagents` (an integer >= 1).
18129
+ * @returns whether the limit is now in effect (already equal, or freshly committed).
18130
+ */
18131
+ function applyGuardianSubagentLimit(subagents, limit) {
18132
+ if (!Number.isInteger(limit) || limit < 1) return false;
18133
+ const ref = subagents?.config?.maxActiveSubagents;
18134
+ if (typeof ref !== "object" || ref === null) return false;
18135
+ const get = Reflect.get(ref, "get");
18136
+ if (typeof get !== "function") return false;
18137
+ if (get.call(ref) === limit) return true;
18138
+ const write = Reflect.get(ref, VOLATILE_WRITE);
18139
+ if (typeof write !== "function") return false;
18140
+ write.call(ref, limit);
18141
+ return true;
18142
+ }
18143
+ //#endregion
18031
18144
  //#region src/memoryHeal.ts
18032
18145
  /**
18033
18146
  * Storage-error alerting for personal memory: notify the guardian session.
@@ -28524,7 +28637,9 @@ function apply(ctx, deploymentConfig) {
28524
28637
  ].join("\n");
28525
28638
  const setupGuardianSchedule = async (attempt) => {
28526
28639
  try {
28527
- if (!await memorySettings.isEnabled("local")) return;
28640
+ const settings = await memorySettings.read(LOCAL_USER_ID);
28641
+ if (!settings.memoryEnabled) return;
28642
+ applyGuardianSubagentLimit(ctx.get("subagents"), settings.guardianMaxSubagents);
28528
28643
  const schedule = ctx.get("schedule");
28529
28644
  const registry = getGuardianWorkspaceRegistry();
28530
28645
  if (schedule === void 0 || registry === void 0) {
@@ -16,6 +16,7 @@
16
16
  * @module @sparkelf/dsh-knowledge-base/client/KnowledgeMemory
17
17
  */
18
18
  import { type ReactNode } from 'react';
19
+ import { type QuickConfigDeps } from './memoryQuickConfig.ts';
19
20
  /** A source pointer attached to one memory. `sessionId` is never rendered. */
20
21
  export interface MemorySourceRef {
21
22
  /** Human label snapshotted when the memory was written, e.g. 驾驶舱下钻. */
@@ -137,6 +138,30 @@ export interface KnowledgeMemoryViewProps {
137
138
  intervalSaved: boolean;
138
139
  onIntervalDraftChange: (value: string) => void;
139
140
  onSaveInterval: () => void;
141
+ /** Saved guardian subagent concurrency. */
142
+ guardianMaxSubagents: number;
143
+ /** Allowed subagent bounds; reported by the host so the page never guesses. */
144
+ subagentsMin: number;
145
+ subagentsMax: number;
146
+ /** The number currently typed in the subagents field. */
147
+ subagentsDraft: string;
148
+ subagentsBusy: boolean;
149
+ subagentsError?: string;
150
+ /** True after a successful save until the field changes again. */
151
+ subagentsSaved: boolean;
152
+ onSubagentsDraftChange: (value: string) => void;
153
+ onSaveSubagents: () => void;
154
+ /** Saved Git remote backup switch; off until the reader opts in. */
155
+ gitRemoteEnabled: boolean;
156
+ gitRemoteBusy: boolean;
157
+ gitRemoteError?: string;
158
+ /** True after a successful save until the next toggle. */
159
+ gitRemoteSaved: boolean;
160
+ onToggleGitRemote: (next: boolean) => void;
161
+ /** Quick-config attempt state; the button opens a guiding conversation. */
162
+ quickConfigBusy: boolean;
163
+ quickConfigError?: string;
164
+ onQuickConfig: () => void;
140
165
  list: MemoryListSnapshot;
141
166
  query: string;
142
167
  typeFilter: string;
@@ -185,6 +210,8 @@ export interface KnowledgeMemoryProps {
185
210
  locale?: string;
186
211
  /** Host hook that opens the source conversation. */
187
212
  onOpenSource?: (entry: MemoryEntryView) => void;
213
+ /** Host wiring for the quick-config conversation (create + prompt + open). */
214
+ quickConfig: QuickConfigDeps;
188
215
  }
189
216
  /**
190
217
  * Render the memory page from an explicit snapshot.
@@ -685,6 +685,17 @@ 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}.";
693
+ readonly memoryQuickConfig: "Quick setup";
694
+ readonly memoryQuickConfigSessionFailed: "Could not open a new conversation for the setup guide. Try again.";
695
+ readonly memoryQuickConfigPromptFailed: "The new conversation did not accept the setup guide. Open it from the session list and try again.";
696
+ readonly memoryGitRemoteLabel: "Git remote backup";
697
+ readonly memoryGitRemoteHint: "Off by default. When on, the guardian pushes your personal memory to its configured Git remote after consolidating; a failed push is reported, never silent.";
698
+ readonly memoryGitRemoteSaved: "Saved";
688
699
  readonly memorySettingsFailed: "Could not read the memory setting.";
689
700
  readonly memoryEnableTitle: "Turn on memory";
690
701
  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,70 @@
1
+ /**
2
+ * The memory page's 「快速配置」 flow: a new conversation that guides the reader
3
+ * through the memory settings.
4
+ *
5
+ * ## Why this goes through a Session
6
+ *
7
+ * Choosing memory settings is a conversation, not a form: the reader may want each
8
+ * option explained before deciding, and the Git remote backup opt-in deserves a
9
+ * plain-language warning about what leaves the machine. So the button does what the
10
+ * workflow plaza's subscription does — create a Session, deliver one guiding prompt,
11
+ * open the Conversation — and the model walks the reader through the choices using
12
+ * the existing `memory.settings` / `memory.save-settings` Host routes.
13
+ *
14
+ * Unlike a subscription there is nothing to verify afterwards: the deliverable IS
15
+ * the conversation. Once the prompt is accepted and the Session opened, the flow is
16
+ * complete; a refusal is reported with a reason the page can show.
17
+ *
18
+ * Every dependency is injected, so a test can drive the sequence without a browser,
19
+ * a model, or a clock.
20
+ *
21
+ * @module @sparkelf/dsh-knowledge-base/client/memoryQuickConfig
22
+ */
23
+ /** Everything the orchestration needs from the outside world. */
24
+ export interface QuickConfigDeps {
25
+ /** Create a Session and return its id. */
26
+ readonly createSession: () => Promise<string>;
27
+ /** Send one text prompt into a Session. Resolves false when it was refused. */
28
+ readonly sendPrompt: (sessionId: string, text: string) => Promise<boolean>;
29
+ /** Focus the new Session immediately; absent on a Host without navigation. */
30
+ readonly openSession?: (sessionId: string) => void;
31
+ }
32
+ /** Why an attempt failed, in terms the page can explain. */
33
+ export type QuickConfigFailure =
34
+ /** The Host refused to create a Session. */
35
+ 'session-failed'
36
+ /** The new Session could not be addressed, so no prompt could be sent. */
37
+ | 'session-unaddressable'
38
+ /** The prompt was refused (e.g. the Session was not ready to accept it). */
39
+ | 'prompt-failed';
40
+ /** How a quick-config attempt ended. */
41
+ export interface QuickConfigOutcome {
42
+ readonly ok: boolean;
43
+ /** The Session created, when one was; useful for a failure message. */
44
+ readonly sessionId?: string;
45
+ /** Present on failure: why. */
46
+ readonly failure?: QuickConfigFailure;
47
+ }
48
+ /**
49
+ * The exact instruction handed to the new Session.
50
+ *
51
+ * Written as a repeatable order rather than a conversation opener: it names the
52
+ * skill to read first, the four configurable items with their bounds and defaults,
53
+ * and the one route that applies the reader's choices. The Git remote backup item
54
+ * is explicitly default-off and opt-in, because pushing personal memory off the
55
+ * machine must never happen as a side effect of a setup conversation.
56
+ *
57
+ * @returns the prompt text.
58
+ */
59
+ export declare function quickConfigPrompt(): string;
60
+ /**
61
+ * Create the guiding Session and open it.
62
+ *
63
+ * The sequence is: create a Session, deliver the guiding prompt, open the
64
+ * Conversation. Success means the prompt was accepted — the configuration itself
65
+ * happens inside the conversation, so there is no post-hoc verification wait.
66
+ *
67
+ * @param deps - injected Host operations.
68
+ * @returns the outcome, including the created Session id.
69
+ */
70
+ export declare function startMemoryQuickConfig(deps: QuickConfigDeps): Promise<QuickConfigOutcome>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Creating a Session and delivering one text prompt to it, from plugin code.
3
+ *
4
+ * This is the same plumbing the workflow plaza's subscription uses, shared so the
5
+ * plaza and the memory quick-config button cannot drift apart:
6
+ *
7
+ * - `sessions.create({})` resolves once the new Session is addressable;
8
+ * - a just-created Session has no scope entry yet, so the prompt goes through
9
+ * `sessions.using(...)`, which retains (and awaits) the opening, then
10
+ * `reference.binding.session.prompt([{ type: 'text', text }], 'queue')`;
11
+ * - `uiWorkspace.openSession(id)` is the UI navigation that switches the main area
12
+ * from a panel page to the Session's Conversation (`sessions.open` is the fallback
13
+ * for a profile without uiWorkspace).
14
+ *
15
+ * The services are read structurally through `ctx.get`, so a Host upgrade that
16
+ * reshapes a class does not silently change what this file promises, and a test can
17
+ * pass a plain object with a `get` method. The context itself is typed as that one
18
+ * method, so a page holding the plugin context as `unknown` can pass it after a
19
+ * single cast instead of importing the cordis class.
20
+ *
21
+ * @module @sparkelf/dsh-knowledge-base/client/sessionLauncher
22
+ */
23
+ /** The one context method this module reads services through. */
24
+ export interface SessionLauncherContext {
25
+ get?: (name: string) => unknown;
26
+ }
27
+ /** The three operations a "new conversation with a first message" flow needs. */
28
+ export interface SessionLauncher {
29
+ /** Create a Session in the current workspace; resolves its id. */
30
+ readonly createSession: () => Promise<string>;
31
+ /** Send one text prompt into an existing Session; resolves false when refused. */
32
+ readonly sendPrompt: (sessionId: string, text: string) => Promise<boolean>;
33
+ /** Focus a Session in the main area; absent when the Host offers no navigation. */
34
+ readonly openSession?: (sessionId: string) => void;
35
+ }
36
+ /**
37
+ * Build the launcher from the client services this plugin can reach.
38
+ *
39
+ * A missing `sessions` service is not a load-time error: `createSession` throws a
40
+ * named failure and `sendPrompt` answers false, so each caller reports the refusal
41
+ * in its own surface instead of the whole plugin failing to mount.
42
+ *
43
+ * @param ctx - client context carrying `sessions` and `uiWorkspace`; undefined reads
44
+ * as "no services", which the operations report instead of throwing at load.
45
+ * @returns the launcher; `openSession` is absent only when neither service offers it.
46
+ */
47
+ export declare function createSessionLauncher(ctx: SessionLauncherContext | undefined): SessionLauncher;
@@ -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,19 @@ 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;
17
+ /**
18
+ * Default Git remote backup state: OFF.
19
+ *
20
+ * Pushing personal memory off the machine is an explicit opt-in; a missing or
21
+ * malformed stored value reads as off, never as on.
22
+ */
23
+ export declare const MEMORY_GIT_REMOTE_DEFAULT = false;
11
24
  /** Persisted settings shape. */
12
25
  export interface MemorySettings {
13
26
  version: typeof MEMORY_SETTINGS_VERSION;
@@ -15,6 +28,10 @@ export interface MemorySettings {
15
28
  memoryEnabled: boolean;
16
29
  /** How often the guardian consolidates memory, in minutes (15–1440). */
17
30
  consolidationIntervalMinutes: number;
31
+ /** Maximum concurrent subagents the guardian may run (1–8). */
32
+ guardianMaxSubagents: number;
33
+ /** Whether the guardian may push the personal scope to its Git remote (default off). */
34
+ gitRemoteEnabled: boolean;
18
35
  }
19
36
  /** The paused default for a user who has never confirmed the enable dialog. */
20
37
  export declare const DEFAULT_MEMORY_SETTINGS: Readonly<MemorySettings>;
@@ -50,6 +67,8 @@ export interface MemorySettingsReadOptions {
50
67
  export interface MemorySettingsPatch {
51
68
  memoryEnabled?: boolean;
52
69
  consolidationIntervalMinutes?: number;
70
+ guardianMaxSubagents?: number;
71
+ gitRemoteEnabled?: boolean;
53
72
  }
54
73
  /**
55
74
  * Validate one consolidation interval.
@@ -63,6 +82,24 @@ export interface MemorySettingsPatch {
63
82
  * @throws {MemorySettingsError} when the value is not an integer in range.
64
83
  */
65
84
  export declare function normalizeConsolidationInterval(value: unknown): number;
85
+ /**
86
+ * Validate one guardian subagent limit.
87
+ * @param value - raw value from an API body or a hand-edited file.
88
+ * @returns the accepted integer.
89
+ * @throws {MemorySettingsError} when the value is not an integer in range.
90
+ */
91
+ export declare function normalizeGuardianSubagents(value: unknown): number;
92
+ /**
93
+ * Validate the Git remote backup switch.
94
+ *
95
+ * A boolean carries no range, so the only guard is the type itself; the route
96
+ * turns a refusal into a 400.
97
+ *
98
+ * @param value - raw value from an API body or a hand-edited file.
99
+ * @returns the accepted boolean.
100
+ * @throws {MemorySettingsError} when the value is not a boolean.
101
+ */
102
+ export declare function normalizeGitRemoteEnabled(value: unknown): boolean;
66
103
  /**
67
104
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
68
105
  *
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.16",
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",
@@ -5,7 +5,7 @@ description: 个人记忆系统的统一入口。记忆守护会话、记忆抽
5
5
 
6
6
  # Memory
7
7
 
8
- 个人记忆只有一套写入链路:普通会话留下消息和工具轨迹,**记忆守护会话**是唯一写入者;抽取与 SOP 评估子代理只产出带证据的判断,不直接写记忆。三条角色准则放在 `references/`,按当前角色只读一份,不要一次全读。
8
+ 个人记忆只有一套写入链路:普通会话留下消息和工具轨迹,**记忆守护会话**是唯一写入者;抽取与 SOP 评估子代理只产出带证据的判断,不直接写记忆。三条角色准则放在 `references/`,按当前角色只读一份,不要一次全读。Git 远程备份是可选能力,见 [references/remote-backup.md](references/remote-backup.md),仅在用户开启 `gitRemoteEnabled` 后才执行。
9
9
 
10
10
  ## 什么时候用
11
11
 
@@ -41,10 +41,10 @@ description: 个人记忆系统的统一入口。记忆守护会话、记忆抽
41
41
  2. 并行派抽取子代理和 SOP 评估子代理,各自按对应参考工作;
42
42
  3. 合并五类记忆,去重、纠偏、遗忘,更新日文档与当前有效快照;
43
43
  4. 评估并晋升 SOP:有效且可复用才沉淀为技能,技能写成功后再删除 SOP;
44
- 5. 写审计,并用个人 scope 的 Git 提交作为 dream 前后恢复点。
45
-
46
- 细节(读什么、怎么合并、怎么写标题、隐私边界、Git 恢复点命令)见 [references/guardian.md](references/guardian.md)。
44
+ 5. 写审计,并用个人 scope 的 Git 提交作为 dream 前后恢复点;用户开启了 Git 远程备份时,再按 [references/remote-backup.md](references/remote-backup.md) 推送到 origin(默认关闭,不自动推送)。
45
+
46
+ 细节(读什么、怎么合并、怎么写标题、隐私边界、Git 恢复点命令)见 [references/guardian.md](references/guardian.md);远程备份的开关读法与推送约束见 [references/remote-backup.md](references/remote-backup.md)。
47
47
 
48
48
  ## 相关技能
49
49
 
50
- - `knowledge-base`:记忆文档、主题卡与知识图谱的读写入口;图谱流程见该技能的 `references/graph.md`。
50
+ - `knowledge-base`:记忆文档、主题卡与知识图谱的读写入口;图谱流程见该技能的 `references/graph.md`。
@@ -91,9 +91,13 @@ dream 用 Git 做恢复点,没有 snapshot 工具,Git 就是恢复点,只
91
91
  2. 本轮 dream 失败,回到开始前:`git -C <个人记忆 scope 目录> reset --hard <pre-commit>`。
92
92
  3. dream 完成并写完全部记忆后,再提交一次:`git -C <个人记忆 scope 目录> commit -m "dream: post <timestamp>"`。
93
93
 
94
- 只提交个人 scope。个人守护会话绝不提交部门或全局仓库;那些仓库不属于你的恢复点。日常的单次写入不需要各自提交。
94
+ 只提交个人 scope。个人守护会话绝不提交部门或全局仓库;那些仓库不属于你的恢复点。日常的单次写入不需要各自提交。
95
+
96
+ ### 9. Git 远程备份(可选,默认关闭)
95
97
 
96
- ## 隐私规则
98
+ 仅当用户开启了 `gitRemoteEnabled`,dream 收尾才按 [remote-backup.md](remote-backup.md) 把个人 scope 推送到已配置的 origin。开关缺失、关闭或读不到时一律不推送;推送失败要如实报告并写进审计,不静默。不得替用户开启开关,不得 force push,不得推送部门或全局仓库。
99
+
100
+ ## 隐私规则
97
101
 
98
102
  - **normal**:普通个人记忆,可以进入个人图谱;可内化时才提炼进部门资产。
99
103
  - **private**:仅 owner。不进部门提炼、不进共享摘要、不导出。
@@ -0,0 +1,48 @@
1
+ # Git 远程备份(可选,默认关闭)
2
+
3
+ 把个人记忆推送到远程 Git 仓库做异地备份。**这是用户的显式选择,不是默认行为**:只有设置里的 `gitRemoteEnabled` 为 `true` 时才允许推送;关闭、缺失或读不到设置时,一律不推送。
4
+
5
+ ## 先读开关
6
+
7
+ 每轮 dream 收尾前,读用户的记忆设置文件:
8
+
9
+ `<知识存储根>/.memory/users/<用户>/settings.json`
10
+
11
+ (这是默认位置;部署配置了 `memoryUsersRoot` 时以配置为准。也可以调用知识库 Host 路由 `POST /knowledge-base/api/memory.settings` 读同一份设置。)
12
+
13
+ - 文件里的 `gitRemoteEnabled` 是布尔值。**只有显式 `true` 才算开启**;字段缺失、文件不存在、值不是布尔,都按关闭处理。
14
+ - 开关由用户在记忆设置页或快速配置会话里决定。守护会话**不得替用户开启**,也不得因为「备份看起来有用」就推送。
15
+
16
+ ## 开启时怎么推
17
+
18
+ 仅对**个人记忆 scope 目录**(`<知识存储根>/personal/<用户>`,即 guardian.md 里做恢复点的那个仓库)操作,推送到它已配置的 `origin`:
19
+
20
+ 1. 确认 dream 的 post 提交已完成(见 guardian.md「审计与 Git 恢复点」);远程备份推的就是这些提交,不额外制造提交。
21
+ 2. 推送当前分支:
22
+ `git -C <个人记忆 scope 目录> push origin HEAD`
23
+ 3. 核对推送结果:命令退出码之外,再看输出里分支是否真的到达远程(例如 `git -C <个人记忆 scope 目录> status -sb` 不再领先 origin)。
24
+
25
+ 约束:
26
+
27
+ - **只推个人 scope。**部门、全局仓库不属于备份范围,绝不推送。
28
+ - **不改远程配置**:不新增/更换 remote URL,不改 ssh 配置;推送走部署已配好的凭据(如 `~/.ssh/config` 里的主机别名)。凭据问题如实报告,不要把密钥、Token 写进记忆或提交。
29
+ - **不 force push**,不重写历史来「解决」推送失败;本地恢复点提交保持原样。
30
+ - 日常单次写入不推送;远程备份只发生在 dream 收尾,频率随 dream。
31
+
32
+ ## 关闭时
33
+
34
+ 什么都不做:不 push、不试探远程连通性、不「顺便」同步。本地 Git 恢复点(dream 前后提交)不受开关影响,照常工作。
35
+
36
+ ## 失败要报告,不静默
37
+
38
+ 推送失败(网络不通、认证被拒、远程拒绝、仓库不存在等)时:
39
+
40
+ 1. 在守护会话的当轮输出里如实写明:失败命令、错误原文、已尝试的办法;
41
+ 2. 把失败与原因写进当轮审计;
42
+ 3. 本地提交保留不动,下一轮 dream 再试;不要为了「看起来成功」而谎称已备份,也不要静默跳过。
43
+
44
+ 连续多轮失败时,把根因(如凭据失效、远程仓库被删)写清楚留给用户决策;是否关闭开关由用户决定。
45
+
46
+ ## 隐私提醒
47
+
48
+ 推送的是**整个个人记忆 scope**,其中可能包含 `private` / `sensitive` 条目。开启前用户应已知情(快速配置引导会说明这一点);守护会话不因此改变隐私分级规则,也不把内容推送到个人 scope 之外的任何仓库。`secret` 级别本来只存凭据引用、不存实际值,该规则不变。