dsh-plugin-memory 0.12.0 → 0.13.1
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 +37 -0
- package/README.md +10 -1
- package/README.zh.md +10 -1
- package/docs/PROACTIVE-PROTOCOL.md +81 -0
- package/lib/client.js +121 -7
- package/lib/index.js +70 -2
- package/lib/recall-nudge.js +62 -1
- package/lib/types/index.d.ts +6 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
|
|
4
4
|
|
|
5
|
+
## [0.13.1] - 2026-10-30
|
|
6
|
+
|
|
7
|
+
### Fixed(面板可用性四连)
|
|
8
|
+
|
|
9
|
+
- **追忆间隔两个输入框缺可访问名**:`recallIntervalMinMinutes` / `recallIntervalMaxMinutes` 的 NumberInput 之前只有视觉标签;现在用新增的 `recallIntervalMin` / `recallIntervalMax` 文案作为 `aria-label`(中英),屏幕阅读器能读出「最短间隔 / 最长间隔」。
|
|
10
|
+
- **语气强度下拉缺可访问名**:`toneIntensity` 的 SelectInput 补 `aria-label`(复用「语气强度」文案)。
|
|
11
|
+
- **`:focus-visible` 焦点环实际从未生效**:原规则带了不存在的 `section` 祖先前缀,而设置面板并不在 `section` 元素内 → 规则永远不命中。改为在面板根 `div` 上打 `data-dsh-memory-panel` 标记,选择器直接命中该 marker(含根自身),键盘焦点环在表单与按钮上真正可见。
|
|
12
|
+
- **「立即回顾」结果提示错乱**:`busy` / `disabled` / `error` 之前全落到「没有新内容」;重写 reason 映射——`busy` → 新增「会话正忙,稍后再试」(`growthNowBusy`,中英)、`disabled` / `growth-disabled` → 「成长回顾已关闭」、`error` / `agent-gone` / `disposed` → 「回顾失败」、`no-content` 才显示「没有新内容」;并让提示 **5 秒后自动消失**。
|
|
13
|
+
|
|
14
|
+
### Notes
|
|
15
|
+
|
|
16
|
+
- **手动「立即回顾」有意不受每会话追忆上限约束**:它是用户显式操作,不计入自动追忆的 `recallMaxPerSession`;但插件启用、agent idle、成长回顾开启、有内容、发言权仲裁仍然全部生效。
|
|
17
|
+
- 另:手动回顾成功后会把自动追忆节律前移(不会紧接着又发一条);多 root 会话时优先投递到当前活跃会话;`types/index.d.ts` 补 `CONTROL_ROUTE_PATH` / `GRAPH_ROUTE_PATH` 常量声明。
|
|
18
|
+
|
|
19
|
+
### Tests
|
|
20
|
+
|
|
21
|
+
- `client-i18n` / `growth-now` 补 aria、reason 映射、5 秒自动清除、节律前移与多 root 选择用例。
|
|
22
|
+
- 全量单测 **258/258 通过**(0.13.0 基线 255,新增 3 条);`node scripts/memory.mjs --self-test` PASS。
|
|
23
|
+
|
|
24
|
+
## [0.13.0] - 2026-10-30
|
|
25
|
+
|
|
26
|
+
### Added(兼容声明 + 立即回顾 + 可访问性 + 工程化)
|
|
27
|
+
|
|
28
|
+
- **`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`;旧宿主会被闸门拦住,而不是让插件半残运行。运行期缺失投影仍优雅降级(不发回顾/不抢发言权,绝不崩)。
|
|
29
|
+
- **「立即回顾」按钮 + 控制路由**:新增 `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。面板按钮带「回顾中 / 已发送 / 另一插件正在说话 / 没有新内容 / 已关闭 / 失败」六态反馈。
|
|
30
|
+
- **面板可访问性**:按钮与表单补 `aria-label`,状态用 `role="status"`、错误用 `role="alert"`,键盘焦点加 `:focus-visible` 焦点环。
|
|
31
|
+
- **工程化**:`.github/workflows/ci.yml`(跑 `node --test` + `--self-test`)、Issue / PR 模板、`CONTRIBUTING.md`、`SECURITY.md`、`docs/PROACTIVE-PROTOCOL.md`(跨插件共享发言协议 v1 的公开说明;`docs/**` 在 `files` 内,因此该文档随 npm 包发布)。
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- 面板控制逻辑把 `recallEnabled` 与「手动立即回顾」解耦:关闭自动追忆不再等于禁用用户显式发起的回顾。
|
|
36
|
+
|
|
37
|
+
### Tests
|
|
38
|
+
|
|
39
|
+
- 新增 `test/control-route.test.mjs`、`test/growth-now.test.mjs`;`client-i18n` 补按钮文案与 a11y 契约。
|
|
40
|
+
- 全量单测 **255/255 通过**(0.12.0 基线 242,新增 13 条);`node scripts/memory.mjs --self-test` PASS。
|
|
41
|
+
|
|
5
42
|
## [0.12.0] - 2026-10-30
|
|
6
43
|
|
|
7
44
|
### 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
|
|
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 / session busy / no content / disabled / failed) — the result notice clears itself after 5 seconds.
|
|
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 **258 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
|
|
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` 关闭也能用,并在面板里给出结果(回顾中 / 已发送 / 让位 / 会话正忙 / 没有新内容 / 已关闭 / 失败),结果提示 5 秒后自动消失。
|
|
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`,当前共 **258 个用例**;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. */
|
|
@@ -57,6 +58,8 @@ window.__ModuleLoader__.load({
|
|
|
57
58
|
recall: '主动追忆',
|
|
58
59
|
recallHint: '对话空闲时,以第一人称主动提起一件关于你的往事(拟人化),可随时关闭',
|
|
59
60
|
recallInterval: '追忆间隔(分钟)',
|
|
61
|
+
recallIntervalMin: '最短间隔',
|
|
62
|
+
recallIntervalMax: '最长间隔',
|
|
60
63
|
recallIntervalHint: '每次随机在最短 ~ 最长之间取一个间隔,避免固定节奏',
|
|
61
64
|
recallMaxPerSession: '每会话追忆次数',
|
|
62
65
|
recallMaxPerSessionHint: '一个会话内最多主动追忆几次,避免打扰',
|
|
@@ -69,6 +72,15 @@ window.__ModuleLoader__.load({
|
|
|
69
72
|
toneOff: 'off(纯工程口吻)',
|
|
70
73
|
growthRecap: '每周成长回顾',
|
|
71
74
|
growthRecapHint: '每周在追忆通道里说一次「这周我记住了什么」(第一人称,最多五句,可随时关闭)',
|
|
75
|
+
growthNow: '立即回顾',
|
|
76
|
+
growthNowHint: '手动触发一次成长回顾(尊重发言权仲裁;没有新内容时不发)',
|
|
77
|
+
growthNowRunning: '回顾中…',
|
|
78
|
+
growthNowOk: '已发送成长回顾',
|
|
79
|
+
growthNowDeferred: '另一插件正在说话,稍后再试',
|
|
80
|
+
growthNowBusy: '会话正忙,稍后再试',
|
|
81
|
+
growthNowEmpty: '这一周没有可回顾的新内容',
|
|
82
|
+
growthNowDisabled: '成长回顾已关闭',
|
|
83
|
+
growthNowFailed: '回顾失败:',
|
|
72
84
|
minutesPlaceholder: '30',
|
|
73
85
|
maxMinutesPlaceholder: '240',
|
|
74
86
|
maxPerSessionPlaceholder: '3',
|
|
@@ -154,6 +166,8 @@ window.__ModuleLoader__.load({
|
|
|
154
166
|
recall: 'Proactive recall',
|
|
155
167
|
recallHint: 'When the conversation is idle, bring up a memory about you in first person (personified); can be turned off anytime',
|
|
156
168
|
recallInterval: 'Recall interval (minutes)',
|
|
169
|
+
recallIntervalMin: 'min interval',
|
|
170
|
+
recallIntervalMax: 'max interval',
|
|
157
171
|
recallIntervalHint: 'A random interval between min and max each time, so the rhythm never feels fixed',
|
|
158
172
|
recallMaxPerSession: 'Recalls per session',
|
|
159
173
|
recallMaxPerSessionHint: 'Maximum proactive recalls in one session, to stay unobtrusive',
|
|
@@ -166,6 +180,15 @@ window.__ModuleLoader__.load({
|
|
|
166
180
|
toneOff: 'off (pure engineering voice)',
|
|
167
181
|
growthRecap: 'Weekly growth recap',
|
|
168
182
|
growthRecapHint: 'Once a week, on the recall channel, say what I kept this week (first person, at most five sentences; can be turned off)',
|
|
183
|
+
growthNow: 'Review now',
|
|
184
|
+
growthNowHint: 'Send one growth recap right away (still respects the speech floor; no new material = no message)',
|
|
185
|
+
growthNowRunning: 'Reviewing…',
|
|
186
|
+
growthNowOk: 'Growth recap sent',
|
|
187
|
+
growthNowDeferred: 'Another plugin holds the floor; try again later',
|
|
188
|
+
growthNowBusy: 'Session busy; try again shortly',
|
|
189
|
+
growthNowEmpty: 'Nothing new to recap this week',
|
|
190
|
+
growthNowDisabled: 'Weekly recap is off',
|
|
191
|
+
growthNowFailed: 'Recap failed: ',
|
|
169
192
|
minutesPlaceholder: '30',
|
|
170
193
|
maxMinutesPlaceholder: '240',
|
|
171
194
|
maxPerSessionPlaceholder: '3',
|
|
@@ -359,11 +382,12 @@ window.__ModuleLoader__.load({
|
|
|
359
382
|
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
360
383
|
}
|
|
361
384
|
|
|
362
|
-
function Toggle({ checked, disabled, onChange }) {
|
|
385
|
+
function Toggle({ checked, disabled, onChange, label }) {
|
|
363
386
|
return React.createElement('button', {
|
|
364
387
|
type: 'button',
|
|
365
388
|
role: 'switch',
|
|
366
389
|
'aria-checked': checked,
|
|
390
|
+
'aria-label': label,
|
|
367
391
|
disabled,
|
|
368
392
|
onClick: () => onChange(!checked),
|
|
369
393
|
style: {
|
|
@@ -394,7 +418,7 @@ window.__ModuleLoader__.load({
|
|
|
394
418
|
|
|
395
419
|
function ErrorText({ message }) {
|
|
396
420
|
const t = useT()
|
|
397
|
-
return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
|
|
421
|
+
return React.createElement('div', { role: 'alert', style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
|
|
398
422
|
t('loadFailed'), message)
|
|
399
423
|
}
|
|
400
424
|
|
|
@@ -593,7 +617,7 @@ window.__ModuleLoader__.load({
|
|
|
593
617
|
}
|
|
594
618
|
|
|
595
619
|
/** 目录输入:草稿态编辑,blur / Enter 才写回,避免每次按键触发 Host 重排。 */
|
|
596
|
-
function DirInput({ value, disabled, onCommit }) {
|
|
620
|
+
function DirInput({ value, disabled, onCommit, label }) {
|
|
597
621
|
const t = useT()
|
|
598
622
|
const [draft, setDraft] = React.useState(undefined)
|
|
599
623
|
const shown = draft !== undefined ? draft : (value ?? '')
|
|
@@ -606,6 +630,7 @@ window.__ModuleLoader__.load({
|
|
|
606
630
|
return React.createElement('input', {
|
|
607
631
|
type: 'text',
|
|
608
632
|
placeholder: t('dirPlaceholder'),
|
|
633
|
+
'aria-label': label,
|
|
609
634
|
disabled,
|
|
610
635
|
value: shown,
|
|
611
636
|
onChange: (event) => setDraft(event.target.value),
|
|
@@ -619,7 +644,7 @@ window.__ModuleLoader__.load({
|
|
|
619
644
|
}
|
|
620
645
|
|
|
621
646
|
/** 数字输入:草稿态编辑,blur / Enter 才写回(分钟/次数)。 */
|
|
622
|
-
function NumberInput({ value, disabled, onCommit, placeholder }) {
|
|
647
|
+
function NumberInput({ value, disabled, onCommit, placeholder, label }) {
|
|
623
648
|
const [draft, setDraft] = React.useState(undefined)
|
|
624
649
|
const shown = draft !== undefined ? draft : (value ?? '')
|
|
625
650
|
const commit = () => {
|
|
@@ -631,6 +656,7 @@ window.__ModuleLoader__.load({
|
|
|
631
656
|
return React.createElement('input', {
|
|
632
657
|
type: 'number',
|
|
633
658
|
placeholder,
|
|
659
|
+
'aria-label': label,
|
|
634
660
|
disabled,
|
|
635
661
|
value: shown,
|
|
636
662
|
onChange: (event) => setDraft(event.target.value),
|
|
@@ -644,8 +670,9 @@ window.__ModuleLoader__.load({
|
|
|
644
670
|
}
|
|
645
671
|
|
|
646
672
|
/** 下拉选择:语气强度这类枚举配置,改动立即写回。 */
|
|
647
|
-
function SelectInput({ value, disabled, options, onChange }) {
|
|
673
|
+
function SelectInput({ value, disabled, options, onChange, label }) {
|
|
648
674
|
return React.createElement('select', {
|
|
675
|
+
'aria-label': label,
|
|
649
676
|
disabled,
|
|
650
677
|
value: value ?? '',
|
|
651
678
|
onChange: (event) => onChange(event.target.value),
|
|
@@ -661,6 +688,51 @@ window.__ModuleLoader__.load({
|
|
|
661
688
|
const [status, setStatus] = React.useState('loading')
|
|
662
689
|
const [error, setError] = React.useState(undefined)
|
|
663
690
|
const [saving, setSaving] = React.useState(false)
|
|
691
|
+
const [growthBusy, setGrowthBusy] = React.useState(false)
|
|
692
|
+
const [growthNotice, setGrowthNotice] = React.useState(undefined)
|
|
693
|
+
|
|
694
|
+
// Visible keyboard focus for every control in this panel (inline styles
|
|
695
|
+
// cannot express :focus-visible). The tag is removed with the panel.
|
|
696
|
+
React.useEffect(() => {
|
|
697
|
+
if (typeof document === 'undefined') return undefined
|
|
698
|
+
const tag = document.createElement('style')
|
|
699
|
+
tag.setAttribute('data-dsh-memory-focus', '')
|
|
700
|
+
tag.textContent = '[data-dsh-memory-panel] :focus-visible, [data-dsh-memory-panel]:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #4c8bf5); outline-offset: 2px; }'
|
|
701
|
+
document.head.appendChild(tag)
|
|
702
|
+
return () => tag.remove()
|
|
703
|
+
}, [])
|
|
704
|
+
|
|
705
|
+
React.useEffect(() => {
|
|
706
|
+
if (growthNotice === undefined || typeof setTimeout !== 'function') return undefined
|
|
707
|
+
const timer = setTimeout(() => setGrowthNotice(undefined), 5000)
|
|
708
|
+
return () => clearTimeout(timer)
|
|
709
|
+
}, [growthNotice])
|
|
710
|
+
|
|
711
|
+
const reviewNow = () => {
|
|
712
|
+
setGrowthBusy(true)
|
|
713
|
+
setGrowthNotice(undefined)
|
|
714
|
+
fetch(CONTROL_URL, {
|
|
715
|
+
method: 'POST',
|
|
716
|
+
headers: { 'content-type': 'application/json' },
|
|
717
|
+
body: JSON.stringify({ action: 'growth-now' }),
|
|
718
|
+
})
|
|
719
|
+
.then(async (response) => {
|
|
720
|
+
const body = await response.json().catch(() => ({}))
|
|
721
|
+
if (!response.ok) throw new Error(body.error ?? `POST ${response.status}`)
|
|
722
|
+
if (body.delivered === true) { setGrowthNotice(t('growthNowOk')); return }
|
|
723
|
+
const reason = body.reason
|
|
724
|
+
if (reason === 'deferred') { setGrowthNotice(t('growthNowDeferred')); return }
|
|
725
|
+
if (reason === 'no-content') { setGrowthNotice(t('growthNowEmpty')); return }
|
|
726
|
+
if (reason === 'disabled' || reason === 'growth-disabled') { setGrowthNotice(t('growthNowDisabled')); return }
|
|
727
|
+
if (reason === 'busy') { setGrowthNotice(t('growthNowBusy')); return }
|
|
728
|
+
if (reason === 'error' || reason === 'agent-gone' || reason === 'disposed') { setGrowthNotice(t('growthNowFailed')); return }
|
|
729
|
+
setGrowthNotice(t('growthNowEmpty'))
|
|
730
|
+
})
|
|
731
|
+
.catch((err) => {
|
|
732
|
+
setGrowthNotice(`${t('growthNowFailed')}${err instanceof Error ? err.message : String(err)}`)
|
|
733
|
+
})
|
|
734
|
+
.finally(() => setGrowthBusy(false))
|
|
735
|
+
}
|
|
664
736
|
|
|
665
737
|
React.useEffect(() => {
|
|
666
738
|
let alive = true
|
|
@@ -712,13 +784,14 @@ window.__ModuleLoader__.load({
|
|
|
712
784
|
const value = config ?? {}
|
|
713
785
|
const disabled = saving
|
|
714
786
|
|
|
715
|
-
return React.createElement('div', { style: { padding: '8px 0' } },
|
|
787
|
+
return React.createElement('div', { style: { padding: '8px 0' }, 'data-dsh-memory-panel': '' },
|
|
716
788
|
React.createElement('div', { style: rowStyle },
|
|
717
789
|
React.createElement('div', null,
|
|
718
790
|
React.createElement('div', { style: labelStyle }, t('enabled')),
|
|
719
791
|
React.createElement('div', { style: subStyle }, t('enabledHint')),
|
|
720
792
|
),
|
|
721
793
|
React.createElement(Toggle, {
|
|
794
|
+
label: t('enabled'),
|
|
722
795
|
checked: value.enabled !== false,
|
|
723
796
|
disabled,
|
|
724
797
|
onChange: (next) => apply({ enabled: next }),
|
|
@@ -730,6 +803,7 @@ window.__ModuleLoader__.load({
|
|
|
730
803
|
React.createElement('div', { style: subStyle }, t('memoryDirHint')),
|
|
731
804
|
),
|
|
732
805
|
React.createElement(DirInput, {
|
|
806
|
+
label: t('memoryDir'),
|
|
733
807
|
value: value.memoryDir,
|
|
734
808
|
disabled,
|
|
735
809
|
onCommit: (next) => apply({ memoryDir: next }),
|
|
@@ -741,6 +815,7 @@ window.__ModuleLoader__.load({
|
|
|
741
815
|
React.createElement('div', { style: subStyle }, t('autoInjectHint')),
|
|
742
816
|
),
|
|
743
817
|
React.createElement(Toggle, {
|
|
818
|
+
label: t('autoInject'),
|
|
744
819
|
checked: value.autoInject !== false,
|
|
745
820
|
disabled,
|
|
746
821
|
onChange: (next) => apply({ autoInject: next }),
|
|
@@ -752,6 +827,7 @@ window.__ModuleLoader__.load({
|
|
|
752
827
|
React.createElement('div', { style: subStyle }, t('deferUntilUserSpeaksHint')),
|
|
753
828
|
),
|
|
754
829
|
React.createElement(Toggle, {
|
|
830
|
+
label: t('deferUntilUserSpeaks'),
|
|
755
831
|
checked: value.deferUntilUserSpeaks !== false,
|
|
756
832
|
disabled,
|
|
757
833
|
onChange: (next) => apply({ deferUntilUserSpeaks: next }),
|
|
@@ -763,6 +839,7 @@ window.__ModuleLoader__.load({
|
|
|
763
839
|
React.createElement('div', { style: subStyle }, t('activeSessionOnlyHint')),
|
|
764
840
|
),
|
|
765
841
|
React.createElement(Toggle, {
|
|
842
|
+
label: t('activeSessionOnly'),
|
|
766
843
|
checked: value.activeSessionOnly !== false,
|
|
767
844
|
disabled,
|
|
768
845
|
onChange: (next) => apply({ activeSessionOnly: next }),
|
|
@@ -774,6 +851,7 @@ window.__ModuleLoader__.load({
|
|
|
774
851
|
React.createElement('div', { style: subStyle }, t('registerSkillHint')),
|
|
775
852
|
),
|
|
776
853
|
React.createElement(Toggle, {
|
|
854
|
+
label: t('registerSkill'),
|
|
777
855
|
checked: value.registerSkill !== false,
|
|
778
856
|
disabled,
|
|
779
857
|
onChange: (next) => apply({ registerSkill: next }),
|
|
@@ -785,6 +863,7 @@ window.__ModuleLoader__.load({
|
|
|
785
863
|
React.createElement('div', { style: subStyle }, t('recallHint')),
|
|
786
864
|
),
|
|
787
865
|
React.createElement(Toggle, {
|
|
866
|
+
label: t('recall'),
|
|
788
867
|
checked: value.recallEnabled !== false,
|
|
789
868
|
disabled,
|
|
790
869
|
onChange: (next) => apply({ recallEnabled: next }),
|
|
@@ -797,6 +876,7 @@ window.__ModuleLoader__.load({
|
|
|
797
876
|
),
|
|
798
877
|
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
799
878
|
React.createElement(NumberInput, {
|
|
879
|
+
label: t('recallIntervalMin'),
|
|
800
880
|
value: value.recallIntervalMinMinutes,
|
|
801
881
|
disabled,
|
|
802
882
|
placeholder: t('minutesPlaceholder'),
|
|
@@ -804,6 +884,7 @@ window.__ModuleLoader__.load({
|
|
|
804
884
|
}),
|
|
805
885
|
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, '~'),
|
|
806
886
|
React.createElement(NumberInput, {
|
|
887
|
+
label: t('recallIntervalMax'),
|
|
807
888
|
value: value.recallIntervalMaxMinutes,
|
|
808
889
|
disabled,
|
|
809
890
|
placeholder: t('maxMinutesPlaceholder'),
|
|
@@ -817,6 +898,7 @@ window.__ModuleLoader__.load({
|
|
|
817
898
|
React.createElement('div', { style: subStyle }, t('recallMaxPerSessionHint')),
|
|
818
899
|
),
|
|
819
900
|
React.createElement(NumberInput, {
|
|
901
|
+
label: t('recallMaxPerSession'),
|
|
820
902
|
value: value.recallMaxPerSession,
|
|
821
903
|
disabled,
|
|
822
904
|
placeholder: t('maxPerSessionPlaceholder'),
|
|
@@ -829,6 +911,7 @@ window.__ModuleLoader__.load({
|
|
|
829
911
|
React.createElement('div', { style: subStyle }, t('toneGuideHint')),
|
|
830
912
|
),
|
|
831
913
|
React.createElement(Toggle, {
|
|
914
|
+
label: t('toneGuide'),
|
|
832
915
|
checked: value.toneGuideEnabled !== false,
|
|
833
916
|
disabled,
|
|
834
917
|
onChange: (next) => apply({ toneGuideEnabled: next }),
|
|
@@ -840,6 +923,7 @@ window.__ModuleLoader__.load({
|
|
|
840
923
|
React.createElement('div', { style: subStyle }, t('toneIntensityHint')),
|
|
841
924
|
),
|
|
842
925
|
React.createElement(SelectInput, {
|
|
926
|
+
label: t('toneIntensity'),
|
|
843
927
|
value: value.toneIntensity ?? 'low',
|
|
844
928
|
disabled: disabled || value.toneGuideEnabled === false,
|
|
845
929
|
options: [
|
|
@@ -856,12 +940,42 @@ window.__ModuleLoader__.load({
|
|
|
856
940
|
React.createElement('div', { style: subStyle }, t('growthRecapHint')),
|
|
857
941
|
),
|
|
858
942
|
React.createElement(Toggle, {
|
|
943
|
+
label: t('growthRecap'),
|
|
859
944
|
checked: value.growthRecapEnabled !== false,
|
|
860
945
|
disabled,
|
|
861
946
|
onChange: (next) => apply({ growthRecapEnabled: next }),
|
|
862
947
|
}),
|
|
863
948
|
),
|
|
864
|
-
|
|
949
|
+
React.createElement('div', { style: rowStyle },
|
|
950
|
+
React.createElement('div', null,
|
|
951
|
+
React.createElement('div', { style: labelStyle }, t('growthNow')),
|
|
952
|
+
React.createElement('div', { style: subStyle }, t('growthNowHint')),
|
|
953
|
+
),
|
|
954
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
|
|
955
|
+
growthNotice !== undefined
|
|
956
|
+
? React.createElement('span', { role: 'status', style: subStyle }, growthNotice)
|
|
957
|
+
: null,
|
|
958
|
+
React.createElement('button', {
|
|
959
|
+
type: 'button',
|
|
960
|
+
role: 'button',
|
|
961
|
+
'aria-label': t('growthNow'),
|
|
962
|
+
disabled: disabled || growthBusy,
|
|
963
|
+
onClick: reviewNow,
|
|
964
|
+
style: {
|
|
965
|
+
padding: '7px 14px',
|
|
966
|
+
fontSize: '13px',
|
|
967
|
+
lineHeight: '18px',
|
|
968
|
+
borderRadius: '6px',
|
|
969
|
+
border: '1px solid var(--dsw-alias-border-l2, #d4d4d8)',
|
|
970
|
+
background: 'var(--dsw-alias-bg-layer-1, #f4f4f5)',
|
|
971
|
+
color: 'var(--dsw-alias-label-primary, #18181b)',
|
|
972
|
+
cursor: disabled || growthBusy ? 'not-allowed' : 'pointer',
|
|
973
|
+
opacity: disabled || growthBusy ? 0.6 : 1,
|
|
974
|
+
},
|
|
975
|
+
}, growthBusy ? t('growthNowRunning') : t('growthNow')),
|
|
976
|
+
),
|
|
977
|
+
),
|
|
978
|
+
error !== undefined ? React.createElement('div', { role: 'alert', style: errorStyle }, t('saveFailed'), error) : null,
|
|
865
979
|
React.createElement('div', { style: { padding: '14px 16px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-secondary, #888)' } },
|
|
866
980
|
value.enabled === false
|
|
867
981
|
? 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
|
-
|
|
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
|
|
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,67 @@ 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(([id, nudge]) => ({ id, nudge }))
|
|
574
|
+
// Prefer the session the user most recently spoke in; the settings
|
|
575
|
+
// panel has no session id of its own, so without this a recap could
|
|
576
|
+
// land in a background conversation.
|
|
577
|
+
.sort((a, b) => {
|
|
578
|
+
const rank = (entry) => (typeof tracker?.isActive === 'function' && tracker.isActive(entry.id) ? 1 : 0)
|
|
579
|
+
return rank(b) - rank(a)
|
|
580
|
+
})
|
|
581
|
+
.map((entry) => entry.nudge)
|
|
582
|
+
if (candidates.length === 0) {
|
|
583
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
|
|
584
|
+
res.end(JSON.stringify({ ok: true, delivered: false, reason: 'no-session' }))
|
|
585
|
+
return
|
|
586
|
+
}
|
|
587
|
+
let last = { delivered: false, reason: 'no-session' }
|
|
588
|
+
for (const nudge of candidates) {
|
|
589
|
+
last = nudge.forceGrowthRecap()
|
|
590
|
+
if (last.delivered) break
|
|
591
|
+
}
|
|
592
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
|
|
593
|
+
res.end(JSON.stringify(last.delivered ? { ok: true, delivered: true } : { ok: true, delivered: false, reason: last.reason }))
|
|
594
|
+
} catch (error) {
|
|
595
|
+
res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
596
|
+
res.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }))
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
})
|
|
600
|
+
webCtx.effect(() => disposeControlRoute, 'memory.control-route()')
|
|
601
|
+
|
|
534
602
|
// Read-only health dashboard payload. Built fresh on every request from the
|
|
535
603
|
// store on disk, so the panel always reflects the newest state and the
|
|
536
604
|
// plugin never caches a stale view of the user's memory.
|
package/lib/recall-nudge.js
CHANGED
|
@@ -197,6 +197,67 @@ 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
|
+
// A manual recap counts as this cycle's proactive message: push the
|
|
250
|
+
// automatic cadence forward so the user never gets two proactive
|
|
251
|
+
// messages back to back. (The per-session recall cap is intentionally
|
|
252
|
+
// NOT consulted here — the user explicitly asked for this one.)
|
|
253
|
+
this.nextRecallAt = now + randomIntervalMs(config.minMinutes, config.maxMinutes)
|
|
254
|
+
return { delivered: true, reason: 'delivered' }
|
|
255
|
+
} catch (error) {
|
|
256
|
+
this.logger?.warn?.(`memory: growth-now failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
257
|
+
return { delivered: false, reason: 'error' }
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
200
261
|
/** Cancel subscriptions and the poll timer; the nudge stops observing. */
|
|
201
262
|
dispose() {
|
|
202
263
|
this.disposed = true
|
|
@@ -216,7 +277,7 @@ export class RecallNudge {
|
|
|
216
277
|
return
|
|
217
278
|
}
|
|
218
279
|
const config = this.readConfig()
|
|
219
|
-
if (!config.enabled) return
|
|
280
|
+
if (!config.enabled || config.recallEnabled === false) return
|
|
220
281
|
// Both gates: don't recall before the user has spoken, and only for the
|
|
221
282
|
// currently active session (most recent user message).
|
|
222
283
|
if (this.tracker && !this.tracker.shouldInject(this.agent.id, config)) return
|
package/lib/types/index.d.ts
CHANGED
|
@@ -88,6 +88,12 @@ export const CONFIG_ROUTE_PATH: '/api/memory/config'
|
|
|
88
88
|
/** Read-only HTTP route serving the memory-health dashboard payload. */
|
|
89
89
|
export const INSIGHTS_ROUTE_PATH: '/api/memory/insights'
|
|
90
90
|
|
|
91
|
+
/** Read-only HTTP route serving the memory graph payload. */
|
|
92
|
+
export const GRAPH_ROUTE_PATH: '/api/memory/graph'
|
|
93
|
+
|
|
94
|
+
/** Manual control route (`growth-now`): deliver one recap on demand. */
|
|
95
|
+
export const CONTROL_ROUTE_PATH: '/api/memory/control'
|
|
96
|
+
|
|
91
97
|
/** User-editable settings (composition config is the base layer). */
|
|
92
98
|
export interface MemorySettings {
|
|
93
99
|
enabled?: boolean
|
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.
|
|
4
|
+
"version": "0.13.1",
|
|
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",
|