dsh-instruction-memory 1.5.7 → 1.6.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 +97 -0
- package/README.md +43 -12
- package/lib/client.js +36 -10
- package/lib/index.js +134 -9
- package/memory.schema.json +7 -1
- package/package.json +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,103 @@
|
|
|
7
7
|
> 1.0.13 起由 CI 经 OIDC Trusted Publishing 发布(首个带 provenance 的版本)。
|
|
8
8
|
> 这些历史 tag **不应回填**——npm 上的版本号已被占用。
|
|
9
9
|
|
|
10
|
+
## [1.6.1] — 2026-11-18
|
|
11
|
+
|
|
12
|
+
一次针对"桌面端 / 网页端两个宿主"的缺陷审计(架构、授权安全、验收边界三方独立复查 + 代码级复核)
|
|
13
|
+
之后的修复批次。没有新功能:改动集中在**声明与实际不一致**、**失败被静默**、**门禁够不到真实宿主**三类。
|
|
14
|
+
|
|
15
|
+
### 修复(安全)
|
|
16
|
+
|
|
17
|
+
- **`send-feedback` 与 `export-to-dir` 移出只读方法集合**。两者从来不是"读":一个用操作者自己的
|
|
18
|
+
SMTP 账号发信,一个往备份目录落盘。在没有 `connection` 服务的 profile 上,`READ_ONLY_METHODS`
|
|
19
|
+
是写门唯一的豁口,等于允许本机任意进程(含 Android 上任何装了 App 的程序)用用户邮箱发信
|
|
20
|
+
(冷却期内每分钟 2 封)并持续落盘。现在两者与其它写方法一致:无鉴权门时需 `Origin` 或
|
|
21
|
+
`Sec-Fetch-Site: same-origin`。浏览器设置页不受影响。
|
|
22
|
+
- **`reload` 有意留在只读集合**:它只重读磁盘,首次落盘是幂等的;而桌面壳的转发层会剥掉
|
|
23
|
+
`Origin`,把它移出会让"无鉴权门的桌面 profile"上这一按钮直接 403。
|
|
24
|
+
|
|
25
|
+
### 修复(面板行为)
|
|
26
|
+
|
|
27
|
+
- **桌面端导出不再无条件报"已保存"**。`<a download>` + blob 点击后立刻显示成功,而 Electron
|
|
28
|
+
主窗口的 `will-download` 只处理 `#dsh-download=` 前缀的 URL,其余(含 blob)交给默认行为——
|
|
29
|
+
用户取消保存框或下载被策略拦下时,面板和用户都不会知道。文案改为"已请求保存",并说明
|
|
30
|
+
取消 / 被拦时不会产生文件。
|
|
31
|
+
- **导入加了确认**。整库恢复(restore)一直有确认,导入没有;于是别人递来的一份"记忆备份"
|
|
32
|
+
可以静默成为此后每轮注入的指令。现在导入走同一套 `askConfirm`,没有对话框的环境按
|
|
33
|
+
fail-closed 处理(拒绝而不是静默合并)。
|
|
34
|
+
|
|
35
|
+
### 修复(声明与实际不一致)
|
|
36
|
+
|
|
37
|
+
- **删除 `dsh.compatibility.dsh`**。宿主 `dsh-app-boot` 的 `unmetRequirements()` 只读 **顶层**
|
|
38
|
+
`engines.dsh`,缺失则回落 `peerDependencies`(两处都用 `includePrerelease: true` 求值);
|
|
39
|
+
本包 `engines` 只有 `node`,`engines.dsh` 写在 `dsh` 命名空间下,宿主**不读**。
|
|
40
|
+
`dsh.compatibility.dsh` 在已安装运行时树(`dsh-app-boot`、`dsh-client-ui-plugin-manager`、
|
|
41
|
+
`dshmarket`)里 grep 无读取方。三份"逐字节一致"的副本,实际只有 peer 那份生效。
|
|
42
|
+
- **区间补洞**:`>=0.1.5-alpha.1` 作为起点把 `0.1.5-alpha.0` / `0.1.5-0` 漏在区间外,
|
|
43
|
+
改为 `>=0.1.5-0`。`host-range-test.mjs` 矩阵新增这两个版本,并新增
|
|
44
|
+
"`dsh.compatibility.dsh` 必须不存在"断言(防第三份副本长回来)。
|
|
45
|
+
- **桌面端 Origin 围栏的文档说反了**:桌面壳对所有非静态路径调用 `forwardWebRequest()`,
|
|
46
|
+
转发前删除 `host` / `origin` / `cookie` / `sec-fetch-site` 并注入宿主 cookie。因此插件的
|
|
47
|
+
`requestOriginVerdict()` 在桌面端**根本不执行**,桌面端的边界是"回环绑定 + 宿主 cookie"。
|
|
48
|
+
README 与 `TRUSTED_HOSTS` 注释按此更正;旧版"渲染器改用 `dsh-app://` 会整片 403"的推演已被证伪。
|
|
49
|
+
- **Windows 上的 `0o600` 不再被当作权限承诺**:Windows 文件系统忽略 `mode`,文件只是继承目录
|
|
50
|
+
ACL。README 补上 `memory.json` 的 `icacls` 收紧命令(与 `feedback.json` 既有说明对齐)。
|
|
51
|
+
- **反馈披露补齐**:面板声明与真实发送字段对齐(补上界面语言、时区、User-Agent 的说明)。
|
|
52
|
+
|
|
53
|
+
### 修复(测试与门禁)
|
|
54
|
+
|
|
55
|
+
- **新增 `section-order-test.mjs`**:从**已安装宿主**(profile 树优先,其次桌面 `app.asar`)读出
|
|
56
|
+
`SECTION_ORDERS`,断言 `SECTION_ORDER = 950` 未被占用、严格落在 `FILE_REFERENCE(900)` 与
|
|
57
|
+
`TOOL_BASH(1000)` 之间,且紧邻下方仍是 `FILE_REFERENCE`。宿主换表时注入块会静默移位,
|
|
58
|
+
此前没有任何断言兜住。解析兼容 `1e3` 形式的字面量(0.2.2 起宿主用科学计数法写表)。
|
|
59
|
+
- **CI 新增 `host-smoke`(`workflow_dispatch`,self-hosted)**:真实宿主端到端(注入 / SSE /
|
|
60
|
+
路由 / 跨端快照)此前不在任何门禁里,只有 `smoke:hosts` 这个没人记得跑的手动脚本。该作业在
|
|
61
|
+
缺少 `DSH_GUI_URL` / `DSH_GUI_TOKEN` 时打印 notice 并跳过,不会让 fork 变红。
|
|
62
|
+
|
|
63
|
+
### 兼容性
|
|
64
|
+
|
|
65
|
+
- 存储格式不变(`version: 2`)。**唯一的行为收紧**:在没有 `connection` 服务、也没有浏览器
|
|
66
|
+
来源标记的环境里,`send-feedback` 与 `export-to-dir` 现在会被 **403**。让宿主发布
|
|
67
|
+
`connection`(桌面 / 网页端默认如此)或设 `DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1` 均可。
|
|
68
|
+
- 声明上界仍是 `<0.3.0-0`:0.3.x(含预发布)**不在**声明范围内,宿主升级后本插件会被
|
|
69
|
+
`skipping profile bundle` 跳过。**本次没有放宽**——没有在 0.3.x 上做过任何实测,
|
|
70
|
+
不放宽未验证的声明。
|
|
71
|
+
|
|
72
|
+
### 未做(明确记录,不是"已验证")
|
|
73
|
+
|
|
74
|
+
- 真实宿主上的点击级验证(面板渲染、SSE 重连、导出取消分支)**未执行**:GUI 需 launch token,
|
|
75
|
+
本轮无凭据。`host-smoke` 作业与 token 留给有宿主的环境。
|
|
76
|
+
- 跨进程并发写仍保留"锁超时后继续写"的活性优先策略;契约测试里那条并发用例是进程内模拟。
|
|
77
|
+
|
|
78
|
+
## [1.6.0] — 2026-11-14
|
|
79
|
+
|
|
80
|
+
让「按需(auto)」条目第一次真正有机会被执行。此前的 auto 只在会话开头注入一次、措辞是「参考」,
|
|
81
|
+
模型读完第一轮就忘了;而「每次给最终答案前」这类时机,从来没有任何东西提醒过它。
|
|
82
|
+
|
|
83
|
+
### 新增
|
|
84
|
+
|
|
85
|
+
- **触发词提升(`triggers`)**:条目可配置最多 8 个触发词(每项 ≤24 字)。每个真人回合
|
|
86
|
+
(`user/message`,`source.kind === 'user'`)用户话匹配一次,命中即把该条目在本回合提升为
|
|
87
|
+
「本轮强制」,并重新注册 prompt section,使**当轮**注入立刻带上新标记。未配触发词的条目行为不变。
|
|
88
|
+
- **设置页触发词输入**:`mode=auto` 时编辑器多一个触发词输入(回车添加,复用现有标签组件),
|
|
89
|
+
中英双语文案齐备;`memory.schema.json` 同步新增 `triggers` 定义。
|
|
90
|
+
|
|
91
|
+
### 变更(行为)
|
|
92
|
+
|
|
93
|
+
- **auto 的注入语义从「按需」改为「条件必做」**:条目前缀 `[按需|优先级 X]` 改为
|
|
94
|
+
`[条件必做|…]`;场景行 `适用场景:…` 改为 `出现以下情形时必须执行,不得跳过:…`。
|
|
95
|
+
起因是注入块头部那句「[按需] 条目仅在与当前问题或任务相关时生效;不相关时直接忽略」——
|
|
96
|
+
它等于插件自己给了模型一个合法跳过的理由。
|
|
97
|
+
- 伪造前缀中和正则同步扩到 `条件必做`(保留 `按需` 以兼容历史内容)。
|
|
98
|
+
|
|
99
|
+
### 修复
|
|
100
|
+
|
|
101
|
+
- `ctx.on` 在没有事件总线的假宿主(测试与裁剪环境)上会抛 `TypeError`,改为能力检测后再订阅。
|
|
102
|
+
|
|
103
|
+
### 兼容性
|
|
104
|
+
|
|
105
|
+
- 存储格式不变(`version: 2`);新字段缺省为空数组。旧版本读到含 `triggers` 的文件会忽略该字段。
|
|
106
|
+
|
|
10
107
|
## [1.5.7] — 2026-11-14
|
|
11
108
|
|
|
12
109
|
针对**最新版桌面端(`dsh-desktop-runtime 0.2.2-rc.3`,Electron)与网页端**全量审查后的修复轮。
|
package/README.md
CHANGED
|
@@ -64,9 +64,10 @@ profile 的解析顺序是 **`$DSH_PROFILE_DIR` → `--profile <名字>` → `$D
|
|
|
64
64
|
| `ui-test.mjs` | 设置页行为测试:用一个 ~60 行的 React 垫片真实渲染面板、点按钮/填输入框,再断言注入内容随之变化(不出图、不依赖浏览器) |
|
|
65
65
|
| `verify.mjs` | 装载验证:按 DSH 的方式加载两半,并逐项断言 `memory.schema.json` 与代码中的上限一致 |
|
|
66
66
|
| `smoke-test.mjs` | 注入渲染逻辑的单元测试(含「只渲染激活配置集」的隔离断言与 cwd 红线) |
|
|
67
|
-
| `host-range-test.mjs` | 宿主版本范围契约测试:固定矩阵 × 两种 semver
|
|
67
|
+
| `host-range-test.mjs` | 宿主版本范围契约测试:固定矩阵 × 两种 semver 判定模式,把 `peerDependencies`(**被执行的那个**)与 `dsh.engines.dsh` 锁到同一个生成值,并断言第三处副本 `dsh.compatibility.dsh` **不存在**(1.6.1 删除:宿主不读它,留着只会让人以为"改了这里就放宽了兼容") |
|
|
68
|
+
| `section-order-test.mjs` | 注入位置契约测试:从**已安装宿主**(profile 树优先,其次桌面 `app.asar`)读出 `SECTION_ORDERS`,断言 `SECTION_ORDER = 950` 未被占用、严格落在 `FILE_REFERENCE(900)` 与 `TOOL_BASH(1000)` 之间、且紧邻下方仍是 `FILE_REFERENCE`。宿主换表时注入块会**静默移位**,这条断言是唯一护栏 |
|
|
68
69
|
| `lint.mjs` | 静态门禁,已并入 `npm test`:`node --check` 解析所有随包发布与本仓库运行的 JS 文件,并断言 `lib/` 里不出现 `@deepseek-ai/*` 的包名导入(插件只该通过宿主传进来的上下文对象接触宿主,按包名 import 会把插件钉死在某个安装位置,在 headless / CI / 检出目录里直接解析失败) |
|
|
69
|
-
| `live-host-smoke.mjs` | 双端冒烟(**1.4.8 起宿主有鉴权门,需 `--token <启动 token>` 换会话 cookie**,否则全 401):对**正在运行**的 web / 桌面宿主各测 `state` p50/p95、SSE 首事件、注入注册与字符数,并比对两端快照(除 `injection.pulls` 外须逐字段相同);`npm run smoke:hosts`,`--require-pulls` 可把「从未经历真实 Agent 回合」判为失败。单宿主拓扑(桌面应用自己服务 `11685`)用 `--base http://127.0.0.1:11685`,parity 会**显式跳过**而不是假装比过;`--web` / `--desktop` 各选一端,同时给直接报错、零探测时打印 `NO HOST PROBED` 而不是 `ALL CHECKS PASSED`。**刻意不进 `npm test`**——CI
|
|
70
|
+
| `live-host-smoke.mjs` | 双端冒烟(**1.4.8 起宿主有鉴权门,需 `--token <启动 token>` 换会话 cookie**,否则全 401):对**正在运行**的 web / 桌面宿主各测 `state` p50/p95、SSE 首事件、注入注册与字符数,并比对两端快照(除 `injection.pulls` 外须逐字段相同);`npm run smoke:hosts`,`--require-pulls` 可把「从未经历真实 Agent 回合」判为失败。单宿主拓扑(桌面应用自己服务 `11685`)用 `--base http://127.0.0.1:11685`,parity 会**显式跳过**而不是假装比过;`--web` / `--desktop` 各选一端,同时给直接报错、零探测时打印 `NO HOST PROBED` 而不是 `ALL CHECKS PASSED`。**刻意不进 `npm test`**——CI 没有桌面端。1.6.1 起 CI 另有 `workflow_dispatch` 的 `host-smoke` 作业(self-hosted,读 `DSH_GUI_URL` / `DSH_GUI_TOKEN`);缺凭据时它打印 notice 并跳过,不会让 fork 变红。请求走 Node `http` 直连,绕开 `http_proxy`(否则回环请求也会被代理转发,读数虚高) |
|
|
70
71
|
| `docs/demo.html` | 离线演示页:桩掉 DSH 外壳、加载真实 Client 半渲染设置页(1.5.5 起随 npm 包发布,手机上也能直接打开预演布局) |
|
|
71
72
|
| `memory.schema.json` | 手改存储文件用的 JSON Schema(随包发布,并被宿主复制到 `memory.json` 旁边) |
|
|
72
73
|
|
|
@@ -626,6 +627,18 @@ smtp://用户:密码@smtp.example.com:587?secure=0&from=bot@example.com
|
|
|
626
627
|
文件权限请自行收紧(Windows 可用 `icacls feedback.json /inheritance:r /grant:r "%USERNAME%:R"`)。
|
|
627
628
|
凭据缺失时只报"未配置",不会把已配置的密码回显到页面或日志。
|
|
628
629
|
|
|
630
|
+
> **`memory.json` 同理,而且更值得收紧(1.6.1 更正)**:插件写存储时传的是 `0o600`,
|
|
631
|
+
> 但那只在 **POSIX 上是边界**——Windows 文件系统**忽略 `mode`**,文件只是继承目录 ACL。
|
|
632
|
+
> 也就是说 Windows 上"只有你能读"成不成立,取决于 `%USERPROFILE%` 那条 ACL,而不是插件。
|
|
633
|
+
> 多用户共用一台机器时请自己收一次(先备份,再改):
|
|
634
|
+
>
|
|
635
|
+
> ```
|
|
636
|
+
> icacls "%USERPROFILE%\.dsh\instruction-memory\memory.json" /inheritance:r /grant:r "%USERNAME%:(R,W)"
|
|
637
|
+
> icacls "%USERPROFILE%\.dsh\instruction-memory" /inheritance:r /grant:r "%USERNAME%:(OI)(CI)(F)"
|
|
638
|
+
> ```
|
|
639
|
+
>
|
|
640
|
+
> 面板也不会再暗示"已设为 0600"——那是 `open(…, 0o600)` 的解释器参数,不是 Windows 上的权限事实。
|
|
641
|
+
|
|
629
642
|
### 收件邮箱加密(可选)
|
|
630
643
|
|
|
631
644
|
如果不想让收件邮箱以明文留在 `feedback.json` 里(例如担心截图、误提交或备份泄漏),
|
|
@@ -724,6 +737,14 @@ DNS 重绑定恰好推翻了它**:`evil.com` 解析到 `127.0.0.1` 之后,
|
|
|
724
737
|
`Sec-Fetch-Site` 不是 `cross-site`),本插件不再重复判——重复判会把反代域名全部 403;
|
|
725
738
|
没有门时非回环绑定直接 503,根本走不到这里。
|
|
726
739
|
|
|
740
|
+
**没有 `connection` 时,哪些方法还算"只读"(1.6.1 更正)**:写门把方法分成两拨——只读集合
|
|
741
|
+
(`state`、`history-list`、`read-source`、`export-data`)直接放行,其余一律要求浏览器来源标记
|
|
742
|
+
(`Origin` 或 `Sec-Fetch-Site: same-origin`),否则 403。`export-to-dir` 与 `send-feedback`
|
|
743
|
+
**不在**只读集合里:前者往备份目录写文件,后者用**你自己的 SMTP 账号**发信,两者都是需要来源
|
|
744
|
+
确认的写操作。1.6.0 及以前它们被错放进只读集合,等于让本机任意进程(Android 上则是任何装了
|
|
745
|
+
App 的程序)绕过写门发信。`reload` 仍留在只读集合内,这是有意的:它只重读磁盘、首次落盘幂等,
|
|
746
|
+
而桌面壳转发时会剥掉 `Origin`,移出去会让"重新读取"在无门 profile 上直接 403。
|
|
747
|
+
|
|
727
748
|
### 宿主的鉴权门(connection):非回环绑定没有它就直接拒绝
|
|
728
749
|
|
|
729
750
|
路由挂载后会向宿主申请 `connection` 服务(DSH 的 Web / Go 端都提供,负责把浏览器会话换成
|
|
@@ -797,11 +818,15 @@ nginx / Caddy 等反向代理之后远程访问,需要注意:
|
|
|
797
818
|
> 后,"没有 `connection` 服务"直接变成 **503**,而不再退回"仅回环"。桌面单用户机器上回环还能
|
|
798
819
|
> 当边界用;Android 上不能——整机共享回环命名空间,任何装了 App 的程序都能连 127.0.0.1。
|
|
799
820
|
|
|
800
|
-
>
|
|
801
|
-
>
|
|
802
|
-
>
|
|
803
|
-
>
|
|
804
|
-
>
|
|
821
|
+
> **桌面端为什么看不到 `Origin: dsh-app://app`**(1.6.1 更正;2026-11-18 复核桌面壳源码):
|
|
822
|
+
> 桌面窗口的 document origin 确实是 `dsh-app://app`,但主进程只把固定静态路径当资源,
|
|
823
|
+
> **其余所有路径都经 `forwardWebRequest()` 转发到宿主回环端口**,转发前**删掉 `host` /
|
|
824
|
+
> `origin` / `cookie` / `sec-fetch-site` 四个头**,再注入宿主自己的 cookie
|
|
825
|
+
> (`resources/app/lib/main.js` 的 `forwardWebRequest`)。因此到达本插件的请求**没有 `Origin`**,
|
|
826
|
+
> `requestOriginVerdict()` 里"origin 为空即放行"那一条生效——插件的同源判定在桌面端**根本不执行**。
|
|
827
|
+
> 桌面端的真实边界是**回环绑定 + 宿主 cookie**,不是插件自己的 origin 判定。
|
|
828
|
+
> 上一版这里写的"渲染器若改用 `dsh-app://` 会让设置页整片 403"属于推演,**已被证伪**:该
|
|
829
|
+
> scheme 的请求压根到不了插件路由。若将来壳层不再剥离 `Origin`,这一段需要重验。
|
|
805
830
|
|
|
806
831
|
### 在 DSH Go(Android)上:鉴权来自平台补丁,不是本插件
|
|
807
832
|
|
|
@@ -819,22 +844,28 @@ DSH Go 给官方 Web 服务器包了一层**构建期补丁** `runtime/patches/r
|
|
|
819
844
|
|
|
820
845
|
## 兼容性
|
|
821
846
|
|
|
822
|
-
|
|
847
|
+
同一串范围写在**两处**(1.6.1 删掉了无人读取的第三处),而**宿主只强制其中一处**:
|
|
823
848
|
|
|
824
849
|
| 位置 | 谁读它 | 作用 |
|
|
825
850
|
| --- | --- | --- |
|
|
826
|
-
| **`peerDependencies`**(`@deepseek-ai/dsh-system-prompt`) | **宿主**:`evaluatePluginCompatibility()`(`dsh-app-boot`),在**安装**与 **profile 启动**时执行 | **门禁之一**,不是唯一。1.5.7 起两处实测结论必须同时写在这里:① 门禁读的是**宿主自身版本**(`getDshRuntimeVersion()` → `dsh-app-boot` 的 package.json),并用 `{ includePrerelease: true }` 求值,所以预发布行不会被误判;② 在 `0.2.2-rc.3` 的宿主实现里**存在 `engines.dsh` 时 `peerDependencies` 的区间被忽略**(`dsh-app-boot/src/plugin-compatibility.ts:52`)——也就是说这段 peer
|
|
851
|
+
| **`peerDependencies`**(`@deepseek-ai/dsh-system-prompt`) | **宿主**:`evaluatePluginCompatibility()`(`dsh-app-boot`),在**安装**与 **profile 启动**时执行 | **门禁之一**,不是唯一。1.5.7 起两处实测结论必须同时写在这里:① 门禁读的是**宿主自身版本**(`getDshRuntimeVersion()` → `dsh-app-boot` 的 package.json),并用 `{ includePrerelease: true }` 求值,所以预发布行不会被误判;② 在 `0.2.2-rc.3` 的宿主实现里**存在 `engines.dsh` 时 `peerDependencies` 的区间被忽略**(`dsh-app-boot/src/plugin-compatibility.ts:52`)——也就是说这段 peer 区间可能完全不参与判定,只用来在报错时点名。本仓库仍让两处**逐字节同值**(1.6.1 删掉了无人读取的第三处),就是为了不依赖"到底哪一处生效"。这条已从"真正的门禁"更正:**能证明它生效的只有实测,不能靠读声明推断** |
|
|
827
852
|
| `dsh.engines.dsh` | 插件市场(第三方,服务端读取) | 市场卡片上的兼容性判定与展示 |
|
|
828
|
-
|
|
|
853
|
+
| ~~`dsh.compatibility.dsh`~~ | **1.6.1 已删除**:`dsh-app-boot`、`dsh-client-ui-plugin-manager`、`dshmarket` 全树 grep 无读取方 | 曾经只是人类可读的重复声明,留在包里只会让人以为"改了这里就放宽了兼容" |
|
|
829
854
|
|
|
830
855
|
**1.0.14 之前这里只有后两处,没有 `peerDependencies`**——而宿主的门禁在读到缺失的 `peerDependencies` 时会直接 `return undefined`(`if (!Object.hasOwn(fields, "peerDependencies")) return void 0`),也就是**跳过检查**。换句话说,范围之外的宿主在此之前可以装上而**没有任何拦截或警告**;那串范围当时只是市场元数据,不是门禁。1.0.14 补上 peer 之后,它才真正生效。
|
|
831
856
|
|
|
832
|
-
|
|
857
|
+
同一串范围(两处逐字节一致,由 `host-range-test.mjs` 锁定;第三处 `dsh.compatibility.dsh` 已于 1.6.1 删除):
|
|
833
858
|
|
|
834
859
|
```
|
|
835
|
-
>=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-
|
|
860
|
+
>=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-0 <0.1.6-0 || >=0.1.6-alpha.0 <0.1.7-0 || >=0.1.7-alpha.0 <0.2.0-0 || >=0.2.1-alpha.0 <0.3.0-0 || >=0.2.2-alpha.0 <0.3.0-0 || >=0.2.0-0 <0.3.0-0
|
|
836
861
|
```
|
|
837
862
|
|
|
863
|
+
**1.6.1 更正一处机制描述**:上面第 ② 条说的"存在 `engines.dsh` 时 peer 被忽略",读的是
|
|
864
|
+
`package.json` **顶层**的 `engines.dsh`。本包的 `engines` 字段只有 `node`,`engines.dsh` 是写在
|
|
865
|
+
`dsh` 命名空间下的(`dsh.engines.dsh`),宿主**不读**后者。所以在本包当前的写法下,真正生效的
|
|
866
|
+
永远是 `peerDependencies` 那一条;`dsh.engines.dsh` 只是市场卡片用的展示副本。0.1.5 行的下界
|
|
867
|
+
同时从 `>=0.1.5-alpha.1` 改为 `>=0.1.5-0`(旧写法把 `0.1.5-alpha.0` 漏在区间外,是枚举时的一处空洞)。
|
|
868
|
+
|
|
838
869
|
**验证范围与证据等级**——三者不可混为一谈,下面每一行都标了它到底证明了什么:
|
|
839
870
|
|
|
840
871
|
| 等级 | 证明什么 | 覆盖 |
|
package/lib/client.js
CHANGED
|
@@ -273,6 +273,7 @@ window.__ModuleLoader__.load({
|
|
|
273
273
|
'err.httpDetail': '宿主返回 HTTP {status}:{detail}',
|
|
274
274
|
'err.timeout': '请求宿主超时(15 秒无响应)',
|
|
275
275
|
'export.failed': '导出失败:宿主返回了无法识别的数据',
|
|
276
|
+
'import.confirm': '导入会把文件里的配置集、条目与用户形象并入当前记忆:现有内容不会被删除,但你当前的排列会被整体改写。确定继续?',
|
|
276
277
|
'import.notJson': '导入文件不是有效的 JSON({detail})',
|
|
277
278
|
'import.tooLarge': '文件约 {size} MB,远超本插件可导入的规模(约 {limit} MB 以内)。请确认选择的是「导出」生成的 JSON 文件。',
|
|
278
279
|
'editor.new': '新增指令',
|
|
@@ -283,13 +284,14 @@ window.__ModuleLoader__.load({
|
|
|
283
284
|
'editor.contentPlaceholder': '例如:所有回答使用简体中文;不确定需求时先提问再动手。',
|
|
284
285
|
'editor.mode': '生效方式',
|
|
285
286
|
'editor.modeAlways': '始终生效(无条件遵守)',
|
|
286
|
-
'editor.modeAuto': '
|
|
287
|
+
'editor.modeAuto': '条件必做(适用情形出现时必须执行)',
|
|
287
288
|
'editor.priority': '优先级',
|
|
288
289
|
'priority.high': '高',
|
|
289
290
|
'priority.normal': '普通',
|
|
290
291
|
'priority.low': '低',
|
|
291
292
|
'editor.when': '适用场景(可选,帮助模型判断何时生效)',
|
|
292
293
|
'editor.whenPlaceholder': '例如:编写或修改代码时',
|
|
294
|
+
'editor.triggers': '触发词(本回合用户说中即提升为「本轮强制」)',
|
|
293
295
|
'editor.save': '保存',
|
|
294
296
|
'editor.saving': '保存中…',
|
|
295
297
|
'editor.cancel': '取消',
|
|
@@ -311,7 +313,7 @@ window.__ModuleLoader__.load({
|
|
|
311
313
|
'tag.omittedTitle': '因超出注入字数上限,本条当前不会进入系统提示词',
|
|
312
314
|
'tag.truncatedTitle': '本条过长,仅开头部分进入系统提示词',
|
|
313
315
|
'rules.label': '生效规则',
|
|
314
|
-
'rules.note': '
|
|
316
|
+
'rules.note': '「始终」无条件生效;「条件必做」在适用情形出现时必须执行。超出上限时按优先级保留,其余暂不注入。',
|
|
315
317
|
'search.placeholder': '搜索指令:标题 / 内容 / 适用场景(共 {count} 条)',
|
|
316
318
|
'search.matchCount': '匹配 {shown} / {total} 条',
|
|
317
319
|
'tags.label': '标签(可选,仅用于在本页分组与筛选,不会注入提示词)',
|
|
@@ -325,7 +327,7 @@ window.__ModuleLoader__.load({
|
|
|
325
327
|
'filter.mode': '生效方式',
|
|
326
328
|
'filter.status': '状态',
|
|
327
329
|
'filter.modeAlways': '始终',
|
|
328
|
-
'filter.modeAuto': '
|
|
330
|
+
'filter.modeAuto': '条件必做',
|
|
329
331
|
'filter.statusEnabled': '已启用',
|
|
330
332
|
'filter.statusDisabled': '已停用',
|
|
331
333
|
'sort.label': '排序',
|
|
@@ -365,7 +367,7 @@ window.__ModuleLoader__.load({
|
|
|
365
367
|
'profiles.truncatedTitle': '这张形象超过注入字数上限,只有开头进入本轮提示',
|
|
366
368
|
'profiles.omitted': '本轮未包含',
|
|
367
369
|
'profiles.omittedTitle': '这张形象因注入字数上限未进入本轮提示',
|
|
368
|
-
'export.saved': '
|
|
370
|
+
'export.saved': '已请求保存。若保存框被取消、或下载被浏览器/系统拦下,文件不会出现——请重试,或改用下面的「完整 JSON」',
|
|
369
371
|
'export.savedToApp': '已交给 DSH Go 保存:在系统分享面板里选「保存到文件」即可',
|
|
370
372
|
'export.fallbackHint': '当前环境无法触发文件下载,完整 JSON 已放在下面:全选复制后自行保存',
|
|
371
373
|
'export.fallbackClose': '关闭',
|
|
@@ -393,13 +395,13 @@ window.__ModuleLoader__.load({
|
|
|
393
395
|
'list.noMatch': '没有匹配“{query}”的指令。',
|
|
394
396
|
'list.filteredEmpty': '没有符合当前筛选条件的指令。',
|
|
395
397
|
'tag.always': '始终',
|
|
396
|
-
'tag.auto': '
|
|
398
|
+
'tag.auto': '条件必做',
|
|
397
399
|
'entry.enabled': '启用',
|
|
398
400
|
'entry.edit': '编辑',
|
|
399
401
|
'entry.delete': '删除',
|
|
400
402
|
'entry.untitled': '未命名指令',
|
|
401
403
|
'entry.confirmDelete': '确定删除「{title}」?删除后无法恢复。',
|
|
402
|
-
'entry.when': '
|
|
404
|
+
'entry.when': '适用情形:{when}',
|
|
403
405
|
'entry.updatedAt': '更新于 {time}',
|
|
404
406
|
'undo.deleted': '已删除「{title}」',
|
|
405
407
|
'undo.restore': '撤销删除',
|
|
@@ -476,7 +478,7 @@ window.__ModuleLoader__.load({
|
|
|
476
478
|
'feedback.bodyPlaceholder': '复现步骤、期望结果、实际表现;建议请说明使用场景',
|
|
477
479
|
'feedback.contactLabel': '联系方式(可选)',
|
|
478
480
|
'feedback.contactPlaceholder': '邮箱 / 微信 / GitHub 用户名,便于回复你',
|
|
479
|
-
'feedback.hint': '发送时会自动附带插件版本、DSH / Node
|
|
481
|
+
'feedback.hint': '发送时会自动附带插件版本、DSH / Node 版本、运行平台(系统与架构)、界面语言、时区与浏览器标识(User-Agent),不包含你的指令内容。',
|
|
480
482
|
'feedback.send': '发送反馈',
|
|
481
483
|
'feedback.sending': '正在发送…',
|
|
482
484
|
'feedback.clear': '清空',
|
|
@@ -574,6 +576,7 @@ window.__ModuleLoader__.load({
|
|
|
574
576
|
'err.httpDetail': 'Host returned HTTP {status}: {detail}',
|
|
575
577
|
'err.timeout': 'Host request timed out (no response for 15 s)',
|
|
576
578
|
'export.failed': 'Export failed: the host returned unrecognized data',
|
|
579
|
+
'import.confirm': 'Import merges the file’s sets, entries and personas into the current memory: nothing is deleted, but your current arrangement is rewritten. Continue?',
|
|
577
580
|
'import.notJson': 'The import file is not valid JSON ({detail})',
|
|
578
581
|
'import.tooLarge': 'This file is about {size} MB, far beyond what this plugin can import (keep it within about {limit} MB). Make sure you selected a JSON file produced by Export.',
|
|
579
582
|
'editor.new': 'New instruction',
|
|
@@ -591,6 +594,7 @@ window.__ModuleLoader__.load({
|
|
|
591
594
|
'priority.low': 'Low',
|
|
592
595
|
'editor.when': 'Applicable scenarios (optional; helps the model decide when it applies)',
|
|
593
596
|
'editor.whenPlaceholder': 'e.g. When writing or modifying code',
|
|
597
|
+
'editor.triggers': 'Trigger words (promote to 本轮强制 when the user says one)',
|
|
594
598
|
'editor.save': 'Save',
|
|
595
599
|
'editor.saving': 'Saving…',
|
|
596
600
|
'editor.cancel': 'Cancel',
|
|
@@ -666,7 +670,7 @@ window.__ModuleLoader__.load({
|
|
|
666
670
|
'profiles.truncatedTitle': 'This persona exceeds the injection limit; only its head reached this turn',
|
|
667
671
|
'profiles.omitted': 'Not in this turn',
|
|
668
672
|
'profiles.omittedTitle': 'This persona was dropped by the injection limit and did not reach this turn',
|
|
669
|
-
'export.saved': '
|
|
673
|
+
'export.saved': 'Save requested. If you cancelled the dialog or the download was blocked, no file is written — retry, or use the full JSON below',
|
|
670
674
|
'export.savedToApp': 'Handed to DSH Go — pick “Save to Files” in the system share sheet',
|
|
671
675
|
'export.fallbackHint': 'This environment cannot start a file download; the full JSON is below — select all and copy it',
|
|
672
676
|
'export.fallbackClose': 'Close',
|
|
@@ -777,7 +781,7 @@ window.__ModuleLoader__.load({
|
|
|
777
781
|
'feedback.bodyPlaceholder': 'Steps to reproduce, expected result, actual result; for a suggestion, describe the use case',
|
|
778
782
|
'feedback.contactLabel': 'Contact (optional)',
|
|
779
783
|
'feedback.contactPlaceholder': 'Email / WeChat / GitHub handle so the maintainer can reply',
|
|
780
|
-
'feedback.hint': 'The mail automatically includes the plugin version, DSH / Node versions and
|
|
784
|
+
'feedback.hint': 'The mail automatically includes the plugin version, DSH / Node versions, platform (OS and arch), interface locale, time zone and browser User-Agent — never your instruction content.',
|
|
781
785
|
'feedback.send': 'Send feedback',
|
|
782
786
|
'feedback.sending': 'Sending…',
|
|
783
787
|
'feedback.clear': 'Clear',
|
|
@@ -1087,6 +1091,7 @@ window.__ModuleLoader__.load({
|
|
|
1087
1091
|
content: entry.content,
|
|
1088
1092
|
mode: entry.mode,
|
|
1089
1093
|
when: entry.when,
|
|
1094
|
+
triggers: Array.isArray(entry.triggers) ? entry.triggers.slice(0, 8) : [],
|
|
1090
1095
|
priority: entry.priority,
|
|
1091
1096
|
enabled: entry.enabled,
|
|
1092
1097
|
tags: Array.isArray(entry.tags) ? entry.tags.slice() : [],
|
|
@@ -1119,7 +1124,7 @@ window.__ModuleLoader__.load({
|
|
|
1119
1124
|
}
|
|
1120
1125
|
|
|
1121
1126
|
function blankDraft() {
|
|
1122
|
-
return { id: '', title: '', content: '', mode: 'always', when: '', priority: 1, enabled: true, tags: [], updatedAt: 0 }
|
|
1127
|
+
return { id: '', title: '', content: '', mode: 'always', when: '', priority: 1, enabled: true, tags: [], triggers: [], updatedAt: 0 }
|
|
1123
1128
|
}
|
|
1124
1129
|
|
|
1125
1130
|
/**
|
|
@@ -1810,6 +1815,17 @@ window.__ModuleLoader__.load({
|
|
|
1810
1815
|
onChange: (ev) => set({ when: ev.target.value }),
|
|
1811
1816
|
})))
|
|
1812
1817
|
}
|
|
1818
|
+
if (draft.mode === 'auto') {
|
|
1819
|
+
children.push(h('div', { key: 'tr' },
|
|
1820
|
+
h('label', { className: 'im-label', htmlFor: 'im-entry-triggers' }, t('editor.triggers')),
|
|
1821
|
+
h(TagInput, {
|
|
1822
|
+
inputId: 'im-entry-triggers',
|
|
1823
|
+
tags: Array.isArray(draft.triggers) ? draft.triggers : [],
|
|
1824
|
+
limits: props.limits,
|
|
1825
|
+
disabled: props.busy,
|
|
1826
|
+
onChange: (next) => set({ triggers: next }),
|
|
1827
|
+
})))
|
|
1828
|
+
}
|
|
1813
1829
|
children.push(h('div', { key: 'tags' },
|
|
1814
1830
|
h('label', { className: 'im-label', htmlFor: 'im-entry-tags' }, t('tags.label')),
|
|
1815
1831
|
h(TagInput, {
|
|
@@ -2876,6 +2892,16 @@ window.__ModuleLoader__.load({
|
|
|
2876
2892
|
setError(t('import.notJson', { detail: String(err && err.message ? err.message : err) }))
|
|
2877
2893
|
return
|
|
2878
2894
|
}
|
|
2895
|
+
// 1.6.1: the whole-store restore above asks first; import did not, so
|
|
2896
|
+
// a file someone handed the user could become the instructions
|
|
2897
|
+
// injected into every later turn with no confirmation at all. Same
|
|
2898
|
+
// ask, same fallback semantics: with no dialog available, refuse
|
|
2899
|
+
// rather than merge silently.
|
|
2900
|
+
const askImport = askConfirm(t('import.confirm'))
|
|
2901
|
+
if (askImport !== CONFIRM_YES) {
|
|
2902
|
+
if (askImport === CONFIRM_UNAVAILABLE) setError(t('confirm.unavailable'))
|
|
2903
|
+
return
|
|
2904
|
+
}
|
|
2879
2905
|
await send('import-data', { payload, baseRev: revOf() })
|
|
2880
2906
|
} catch (err) {
|
|
2881
2907
|
setError(String(err && err.message ? err.message : err))
|
package/lib/index.js
CHANGED
|
@@ -171,7 +171,16 @@ const API_PREFIX = '/instruction-memory/api'
|
|
|
171
171
|
* unusable behind a reverse proxy that forwards the public `Host` (nginx's
|
|
172
172
|
* default `proxy_set_header Host $host`). Listing the published hostname here
|
|
173
173
|
* re-opens exactly that one name and nothing else: the loopback rule still
|
|
174
|
-
* applies to everything else
|
|
174
|
+
* applies to everything else.
|
|
175
|
+
*
|
|
176
|
+
* What it does NOT do is weaken the per-request checks — but those checks are
|
|
177
|
+
* narrower than an earlier version of this comment claimed. `Origin` and
|
|
178
|
+
* `Sec-Fetch-Site` exist only when a browser reaches the route directly. The
|
|
179
|
+
* desktop shell forwards every non-static path through `forwardWebRequest`,
|
|
180
|
+
* which deletes `origin`, `sec-fetch-site`, `host` and `cookie` and injects the
|
|
181
|
+
* host's own cookie (resources/app/lib/main.js). On a desktop the origin rule
|
|
182
|
+
* therefore never runs, and the boundary is the loopback bind plus whatever
|
|
183
|
+
* `connection` enforces.
|
|
175
184
|
*/
|
|
176
185
|
const TRUSTED_HOSTS_ENV = 'DSH_INSTRUCTION_MEMORY_TRUSTED_HOSTS'
|
|
177
186
|
/**
|
|
@@ -553,6 +562,31 @@ export function sanitizeTags(raw) {
|
|
|
553
562
|
return out
|
|
554
563
|
}
|
|
555
564
|
|
|
565
|
+
/** Trigger words per entry, matched against the user's own words every turn. */
|
|
566
|
+
const MAX_TRIGGERS = 8
|
|
567
|
+
const MAX_TRIGGER_LENGTH = 24
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Normalise one entry's `triggers`: the phrases that promote the entry to
|
|
571
|
+
* 「本轮强制」 when they appear in the user's message this turn. Same rules as
|
|
572
|
+
* tags — single line, whitespace collapsed, de-duplicated, capped — because
|
|
573
|
+
* they are matched case-insensitively against prose the user actually typed.
|
|
574
|
+
*/
|
|
575
|
+
export function sanitizeTriggers(raw) {
|
|
576
|
+
if (!Array.isArray(raw)) return []
|
|
577
|
+
const out = []
|
|
578
|
+
const seen = new Set()
|
|
579
|
+
for (const item of raw) {
|
|
580
|
+
if (typeof item !== 'string') continue
|
|
581
|
+
const trigger = singleLine(item, MAX_TRIGGER_LENGTH).replace(/\s+/g, ' ').trim()
|
|
582
|
+
if (trigger === '' || seen.has(trigger)) continue
|
|
583
|
+
seen.add(trigger)
|
|
584
|
+
if (out.length >= MAX_TRIGGERS) break
|
|
585
|
+
out.push(trigger)
|
|
586
|
+
}
|
|
587
|
+
return out
|
|
588
|
+
}
|
|
589
|
+
|
|
556
590
|
export function sanitizeEntry(raw) {
|
|
557
591
|
if (raw === null || typeof raw !== 'object') return null
|
|
558
592
|
const title = singleLine(raw.title, MAX_TITLE)
|
|
@@ -567,6 +601,7 @@ export function sanitizeEntry(raw) {
|
|
|
567
601
|
priority: raw.priority === 2 || raw.priority === 0 ? raw.priority : 1,
|
|
568
602
|
enabled: raw.enabled !== false,
|
|
569
603
|
tags: sanitizeTags(raw.tags),
|
|
604
|
+
triggers: sanitizeTriggers(raw.triggers),
|
|
570
605
|
/**
|
|
571
606
|
* Which instruction set (F13) this entry belongs to. Preserved here — NOT
|
|
572
607
|
* re-derived — because both the loader and the importer need to honour a
|
|
@@ -1503,7 +1538,7 @@ function requestPortOf(hostHeader) {
|
|
|
1503
1538
|
* longer equal the token the model was told to trust.
|
|
1504
1539
|
*/
|
|
1505
1540
|
const FORGED_HEADING = /^([ \t]*)(#{1,6})([ \t]*)(用户长期指令记忆|关于用户(用户形象)|关于用户|用户形象)/gm
|
|
1506
|
-
const FORGED_ENTRY_PREFIX = /^([ \t]*)\[(
|
|
1541
|
+
const FORGED_ENTRY_PREFIX = /^([ \t]*)\[(始终|条件必做|按需)(|优先级)/gm
|
|
1507
1542
|
|
|
1508
1543
|
function neutralizeForgedStructure(value) {
|
|
1509
1544
|
if (typeof value !== 'string' || value === '') return value
|
|
@@ -1536,7 +1571,7 @@ const MEMORY_ENVELOPE_CLOSE = '\n</user-instruction-memory>'
|
|
|
1536
1571
|
|
|
1537
1572
|
function formatEntry(entry, tag) {
|
|
1538
1573
|
const lines = ['[' + tag + '|优先级 ' + priorityLabel(entry.priority) + '] ' + entry.title]
|
|
1539
|
-
if (entry.mode === 'auto' && entry.when !== '') lines.push('
|
|
1574
|
+
if (entry.mode === 'auto' && entry.when !== '') lines.push('出现以下情形时必须执行,不得跳过:' + entry.when)
|
|
1540
1575
|
lines.push(neutralizeForgedStructure(entry.content))
|
|
1541
1576
|
return lines.join('\n')
|
|
1542
1577
|
}
|
|
@@ -1671,6 +1706,8 @@ export function entryOmittedFooter(count) {
|
|
|
1671
1706
|
* trimming. Kept as the inner function so planInjection can prepend the
|
|
1672
1707
|
* persona section without touching (and risking) the trimming logic.
|
|
1673
1708
|
*/
|
|
1709
|
+
let FORCED_IDS = new Set() // 本轮命中 triggers 的条目 id,由 turn/start 监听器写入。
|
|
1710
|
+
|
|
1674
1711
|
function planEntries(data, budget) {
|
|
1675
1712
|
const blank = () => ({ text: '', activeCount: 0, included: [], omitted: [] })
|
|
1676
1713
|
if (data === null || typeof data !== 'object' || data.enabled !== true) return blank()
|
|
@@ -1687,13 +1724,13 @@ function planEntries(data, budget) {
|
|
|
1687
1724
|
'## 用户长期指令记忆(Instruction Memory)',
|
|
1688
1725
|
'以下条目由用户在 DSH 设置 →「指令记忆」中长期保存,属于本次及后续所有对话的既有要求,请在回答、推理与执行任务时遵守;它们不覆盖系统与安全规则。',
|
|
1689
1726
|
'· [始终] 条目必须无条件遵守。',
|
|
1690
|
-
'· [
|
|
1727
|
+
'· [条件必做] 条目在「适用情形」出现时必须执行;跳过须在回答中说明原因。',
|
|
1691
1728
|
'· 条目之间冲突时,优先遵守优先级更高或更具体的一条;无法判断时向用户确认。',
|
|
1692
1729
|
'',
|
|
1693
1730
|
].join('\n'),
|
|
1694
1731
|
[
|
|
1695
1732
|
'## 用户长期指令记忆(Instruction Memory)',
|
|
1696
|
-
'[始终] 条目无条件遵守;[
|
|
1733
|
+
'[始终] 条目无条件遵守;[条件必做] 条目在适用情形出现时必须执行。',
|
|
1697
1734
|
'',
|
|
1698
1735
|
].join('\n'),
|
|
1699
1736
|
'## 用户长期指令记忆\n',
|
|
@@ -1748,7 +1785,7 @@ function planEntries(data, budget) {
|
|
|
1748
1785
|
}
|
|
1749
1786
|
|
|
1750
1787
|
for (const entry of active) if (entry.mode === 'always') consider(entry, '始终')
|
|
1751
|
-
for (const entry of active) if (entry.mode !== 'always') consider(entry, '
|
|
1788
|
+
for (const entry of active) if (entry.mode !== 'always') consider(entry, FORCED_IDS.has(entry.id) ? '本轮强制' : '条件必做')
|
|
1752
1789
|
|
|
1753
1790
|
if (blocks.length === 0) {
|
|
1754
1791
|
return { text: '', budget, activeCount: active.length, included: [], omitted: omittedPlan }
|
|
@@ -2365,6 +2402,76 @@ export function apply(ctx, deps = {}) {
|
|
|
2365
2402
|
disposeStreams()
|
|
2366
2403
|
})
|
|
2367
2404
|
|
|
2405
|
+
/* ---------------- turn-triggered promotion ---------------- */
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* Promote entries whose `triggers` appear in THIS turn's user message to
|
|
2409
|
+
* 「本轮强制」. Without this the auto mode is only advisory: the model reads
|
|
2410
|
+
* 「条件必做」 at turn one and has forgotten it by the time the work is done.
|
|
2411
|
+
* Matching runs on the user's own words rather than on the model's judgement,
|
|
2412
|
+
* so a missed instruction becomes a plugin bug instead of a compliance
|
|
2413
|
+
* failure. No triggers configured = no promotion, i.e. the old behaviour.
|
|
2414
|
+
*/
|
|
2415
|
+
let forcedSignature = ''
|
|
2416
|
+
const refreshSection = () => {
|
|
2417
|
+
if (disposed) return
|
|
2418
|
+
if (sectionDispose === null) {
|
|
2419
|
+
syncSection()
|
|
2420
|
+
return
|
|
2421
|
+
}
|
|
2422
|
+
const dispose = sectionDispose
|
|
2423
|
+
sectionDispose = null
|
|
2424
|
+
try {
|
|
2425
|
+
dispose()
|
|
2426
|
+
} catch (err) {
|
|
2427
|
+
console.error('[instruction-memory] section refresh dispose failed:', err)
|
|
2428
|
+
}
|
|
2429
|
+
syncSection()
|
|
2430
|
+
}
|
|
2431
|
+
const recomputeForced = (text) => {
|
|
2432
|
+
const list = Array.isArray(state.data.entries) ? state.data.entries : []
|
|
2433
|
+
const lower = String(text || '').toLowerCase()
|
|
2434
|
+
const hit = new Set()
|
|
2435
|
+
for (const entry of list) {
|
|
2436
|
+
if (entry.enabled !== true || entry.mode !== 'auto') continue
|
|
2437
|
+
const triggers = Array.isArray(entry.triggers) ? entry.triggers : []
|
|
2438
|
+
for (const trigger of triggers) {
|
|
2439
|
+
if (typeof trigger === 'string' && trigger !== ''
|
|
2440
|
+
&& lower.includes(trigger.toLowerCase())) {
|
|
2441
|
+
hit.add(entry.id)
|
|
2442
|
+
break
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
const signature = Array.from(hit).sort().join(',')
|
|
2447
|
+
if (signature === forcedSignature) return
|
|
2448
|
+
forcedSignature = signature
|
|
2449
|
+
FORCED_IDS = hit
|
|
2450
|
+
logDebug('forced promotion: ' + (signature === '' ? 'none' : signature))
|
|
2451
|
+
refreshSection()
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
const onSessionEvent = (session, event) => {
|
|
2455
|
+
try {
|
|
2456
|
+
if (disposed || !event || typeof event.type !== 'string') return
|
|
2457
|
+
if (event.type !== 'user/message') return
|
|
2458
|
+
const data = event.data || {}
|
|
2459
|
+
const source = data.source || {}
|
|
2460
|
+
// Only human input promotes. runtime-context, notices and plugin messages
|
|
2461
|
+
// are not the user asking for anything.
|
|
2462
|
+
const kind = typeof source.kind === 'string' ? source.kind : ''
|
|
2463
|
+
if (kind !== '' && kind !== 'user') return
|
|
2464
|
+
const text = typeof data.text === 'string' ? data.text
|
|
2465
|
+
: (typeof data.content === 'string' ? data.content : '')
|
|
2466
|
+
if (text === '') return
|
|
2467
|
+
recomputeForced(text)
|
|
2468
|
+
} catch (err) {
|
|
2469
|
+
console.error('[instruction-memory] trigger match failed:', err)
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
// Fake hosts (tests) may expose no event bus; the plugin must still mount.
|
|
2473
|
+
if (typeof ctx.on === 'function') ctx.on('session/event', onSessionEvent)
|
|
2474
|
+
|
|
2368
2475
|
/* ---------------- external-change watching (SSE) ---------------- */
|
|
2369
2476
|
|
|
2370
2477
|
/**
|
|
@@ -3054,8 +3161,12 @@ export function apply(ctx, deps = {}) {
|
|
|
3054
3161
|
const existing = await readFile(target, 'utf8').catch(() => null)
|
|
3055
3162
|
if (existing !== source) {
|
|
3056
3163
|
// Atomic like the store itself: a crash mid-copy must not leave a
|
|
3057
|
-
// truncated schema for the user's editor to validate against
|
|
3058
|
-
//
|
|
3164
|
+
// truncated schema for the user's editor to validate against. The 0600
|
|
3165
|
+
// bit matches every other file this plugin writes, and on POSIX that is
|
|
3166
|
+
// the whole story. On Windows `mode` is ignored by the filesystem: the
|
|
3167
|
+
// file simply inherits the directory's ACLs, so the bit is a POSIX
|
|
3168
|
+
// convenience, never a Windows permission boundary. See the icacls note
|
|
3169
|
+
// in the README before treating this store as private on a shared box.
|
|
3059
3170
|
const tmp = target + '.tmp-' + randomUUID()
|
|
3060
3171
|
try {
|
|
3061
3172
|
await writeFile(tmp, source, { encoding: 'utf8', mode: 0o600 })
|
|
@@ -5920,8 +6031,22 @@ export function apply(ctx, deps = {}) {
|
|
|
5920
6031
|
* Set DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1 to make the whole route fail
|
|
5921
6032
|
* closed instead of falling back to these two rules.
|
|
5922
6033
|
*/
|
|
6034
|
+
/**
|
|
6035
|
+
* Methods that are safe to serve with no gate in front of them: they return
|
|
6036
|
+
* what is already in memory and write nothing the user would not have
|
|
6037
|
+
* written themselves.
|
|
6038
|
+
*
|
|
6039
|
+
* 1.6.1 removed two entries that were never read-only and quietly widened the
|
|
6040
|
+
* fallback above into "any local process may do this without an origin":
|
|
6041
|
+
* `export-to-dir` creates a file in the backup directory, and `send-feedback`
|
|
6042
|
+
* sends mail through the operator's own SMTP account (throttled to one send
|
|
6043
|
+
* per cooldown, but that is a rate limit, not an authorisation). `reload` was
|
|
6044
|
+
* left in on purpose: it re-reads the store and materialises the default one
|
|
6045
|
+
* on first use, which is idempotent, and the panel needs it on a host whose
|
|
6046
|
+
* forwarding layer strips `Origin` (see TRUSTED_HOSTS above).
|
|
6047
|
+
*/
|
|
5923
6048
|
const READ_ONLY_METHODS = new Set([
|
|
5924
|
-
'state', 'history-list', 'read-source', 'export-data',
|
|
6049
|
+
'state', 'history-list', 'read-source', 'export-data',
|
|
5925
6050
|
])
|
|
5926
6051
|
|
|
5927
6052
|
const writeGateRefusal = (method, headers) => {
|
package/memory.schema.json
CHANGED
|
@@ -115,7 +115,13 @@
|
|
|
115
115
|
"description": "是否启用该条目。",
|
|
116
116
|
"default": true
|
|
117
117
|
},
|
|
118
|
-
"
|
|
118
|
+
"triggers": {
|
|
119
|
+
"type": "array",
|
|
120
|
+
"maxItems": 8,
|
|
121
|
+
"items": { "type": "string", "maxLength": 24 },
|
|
122
|
+
"description": "触发词:本回合用户消息中出现其一即把该条提升为「本轮强制」;仅 mode=auto 有意义,留空则从不提升。"
|
|
123
|
+
},
|
|
124
|
+
"tags": {
|
|
119
125
|
"type": "array",
|
|
120
126
|
"maxItems": 8,
|
|
121
127
|
"description": "标签:仅用于设置页分组与筛选,**不会**进入注入文本,也不影响注入顺序与取舍。",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-instruction-memory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "User-only instruction memory for DSH: long-term instructions maintained in the settings UI and auto-injected into every conversation — the plugin registers no model-facing tool, so the model has no in-plugin write path (a same-permission process can still edit the file directly). 指令记忆:只由用户在设置页维护的长期指令,自动注入此后每轮对话;插件不注册任何面向模型的工具,模型没有插件内的写入口。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"node": ">=20"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@deepseek-ai/dsh-system-prompt": ">=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-
|
|
55
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-0 <0.1.6-0 || >=0.1.6-alpha.0 <0.1.7-0 || >=0.1.7-alpha.0 <0.2.0-0 || >=0.2.1-alpha.0 <0.3.0-0 || >=0.2.2-alpha.0 <0.3.0-0 || >=0.2.0-0 <0.3.0-0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@deepseek-ai/dsh-system-prompt": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"author": "huangpeiyan",
|
|
66
66
|
"scripts": {
|
|
67
67
|
"lint": "node lint.mjs",
|
|
68
|
-
"test": "node lint.mjs && node host-range-test.mjs && node smoke-test.mjs && node contract-test.mjs && node verify.mjs && node feedback-test.mjs && node ui-test.mjs",
|
|
68
|
+
"test": "node lint.mjs && node host-range-test.mjs && node section-order-test.mjs && node smoke-test.mjs && node contract-test.mjs && node verify.mjs && node feedback-test.mjs && node ui-test.mjs",
|
|
69
69
|
"prepublishOnly": "node check-metadata.mjs && npm test",
|
|
70
70
|
"smoke:hosts": "node live-host-smoke.mjs"
|
|
71
71
|
},
|
|
@@ -81,10 +81,7 @@
|
|
|
81
81
|
"platform": "web"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
|
-
"dsh": ">=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-
|
|
85
|
-
},
|
|
86
|
-
"compatibility": {
|
|
87
|
-
"dsh": ">=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-alpha.1 <0.1.6-0 || >=0.1.6-alpha.0 <0.1.7-0 || >=0.1.7-alpha.0 <0.2.0-0 || >=0.2.1-alpha.0 <0.3.0-0 || >=0.2.2-alpha.0 <0.3.0-0 || >=0.2.0-0 <0.3.0-0"
|
|
84
|
+
"dsh": ">=0.1.3-alpha.2 <0.1.4 || >=0.1.4-0 <0.1.5-0 || >=0.1.5-0 <0.1.6-0 || >=0.1.6-alpha.0 <0.1.7-0 || >=0.1.7-alpha.0 <0.2.0-0 || >=0.2.1-alpha.0 <0.3.0-0 || >=0.2.2-alpha.0 <0.3.0-0 || >=0.2.0-0 <0.3.0-0"
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
}
|