@klarkxy/dsh-memory 0.1.2 → 0.1.3

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
@@ -568,58 +568,33 @@ function MemorySettingsPanel({ client, sessionId, locale }) {
568
568
  }),
569
569
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
570
570
  className: "dsh-memory-card",
571
- children: [
572
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t(locale, "闲时梦境", "Idle Dream") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
573
- className: "dsh-memory-meta",
574
- children: t(locale, "闲时自动整理记忆(每天至多一次,自动生效)。", "Auto-organizes memory while idle (at most once a day, applies automatically).")
575
- })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
576
- type: "button",
577
- role: "switch",
578
- className: `dsh-memory-switch${draft.dreamIdleEnabled ? " is-on" : ""}`,
579
- "aria-checked": draft.dreamIdleEnabled,
580
- "aria-label": draft.dreamIdleEnabled ? t(locale, "关闭闲时整理", "Disable idle Dream") : t(locale, "启用闲时整理", "Enable idle Dream"),
581
- disabled: busy,
582
- onClick: () => void action(async () => {
583
- await rpc("settings.update", {
584
- expectedRevision: draft.revision,
585
- settings: {
586
- ...editable(draft),
587
- dreamIdleEnabled: !draft.dreamIdleEnabled
588
- }
589
- });
590
- }),
591
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
592
- className: "dsh-memory-switch-thumb",
593
- "aria-hidden": "true"
594
- })
595
- })] }),
596
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t(locale, "空闲间隔(分钟)", "Idle interval (minutes)"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
597
- type: "number",
598
- min: 1,
599
- max: 180,
600
- step: 1,
601
- disabled: busy,
602
- value: Math.round(draft.idleMs / 6e4),
603
- onChange: (event) => {
604
- settingsDirty.current = true;
605
- setDraft({
606
- ...draft,
607
- idleMs: Math.round(Number(event.target.value) * 6e4)
608
- });
609
- }
610
- })] }),
611
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
612
- type: "button",
613
- disabled: busy,
614
- onClick: () => void action(async () => {
615
- await rpc("settings.update", {
616
- expectedRevision: draft.revision,
617
- settings: editable(draft)
618
- });
619
- }),
620
- children: t(locale, "保存", "Save")
571
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t(locale, "闲时梦境", "Idle Dream") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
572
+ className: "dsh-memory-meta",
573
+ children: t(locale, "闲时自动整理记忆(每天至多一次,自动生效)。", "Auto-organizes memory while idle (at most once a day, applies automatically).")
574
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
575
+ type: "button",
576
+ role: "switch",
577
+ className: `dsh-memory-switch${draft.dreamIdleEnabled ? " is-on" : ""}`,
578
+ "aria-checked": draft.dreamIdleEnabled,
579
+ "aria-label": draft.dreamIdleEnabled ? t(locale, "关闭闲时整理", "Disable idle Dream") : t(locale, "启用闲时整理", "Enable idle Dream"),
580
+ disabled: busy,
581
+ onClick: () => void action(async () => {
582
+ await rpc("settings.update", {
583
+ expectedRevision: draft.revision,
584
+ settings: {
585
+ ...editable(draft),
586
+ dreamIdleEnabled: !draft.dreamIdleEnabled
587
+ }
588
+ });
589
+ }),
590
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
591
+ className: "dsh-memory-switch-thumb",
592
+ "aria-hidden": "true"
621
593
  })
622
- ]
594
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
595
+ className: "dsh-memory-meta",
596
+ children: t(locale, "闲时整理在会话空闲约 15 分钟后尝试。", "Idle organization waits about 15 minutes of inactivity.")
597
+ })]
623
598
  })
624
599
  ]
625
600
  });
@@ -1106,23 +1081,53 @@ function DreamPanel(props) {
1106
1081
  ]
1107
1082
  });
1108
1083
  }
