sage-mem 2.24.0 → 2.25.0

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 CHANGED
@@ -2188,6 +2188,19 @@ const StarmapRuntime = (function (require, _react) {
2188
2188
  result: { mode: "strict", typeSymbol: "sage-mem/types#MemorySettingsResult", schema: objCodec, create: () => objCodec },
2189
2189
  sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
2190
2190
  },
2191
+ {
2192
+ // 2.25.0:外部访问读侧的**运行状态**(只读、无入参)。设置走 setSettings({ external }),
2193
+ // 这里回答「现在跑成什么样」—— 暴露条目数 / 最近一轮的时间与错误 / 端点是否在听。
2194
+ // 与 getSettings 同一个理由用 objCodec:顶层严格、内部宽松,host 加字段不用改这里。
2195
+ id: "sage-mem#memory/externalStatus",
2196
+ service: "memory",
2197
+ namespace: "memory",
2198
+ method: "externalStatus",
2199
+ invocation: { kind: "direct" },
2200
+ parameters: [],
2201
+ result: { mode: "strict", typeSymbol: "sage-mem/types#ExternalStatus", schema: objCodec, create: () => objCodec },
2202
+ sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
2203
+ },
2191
2204
  {
2192
2205
  id: "sage-mem#memory/readRaw",
2193
2206
  service: "memory",
@@ -2901,6 +2914,13 @@ const StarmapRuntime = (function (require, _react) {
2901
2914
  ".smem-todo-cp-note{font-size:11px;color:var(--dsw-alias-label-secondary);}",
2902
2915
  ".smem-todo-done-state{display:flex;flex-direction:column;gap:6px;padding:16px 12px;}",
2903
2916
  ".smem-todo-done-title{font-weight:600;}",
2917
+ // 2.25.0:「外部访问」逐条勾选清单 —— 只是一个带边框的滚动列表,
2918
+ // 勾上的行用左侧强调条区分(不整行换底色,长列表里那样太吵)。
2919
+ ".smem-ext-list{display:flex;flex-direction:column;gap:2px;max-height:260px;overflow:auto;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:6px 8px;}",
2920
+ ".smem-ext-row{display:flex;align-items:center;gap:8px;padding:3px 4px;border-radius:6px;border-left:2px solid transparent;cursor:pointer;font-size:12.5px;}",
2921
+ ".smem-ext-row:hover{background:var(--dsw-alias-bg-l2,transparent);}",
2922
+ '.smem-ext-row--on{border-left-color:var(--dsw-alias-brand-primary,#4d76e6);}',
2923
+ ".smem-ext-name{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere;}",
2904
2924
  ].join("\n");
2905
2925
 
2906
2926
  /**
@@ -4254,6 +4274,42 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
4254
4274
  "tab.auto": "自动整理",
4255
4275
  "tab.health": "库健康",
4256
4276
  "tab.lab": "实验性",
4277
+ "tab.external": "外部访问",
4278
+ // ── 2.25.0 外部访问(读侧)──────────────────────────────────
4279
+ "ext.title": "外部访问(只读)",
4280
+ "ext.switch": "允许本机其他 agent 读取记忆副本",
4281
+ "ext.switch.onTitle": "现在开启:白名单内的记忆会被导出成副本,端点对 127.0.0.1 开放",
4282
+ "ext.switch.offTitle": "现在关闭:不导出、不开端口(默认)",
4283
+ "ext.what1": "开关打开后,白名单内的记忆会被复制到状态目录下的 mirror/ 里,其他 agent 通过 127.0.0.1 上的只读接口读那一份副本。",
4284
+ "ext.what2": "接口只有读:没有写入、不给文件路径、拿不到没勾选的条目。主库一个字都不会被它们改到。",
4285
+ "ext.status.on": "已开启 · 暴露 {count} 条",
4286
+ "ext.status.off": "关闭(默认)",
4287
+ "ext.prefixes": "按前缀整类开放",
4288
+ "ext.prefixesHint": "默认只开 project_ 与 reference_;user_ 与 feedback_ 是「关于我自己」的记忆,默认不给。",
4289
+ "ext.tags": "按标签开放",
4290
+ "ext.tagsPlaceholder": "用逗号分隔,例如:记忆系统, 发布",
4291
+ "ext.tagsHint": "留空 = 不按标签开放。标签写在记忆的 frontmatter 里。",
4292
+ "ext.files": "逐条勾选",
4293
+ "ext.filesHint": "勾上就包含、取消就排除;前缀整类开着时,取消勾选会记成「逐条排除」并压过前缀。",
4294
+ "ext.filesEmpty": "记忆目录里还没有可导出的条目。",
4295
+ "ext.exposed": "当前实际暴露 {count} 条(以上一轮导出为准)",
4296
+ "ext.port": "端点端口",
4297
+ "ext.endpointLabel": "只读端点:",
4298
+ "ext.endpoint.on": "在听 {url}",
4299
+ "ext.endpoint.off": "未启动",
4300
+ "ext.endpoint.error": "起不来:{error}",
4301
+ "ext.lastExport": "最近一轮:{time} · 写 {written} / 未变 {unchanged} / 删 {deleted}",
4302
+ "ext.lastExport.never": "最近一轮:还没有导出过",
4303
+ "ext.dir": "副本目录:{dir}",
4304
+ "ext.notice.on": "已开启:下一轮导出最多 10 秒后开始,端点随即就绪",
4305
+ "ext.notice.off": "已关闭,端点已停",
4306
+ "ext.notice.prefix": "前缀白名单已更新",
4307
+ "ext.notice.file": "逐条名单已更新",
4308
+ "ext.notice.port": "端口已保存(端点已按新端口重启)",
4309
+ "ext.notice.saved": "已保存",
4310
+ "ext.err.noSettings": "宿主侧还没有外部访问接口(插件版本较旧)",
4311
+ "ext.err.rejected": "保存被拒绝",
4312
+ "ext.err.port": "端口要填 1024–65535 的整数",
4257
4313
  "lab.title": "MMR 去重(实验性)",
4258
4314
  "lab.switch": "启用 MMR 去重",
4259
4315
  "lab.switch.onTitle": "现在开启:注入时优先让不同主题的记忆占名额",
@@ -4924,6 +4980,41 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
4924
4980
  "tab.auto": "Automation",
4925
4981
  "tab.health": "Health",
4926
4982
  "tab.lab": "Lab",
4983
+ "tab.external": "External",
4984
+ "ext.title": "External access (read-only)",
4985
+ "ext.switch": "Let other local agents read a copy of the memory library",
4986
+ "ext.switch.onTitle": "On: whitelisted memories are exported to a copy, and the endpoint listens on 127.0.0.1",
4987
+ "ext.switch.offTitle": "Off: nothing is exported and no port is opened (default)",
4988
+ "ext.what1": "When enabled, whitelisted memories are copied into mirror/ under the state directory, and other agents read that copy through a read-only endpoint on 127.0.0.1.",
4989
+ "ext.what2": "The endpoint can only read: no writes, no file paths, nothing outside the whitelist. Your main library is never modified by them.",
4990
+ "ext.status.on": "On · {count} exposed",
4991
+ "ext.status.off": "Off (default)",
4992
+ "ext.prefixes": "Expose whole prefix groups",
4993
+ "ext.prefixesHint": "Only project_ and reference_ are on by default; user_ and feedback_ are memories about you and stay private.",
4994
+ "ext.tags": "Expose by tag",
4995
+ "ext.tagsPlaceholder": "Comma separated, e.g. memory-system, release",
4996
+ "ext.tagsHint": "Empty means no tag-based exposure. Tags live in each memory's frontmatter.",
4997
+ "ext.files": "Per-file selection",
4998
+ "ext.filesHint": "Checked means included, unchecked means excluded; when a prefix group is on, unchecking records a per-file exclusion that overrides it.",
4999
+ "ext.filesEmpty": "No exportable entries in the memory directory yet.",
5000
+ "ext.exposed": "{count} exposed right now (from the last export)",
5001
+ "ext.port": "Endpoint port",
5002
+ "ext.endpointLabel": "Read-only endpoint:",
5003
+ "ext.endpoint.on": "listening on {url}",
5004
+ "ext.endpoint.off": "not running",
5005
+ "ext.endpoint.error": "failed to start: {error}",
5006
+ "ext.lastExport": "Last export: {time} · {written} written / {unchanged} unchanged / {deleted} deleted",
5007
+ "ext.lastExport.never": "Last export: never ran",
5008
+ "ext.dir": "Copy directory: {dir}",
5009
+ "ext.notice.on": "Enabled: the first export starts within 10 seconds and the endpoint comes up right after",
5010
+ "ext.notice.off": "Disabled, endpoint stopped",
5011
+ "ext.notice.prefix": "Prefix whitelist updated",
5012
+ "ext.notice.file": "Per-file selection updated",
5013
+ "ext.notice.port": "Port saved (endpoint restarted on the new port)",
5014
+ "ext.notice.saved": "Saved",
5015
+ "ext.err.noSettings": "The host has no external-access API yet (older plugin version)",
5016
+ "ext.err.rejected": "The save was rejected",
5017
+ "ext.err.port": "Port must be an integer between 1024 and 65535",
4927
5018
  "lab.title": "MMR de-duplication (experimental)",
4928
5019
  "lab.switch": "Enable MMR de-duplication",
4929
5020
  "lab.switch.onTitle": "On: injection prefers memories on different topics for the same slots",
@@ -7822,6 +7913,272 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
7822
7913
  ]),
7823
7914
  ]);
7824
7915
  }
7916
+ /**
7917
+ * 「外部访问」一屏(2.25.0)—— **读侧**:把白名单内的记忆导出成副本,本机其他 agent 只能读它。
7918
+ *
7919
+ * 为什么单开一屏而不是塞进「实验性」:这一屏控制的是**谁能看见我的记忆**,不是选材
7920
+ * 也不是预算。它出事的样子和前两屏都不一样 —— 「本不该给外面看的那条,被导出去了」。
7921
+ * 用户必须能一眼看到「现在暴露了几条」,并且能一条条关掉。
7922
+ *
7923
+ * 数据全走已有的 remote:
7924
+ * - `memory.getSettings()` → `{ external, externalDiagnostics, ... }`(设置是生效值,**不进重启**)
7925
+ * - `memory.externalStatus()` → 暴露条目数 / 名单 / 最近一轮 / 端点状态(只读)
7926
+ * - `memory.listFiles()` → 逐条勾选的那个列表
7927
+ * - `memory.setSettings({ external })` → 补丁式保存;返回 `{ ok, settings, restartRequired }`
7928
+ *
7929
+ * ⚠️ **白名单判据不在客户端复制一份**:哪些条目现在算暴露,由宿主 `externalStatus().exposedNames`
7930
+ * 直接给(它就是副本目录里的实际内容)。客户端只负责「勾 / 取消 → 写成 include / exclude」,
7931
+ * 判据仍然只有 `lib/mirror/policy.js` 一处 —— 面板算一套、导出算另一套,正是要避免的那种漂移。
7932
+ */
7933
+ function ExternalAccessPanel(props) {
7934
+ const remote = stableRemote(props.ctx, "remote.memory");
7935
+ const sSet = react.useState(null); const memSet = sSet[0], setMemSet = sSet[1];
7936
+ const sStatus = react.useState(null); const status = sStatus[0], setStatus = sStatus[1];
7937
+ const sFiles = react.useState([]); const files = sFiles[0], setFiles = sFiles[1];
7938
+ const sTags = react.useState(""); const tagDraft = sTags[0], setTagDraft = sTags[1];
7939
+ const sPort = react.useState(""); const portDraft = sPort[0], setPortDraft = sPort[1];
7940
+ const sBusy = react.useState(false); const busy = sBusy[0], setBusy = sBusy[1];
7941
+ const sErr = react.useState(null); const err = sErr[0], setErr = sErr[1];
7942
+ const sNotice = react.useState(""); const notice = sNotice[0], setNotice = sNotice[1];
7943
+
7944
+ const ext = (memSet && memSet.external) || null;
7945
+ const enabled = !!(ext && ext.enabled);
7946
+ const prefixes = (ext && ext.prefixes) || [];
7947
+ const exposedNames = (status && status.exposedNames) || [];
7948
+ const exposed = new Set(exposedNames);
7949
+ const endpoint = (status && status.endpoint) || null;
7950
+
7951
+ /** 前缀候选:默认那两个 + 另外两类(面板把「不给」也画出来,免得以为漏了)。 */
7952
+ const PREFIX_CHOICES = ["project_", "reference_", "user_", "feedback_"];
7953
+
7954
+ function load() {
7955
+ if (!remote || typeof remote.getSettings !== "function") {
7956
+ setErr(t("ext.err.noSettings"));
7957
+ return;
7958
+ }
7959
+ Promise.resolve(remote.getSettings()).then(function (res) {
7960
+ const d = unwrap(res) || {};
7961
+ setMemSet(d);
7962
+ const cur = d.external || {};
7963
+ setTagsOf(cur.tags);
7964
+ setPortDraft(String(typeof cur.port === "number" ? cur.port : ""));
7965
+ }, function (e) { setErr(String((e && e.message) || e)); });
7966
+ if (typeof remote.externalStatus === "function") {
7967
+ Promise.resolve(remote.externalStatus()).then(function (res) {
7968
+ setStatus(unwrap(res) || {});
7969
+ }, function () { /* 状态读不到不影响设置那一半 */ });
7970
+ }
7971
+ if (typeof remote.listFiles === "function") {
7972
+ Promise.resolve(remote.listFiles()).then(function (res) {
7973
+ setFiles(Array.isArray(unwrap(res)) ? unwrap(res) : []);
7974
+ }, function () { /* 列表读不到就只显示开关与端点 */ });
7975
+ }
7976
+ }
7977
+
7978
+ function setTagsOf(list) { setTagDraft((Array.isArray(list) ? list : []).join(", ")); }
7979
+
7980
+ react.useEffect(function () { load(); }, []);
7981
+
7982
+ /** 保存一段 `external` 补丁。`setSettings` 自带 `{ok, settings}`,不要过 unwrap。 */
7983
+ function saveExternal(patch, okMsg) {
7984
+ if (!remote || typeof remote.setSettings !== "function") { setErr(t("ext.err.noSettings")); return; }
7985
+ setBusy(true); setErr(null); setNotice("");
7986
+ Promise.resolve(remote.setSettings({ external: patch })).then(function (out) {
7987
+ setBusy(false);
7988
+ if (out && out.ok === false) { setErr(out.error || t("ext.err.rejected")); return; }
7989
+ if (out && out.settings) {
7990
+ setMemSet(out.settings);
7991
+ const cur = out.settings.external || {};
7992
+ setTagsOf(cur.tags);
7993
+ setPortDraft(String(typeof cur.port === "number" ? cur.port : ""));
7994
+ }
7995
+ // 保存完立刻重读状态:暴露条数与端点都要马上反映出来(宿主那边已经 refresh 过)。
7996
+ refreshStatus();
7997
+ setNotice(okMsg);
7998
+ }, function (e) {
7999
+ setBusy(false);
8000
+ setErr(String((e && e.message) || e));
8001
+ });
8002
+ }
8003
+
8004
+ function refreshStatus() {
8005
+ if (!remote || typeof remote.externalStatus !== "function") return;
8006
+ Promise.resolve(remote.externalStatus()).then(function (res) {
8007
+ setStatus(unwrap(res) || {});
8008
+ }, function () { /* 同上 */ });
8009
+ }
8010
+
8011
+ function toggleEnabled() {
8012
+ saveExternal({ enabled: enabled ? 0 : 1 }, enabled ? t("ext.notice.off") : t("ext.notice.on"));
8013
+ }
8014
+
8015
+ /** 前缀整类开关:在数组里加 / 减一项,其余原样(顺序按 PREFIX_CHOICES 归一)。 */
8016
+ function togglePrefix(prefix) {
8017
+ const has = prefixes.some(function (p) { return String(p).toLowerCase() === prefix.toLowerCase(); });
8018
+ const next = has
8019
+ ? prefixes.filter(function (p) { return String(p).toLowerCase() !== prefix.toLowerCase(); })
8020
+ : prefixes.concat([prefix]);
8021
+ saveExternal({ prefixes: next }, t("ext.notice.prefix"));
8022
+ }
8023
+
8024
+ /** 标签白名单:逗号分隔(中英文逗号都收)。空 = 不按标签开放。 */
8025
+ function saveTags() {
8026
+ const list = String(tagDraft == null ? "" : tagDraft)
8027
+ .split(/[,,]/)
8028
+ .map(function (s) { return s.trim(); })
8029
+ .filter(function (s) { return s !== ""; });
8030
+ saveExternal({ tags: list }, t("ext.notice.saved"));
8031
+ }
8032
+
8033
+ /**
8034
+ * 逐条勾选:勾上 → include、取消 → exclude(同时从另一侧摘掉,免得两份名单都记着它)。
8035
+ * 「取消」写的是 exclude 而不是「什么都不做」—— 前缀整类打开时,只有 exclude 能压过它。
8036
+ */
8037
+ function toggleFile(name) {
8038
+ if (!ext) return;
8039
+ const include = (ext.include || []).filter(function (n) { return n !== name; });
8040
+ const exclude = (ext.exclude || []).filter(function (n) { return n !== name; });
8041
+ if (exposed.has(name)) exclude.push(name);
8042
+ else include.push(name);
8043
+ saveExternal({ include: include, exclude: exclude }, t("ext.notice.file"));
8044
+ }
8045
+
8046
+ function savePort() {
8047
+ const raw = String(portDraft == null ? "" : portDraft).trim();
8048
+ const n = Number(raw);
8049
+ if (raw === "" || !Number.isInteger(n) || n < 1024 || n > 65535) { setErr(t("ext.err.port")); return; }
8050
+ saveExternal({ port: n }, t("ext.notice.port"));
8051
+ }
8052
+
8053
+ const statusText = busy
8054
+ ? t("lab.action.saving")
8055
+ : (enabled
8056
+ ? t("ext.status.on", { count: exposedNames.length })
8057
+ : t("ext.status.off"));
8058
+
8059
+ /** 最近一轮那一行:没有导出过就明说「还没跑过」,不要显示成 0 秒前。 */
8060
+ const lastLine = !status || !status.lastExportAt
8061
+ ? t("ext.lastExport.never")
8062
+ : t("ext.lastExport", {
8063
+ time: new Date(status.lastExportAt).toLocaleTimeString(),
8064
+ written: status.written, unchanged: status.unchanged, deleted: status.deleted,
8065
+ });
8066
+
8067
+ const endpointLine = !endpoint
8068
+ ? t("ext.endpoint.off")
8069
+ : (endpoint.listening
8070
+ ? t("ext.endpoint.on", { url: endpoint.url })
8071
+ : (endpoint.error ? t("ext.endpoint.error", { error: endpoint.error }) : t("ext.endpoint.off")));
8072
+
8073
+ return h("div", { className: "smem-external smem-module-card" }, [
8074
+ h("div", { className: "smem-modcard-head", key: "head" }, [
8075
+ h(Switch, {
8076
+ key: "sw",
8077
+ on: enabled,
8078
+ label: t("ext.switch"),
8079
+ title: enabled ? t("ext.switch.onTitle") : t("ext.switch.offTitle"),
8080
+ disabled: busy || !memSet,
8081
+ onClick: toggleEnabled,
8082
+ }),
8083
+ h("span", { className: "smem-modcard-title", key: "t" }, t("ext.title")),
8084
+ h("span", { className: "smem-modcard-status", key: "s" }, statusText),
8085
+ ]),
8086
+
8087
+ h("div", { className: "smem-autodream-sec", key: "what" }, [
8088
+ h("div", { className: "smem-autodream-note", key: "p1" }, t("ext.what1")),
8089
+ h("div", { className: "smem-autodream-note", key: "p2" }, t("ext.what2")),
8090
+ ]),
8091
+
8092
+ // ── 白名单:按前缀整类 ──
8093
+ h("div", { className: "smem-autodream-sec", key: "prefix" }, [
8094
+ h("div", { className: "smem-autodream-key", key: "k" }, t("ext.prefixes")),
8095
+ h("div", { className: "smem-chips", key: "chips" }, PREFIX_CHOICES.map(function (p) {
8096
+ const on = prefixes.some(function (x) { return String(x).toLowerCase() === p.toLowerCase(); });
8097
+ return h(Chip, {
8098
+ key: p,
8099
+ label: p + "*",
8100
+ on: on,
8101
+ onClick: function () { if (!busy && memSet) togglePrefix(p); },
8102
+ });
8103
+ })),
8104
+ h("div", { className: "smem-autodream-note", key: "hint" }, t("ext.prefixesHint")),
8105
+ ]),
8106
+
8107
+ // ── 白名单:按标签 ──
8108
+ h("div", { className: "smem-autodream-sec", key: "tags" }, [
8109
+ h("div", { className: "smem-autodream-row", key: "r" }, [
8110
+ h("span", { className: "smem-autodream-key", key: "k" }, t("ext.tags")),
8111
+ h("input", {
8112
+ className: "smem-input", key: "i", type: "text",
8113
+ value: tagDraft,
8114
+ disabled: busy || !memSet,
8115
+ placeholder: t("ext.tagsPlaceholder"),
8116
+ onChange: function (e) { setTagDraft(e.target.value); },
8117
+ }),
8118
+ h("button", {
8119
+ type: "button", className: "smem-btn smem-btn-primary", key: "save",
8120
+ disabled: busy || !memSet, onClick: saveTags,
8121
+ }, busy ? t("lab.action.saving") : t("lab.action.save")),
8122
+ ]),
8123
+ h("div", { className: "smem-autodream-note", key: "hint" }, t("ext.tagsHint")),
8124
+ ]),
8125
+
8126
+ // ── 逐条勾选 ──
8127
+ h("div", { className: "smem-autodream-sec", key: "files" }, [
8128
+ h("div", { className: "smem-autodream-key", key: "k" }, t("ext.files")),
8129
+ h("div", { className: "smem-autodream-note", key: "hint" }, t("ext.filesHint")),
8130
+ files.length === 0
8131
+ ? h("div", { className: "smem-muted", key: "empty" }, t("ext.filesEmpty"))
8132
+ : h("div", { className: "smem-ext-list", key: "list" }, files.map(function (f) {
8133
+ const name = String(f && f.file ? f.file : "");
8134
+ const on = exposed.has(name);
8135
+ return h("label", { className: "smem-ext-row" + (on ? " smem-ext-row--on" : ""), key: name, title: String((f && f.description) || "") }, [
8136
+ h("input", {
8137
+ type: "checkbox", key: "c", checked: on,
8138
+ disabled: busy || !memSet,
8139
+ onChange: function () { toggleFile(name); },
8140
+ }),
8141
+ h("span", { className: "smem-ext-name", key: "n" }, name),
8142
+ h("span", { className: "smem-muted", key: "d" }, String((f && f.description) || "").slice(0, 60)),
8143
+ ]);
8144
+ })),
8145
+ exposed.size > 0
8146
+ ? h("div", { className: "smem-autodream-note", key: "count" }, t("ext.exposed", { count: exposed.size }))
8147
+ : null,
8148
+ ]),
8149
+
8150
+ // ── 端点与最近一轮 ──
8151
+ h("div", { className: "smem-autodream-sec", key: "endpoint" }, [
8152
+ h("div", { className: "smem-autodream-row", key: "r" }, [
8153
+ h("span", { className: "smem-autodream-key", key: "k" }, t("ext.port")),
8154
+ h("input", {
8155
+ className: "smem-input smem-num", key: "i", type: "number", min: 1024, max: 65535, step: 1,
8156
+ value: portDraft,
8157
+ disabled: busy || !memSet,
8158
+ onChange: function (e) { setPortDraft(e.target.value); },
8159
+ }),
8160
+ h("button", {
8161
+ type: "button", className: "smem-btn smem-btn-primary", key: "save",
8162
+ disabled: busy || !memSet, onClick: savePort,
8163
+ }, busy ? t("lab.action.saving") : t("lab.action.save")),
8164
+ ]),
8165
+ h("div", { className: "smem-autodream-note", key: "ep" }, t("ext.endpointLabel") + " " + endpointLine),
8166
+ h("div", { className: "smem-autodream-note", key: "last" }, lastLine),
8167
+ status && status.mirrorDir
8168
+ ? h("div", { className: "smem-autodream-note", key: "dir" }, t("ext.dir", { dir: status.mirrorDir }))
8169
+ : null,
8170
+ status && Array.isArray(status.errors) && status.errors.length > 0
8171
+ ? h("div", { className: "smem-err", key: "errs" }, "⚠ " + status.errors.join(" · "))
8172
+ : null,
8173
+ (memSet && Array.isArray(memSet.externalDiagnostics) && memSet.externalDiagnostics.length > 0)
8174
+ ? h("div", { className: "smem-err", key: "diag" }, "⚠ " + memSet.externalDiagnostics.join(" · "))
8175
+ : null,
8176
+ ]),
8177
+
8178
+ err ? h("div", { className: "smem-err", key: "err" }, "⚠ " + err) : null,
8179
+ notice ? h("div", { className: "smem-ok", key: "ok" }, "✓ " + notice) : null,
8180
+ ]);
8181
+ }
7825
8182
  // ── 文件列表这一屏(1.5.3 从 Section 里抽出;D23 计划的 72 片)──────────
7826
8183
  // 只负责「按状态/筛选把卡片摆出来 + 四种空态」;状态、筛选语义、动作回调全部由 Section 传。
7827
8184
  // 抽出的判据:它是 Section 里最大的一块纯渲染,而卡片组件(Card / ArchivedCard)本来就在 50 共享层。
@@ -9243,6 +9600,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9243
9600
  // 2.9.0:实验性设置单开一页(只放会改变**选材**的开关;见 64-lab-settings.js 开头)。
9244
9601
  // 排在库健康之后:先看「库有没有事」,再决定「要不要动实验性开关」。
9245
9602
  h("button", { type: "button", className: "smem-tab" + (tab === "lab" ? " smem-tab--on" : ""), key: "l", role: "tab", "aria-selected": tab === "lab" ? "true" : "false", onClick: function () { setTab("lab"); } }, t("tab.lab")),
9603
+ // 2.25.0:外部访问(读侧)—— 控制「谁能看见我的记忆」,与选材 / 预算都不是一回事,
9604
+ // 所以单开一页而不是塞进实验性(见 68-external-settings.js 开头)。
9605
+ h("button", { type: "button", className: "smem-tab" + (tab === "ext" ? " smem-tab--on" : ""), key: "x", role: "tab", "aria-selected": tab === "ext" ? "true" : "false", onClick: function () { setTab("ext"); } }, t("tab.external")),
9246
9606
  ]),
9247
9607
  // 四个 tab 共用的一条头部带:我在哪 · 目录状态 · 活动/归档计数 · 体检徽标 · 待重启徽标 · 主操作。
9248
9608
  // 层级形状固定:导航=下划线(.smem-tabs)、筛选=chip、动作=按钮,三种不混用。
@@ -9521,6 +9881,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9521
9881
  ])
