@sparkelf/dsh-knowledge-base 0.6.15 → 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
@@ -17634,7 +17637,8 @@ const DEFAULT_MEMORY_SETTINGS = Object.freeze({
17634
17637
  version: 2,
17635
17638
  memoryEnabled: false,
17636
17639
  consolidationIntervalMinutes: 60,
17637
- guardianMaxSubagents: 4
17640
+ guardianMaxSubagents: 4,
17641
+ gitRemoteEnabled: false
17638
17642
  });
17639
17643
  /** A malformed interval or write patch; the route maps this to HTTP 400. */
17640
17644
  var MemorySettingsError = class extends Error {
@@ -17689,6 +17693,29 @@ function readStoredGuardianSubagents(value) {
17689
17693
  }
17690
17694
  }
17691
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
+ /**
17692
17719
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
17693
17720
  *
17694
17721
  * `read()` tolerates a corrupt file by returning the paused default; the next
@@ -17754,7 +17781,8 @@ var MemorySettingsStore = class {
17754
17781
  version: 2,
17755
17782
  memoryEnabled,
17756
17783
  consolidationIntervalMinutes: readStoredInterval(parsed.consolidationIntervalMinutes),
17757
- guardianMaxSubagents: readStoredGuardianSubagents(parsed.guardianMaxSubagents)
17784
+ guardianMaxSubagents: readStoredGuardianSubagents(parsed.guardianMaxSubagents),
17785
+ gitRemoteEnabled: readStoredGitRemoteEnabled(parsed.gitRemoteEnabled)
17758
17786
  };
17759
17787
  }
17760
17788
  /** Whether learning is enabled for this user (default `false`). */
@@ -17771,16 +17799,18 @@ var MemorySettingsStore = class {
17771
17799
  * @returns the normalized settings actually written.
17772
17800
  */
17773
17801
  async save(userId, patch, options = {}) {
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");
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");
17775
17803
  if (patch.memoryEnabled !== void 0 && typeof patch.memoryEnabled !== "boolean") throw new MemorySettingsError("invalid-settings", "memoryEnabled must be a boolean");
17776
17804
  const interval = patch.consolidationIntervalMinutes === void 0 ? void 0 : normalizeConsolidationInterval(patch.consolidationIntervalMinutes);
17777
17805
  const subagents = patch.guardianMaxSubagents === void 0 ? void 0 : normalizeGuardianSubagents(patch.guardianMaxSubagents);
17806
+ const gitRemote = patch.gitRemoteEnabled === void 0 ? void 0 : normalizeGitRemoteEnabled(patch.gitRemoteEnabled);
17778
17807
  const current = await this.read(userId, options);
17779
17808
  const settings = {
17780
17809
  version: 2,
17781
17810
  memoryEnabled: patch.memoryEnabled ?? current.memoryEnabled,
17782
17811
  consolidationIntervalMinutes: interval ?? current.consolidationIntervalMinutes,
17783
- guardianMaxSubagents: subagents ?? current.guardianMaxSubagents
17812
+ guardianMaxSubagents: subagents ?? current.guardianMaxSubagents,
17813
+ gitRemoteEnabled: gitRemote ?? current.gitRemoteEnabled
17784
17814
  };
17785
17815
  await writeFileAtomic(this.filePath(userId), `${JSON.stringify(settings, null, 2)}\n`, { mode: 384 });
17786
17816
  return settings;
@@ -17845,7 +17875,8 @@ function settingsPayload(settings) {
17845
17875
  guardianMaxSubagents: settings.guardianMaxSubagents,
17846
17876
  subagentsMin: 1,
17847
17877
  subagentsMax: 8,
17848
- subagentsDefault: 4
17878
+ subagentsDefault: 4,
17879
+ gitRemoteEnabled: settings.gitRemoteEnabled
17849
17880
  };
17850
17881
  }
17851
17882
  /** Options for a settings read that already knows the caller's first-read default. */
@@ -17944,7 +17975,7 @@ function readUpdatePatch(body, entry) {
17944
17975
  /** Extract and validate the settings write, translating `enabled` to the stored field. */
17945
17976
  function readSettingsPatch(body, options) {
17946
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") };
17947
- const unknown = Object.keys(body).filter((key) => key !== "enabled" && key !== "consolidationIntervalMinutes" && key !== "guardianMaxSubagents");
17978
+ const unknown = Object.keys(body).filter((key) => key !== "enabled" && key !== "consolidationIntervalMinutes" && key !== "guardianMaxSubagents" && key !== "gitRemoteEnabled");
17948
17979
  if (unknown.length > 0) return { error: fail$1(400, `unsupported settings field(s): ${unknown.join(", ")}`, "invalid") };
17949
17980
  if (options.requireEnabled && body.enabled === void 0) return { error: fail$1(400, "enabled must be a boolean", "invalid") };
17950
17981
  const patch = {};
@@ -17970,7 +18001,13 @@ function readSettingsPatch(body, options) {
17970
18001
  }) };
17971
18002
  throw error;
17972
18003
  }
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") };
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") };
17974
18011
  return { patch };