1109
- function MemorySettings({ client, props }) {
1084
+ function readSelfImprovementReview(host) {
1085
+ if (!host || typeof host !== "object") return void 0;
1086
+ const context = host;
1087
+ if (typeof context.get !== "function") return void 0;
1088
+ let row;
1089
+ try {
1090
+ row = context.get("dshSelfImprovementReview");
1091
+ } catch {
1092
+ return;
1093
+ }
1094
+ if (!row || typeof row !== "object") return void 0;
1095
+ const render = row.render;
1096
+ if (typeof render !== "function") return void 0;
1097
+ return { render };
1098
+ }
1099
+ function MemorySettings({ client, host, props }) {
1110
1100
  const seat = useNativeSeat(client, props);
1101
+ const review = readSelfImprovementReview(host);
1111
1102
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1112
1103
  className: "dsh-memory-settings-root",
1113
1104
  "data-testid": "memory-settings-root",
1114
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemorySettingsPanel, {
1115
- client,
1116
- sessionId: seat.sessionId,
1117
- locale: seat.locale
1118
- }, `settings:${memoryPanelKey(seat.sessionId, seat.locale)}`), seat.sessionId && !seat.hidden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoryChatPanel, {
1119
- client,
1120
- sessionId: seat.sessionId,
1121
- locale: seat.locale
1122
- }, `manage:${memoryPanelKey(seat.sessionId, seat.locale)}`) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1123
- className: "dsh-memory-meta",
1124
- children: t(seat.locale, "选择一个会话后可以管理该会话的记忆。", "Select a session to manage its memory.")
1125
- })]
1105
+ children: [
1106
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemorySettingsPanel, {
1107
+ client,
1108
+ sessionId: seat.sessionId,
1109
+ locale: seat.locale
1110
+ }, `settings:${memoryPanelKey(seat.sessionId, seat.locale)}`),
1111
+ review && seat.sessionId && !seat.hidden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1112
+ className: "dsh-memory-si",
1113
+ "data-testid": "self-improvement-entry",
1114
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t(seat.locale, "自我改进", "Self-improvement") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1115
+ className: "dsh-memory-si-body",
1116
+ children: review.render({
1117
+ sessionId: seat.sessionId,
1118
+ locale: seat.locale
1119
+ })
1120
+ })]
1121
+ }) : null,
1122
+ seat.sessionId && !seat.hidden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoryChatPanel, {
1123
+ client,
1124
+ sessionId: seat.sessionId,
1125
+ locale: seat.locale
1126
+ }, `manage:${memoryPanelKey(seat.sessionId, seat.locale)}`) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1127
+ className: "dsh-memory-meta",
1128
+ children: t(seat.locale, "选择一个会话后可以管理该会话的记忆。", "Select a session to manage its memory.")
1129
+ })
1130
+ ]
1126
1131
  });
1127
1132
  }
1128
1133
  const styles = `
@@ -1132,7 +1137,7 @@ const styles = `
1132
1137
  .dsh-memory-settings p,.dsh-memory-chat p{margin:0;line-height:1.5}
1133
1138
  .dsh-memory-meta,.dsh-memory-chat small{font-size:var(--font-size-1,13px);color:var(--gray-11,inherit)}
1134
1139
  .dsh-memory-error{color:var(--red-11,#b42318)}
1135
- .dsh-memory-card,.dsh-memory-dream,.dsh-memory-add{display:grid;gap:10px;padding:14px 16px;border:1px solid var(--gray-6,color-mix(in srgb,currentColor 15%,transparent));border-radius:12px}
1140
+ .dsh-memory-card,.dsh-memory-dream,.dsh-memory-add,.dsh-memory-si{display:grid;gap:10px;padding:14px 16px;border:1px solid var(--gray-6,color-mix(in srgb,currentColor 15%,transparent));border-radius:12px}
1136
1141
  .dsh-memory-card header,.dsh-memory-chat-body header{display:flex;justify-content:space-between;gap:12px;align-items:center}
1137
1142
  .dsh-memory-card h3,.dsh-memory-add h4,.dsh-memory-dream h4{margin:0;font-size:var(--font-size-3,16px);font-weight:600}
1138
1143
  .dsh-memory-settings input,.dsh-memory-chat input,.dsh-memory-chat textarea,.dsh-memory-chat select{box-sizing:border-box;width:100%;min-width:0;padding:8px 10px;border:1px solid var(--gray-6,color-mix(in srgb,currentColor 22%,transparent));border-radius:8px;background:var(--color-surface,transparent);color:inherit;font:inherit;transition:border-color 150ms ease,box-shadow 150ms ease}
@@ -1152,7 +1157,8 @@ const styles = `
1152
1157
  .dsh-memory-row-actions{display:flex;flex-wrap:wrap;gap:8px}
1153
1158
  .dsh-memory-check{display:flex;gap:8px;align-items:center}
1154
1159
  .dsh-memory-check input{width:auto}
1155
- .dsh-memory-chat>summary{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:baseline;cursor:pointer;min-height:34px;list-style:revert}
1160
+ .dsh-memory-chat>summary,.dsh-memory-si>summary{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:baseline;cursor:pointer;min-height:34px;list-style:revert}
1161
+ .dsh-memory-si-body{margin-top:8px}
1156
1162
  @media(prefers-reduced-motion:reduce){.dsh-memory-switch-thumb{transition:none}.dsh-memory-settings button:not([role="switch"]),.dsh-memory-chat button:not([role="switch"]),.dsh-memory-settings input,.dsh-memory-chat input,.dsh-memory-chat textarea,.dsh-memory-chat select{transition:none}}
1157
1163
  `;
1158
1164
  function apply(ctx) {
@@ -1172,6 +1178,7 @@ function apply(ctx) {
1172
1178
  label: "记忆"
1173
1179
  }, (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemorySettings, {
1174
1180
  client,
1181
+ host: ctx,
1175
1182
  props
1176
1183
  }))), "dsh-memory.settings");