9522
9882
  : tab === "lab"
9523
9883
  ? h("div", { className: "smem-stack smem-view", key: "lab" }, [guideCard, h(LabSettingsPanel, { key: "lab-card", ctx: props.ctx })])
9884
+ : tab === "ext"
9885
+ // 2.25.0 外部访问(读侧):白名单 + 逐条勾选 + 只读端点状态。
9886
+ ? h("div", { className: "smem-stack smem-view", key: "ext" }, [h(ExternalAccessPanel, { key: "ext-card", ctx: props.ctx })])
9524
9887
  : h("div", { className: "smem-view", key: "files" }, filesView),
9525
9888
  // 2.8.0:第三方注入的视图(`settings.memory.starmap` 子槽)。没有占用者时是 null,
9526
9889
  // 一个 div 都不出 —— 所以默认安装下界面与 2.7.0 逐像素相同。
package/lib/index.js CHANGED
@@ -26,9 +26,9 @@ import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
26
26
  import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises'
27
27
  import { join } from 'node:path'
28
28
  import { checkUpdate as checkUpdateImpl } from './update.js'
29
- import { applySettingsPatch, autodreamConfigSnapshot, clampInt, MAX_RAW_BYTES, parseExperimentalPatch, parseUiPatch, pendingExperimental, pendingUi, rawName, readReservedFile, readSettingsFileDetailed, readSettingsSnapshot, RESERVED_FILE, SETTINGS_FILE } from './settings.js'
29
+ import { applySettingsPatch, autodreamConfigSnapshot, MAX_RAW_BYTES, parseExperimentalPatch, parseUiPatch, pendingExperimental, pendingUi, rawName, readExternalSettings, readReservedFile, readSettingsFileDetailed, readSettingsSnapshot, RESERVED_FILE, SETTINGS_FILE } from './settings.js'
30
30
  import { createRecallInjector, createSessionInjectState, readRecallDebug } from './recall/index.js'