17975
18012
  }
17976
18013
  /** Reconcile the personal-memory graph; a derived failure must not undo the write. */
@@ -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. 驾驶舱下钻. */
@@ -150,6 +151,17 @@ export interface KnowledgeMemoryViewProps {
150
151
  subagentsSaved: boolean;
151
152
  onSubagentsDraftChange: (value: string) => void;
152
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;
153
165
  list: MemoryListSnapshot;
154
166
  query: string;
155
167
  typeFilter: string;
@@ -198,6 +210,8 @@ export interface KnowledgeMemoryProps {
198
210
  locale?: string;
199
211
  /** Host hook that opens the source conversation. */
200
212
  onOpenSource?: (entry: MemoryEntryView) => void;
213
+ /** Host wiring for the quick-config conversation (create + prompt + open). */
214
+ quickConfig: QuickConfigDeps;
201
215
  }
202
216
  /**
203
217
  * Render the memory page from an explicit snapshot.
@@ -690,6 +690,12 @@ export declare const en: {
690
690
  readonly memorySaveSubagents: "Save";
691
691
  readonly memorySubagentsSaved: "Saved";
692
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";
693
699
  readonly memorySettingsFailed: "Could not read the memory setting.";
694
700
  readonly memoryEnableTitle: "Turn on memory";
695
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;
@@ -14,6 +14,13 @@ export declare const MEMORY_GUARDIAN_SUBAGENTS_MIN = 1;
14
14
  export declare const MEMORY_GUARDIAN_SUBAGENTS_MAX = 8;
15
15
  /** Default concurrent guardian subagents. */
16
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;
17
24
  /** Persisted settings shape. */
18
25
  export interface MemorySettings {
19
26
  version: typeof MEMORY_SETTINGS_VERSION;
@@ -23,6 +30,8 @@ export interface MemorySettings {
23
30
  consolidationIntervalMinutes: number;
24
31
  /** Maximum concurrent subagents the guardian may run (1–8). */
25
32
  guardianMaxSubagents: number;
33
+ /** Whether the guardian may push the personal scope to its Git remote (default off). */
34
+ gitRemoteEnabled: boolean;
26
35
  }
27
36
  /** The paused default for a user who has never confirmed the enable dialog. */
28
37
  export declare const DEFAULT_MEMORY_SETTINGS: Readonly<MemorySettings>;
@@ -59,6 +68,7 @@ export interface MemorySettingsPatch {
59
68
  memoryEnabled?: boolean;
60
69
  consolidationIntervalMinutes?: number;
61
70
  guardianMaxSubagents?: number;
71
+ gitRemoteEnabled?: boolean;
62
72
  }
63
73
  /**
64
74
  * Validate one consolidation interval.
@@ -79,6 +89,17 @@ export declare function normalizeConsolidationInterval(value: unknown): number;
79
89
  * @throws {MemorySettingsError} when the value is not an integer in range.
80
90
  */
81
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;
82
103
  /**
83
104
  * Atomic settings store over `<usersRoot>/<userId>/settings.json`.
84
105
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-knowledge-base",
3
- "version": "0.6.15",
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` 级别本来只存凭据引用、不存实际值,该规则不变。