1177
1184
  }
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CHAT_EVENTS_SLOT, INJECT_KINDS, MAX_PROJECT_ID_CHARS, MEMORY_ACTIVATE_ID, MEMORY_DREAM_PURPOSE, MEMORY_INJECTION_SECTION, MEMORY_PLUGIN, MEMORY_RPC_CHANNEL, MEMORY_SOURCE_KIND, RECALL_EXCLUDED_STATUSES, cloneRecord, defaultSettings, fail as fail$1, ok, parseSessionId, projectIdFromCwd, scopeKey, scopesEqual, sessionCwd } from "./contracts.js";
1
+ import { CHAT_EVENTS_SLOT, DEFAULT_IDLE_MS, INJECT_KINDS, MAX_PROJECT_ID_CHARS, MEMORY_ACTIVATE_ID, MEMORY_DREAM_PURPOSE, MEMORY_INJECTION_SECTION, MEMORY_PLUGIN, MEMORY_RPC_CHANNEL, MEMORY_SOURCE_KIND, RECALL_EXCLUDED_STATUSES, cloneRecord, defaultSettings, fail as fail$1, ok, parseSessionId, projectIdFromCwd, scopeKey, scopesEqual, sessionCwd } from "./contracts.js";
2
2
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
3
3
  import { registerHostRpc } from "@klarkxy/dsh-ai-services/host-rpc";
4
4
  import { defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
@@ -224,10 +224,13 @@ const memoryDomain = defineDomain({
224
224
  tables: { state: domainTable(memoryStateSchema) }
225
225
  });
226
226
  function storedSettings(value) {
227
- return value ? {
228
- ...defaultSettings(),
229
- ...value
230
- } : defaultSettings();
227
+ return {
228
+ ...value ? {
229
+ ...defaultSettings(),
230
+ ...value
231
+ } : defaultSettings(),
232
+ idleMs: DEFAULT_IDLE_MS
233
+ };
231
234
  }
232
235
  //#endregion
233
236
  //#region src/rpc.ts
@@ -724,6 +727,10 @@ var MemoryRuntime = class {
724
727
  constructor(options) {
725
728
  this.options = options;
726
729
  this.live = cloneState(options.store.load());
730
+ this.live.settings = {
731
+ ...this.live.settings,
732
+ idleMs: DEFAULT_IDLE_MS
733
+ };
727
734
  this.now = options.now ?? Date.now;
728
735
  this.customId = options.id;
729
736
  this.syncAi();
@@ -763,6 +770,7 @@ var MemoryRuntime = class {
763
770
  const proposed = this.snapshot();
764
771
  proposed.settings = {
765
772
  ...next,
773
+ idleMs: DEFAULT_IDLE_MS,
766
774
  revision: expectedRevision + 1
767
775
  };
768
776
  const disableInject = this.live.settings.injectEnabled && !proposed.settings.injectEnabled;