31
- import { mountAutodream, mountMemoryTools, mountObserve, mountPreCompact, mountWriteGate } from './assembly/index.js'
31
+ import { mountAutodream, mountMemoryTools, mountMirror, mountObserve, mountPreCompact, mountWriteGate } from './assembly/index.js'
32
32
 
33
33
  /**
34
34
  * 读方法的拒绝:**抛**一个带 `.code` 的 Error(写方法返回 `{ok:false, code}` 回执,见 prepareWrite)。
@@ -83,6 +83,12 @@ export class MemoryGateway extends TypertRemoteService {
83
83
  // 2.17.0:压缩前提醒(实验性,默认关;关着时每步只是一次开关读取)。
84
84
  mountPreCompact(ctx, { memoryDir: MEMORY_DIR })
85
85
 
86
+ // 2.25.0:外部访问读侧(白名单导出 + 只读 MCP)。默认关,关着时一行都不跑。
87
+ // `readExternal` 给的是**现读**设置(不进 restartRequired):开关改完立刻起停。
88
+ this.mirror = mountMirror(ctx, { memoryDir: MEMORY_DIR, stateRoot: STATE_ROOT, readExternal: readExternalSettings })
89
+ this.mirror.refresh().catch(() => {})
90
+ if (typeof ctx.effect === 'function') ctx.effect(() => () => this.mirror.dispose())
91
+
86
92
  // 会话级注入状态:一处持有、一处提交(见 lib/recall/state.js 的头注)。
87
93
  const injectState = createSessionInjectState()
88
94
 
@@ -507,9 +513,27 @@ export class MemoryGateway extends TypertRemoteService {
507
513
 
508
514
  /**
509
515
  * 改设置:先全验、后一起写,任何一个非法就整份不落盘。实现在 `lib/settings.js`。
516
+ *
517
+ * 2.25.0:补丁里有 `external`(或任何补丁)成功落盘后,让外部访问挂载层重读一次 ——
518
+ * 开关 / 白名单 / 端口都是**现读现用**的,点完保存就该生效,不该等人重启。
510
519
  */
