dsh-plugin-memory 0.12.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.13.0] - 2026-10-30
6
+
7
+ ### Added(兼容声明 + 立即回顾 + 可访问性 + 工程化)
8
+
9
+ - **`engines.dsh` 兼容声明**:`package.json` 声明 `engines.dsh: "^0.2.1-rc.5"`——宿主引擎闸门用 semver(`includePrerelease: true`)校验,注意 `^0.2.1` / `>=0.2.0` 匹配不上 prerelease,必须写 `^0.2.1-rc.5`;旧宿主会被闸门拦住,而不是让插件半残运行。运行期缺失投影仍优雅降级(不发回顾/不抢发言权,绝不崩)。
10
+ - **「立即回顾」按钮 + 控制路由**:新增 `POST /api/memory/control`,action `growth-now` → 立即触发一次成长回顾。语义:尊重发言权仲裁;本周没有新内容就不发;**不受 `recallEnabled` 关闭影响**(显式手动操作),但要求插件启用、agent idle、成长回顾本身开启。响应 `{ ok, delivered, reason }`(`no-content` / `deferred` / `disabled` / `busy` / `growth-disabled` / `no-session` 等);非 POST → 405,未知 action / 坏 JSON → 400。面板按钮带「回顾中 / 已发送 / 另一插件正在说话 / 没有新内容 / 已关闭 / 失败」六态反馈。
11
+ - **面板可访问性**:按钮与表单补 `aria-label`,状态用 `role="status"`、错误用 `role="alert"`,键盘焦点加 `:focus-visible` 焦点环。
12
+ - **工程化**:`.github/workflows/ci.yml`(跑 `node --test` + `--self-test`)、Issue / PR 模板、`CONTRIBUTING.md`、`SECURITY.md`、`docs/PROACTIVE-PROTOCOL.md`(跨插件共享发言协议 v1 的公开说明;`docs/**` 在 `files` 内,因此该文档随 npm 包发布)。
13
+
14
+ ### Changed
15
+
16
+ - 面板控制逻辑把 `recallEnabled` 与「手动立即回顾」解耦:关闭自动追忆不再等于禁用用户显式发起的回顾。
17
+
18
+ ### Tests
19
+
20
+ - 新增 `test/control-route.test.mjs`、`test/growth-now.test.mjs`;`client-i18n` 补按钮文案与 a11y 契约。
21
+ - 全量单测 **255/255 通过**(0.12.0 基线 242,新增 13 条);`node scripts/memory.mjs --self-test` PASS。
22
+
5
23
  ## [0.12.0] - 2026-10-30
6
24
 
7
25
  ### Added(A 仲裁 + B 语气漂移 + C 表达层 + D 每周成长回顾)
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://github.com/LittleBlackTong/dsh-plugin-memory"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-LittleBlackTong%2Fdsh--plugin--memory-blue?logo=github"></a>
7
+ <a href="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml/badge.svg"></a>
7
8
  <a href="https://www.npmjs.com/package/dsh-plugin-memory"><img alt="npm" src="https://img.shields.io/npm/v/dsh-plugin-memory?logo=npm"></a>
8
9
  <img alt="license" src="https://img.shields.io/badge/license-MIT-blue">
9
10
  <img alt="node" src="https://img.shields.io/badge/node-%3E%3D18-green">
@@ -97,7 +98,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
97
98
 
98
99
  Restart the profile (restart the DSH Desktop app) to take effect.
99
100
 