511
520
  async setSettings(patch) {
512
- return applySettingsPatch(this.ctx, patch)
521
+ const result = await applySettingsPatch(this.ctx, patch)
522
+ if (result?.ok && this.mirror) {
523
+ // 失败不影响保存结果(设置已经落盘了):状态在 externalStatus 里如实显示。
524
+ await this.mirror.refresh().catch(() => {})
525
+ }
526
+ return result
527
+ }
528
+
529
+ /**
530
+ * 外部访问(2.25.0 读侧)的**运行状态**:开关、当前暴露条目数、最近一轮导出的时间与错误、
531
+ * 端点是否在听。设置本身在 `getSettings().external`,这里只答「现在跑成什么样」。
532
+ *
533
+ * 不需要入参 —— 面板拿到就显示,改设置走 `setSettings({ external })`。
534
+ */
535
+ async externalStatus() {
536
+ return this.mirror.status()
513
537
  }
514
538
 
515
539
  /**
@@ -580,6 +604,8 @@ markRemote(MemoryGateway, 'setLocked', 'setLocked')
580
604
  markRemote(MemoryGateway, 'archiveCandidates', 'archiveCandidates')
581
605
  markRemote(MemoryGateway, 'getSettings', 'getSettings')
582
606
  markRemote(MemoryGateway, 'setSettings', 'setSettings')
607
+ // 2.25.0:外部访问读侧的运行状态(第 41 条)。只读、无入参 —— 面板不看账,只看出没出问题。
608
+ markRemote(MemoryGateway, 'externalStatus', 'externalStatus')
583
609
  markRemote(MemoryGateway, 'readRaw', 'readRaw')
584
610
  markRemote(MemoryGateway, 'writeRaw', 'writeRaw')
585
611
  // 1.7.0:注入调试账(只读;开关关着时返回 { enabled: false, records: [] })
@@ -9,6 +9,7 @@ import { readFileSync } from 'node:fs'
9
9
  import { homedir } from 'node:os'
10
10
  import { dirname, join } from 'node:path'
11
11
  import { INDEX_FILE_KEY, SESSION_LOG_KEY, isPlainMdName } from '../shared/md-name.js'
12
+ import { parseLimitValue } from '../shared/int-spec.js'
12
13
 
13
14
  export const MEMORY_DIR = process.env.SAGE_MEM_DIR || join(homedir(), '.sage-mem', 'memory')
14
15
  /**
@@ -77,22 +78,13 @@ export const LIMIT_SPECS = {
77
78
  staleDays: { env: 'SAGE_MEM_STALE_DAYS', dflt: 1, lo: 0, hi: 365 },
78
79
  }
79
80
  /**
80
- * 单项上限的**唯一**校验:非法返回 `undefined`,合法返回收敛到 `[lo, hi]` 的整数。 *
81
- * 与 `envInt()` 同一套语义,区别只在「非法」的出口由调用方决定(环境变量回落默认、
82
- * 持久设置回落环境变量并留诊断)。**必须先 trim**:`Number(' ')` 是 0 而不是 NaN,
83
- * 不 trim 的话纯空格会被当成「用户填了 0」。
81
+ * 单项上限的**唯一**校验:非法返回 `undefined`,合法返回收敛到 `[lo, hi]` 的整数。
82
+ *
83
+ * 2.25.0 起实现在 `lib/shared/int-spec.js`:`mirror/policy.js`(纯逻辑层,不许 import 本模块,
84
+ * 因为本模块在加载时就读盘)也要用同一套语义。这里 import 进来自己用、并原样转出 ——
85
+ * `resolveLimits` 用的仍是同一个函数,判据没有第二份。
84
86
  */
85
- export function parseLimitValue(raw, spec) {
86
- if (typeof raw === 'number') {
87
- return Number.isFinite(raw) ? Math.max(spec.lo, Math.min(spec.hi, Math.round(raw))) : undefined
88
- }
89
- if (typeof raw !== 'string') return undefined
90
- const text = raw.trim()
91
- if (text === '') return undefined
92
- const n = Number(text)
93
- if (!Number.isFinite(n)) return undefined
94
- return Math.max(spec.lo, Math.min(spec.hi, Math.round(n)))
95
- }
87
+ export { parseLimitValue }
96
88
 
97
89
  /**
98
90
  * 五项上限的**单一解析器**:持久设置 > 环境变量 > 内置默认。