100
- > 📌 **Version requirement: DSH session format v4 (official DeepSeek Harness 0.1.7+)**
101
+ > 📌 **Version requirement: DSH session format v4 + official DeepSeek Harness 0.2.1-rc.5 series** (0.13.x declares `engines.dsh`; older hosts are refused by the gate — see [Compatibility](#compatibility))
101
102
  >
102
103
  > Injected messages use the producer-owned source kind `plugin:memory`. v4's native admission explicitly rejects the v3-era `{ kind: 'plugin', plugin: 'memory' }` wrapper with
103
104
  > `format v4 message requires a producer-owned source kind` (the error is wrapped as `code: "UNKNOWN"`, so it surfaces in the UI as `... source kind UNKNOWN` — `UNKNOWN` is the error code, not a kind value).
@@ -145,10 +146,16 @@ The section is registered as **"Memory"** in the English UI and **「记忆」**
145
146
 
146
147
  Fifteen settings are editable in the "Memory" section of the DSH settings page and take effect **immediately**: `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` / `proactiveCooldownSeconds` / `toneGuideEnabled` / `toneIntensity` / `growthRecapEnabled` / `growthRecapIntervalDays` — boot injection, the two polite gates, skill registration, proactive recall (including its random interval and cap), speech-right arbitration, the tone section and the weekly growth recap all follow the change at once; switching the store directory scaffolds the new one automatically (when `scaffold: true`). The remaining keys (`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`) only apply at the composition layer and need a restart.
147
148
 
149
+ A **Review now** button sits beside them: it is a **control, not a setting** — it asks the plugin to send one growth recap immediately. It still respects the speech floor (it backs off if the other plugin is speaking), sends nothing when this week has no new material, works even while `recallEnabled` is off, and reports the outcome in the panel (sending / sent / deferred / no content / disabled / failed).
150
+
148
151
  ### Language
149
152
 
150
153
  The settings panel and its sidebar label follow DSH's own language setting (**Settings → General → Language**) and switch live — no restart: Chinese shows 「记忆」, English shows "Memory". Panel copy is registered as the `memory` locale namespace through `ctx.locale`, so the renderer re-renders the whole panel (form, health dashboard, graph card) in the active language and injects a `t(key)` seat into the section. The sidebar icon claim key is derived from that same label, so a language switch re-claims the right row. The dashboard's health-check labels **and details** are rebuilt client-side from locale-neutral `data` the insights route ships (`lib/insights.js` keeps the Chinese `label`/`detail` strings for the CLI); an older host payload without `data` falls back to those Chinese strings. User content (page titles, `log.md` headlines) and the CLI's own Chinese output are content, not UI copy, and stay as-is.
151
154
 
155
+ ### Compatibility
156
+
157
+ `package.json` declares `engines.dsh: "^0.2.1-rc.5"`, and the host enforces it with `semver.satisfies(..., { includePrerelease: true })` — the prerelease detail matters: `^0.2.1` or `>=0.2.0` do **not** match `0.2.1-rc.5`, so only the explicit prerelease range works (it also covers the eventual 0.2.1 stable). Two host services became load-bearing on the way here: the `locale` service (0.11+: the panel registers its dictionaries through it) and session projections (0.12+: speech arbitration and the growth recap read them). On an older host the gate refuses to load the plugin instead of letting it run half-broken; at runtime a missing projection still degrades gracefully — no recap, no speech-floor claim, never a crash.
158
+
152
159
  ### Boot budget allocation (why the index is not truncated first)
153
160
 
154
161
  `bootMaxChars` is a total budget, allocated per file rather than split evenly:
@@ -244,6 +251,8 @@ node scripts/memory.mjs --self-test # smoke test (no dependencies to install)
244
251
 
245
252
  Zero build: `lib/` is runtime code as-is, and `lib/types/index.d.ts` serves TypeScript consumers. `boot.js` / `scaffold.js` depend only on `node:*` built-ins and can be reused standalone.
246
253
 
254
+ The test suite (`node --test`) currently holds **255 tests**, and CI (`.github/workflows/ci.yml`) runs it together with `node scripts/memory.mjs --self-test`. Contribution and security policies live in [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md); the cross-plugin speech-floor protocol is documented in [docs/PROACTIVE-PROTOCOL.md](docs/PROACTIVE-PROTOCOL.md).
255
+
247
256
  ## Roadmap
248
257
 
249
258
  - [ ] TypeScript rewrite (full types and a build step)
package/README.zh.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://github.com/LittleBlackTong/dsh-plugin-memory"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-LittleBlackTong%2Fdsh--plugin--memory-blue?logo=github"></a>
7
+ <a href="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml/badge.svg"></a>
7
8
  <a href="https://www.npmjs.com/package/dsh-plugin-memory"><img alt="npm" src="https://img.shields.io/npm/v/dsh-plugin-memory?logo=npm"></a>
8
9
  <img alt="license" src="https://img.shields.io/badge/license-MIT-blue">
9
10
  <img alt="node" src="https://img.shields.io/badge/node-%3E%3D18-green">
@@ -97,7 +98,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
97
98
 
98
99
  重启 profile(DSH Desktop 重启应用)后生效。
99
100
 
100
- > 📌 **版本要求:DSH session format v4(官方 DeepSeek Harness 0.1.7+)**
101
+ > 📌 **版本要求:DSH session format v4 + 官方 DeepSeek Harness 0.2.1-rc.5 系列**(0.13.x 已声明 `engines.dsh`;旧宿主会被闸门拒绝,见[兼容性](#兼容性))
101
102
  >
102
103
  > 注入消息的 source 使用 producer-owned kind `plugin:memory`。v4 的原生准入明确拒绝 v3 时代的
103
104
  > `{ kind: 'plugin', plugin: 'memory' }` wrapper,报
@@ -151,10 +152,16 @@ dsh plugin --profile <profile> add dsh-plugin-memory
151
152
 
152
153
  `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` / `proactiveCooldownSeconds` / `toneGuideEnabled` / `toneIntensity` / `growthRecapEnabled` / `growthRecapIntervalDays` 十五项在 DSH 设置页的「记忆 / Memory」区块中可改(跟随语言),**即时生效**:boot 注入、两道礼貌闸门、技能注册、主动追忆(含随机间隔与次数)、发言权仲裁、语气段与每周成长回顾随修改立即生效;记忆目录切换时自动为新目录初始化脚手架(`scaffold: true` 时)。其余键(`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`)只在 composition 配置层生效,改完需重启。
153
154
 
155
+ 旁边还有一个 **「立即回顾」按钮**:它是**控制动作,不是配置项**——让插件立刻发一次成长回顾。仍尊重发言权仲裁(别的插件在说话就让位)、本周没有新内容就不发、即使 `recallEnabled` 关闭也能用,并在面板里给出结果(回顾中 / 已发送 / 让位 / 没有新内容 / 已关闭 / 失败)。
156
+
154
157
  ### 语言 / Language
155
158
 
156
159
  设置面板与侧栏 label 跟随 DSH 自己的语言设置(**设置 → 通用设置 → 语言**),切换即时生效、无需重启:中文显示「记忆」,英文显示 "Memory"。面板文案通过 `ctx.locale` 注册在 `memory` 命名空间,renderer 会给区块注入 `t(key)` 座位,于是表单、健康看板、图谱卡片整体重渲染为当前语言;侧栏图标的认领键取自同一个 label 解析函数,语言切换后自动重新认领正确的那一行。健康看板的四项体检 **label 与 detail** 由 insights 路由新增的结构化 `data` 在客户端按语言重建(`lib/insights.js` 仍保留中文 `label`/`detail` 供 CLI 使用);旧版本宿主 payload 没有 `data` 时回退中文串。用户内容(页面标题、`log.md` 动态)与 CLI 自身的中文输出属于内容而非界面文案,不在翻译范围内。
157
160
 
161
+ ### 兼容性
162
+
163
+ `package.json` 声明 `engines.dsh: "^0.2.1-rc.5"`,宿主用 `semver.satisfies(..., { includePrerelease: true })` 强制校验——prerelease 细节很关键:`^0.2.1` / `>=0.2.0` **匹配不上** `0.2.1-rc.5`,只有显式写 prerelease range 才认(它同时覆盖将来的 0.2.1 正式版)。一路走来有两个宿主服务变成「承重」的:`locale` 服务(0.11+:面板通过它注册语言包)与会话投影(0.12+:发言权仲裁与成长回顾要读)。旧宿主会被闸门直接拒绝加载,而不是让插件半残运行;运行期缺投影则优雅降级——不发回顾、不抢发言权,绝不崩。
164
+
158
165
  ### boot 预算分配(为什么 index 不会先被截掉)
159
166
 
160
167
  `bootMaxChars` 是总预算,按文件分配而不是简单平摊:
@@ -250,6 +257,8 @@ node scripts/memory.mjs --self-test # 冒烟测试(无需安装依赖)
250
257
 
251
258
  零构建:`lib/` 直接是运行时代码,`lib/types/index.d.ts` 供 TS 消费方使用。`boot.js` / `scaffold.js` 只依赖 `node:*` 内置模块,可独立复用。
252
259
 
260
+ 测试用 `node --test`,当前共 **255 个用例**;CI(`.github/workflows/ci.yml`)会连同 `node scripts/memory.mjs --self-test` 一起跑。贡献与安全策略见 [CONTRIBUTING.md](CONTRIBUTING.md)、[SECURITY.md](SECURITY.md);跨插件发言协议见 [docs/PROACTIVE-PROTOCOL.md](docs/PROACTIVE-PROTOCOL.md)。
261
+
253
262
  ## 路线图
254
263
 
255
264
  - [ ] TypeScript 重写(带完整类型与构建步骤)
@@ -0,0 +1,81 @@
1
+ # Proactive-cooldown protocol (v1)
2
+
3
+ Two DSH plugins may independently decide, on their own timers, that the agent
4
+ should say something unprompted:
5
+
6
+ - **dsh-plugin-memory** — recall nudges, digest reminders, weekly growth recaps;
7
+ - **dsh-plugin-heartbeat** — L1 reports, L2 questions, L4 escalations.
8
+
9
+ Talking over each other in the same quiet window looks like a split
10
+ personality, so both plugins honour one shared, advisory **speech floor**. The
11
+ protocol deliberately lives in a **plain JSON file**, not an import: each plugin
12
+ ships its own tiny implementation, so either one can be installed, upgraded or
13
+ removed without touching the other (`zero cross-plugin imports`).
14
+
15
+ ## File
16
+
17
+ ```
18
+ ${DSH_HOME:-~/.dsh}/proactive-cooldown.json
19
+ ```
20
+
21
+ ```json
22
+ { "version": 1, "speaker": "memory" | "heartbeat", "at": 1760000000000 }
23
+ ```
24
+
25
+ - `at` is an epoch-millisecond timestamp of the last claim.
26
+ - Writes are atomic (`temp file + rename`): a reader never sees a partial
27
+ document.
28
+ - A missing, unreadable or malformed file means **"no lock"** — a broken
29
+ cooldown must never silence a plugin forever.
30
+
31
+ ## Claim algorithm
32
+
33
+ Before injecting a proactive followup, a plugin calls:
34
+
35
+ ```js
36
+ claimProactiveLock({ path, speaker, cooldownSeconds, now })
37
+ ```
38
+
39
+ 1. Read the file. If it is missing/corrupt → no lock.
40
+ 2. If `at > now - cooldownSeconds * 1000` **and** `speaker !== self`:
41
+ - return `{ ok: false, deferredBy: <other speaker> }`;
42
+ - the caller yields **for this attempt only** (do not consume its own
43
+ cadence or signal set — retry on a later trigger);
44
+ - heartbeat records the yield as `L0 · proactive-cooldown` and re-arms.
45
+ 3. Otherwise write `{ version: 1, speaker: self, at: now }` (atomic) and
46
+ return `{ ok: true }`.
47
+
48
+ `cooldownSeconds <= 0` disables arbitration: claim returns `{ ok: true }`
49
+ without writing anything.
50
+
51
+ ## Rules
52
+
53
+ - The lock is **advisory**: a failed write (read-only home, EACCES, …) must
54
+ degrade to "go ahead" — politeness, not a hard dependency.
55
+ - **Manual user actions bypass the floor** (e.g. heartbeat's *Beat now*), since
56
+ the user explicitly asked for speech.
57
+ - A speaker may re-claim/refresh its **own** lock (same `speaker`) at any time.
58
+ - Default cooldown: **180 seconds** (`proactiveCooldownSeconds` in both plugins;
59
+ `0` turns arbitration off).
60
+ - Old files without `version`/`speaker` are treated as no lock; only
61
+ `{version:1, speaker, at}` is written by both implementations.
62
+
63
+ ## Compatibility matrix
64
+
65
+ | Plugin | 0.12.x | 0.13.x | Notes |
66
+ | --- | --- | --- | --- |
67
+ | dsh-plugin-memory | v1 | v1 | since 0.12.0 |
68
+ | dsh-plugin-heartbeat | v1 | v1 | since 0.7.0 |
69
+
70
+ A third-party plugin is welcome to participate: implement the same claim
71
+ algorithm, use a unique `speaker` value, and read the same file. Unknown
72
+ speakers are treated as "someone else holds the floor" until the cooldown
73
+ expires.
74
+
75
+ ## Tests
76
+
77
+ Both repositories test the protocol independently and cross-check each other's
78
+ implementation (`test/proactive-lock.test.mjs` in
79
+ [dsh-plugin-memory](https://github.com/LittleBlackTong/dsh-plugin-memory) and
80
+ [dsh-plugin-heartbeat](https://github.com/LittleBlackTong/dsh-plugin-heartbeat))
81
+ with real files and real timestamps.
package/lib/client.js CHANGED
@@ -18,6 +18,7 @@ window.__ModuleLoader__.load({
18
18
 
19
19
  const React = react
20
20
  const CONFIG_URL = '/api/memory/config'
21
+ const CONTROL_URL = '/api/memory/control'
21
22
  const INSIGHTS_URL = '/api/memory/insights'
22
23
  const GRAPH_URL = '/api/memory/graph'
23
24
  /** Poll while the panel is open, so memory edits show up without a reload. */
@@ -69,6 +70,14 @@ window.__ModuleLoader__.load({
69
70
  toneOff: 'off(纯工程口吻)',
70
71
  growthRecap: '每周成长回顾',
71
72
  growthRecapHint: '每周在追忆通道里说一次「这周我记住了什么」(第一人称,最多五句,可随时关闭)',
73
+ growthNow: '立即回顾',
74
+ growthNowHint: '手动触发一次成长回顾(尊重发言权仲裁;没有新内容时不发)',
75
+ growthNowRunning: '回顾中…',
76
+ growthNowOk: '已发送成长回顾',
77
+ growthNowDeferred: '另一插件正在说话,稍后再试',
78
+ growthNowEmpty: '这一周没有可回顾的新内容',
79
+ growthNowDisabled: '成长回顾已关闭',
80
+ growthNowFailed: '回顾失败:',
72
81
  minutesPlaceholder: '30',
73
82
  maxMinutesPlaceholder: '240',
74
83
  maxPerSessionPlaceholder: '3',
@@ -166,6 +175,14 @@ window.__ModuleLoader__.load({
166
175
  toneOff: 'off (pure engineering voice)',
167
176
  growthRecap: 'Weekly growth recap',
168
177
  growthRecapHint: 'Once a week, on the recall channel, say what I kept this week (first person, at most five sentences; can be turned off)',
178
+ growthNow: 'Review now',
179
+ growthNowHint: 'Send one growth recap right away (still respects the speech floor; no new material = no message)',
180
+ growthNowRunning: 'Reviewing…',
181
+ growthNowOk: 'Growth recap sent',
182
+ growthNowDeferred: 'Another plugin holds the floor; try again later',
183
+ growthNowEmpty: 'Nothing new to recap this week',
184
+ growthNowDisabled: 'Weekly recap is off',
185
+ growthNowFailed: 'Recap failed: ',
169
186
  minutesPlaceholder: '30',
170
187
  maxMinutesPlaceholder: '240',
171
188
  maxPerSessionPlaceholder: '3',
@@ -359,11 +376,12 @@ window.__ModuleLoader__.load({
359
376
  color: 'var(--dsw-alias-label-primary, inherit)',
360
377
  }
361
378
 
362
- function Toggle({ checked, disabled, onChange }) {
379
+ function Toggle({ checked, disabled, onChange, label }) {
363
380
  return React.createElement('button', {
364
381
  type: 'button',
365
382
  role: 'switch',
366
383
  'aria-checked': checked,
384
+ 'aria-label': label,
367
385
  disabled,
368
386
  onClick: () => onChange(!checked),
369
387
  style: {
@@ -394,7 +412,7 @@ window.__ModuleLoader__.load({
394
412
 
395
413
  function ErrorText({ message }) {
396
414
  const t = useT()
397
- return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
415
+ return React.createElement('div', { role: 'alert', style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
398
416
  t('loadFailed'), message)
399
417
  }
400
418
 
@@ -593,7 +611,7 @@ window.__ModuleLoader__.load({
593
611
  }
594
612
 
595
613
  /** 目录输入:草稿态编辑,blur / Enter 才写回,避免每次按键触发 Host 重排。 */
596
- function DirInput({ value, disabled, onCommit }) {
614
+ function DirInput({ value, disabled, onCommit, label }) {
597
615
  const t = useT()
598
616
  const [draft, setDraft] = React.useState(undefined)
599
617
  const shown = draft !== undefined ? draft : (value ?? '')
@@ -606,6 +624,7 @@ window.__ModuleLoader__.load({
606
624
  return React.createElement('input', {
607
625
  type: 'text',
608
626
  placeholder: t('dirPlaceholder'),
627
+ 'aria-label': label,
609
628
  disabled,
610
629
  value: shown,
611
630
  onChange: (event) => setDraft(event.target.value),
@@ -619,7 +638,7 @@ window.__ModuleLoader__.load({
619
638
  }
620
639
 
621
640
  /** 数字输入:草稿态编辑,blur / Enter 才写回(分钟/次数)。 */
622
- function NumberInput({ value, disabled, onCommit, placeholder }) {
641
+ function NumberInput({ value, disabled, onCommit, placeholder, label }) {
623
642
  const [draft, setDraft] = React.useState(undefined)
624
643
  const shown = draft !== undefined ? draft : (value ?? '')
625
644
  const commit = () => {
@@ -631,6 +650,7 @@ window.__ModuleLoader__.load({
631
650
  return React.createElement('input', {
632
651
  type: 'number',
633
652
  placeholder,
653
+ 'aria-label': label,
634
654
  disabled,
635
655
  value: shown,
636
656
  onChange: (event) => setDraft(event.target.value),
@@ -644,8 +664,9 @@ window.__ModuleLoader__.load({
644
664
  }
645
665
 
646
666
  /** 下拉选择:语气强度这类枚举配置,改动立即写回。 */
647
- function SelectInput({ value, disabled, options, onChange }) {
667
+ function SelectInput({ value, disabled, options, onChange, label }) {
648
668
  return React.createElement('select', {
669
+ 'aria-label': label,
649
670
  disabled,
650
671
  value: value ?? '',
651
672
  onChange: (event) => onChange(event.target.value),
@@ -661,6 +682,43 @@ window.__ModuleLoader__.load({
661
682
  const [status, setStatus] = React.useState('loading')
662
683
  const [error, setError] = React.useState(undefined)
663
684
  const [saving, setSaving] = React.useState(false)
685
+ const [growthBusy, setGrowthBusy] = React.useState(false)
686
+ const [growthNotice, setGrowthNotice] = React.useState(undefined)
687
+
688
+ // Visible keyboard focus for every control in this panel (inline styles
689
+ // cannot express :focus-visible). The tag is removed with the panel.
690
+ React.useEffect(() => {
691
+ if (typeof document === 'undefined') return undefined
692
+ const tag = document.createElement('style')
693
+ tag.setAttribute('data-dsh-memory-focus', '')
694
+ tag.textContent = 'section [role="switch"]:focus-visible, section input:focus-visible, section select:focus-visible, section button:focus-visible, section a:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #4c8bf5); outline-offset: 2px; }'
695
+ document.head.appendChild(tag)
696
+ return () => tag.remove()
697
+ }, [])
698
+
699
+ const reviewNow = () => {
700
+ setGrowthBusy(true)
701
+ setGrowthNotice(undefined)
702
+ fetch(CONTROL_URL, {
703
+ method: 'POST',
704
+ headers: { 'content-type': 'application/json' },
705
+ body: JSON.stringify({ action: 'growth-now' }),
706
+ })
707
+ .then(async (response) => {
708
+ const body = await response.json().catch(() => ({}))
709
+ if (!response.ok) throw new Error(body.error ?? `POST ${response.status}`)
710
+ if (body.delivered === true) { setGrowthNotice(t('growthNowOk')); return }
711
+ const reason = body.reason
712
+ if (reason === 'deferred') { setGrowthNotice(t('growthNowDeferred')); return }
713
+ if (reason === 'empty') { setGrowthNotice(t('growthNowEmpty')); return }
714
+ if (reason === 'growth-disabled') { setGrowthNotice(t('growthNowDisabled')); return }
715
+ setGrowthNotice(t('growthNowEmpty'))
716
+ })
717
+ .catch((err) => {
718
+ setGrowthNotice(`${t('growthNowFailed')}${err instanceof Error ? err.message : String(err)}`)
719
+ })
720
+ .finally(() => setGrowthBusy(false))
721
+ }
664
722
 
665
723
  React.useEffect(() => {
666
724
  let alive = true
@@ -719,6 +777,7 @@ window.__ModuleLoader__.load({
719
777
  React.createElement('div', { style: subStyle }, t('enabledHint')),
720
778
  ),
721
779
  React.createElement(Toggle, {
780
+ label: t('enabled'),
722
781
  checked: value.enabled !== false,
723
782
  disabled,
724
783
  onChange: (next) => apply({ enabled: next }),
@@ -730,6 +789,7 @@ window.__ModuleLoader__.load({
730
789
  React.createElement('div', { style: subStyle }, t('memoryDirHint')),
731
790
  ),
732
791
  React.createElement(DirInput, {
792
+ label: t('memoryDir'),
733
793
  value: value.memoryDir,
734
794
  disabled,
735
795
  onCommit: (next) => apply({ memoryDir: next }),
@@ -741,6 +801,7 @@ window.__ModuleLoader__.load({
741
801
  React.createElement('div', { style: subStyle }, t('autoInjectHint')),
742
802
  ),
743
803
  React.createElement(Toggle, {
804
+ label: t('autoInject'),
744
805
  checked: value.autoInject !== false,
745
806
  disabled,
746
807
  onChange: (next) => apply({ autoInject: next }),
@@ -752,6 +813,7 @@ window.__ModuleLoader__.load({
752
813
  React.createElement('div', { style: subStyle }, t('deferUntilUserSpeaksHint')),
753
814
  ),
754
815
  React.createElement(Toggle, {
816
+ label: t('deferUntilUserSpeaks'),
755
817
  checked: value.deferUntilUserSpeaks !== false,
756
818
  disabled,
757
819
  onChange: (next) => apply({ deferUntilUserSpeaks: next }),
@@ -763,6 +825,7 @@ window.__ModuleLoader__.load({
763
825
  React.createElement('div', { style: subStyle }, t('activeSessionOnlyHint')),
764
826
  ),
765
827
  React.createElement(Toggle, {
828
+ label: t('activeSessionOnly'),
766
829
  checked: value.activeSessionOnly !== false,
767
830
  disabled,
768
831
  onChange: (next) => apply({ activeSessionOnly: next }),
@@ -774,6 +837,7 @@ window.__ModuleLoader__.load({
774
837
  React.createElement('div', { style: subStyle }, t('registerSkillHint')),
775
838
  ),
776
839
  React.createElement(Toggle, {
840
+ label: t('registerSkill'),
777
841
  checked: value.registerSkill !== false,
778
842
  disabled,
779
843
  onChange: (next) => apply({ registerSkill: next }),
@@ -785,6 +849,7 @@ window.__ModuleLoader__.load({
785
849
  React.createElement('div', { style: subStyle }, t('recallHint')),
786
850
  ),
787
851
  React.createElement(Toggle, {
852
+ label: t('recall'),
788
853
  checked: value.recallEnabled !== false,
789
854
  disabled,
790
855
  onChange: (next) => apply({ recallEnabled: next }),
@@ -817,6 +882,7 @@ window.__ModuleLoader__.load({
817
882
  React.createElement('div', { style: subStyle }, t('recallMaxPerSessionHint')),
818
883
  ),
819
884
  React.createElement(NumberInput, {
885
+ label: t('recallMaxPerSession'),
820
886
  value: value.recallMaxPerSession,
821
887
  disabled,
822
888
  placeholder: t('maxPerSessionPlaceholder'),
@@ -829,6 +895,7 @@ window.__ModuleLoader__.load({
829
895
  React.createElement('div', { style: subStyle }, t('toneGuideHint')),
830
896
  ),
831
897
  React.createElement(Toggle, {
898
+ label: t('toneGuide'),
832
899
  checked: value.toneGuideEnabled !== false,
833
900
  disabled,
834
901
  onChange: (next) => apply({ toneGuideEnabled: next }),
@@ -856,12 +923,42 @@ window.__ModuleLoader__.load({
856
923
  React.createElement('div', { style: subStyle }, t('growthRecapHint')),
857
924
  ),
858
925
  React.createElement(Toggle, {
926
+ label: t('growthRecap'),
859
927
  checked: value.growthRecapEnabled !== false,
860
928
  disabled,
861
929
  onChange: (next) => apply({ growthRecapEnabled: next }),
862
930
  }),
863
931
  ),
864
- error !== undefined ? React.createElement('div', { style: errorStyle }, t('saveFailed'), error) : null,
932
+ React.createElement('div', { style: rowStyle },
933
+ React.createElement('div', null,
934
+ React.createElement('div', { style: labelStyle }, t('growthNow')),
935
+ React.createElement('div', { style: subStyle }, t('growthNowHint')),
936
+ ),
937
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
938
+ growthNotice !== undefined
939
+ ? React.createElement('span', { role: 'status', style: subStyle }, growthNotice)
940
+ : null,
941
+ React.createElement('button', {
942
+ type: 'button',
943
+ role: 'button',
944
+ 'aria-label': t('growthNow'),
945
+ disabled: disabled || growthBusy,
946
+ onClick: reviewNow,
947
+ style: {
948
+ padding: '7px 14px',
949
+ fontSize: '13px',
950
+ lineHeight: '18px',
951
+ borderRadius: '6px',
952
+ border: '1px solid var(--dsw-alias-border-l2, #d4d4d8)',
953
+ background: 'var(--dsw-alias-bg-layer-1, #f4f4f5)',
954
+ color: 'var(--dsw-alias-label-primary, #18181b)',
955
+ cursor: disabled || growthBusy ? 'not-allowed' : 'pointer',
956
+ opacity: disabled || growthBusy ? 0.6 : 1,
957
+ },
958
+ }, growthBusy ? t('growthNowRunning') : t('growthNow')),
959
+ ),
960
+ ),
961
+ error !== undefined ? React.createElement('div', { role: 'alert', style: errorStyle }, t('saveFailed'), error) : null,
865
962
  React.createElement('div', { style: { padding: '14px 16px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-secondary, #888)' } },
866
963
  value.enabled === false
867
964
  ? t('footerDisabled')
package/lib/index.js CHANGED
@@ -125,6 +125,7 @@ export const INSIGHTS_ROUTE_PATH = '/api/memory/insights'
125
125
 
126
126
  /** Read-only HTTP route serving the memory graph (nodes + edges). */
127
127
  export const GRAPH_ROUTE_PATH = '/api/memory/graph'
128
+ export const CONTROL_ROUTE_PATH = '/api/memory/control'
128
129
 
129
130
  export const inject = ['systemPrompt', 'skills', 'agents']
130
131
 
@@ -441,7 +442,10 @@ export function apply(ctx, config = {}) {
441
442
  // Recall nudge: one per live ROOT agent, on the same idle boundary as the
442
443
  // digest guard but on a cadence (interval + per-session cap) instead of
443
444
  // store staleness. Conversational only — it never writes the store.
444
- if (config.recallEnabled !== false) {
445
+ // Live recall nudges by agent id: the settings-panel "review now" button
446
+ // reaches them through /api/memory/control (manual growth recap).
447
+ const nudges = new Map()
448
+ {
445
449
  ctx.effect(() => {
446
450
  const stopCreated = ctx.on('agent/created', ({ agent }) => {
447
451
  if (!ctx.agents.roots().includes(agent)) return
@@ -449,7 +453,8 @@ export function apply(ctx, config = {}) {
449
453
  readConfig: () => {
450
454
  const resolved = store.get()
451
455
  return {
452
- enabled: resolved.enabled && resolved.recallEnabled !== false,
456
+ enabled: resolved.enabled,
457
+ recallEnabled: resolved.recallEnabled !== false,
453
458
  minMinutes: resolved.recallIntervalMinMinutes,
454
459
  maxMinutes: resolved.recallIntervalMaxMinutes,
455
460
  maxPerSession: resolved.recallMaxPerSession,
@@ -472,9 +477,11 @@ export function apply(ctx, config = {}) {
472
477
  logger: ctx.logger,
473
478
  claimLock: claimSharedProactiveLock,
474
479
  })
480
+ nudges.set(agent.id, nudge)
475
481
  agent.ctx.effect(() => {
476
482
  nudge.start()
477
483
  return () => {
484
+ nudges.delete(agent.id)
478
485
  nudge.dispose()
479
486
  }
480
487
  })
@@ -531,6 +538,59 @@ export function apply(ctx, config = {}) {
531
538
  webCtx.effect(() => disposeRoute, 'memory.config-route()')
532
539
  ctx.logger?.info(`memory: config route at ${CONFIG_ROUTE_PATH} (store ${store.path})`)
533
540
 
541
+ // Manual proactive controls: today only "review my week now", which rides
542
+ // the same recall channel as the weekly recap (same message shape, same
543
+ // arbitration lock) but ignores the weekly cadence because the user asked.
544
+ const disposeControlRoute = webCtx.webServer.register({
545
+ kind: 'exact',
546
+ path: CONTROL_ROUTE_PATH,
547
+ handler: async (req, res) => {
548
+ try {
549
+ if (req.method !== 'POST') {
550
+ res.writeHead(405, { 'content-type': 'application/json; charset=utf-8' })
551
+ res.end(JSON.stringify({ error: 'method not allowed' }))
552
+ return
553
+ }
554
+ const chunks = []
555
+ for await (const chunk of req) chunks.push(chunk)
556
+ let body
557
+ try {
558
+ body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}')
559
+ } catch {
560
+ res.writeHead(400, { 'content-type': 'application/json; charset=utf-8' })
561
+ res.end(JSON.stringify({ error: 'body must be JSON' }))
562
+ return
563
+ }
564
+ const action = typeof body?.action === 'string' ? body.action : ''
565
+ if (action !== 'growth-now') {
566
+ res.writeHead(400, { 'content-type': 'application/json; charset=utf-8' })
567
+ res.end(JSON.stringify({ error: `unknown action ${JSON.stringify(action)}` }))
568
+ return
569
+ }
570
+ const wanted = typeof body?.sessionId === 'string' ? body.sessionId : undefined
571
+ const candidates = [...nudges.entries()]
572
+ .filter(([id]) => wanted === undefined || id === wanted)
573
+ .map(([, nudge]) => nudge)
574
+ if (candidates.length === 0) {
575
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
576
+ res.end(JSON.stringify({ ok: true, delivered: false, reason: 'no-session' }))
577
+ return
578
+ }
579
+ let last = { delivered: false, reason: 'no-session' }
580
+ for (const nudge of candidates) {
581
+ last = nudge.forceGrowthRecap()
582
+ if (last.delivered) break
583
+ }
584
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
585
+ res.end(JSON.stringify(last.delivered ? { ok: true, delivered: true } : { ok: true, delivered: false, reason: last.reason }))
586
+ } catch (error) {
587
+ res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
588
+ res.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }))
589
+ }
590
+ },
591
+ })
592
+ webCtx.effect(() => disposeControlRoute, 'memory.control-route()')
593
+
534
594
  // Read-only health dashboard payload. Built fresh on every request from the
535
595
  // store on disk, so the panel always reflects the newest state and the
536
596
  // plugin never caches a stale view of the user's memory.
@@ -197,6 +197,62 @@ export class RecallNudge {
197
197
  }
198
198
  }
199
199
 
200
+ /**
201
+ * Deliver one growth recap now because the user asked for it (settings-panel
202
+ * "review now"). Manual means: the weekly cadence is not required and the
203
+ * per-session recall cap is not consulted, but the plugin must still be
204
+ * enabled, the agent idle, growth material must exist, and the shared
205
+ * speech-floor lock still wins. Never throws.
206
+ *
207
+ * @returns {{ delivered: boolean, reason: string }}
208
+ */
209
+ forceGrowthRecap() {
210
+ if (this.disposed) return { delivered: false, reason: 'disposed' }
211
+ if (this.agents && this.agents.get(this.agent.id) !== this.agent) return { delivered: false, reason: 'agent-gone' }
212
+ let config
213
+ try {
214
+ config = this.readConfig()
215
+ } catch (error) {
216
+ this.logger?.warn?.(`memory: growth-now config read failed: ${error instanceof Error ? error.message : String(error)}`)
217
+ return { delivered: false, reason: 'error' }
218
+ }
219
+ if (!config || config.enabled !== true) return { delivered: false, reason: 'disabled' }
220
+ if (this.agent.status !== 'idle') return { delivered: false, reason: 'busy' }
221
+ if (typeof this.readGrowthConfig !== 'function') return { delivered: false, reason: 'growth-disabled' }
222
+ let growthConfig
223
+ try {
224
+ growthConfig = this.readGrowthConfig()
225
+ } catch {
226
+ return { delivered: false, reason: 'growth-disabled' }
227
+ }
228
+ if (!growthConfig || growthConfig.enabled !== true) return { delivered: false, reason: 'growth-disabled' }
229
+ const now = Date.now()
230
+ try {
231
+ const storeDir = this.getMemoryDir()
232
+ const intervalDays = Math.max(1, Number(growthConfig.intervalDays ?? 7))
233
+ const growth = collectGrowth({ storeDir, sinceDays: intervalDays, max: 5, now })
234
+ if (growth.entries.length === 0 && growth.pagesChanged === 0) return { delivered: false, reason: 'no-content' }
235
+ const recap = renderGrowthRecap({
236
+ ...growth,
237
+ language: growthConfig.language === 'en' ? 'en' : 'zh',
238
+ })
239
+ if (recap.length === 0) return { delivered: false, reason: 'no-content' }
240
+ const claim = this.claimProactive(now, config)
241
+ if (!claim.ok) return { delivered: false, reason: 'deferred', deferredBy: claim.deferredBy }
242
+ try {
243
+ writeGrowthState(join(storeDir, GROWTH_STATE_FILENAME), now)
244
+ } catch (error) {
245
+ this.logger?.warn?.(`memory: growth-now state write failed: ${error instanceof Error ? error.message : String(error)}`)
246
+ }
247
+ this.agent.followup(buildGrowthRecapNudgeMessage(recap))
248
+ this.recalls += 1
249
+ return { delivered: true, reason: 'delivered' }
250
+ } catch (error) {
251
+ this.logger?.warn?.(`memory: growth-now failed: ${error instanceof Error ? error.message : String(error)}`)
252
+ return { delivered: false, reason: 'error' }
253
+ }
254
+ }
255
+
200
256
  /** Cancel subscriptions and the poll timer; the nudge stops observing. */
201
257
  dispose() {
202
258
  this.disposed = true
@@ -216,7 +272,7 @@ export class RecallNudge {
216
272
  return
217
273
  }
218
274
  const config = this.readConfig()
219
- if (!config.enabled) return
275
+ if (!config.enabled || config.recallEnabled === false) return
220
276
  // Both gates: don't recall before the user has spoken, and only for the
221
277
  // currently active session (most recent user message).
222
278
  if (this.tracker && !this.tracker.shouldInject(this.agent.id, config)) return
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-plugin-memory",
3
3
  "description": "Long-term memory plugin for DeepSeek Harness: persistent cross-session markdown memory with a soul/persona file, auto-injected at every session start, plus remember/recall/consolidate/forget workflows and portable migration tooling.",
4
- "version": "0.12.0",
4
+ "version": "0.13.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
@@ -42,7 +42,8 @@
42
42
  "lint:memory": "node scripts/memory.mjs lint"
43
43
  },
44
44
  "engines": {
45
- "node": ">=18"
45
+ "node": ">=18",
46
+ "dsh": "^0.2.1-rc.5"
46
47
  },
47
48
  "keywords": [
48
49
  "deepseek-harness",