dsh-instruction-memory 1.6.2 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/README.md +60 -22
- package/lib/client.js +81 -14
- package/lib/index.js +6753 -6382
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,101 @@
|
|
|
7
7
|
> 1.0.13 起由 CI 经 OIDC Trusted Publishing 发布(首个带 provenance 的版本)。
|
|
8
8
|
> 这些历史 tag **不应回填**——npm 上的版本号已被占用。
|
|
9
9
|
|
|
10
|
+
## [1.6.3] — 2026-11-20
|
|
11
|
+
|
|
12
|
+
第三轮审计(技术方案评审团:架构 / 应用安全 / 验收三条线)的修复批次。**一条阻断级缺陷**:
|
|
13
|
+
v1.6.0 的头号功能「触发词 → 本轮强制」在真实宿主上是死代码,桌面端与网页端同时失效;
|
|
14
|
+
`npm test` 全绿(1065 PASS)与机制不可用并存,因为整个套件里没有任何一条用例用过宿主真实
|
|
15
|
+
发送的消息形状。
|
|
16
|
+
|
|
17
|
+
### 修复(阻断)
|
|
18
|
+
|
|
19
|
+
- **触发词取不到文本,功能从未触发**。`lib/index.js` 的 `user/message` 处理器读
|
|
20
|
+
`event.data.text`,而宿主交给插件的是**消息对象本身**——`{ id, role, content:
|
|
21
|
+
ContentBlock[], source }`(`dsh-llm` 的 `MessageBase`;`dsh-session` 里
|
|
22
|
+
`event.type === 'user/message' ? data : data.message`)。`text` 因此在真机上恒为空,
|
|
23
|
+
处理器在 `text === ''` 处直接 return,只有手工构造 `{ text }` 的夹具能触发。现在按
|
|
24
|
+
`content` 的 text 块拼接(保留两种字符串回退供夹具与旧宿主使用)。
|
|
25
|
+
- **提升赶不上本轮第一个请求**。宿主 `preStep()` 先 `systemPrompt.assemble()`、
|
|
26
|
+
`step()` 里才 `append('user/message')`,而 section 文本在 assemble 时就已求值。所以即使
|
|
27
|
+
上面那条修好,无工具调用的单步回合也拿不到提升。**文案已按事实更正**:标注与注释统一为
|
|
28
|
+
「从命中之后的下一次注入开始生效,不追溯已发出的请求,到本回合结束为止」,不再宣称「当轮
|
|
29
|
+
立刻生效」。
|
|
30
|
+
|
|
31
|
+
### 修复(安全)
|
|
32
|
+
|
|
33
|
+
- **无 `connection` 服务的 profile 默认停用写操作(fail-closed)**。v1.6.2 的写门判据是
|
|
34
|
+
「请求像不像浏览器」(`Origin` 或 `Sec-Fetch-Site: same-origin`),而这两个头都由调用方
|
|
35
|
+
自带——注释自己写着"只加一行 `Sec-Fetch-Site: same-origin` 即从 403 变 200"。这条路径能
|
|
36
|
+
改写每轮注入的指令,等于把持久化提示注入放在一个自证头之后。现在没有宿主 `connection`
|
|
37
|
+
服务时,所有修改方法一律 503(读操作照常,设置页可打开查看);单用户设备可显式
|
|
38
|
+
`DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1` 恢复旧的宽松判据(重启生效)。
|
|
39
|
+
设置页会读取快照里的 `security.writeGate`(`fence` / `opt-in` / `refused`)**在用户动手
|
|
40
|
+
之前**就把这件事说出来。
|
|
41
|
+
- **`reload` 真正只读**。它列在只读集合里,但 `readFromDisk()` 的 `.bak` 提升分支会
|
|
42
|
+
`writeToDisk()`——一个被归为"读"的方法能落盘。现在 `reload` 传 `write: false`:备份被载入
|
|
43
|
+
内存、注入照常,但写回留给下一次真实保存,且 `saved` 恒为 `false`(字段含义保持"本次操作
|
|
44
|
+
是否持久化了存储")。
|
|
45
|
+
- **导入 / 整体恢复 / 迁移旧文件的确认从客户端移到宿主**。v1.6.1 只加了面板对话框,任何能
|
|
46
|
+
通过写门的调用方都可以不经确认直接 POST 同一份 payload,而导入的条目会保留 `triggers`
|
|
47
|
+
与 `when`——配合 1.6.0 的语义,一行文本就能变成"每轮必执行"。现在
|
|
48
|
+
`import-data` / `restore-data` / `adopt-legacy` 要求 `args.confirm === true`,面板在用户
|
|
49
|
+
同意后发送该字段;确认文案也补上了"会保留触发词"这一句。
|
|
50
|
+
- **`本轮强制` 纳入防伪造白名单**。`FORGED_ENTRY_PREFIX` 只列了「始终 / 条件必做 / 按需」,
|
|
51
|
+
而 1.6.0 开始输出「本轮强制」——条目正文里手写的同名行可以原样通过,读起来与本插件自己的
|
|
52
|
+
结构行完全一样。标签列表改为 `ENTRY_TAGS` 一处定义,"打印的标签 ⊆ 中立化的标签"这条不变式
|
|
53
|
+
由测试逐项枚举。
|
|
54
|
+
- **临时文件改为独占创建(`wx`)**。`.bak` 提升或重试路径会用 `open(tmpPath, 'w')` 在原路径
|
|
55
|
+
重建临时文件;同一路径若被放置符号链接,会写到链接目标。`ensureSchemaFile` 同型。
|
|
56
|
+
- **请求体并发上限**。单个请求体有上限,但同时在途的数量没有,同用户进程可以并行打开多个大包
|
|
57
|
+
压宿主堆。现在最多 8 个在途(`MAX_BODY_IN_FLIGHT`),按"仍在累积字节"计时,body 读完即
|
|
58
|
+
释放,不会让慢写饿死面板自己的 `state` 轮询。
|
|
59
|
+
|
|
60
|
+
### 修复(正确性 / 可观测)
|
|
61
|
+
|
|
62
|
+
- **`FORCED_IDS` 不再是模块级全局**。它被同进程内所有会话共享,A 会话命中触发词会把该条在
|
|
63
|
+
B 会话里也提升为「本轮强制」(实测:同进程两个实例,驱动 A 的监听器,A 与 B 同时变红);
|
|
64
|
+
且全文没有任何回合结束清理,提升会一直残留。现在按会话键存 `Map`,`turn/end` /
|
|
65
|
+
`turn/abort` 清理;section 渲染时从装配上下文取会话键,取不到才回退到"最近一次",因此单
|
|
66
|
+
会话宿主行为不变。上下文明确给出会话时,无记录即"该会话没有提升",绝不借用别人的。
|
|
67
|
+
- **提升只作用于激活集合**。匹配与键都改用 `setId\0id`(库内其它地方一致的去重键),排序前先
|
|
68
|
+
过 `activeScope`/`inScope`:非激活集合里的触发词不再能改写激活集合的同 id 条目(F13)。
|
|
69
|
+
- **`refreshSection` 不再 dispose + 重注册**。section 文本本来就是活 thunk,每次装配都会被
|
|
70
|
+
重新求值,重注册既多余又危险:它发生在 `session/event` 处理器里(与当轮装配并发),且
|
|
71
|
+
dispose 抛异常时句柄已被置空,`syncSection()` 会再注册一份而旧的仍然活着——同一 prompt 里
|
|
72
|
+
两份记忆块。现在只做 `syncSection()`(处理呈现/移除边沿)与快照推送。
|
|
73
|
+
- **`injection.forced`**:快照发布当前被提升的条目 id,面板不再"标签变了但界面什么都不说"。
|
|
74
|
+
- **`maxTriggers` / `maxTriggerLength` 进入 `limits`**:面板此前硬编码 `slice(0, 8)` 并复用
|
|
75
|
+
标签上限,8/24 与标签上限相等只是数值巧合。schema 与代码的两侧漂移也进了 `verify.mjs` 的
|
|
76
|
+
比对清单。
|
|
77
|
+
- **客户端能区分桌面壳**(`location.protocol === 'dsh-app:'`)。桌面导出此前没有分支,全部落
|
|
78
|
+
通用 `blob:` 下载,而宿主的下载处理只认自己标记的链接——现在桌面导出会同时给出"完整 JSON"
|
|
79
|
+
这条保底通道,不再声称文件一定落地。
|
|
80
|
+
|
|
81
|
+
### 测试
|
|
82
|
+
|
|
83
|
+
- `contract-test.mjs`:新增真实 `user/message` 形状用例组(真实形状提升、另一会话不继承、
|
|
84
|
+
`turn/end` 回落、非人类来源不提升、扁平 `{ text }` 兼容、同一条目只出现一次提升标签);
|
|
85
|
+
新增 `desktop + fence` 形状(无 `Origin`、无 `Sec-Fetch-Site`、注入 cookie、门放行 → 写
|
|
86
|
+
必须 200)——此前只测了"桌面 + 无 connection"这种出厂 profile 不存在的组合;
|
|
87
|
+
新增 fence-less 默认 fail-closed 的六条断言(写 503、伪造单头无效、读仍 200);
|
|
88
|
+
`READ_ONLY_METHODS` 的源码钉改为 `METHOD_KINDS` 表 + 与 dispatch switch 的**双向**差集断言。
|
|
89
|
+
- `smoke-test.mjs`:四种标签(含「本轮强制」)逐项枚举中立化;`planInjection` 的 forced 参数
|
|
90
|
+
与跨集合键的用例。
|
|
91
|
+
- `section-order-test.mjs`:候选集加入**未打包安装**(本机 `app.asar` 已改名,真正在跑的是
|
|
92
|
+
`resources/app/dsh` 的 0.2.2-rc.5);无宿主时打印 `SKIPPED` 而不是 `ALL PASS`,CI 不再把
|
|
93
|
+
"什么都没断言"计成绿。
|
|
94
|
+
- `verify.mjs`:`triggers.maxItems` / `trigger.maxLength` 进入 schema ↔ 代码漂移比对。
|
|
95
|
+
|
|
96
|
+
### 已知边界
|
|
97
|
+
|
|
98
|
+
- 「本轮强制」的生效时机是**下一次注入**(原:当轮)。若要做到真正的同回合,需要把提升改由
|
|
99
|
+
runtime-context provider 承载,并在 `agent/pre-step` waterfall 里用本轮消息计算——那是宿主
|
|
100
|
+
侧装配顺序的改动,需要单独验证,本版只把语义写诚实。
|
|
101
|
+
- 插件仍不注册任何面向模型的工具,模型没有"被注入后自己调用工具持久化"的写入面。
|
|
102
|
+
- `reload`、`state`、`read-source` 仍会物化一份**本插件自己的默认空 store**(首次运行、设置页
|
|
103
|
+
打开时),但物化内容从不是调用方给的。
|
|
104
|
+
|
|
10
105
|
## [1.6.2] — 2026-11-19
|
|
11
106
|
|
|
12
107
|
第二轮增量审计(桌面端 runtime 已升到 0.2.2-rc.5)的修复批次,主体是**修 1.6.1 自己引入的一个
|
package/README.md
CHANGED
|
@@ -74,7 +74,13 @@ profile 的解析顺序是 **`$DSH_PROFILE_DIR` → `--profile <名字>` → `$D
|
|
|
74
74
|
## 生效方式
|
|
75
75
|
|
|
76
76
|
- **始终** 条目:无条件遵守。
|
|
77
|
-
-
|
|
77
|
+
- **条件必做** 条目(旧称「按需」):在「适用情形」出现时必须执行,跳过须在回答中说明原因。
|
|
78
|
+
它不再是"由模型自行决定是否相关"——1.6.0 起这个退出语义已经取消。
|
|
79
|
+
- **本轮强制**:条件必做条目可以填**触发词**(最多 8 个、单个不超过 24 字符)。本回合用户消息里
|
|
80
|
+
出现任一触发词时,该条目在**下一次注入**中带上 `[本轮强制]` 前缀,效力等同条件必做、优先级
|
|
81
|
+
更高;之后一轮若没有再命中就退回条件必做,回合结束也会清除。
|
|
82
|
+
**生效时机是"下一次注入",不是"当轮"**:宿主先装配系统提示词、再追加用户消息,所以命中发生在
|
|
83
|
+
本轮提示词定稿之后,已发出的请求不会被追溯改写(无工具调用的单步回合因此要到下一次请求才看到)。
|
|
78
84
|
- **优先级** 高 > 普通 > 低,决定注入顺序。
|
|
79
85
|
- **注入字数上限**:超出时按优先级保留,被略过的条目数会在注入文本末尾注明。
|
|
80
86
|
上限单位是**字符**而非 token——按 DeepSeek 官方分词比例约 1 个中文字符 ≈ 0.6 token、
|
|
@@ -87,8 +93,9 @@ profile 的解析顺序是 **`$DSH_PROFILE_DIR` → `--profile <名字>` → `$D
|
|
|
87
93
|
存储格式不变,旧宿主/旧客户端对新字段一律忽略,互不影响。
|
|
88
94
|
- **标签、筛选与排序**:每条指令可加若干**标签**(回车或逗号添加,最多 8 个、单个不超过 24 字符)。
|
|
89
95
|
标签只用于设置页分组与筛选,**不会进入注入文本**;标签缺失的旧记忆照常加载(等同无标签)。
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
列表可按标签、生效方式(始终/条件必做)、启用状态组合筛选,并在「按优先级 / 按更新时间 / 按标题」
|
|
97
|
+
之间切换排序;列表排序纯为查看方便,不改变宿主侧的注入顺序。被触发词提升的条目,列表会依据快照里
|
|
98
|
+
的 `injection.forced` 标出「本轮强制」。
|
|
92
99
|
- **批量操作**:点「批量操作」进入多选,可对勾选条目一次性启用、停用、设置优先级、加标签或删除;
|
|
93
100
|
多选与上方的筛选/搜索叠加(「全选」只作用于当前可见条目)。整批修改在宿主侧是**单次写入**
|
|
94
101
|
(只产生一次落盘、一次修订号递增与一次同步推送),全部条目已是目标状态时不写盘;批量删除需确认。
|
|
@@ -414,6 +421,11 @@ DSH 就会得到第二份空记忆,看起来像"记忆消失"。相对的 `$DS
|
|
|
414
421
|
选择本插件导出的文件,确认后**整体替换**当前记忆。同样是"可反悔"的——替换前的内容已经在
|
|
415
422
|
`.bak` 与版本历史里。
|
|
416
423
|
|
|
424
|
+
> **改版后回退到旧版本之前,先「导出」一份 JSON。** 1.6.0 给条目加了 `triggers` 字段,
|
|
425
|
+
> 而 1.5.7 及更早的 `sanitizeEntry` 不认识它——白名单重建会把该字段**丢掉**(读取本身不报错,
|
|
426
|
+
> 所以丢得没有声音)。存储格式版本没有变,因此文件能打开,只是触发词在回退后就没了。导出的
|
|
427
|
+
> JSON 可原样再导入回来。
|
|
428
|
+
|
|
417
429
|
## 手改与 JSON Schema(F15)
|
|
418
430
|
|
|
419
431
|
随包发布一份 `memory.schema.json`(JSON Schema draft-07),描述版本 1/2 两种文件形状与全部
|
|
@@ -477,19 +489,21 @@ DSH 就会得到第二份空记忆,看起来像"记忆消失"。相对的 `$DS
|
|
|
477
489
|
**不要同步存储目录本身**(`memory.json`)——两台机器同时写入会互相覆盖,插件那套
|
|
478
490
|
rev 冲突检测与写锁都只在同一台机器内有效。换机器时用「导出 → 另一台导入/恢复」。
|
|
479
491
|
|
|
480
|
-
##
|
|
492
|
+
## 条件必做条目的本地预演(F17)
|
|
481
493
|
|
|
482
|
-
|
|
483
|
-
|
|
494
|
+
「条件必做」条目(旧称「按需」)到底会不会被采纳,本质上是模型的判断,插件看不到也猜不准。
|
|
495
|
+
设置页提供一个**本地预演**:输入一句当前任务描述,前端**纯字面关键词**匹配各条条目的
|
|
484
496
|
「适用场景 / 标题 / 内容」(场景权重最高、正文最低),列出字面重合度较高的条目并给出
|
|
485
497
|
高/中/低分档,同时在列表里给这些条目打上「预演·高/中/低」标记。
|
|
486
498
|
|
|
487
|
-
|
|
499
|
+
它的用途只有一个:**帮你把「适用情形」写清楚、预判取舍**(例如"没写场景的条目只能靠正文
|
|
488
500
|
碰运气"、"这条优先级低、一旦超出字数上限会先被丢下")。因此:
|
|
489
501
|
|
|
490
502
|
- 措辞是克制的:界面上明确写着**「本地预演 ≠ 模型的真实判断」**,它不参与注入,也不代表模型
|
|
491
503
|
实际会不会采纳;`verify.mjs` 断言了这句免责声明在两种语言里都存在。
|
|
492
|
-
-
|
|
504
|
+
- 预演只做启发式打分,与**触发词提升是两条独立机制**:触发词是确定性的字面命中(由宿主判定),
|
|
505
|
+
预演只是给你看的参考。1.6.0 起"不相关就可以忽略"的退出语义已取消,未命中触发词的条件必做
|
|
506
|
+
条目仍然是"适用情形出现时必须执行"。
|
|
493
507
|
- 匹配是启发式的:中文按 2/3 字滑窗切词(无分词依赖),英文/数字按词切分,术语上限 40 个,
|
|
494
508
|
纯前端计算、不发任何请求。
|
|
495
509
|
|
|
@@ -740,19 +754,28 @@ content-type 校验兜底;在**没有**门的 profile 里,1.6.1 起「写方
|
|
|
740
754
|
`Sec-Fetch-Site` 不是 `cross-site`),本插件不再重复判——重复判会把反代域名全部 403;
|
|
741
755
|
没有门时非回环绑定直接 503,根本走不到这里。
|
|
742
756
|
|
|
743
|
-
**没有 `connection` 时,哪些方法还算"只读"(1.6.
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
757
|
+
**没有 `connection` 时,哪些方法还算"只读"(1.6.3 口径)**:写门依据**一张表**(`METHOD_KINDS`)
|
|
758
|
+
分拨——只读方法(`state`、`history-list`、`read-source`、`export-data`、`reload`)直接放行,
|
|
759
|
+
其余在 1.6.3 起**默认一律 503**(见下一段)。`export-to-dir` 与 `send-feedback` **不在**只读
|
|
760
|
+
集合里:前者往备份目录写文件,后者用**你自己的 SMTP 账号**发信,两者都是需要来源确认的写操作。
|
|
761
|
+
1.6.0 及以前它们被错放进只读集合,等于让本机任意进程(Android 上则是任何装了 App 的程序)
|
|
762
|
+
绕过写门发信;1.6.1 修复时又把 `reload` 一并误删,1.6.2 已放回。1.6.3 起 `reload` 是**真只读**:
|
|
763
|
+
`readFromDisk` 的 `.bak` 提升分支(会 `writeToDisk`)在 `reload` 路径上被跳过,写回留给下一次
|
|
764
|
+
真实保存,`saved` 恒为 `false`。
|
|
765
|
+
|
|
766
|
+
**1.6.3:无门 profile 的写操作默认停用(fail-closed)**。之前那套"浏览器来源标记"判据对同机
|
|
767
|
+
进程不设防——`Origin` 与 `Sec-Fetch-Site` 都是普通请求头,本机任何进程都能自带一个(实测:加
|
|
768
|
+
一行 `Sec-Fetch-Site: same-origin` 就把 403 变成 200),而这条路径能改写此后每一轮注入的指令,
|
|
769
|
+
等于把持久化提示注入放在一个自证头之后。所以现在:
|
|
770
|
+
|
|
771
|
+
- 没有 `connection` 服务时,**所有修改方法返回 503**,拒绝文案说明原因;读操作照常,设置页能
|
|
772
|
+
打开查看。设置页读取快照里的 `security.writeGate`(`fence` / `opt-in` / `refused`),在用户
|
|
773
|
+
动手之前就把这件事显示出来。
|
|
774
|
+
- 单用户设备(Android / DSH Go / 沙箱)若接受该暴露面,设
|
|
775
|
+
`DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1` 后重启,恢复原来的来源标记判据(仍只挡
|
|
776
|
+
浏览器跨站,不是身份校验)。
|
|
777
|
+
- 真正的边界仍是宿主的 `connection` 服务;或设 `DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1`
|
|
778
|
+
让整条路由 fail-closed(连只读方法都是 503)。
|
|
756
779
|
|
|
757
780
|
### 宿主的鉴权门(connection):非回环绑定没有它就直接拒绝
|
|
758
781
|
|
|
@@ -770,8 +793,23 @@ profile 的写入对**同机进程**不设防;真正的边界是宿主的 `con
|
|
|
770
793
|
早先没有这一条,把服务器绑到局域网地址(`--host <具体 IP>`)的机器等于把"改写此后每一轮
|
|
771
794
|
注入内容"的写入口敞开给整个局域网。设置页在这种状态下会直接显示这条 503 的原因,而不是装作存储是空的。
|
|
772
795
|
|
|
773
|
-
###
|
|
796
|
+
### 无鉴权写的显式开关(`DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES`)
|
|
797
|
+
|
|
798
|
+
1.6.3 起,**没有 `connection` 服务的 profile 默认拒绝所有修改方法**(503)。这是默认行为,
|
|
799
|
+
不需要任何环境变量。只有当你在单用户设备上明确接受"同机任意进程也能写"的暴露面、并希望设置页
|
|
800
|
+
恢复可写时,才设:
|
|
774
801
|
|
|
802
|
+
```bash
|
|
803
|
+
# 单用户设备 / 沙箱 / Android,接受该风险时才设
|
|
804
|
+
DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
设了之后恢复的是 v1.6.2 的判据:修改请求必须带浏览器来源标记(`Origin` 或
|
|
808
|
+
`Sec-Fetch-Site: same-origin`)。**它仍然不是身份校验**——两个头本机进程也能自带。要真正的
|
|
809
|
+
边界,请让宿主提供 `connection` 服务,或设 `DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1`
|
|
810
|
+
让整条路由 fail-closed。
|
|
811
|
+
|
|
812
|
+
### 可信主机名(`DSH_INSTRUCTION_MEMORY_TRUSTED_HOSTS`)
|
|
775
813
|
> ⚠️ 这一项**只放宽主机名校验,不提供任何身份认证**。在没有宿主 `connection` 服务的 profile
|
|
776
814
|
> 上,如果一个反代把请求转成"合法主机名",这条路由就是无登录可读写的。面板在该组合
|
|
777
815
|
> (`security.hostGuarded=false`、`security.authFence=false`、`trustedHostCount>0`)下会显示
|
package/lib/client.js
CHANGED
|
@@ -273,7 +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
|
+
'import.confirm': '导入会把文件里的配置集、条目与用户形象并入当前记忆:现有内容不会被删除,但你当前的排列会被整体改写。注意导入的条目会保留其「触发词」与「适用情形」——一旦命中,该条目会在下一次注入中变成「本轮强制」。确定继续?',
|
|
277
277
|
'import.notJson': '导入文件不是有效的 JSON({detail})',
|
|
278
278
|
'import.tooLarge': '文件约 {size} MB,远超本插件可导入的规模(约 {limit} MB 以内)。请确认选择的是「导出」生成的 JSON 文件。',
|
|
279
279
|
'editor.new': '新增指令',
|
|
@@ -319,6 +319,7 @@ window.__ModuleLoader__.load({
|
|
|
319
319
|
'tags.label': '标签(可选,仅用于在本页分组与筛选,不会注入提示词)',
|
|
320
320
|
'tags.placeholder': '输入标签后回车,逗号分隔多个,例如:代码规范',
|
|
321
321
|
'tags.hint': '每条最多 {max} 个标签,单个不超过 {len} 字符',
|
|
322
|
+
'triggers.hint': '每条最多 {max} 个触发词,单个不超过 {len} 字符;用户消息里出现任一触发词时,该条目在下一次注入中临时提升为「本轮强制」',
|
|
322
323
|
'tags.remove': '移除标签 {tag}',
|
|
323
324
|
'tags.duplicate': '已有同名标签',
|
|
324
325
|
'tags.full': '每条最多 {max} 个标签',
|
|
@@ -370,6 +371,7 @@ window.__ModuleLoader__.load({
|
|
|
370
371
|
'export.saved': '已请求保存。若保存框被取消、或下载被浏览器/系统拦下,文件不会出现——请重试,或改用下面的「完整 JSON」',
|
|
371
372
|
'export.savedToApp': '已交给 DSH Go 保存:在系统分享面板里选「保存到文件」即可',
|
|
372
373
|
'export.fallbackHint': '当前环境无法触发文件下载,完整 JSON 已放在下面:全选复制后自行保存',
|
|
374
|
+
'export.desktopHint': '桌面端:已尝试用浏览器下载通道保存,但宿主的下载处理只接管自身标记的链接,插件无法确认文件是否落地。下面的「完整 JSON」是保底通道——若下载目录里没有文件,请全选复制后自行保存。',
|
|
373
375
|
'export.fallbackClose': '关闭',
|
|
374
376
|
'import.webviewHint': 'Android / WebView 上若文件选择器不弹出,请改用「源码模式」粘贴 JSON',
|
|
375
377
|
'sse.down': '实时更新已断开(连续重试仍失败),数据可能是旧的:请点「重新载入」',
|
|
@@ -436,6 +438,7 @@ window.__ModuleLoader__.load({
|
|
|
436
438
|
'diag.copied': '诊断信息已复制到剪贴板',
|
|
437
439
|
'diag.copyManual': '自动复制不可用;请手动全选复制下方文本。',
|
|
438
440
|
'diag.hostWarn': '安全提示:设置路由当前绑定在非回环地址({host}),同一网络内的设备可以无鉴权访问此页面,请勿在不可信网络暴露;如需对外发布,请阅读 README 的「经反向代理对外发布」。',
|
|
441
|
+
'diag.writeRefused': '写操作已停用:当前 profile 没有宿主的 connection 会话鉴权门。没有该门时,插件无法区分「设置页发出的请求」与「本机任意进程伪造的请求」,因此保存、导入、删除等修改一律返回 503(读取不受影响)。请让宿主提供 connection 服务;单用户设备可用环境变量 DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1 显式恢复(重启后生效)。',
|
|
439
442
|
'diag.hostWarnFence': '安全提示:设置路由当前绑定在非回环地址({host}),但宿主鉴权门已挂载——访问仍需登录 DSH 后的浏览器会话,未登录请求会被 401/403 拒绝;仍建议只在可信网络暴露。',
|
|
440
443
|
'diag.hostWarnTrusted': '安全提示:设置路由绑定在非回环地址({host}),且宿主没有发布鉴权服务;当前唯一放行条件是你配置的 {count} 个可信主机名——那只放宽主机名校验,不提供任何身份认证。请仅在可信网络暴露,或改用隧道方案。',
|
|
441
444
|
'diag.groupStorage': '存储',
|
|
@@ -576,7 +579,7 @@ window.__ModuleLoader__.load({
|
|
|
576
579
|
'err.httpDetail': 'Host returned HTTP {status}: {detail}',
|
|
577
580
|
'err.timeout': 'Host request timed out (no response for 15 s)',
|
|
578
581
|
'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?',
|
|
582
|
+
'import.confirm': 'Import merges the file’s sets, entries and personas into the current memory: nothing is deleted, but your current arrangement is rewritten. Imported entries keep their trigger words and conditions — once one matches, that entry becomes 本轮强制 on the next injection. Continue?',
|
|
580
583
|
'import.notJson': 'The import file is not valid JSON ({detail})',
|
|
581
584
|
'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.',
|
|
582
585
|
'editor.new': 'New instruction',
|
|
@@ -622,6 +625,7 @@ window.__ModuleLoader__.load({
|
|
|
622
625
|
'tags.label': 'Tags (optional; used only for grouping/filtering on this page, never injected)',
|
|
623
626
|
'tags.placeholder': 'Type a tag and press Enter; separate several with commas, e.g. code-style',
|
|
624
627
|
'tags.hint': 'Up to {max} tags per entry, each at most {len} characters',
|
|
628
|
+
'triggers.hint': 'Up to {max} trigger words per entry, each at most {len} characters; when a user message contains one, the entry is promoted to 本轮强制 for the next injection',
|
|
625
629
|
'tags.remove': 'Remove tag {tag}',
|
|
626
630
|
'tags.duplicate': 'This tag already exists',
|
|
627
631
|
'tags.full': 'Up to {max} tags per entry',
|
|
@@ -673,6 +677,7 @@ window.__ModuleLoader__.load({
|
|
|
673
677
|
'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',
|
|
674
678
|
'export.savedToApp': 'Handed to DSH Go — pick “Save to Files” in the system share sheet',
|
|
675
679
|
'export.fallbackHint': 'This environment cannot start a file download; the full JSON is below — select all and copy it',
|
|
680
|
+
'export.desktopHint': 'Desktop: the browser download path was attempted, but the host only claims its own marked links, so the plugin cannot confirm a file landed. The full JSON below is the guaranteed route — if nothing appeared in your downloads, copy it from there.',
|
|
676
681
|
'export.fallbackClose': 'Close',
|
|
677
682
|
'import.webviewHint': 'On Android / WebView, if the file picker does not open, paste the JSON into “Source mode” instead',
|
|
678
683
|
'sse.down': 'Live updates stopped (retries kept failing) and the data may be stale — click “Reload”',
|
|
@@ -739,6 +744,7 @@ window.__ModuleLoader__.load({
|
|
|
739
744
|
'diag.copied': 'Diagnostics copied to the clipboard',
|
|
740
745
|
'diag.copyManual': 'Automatic copy is unavailable; select and copy the text below manually.',
|
|
741
746
|
'diag.hostWarn': 'Security notice: the settings route is bound to a non-loopback address ({host}); other devices on the same network can reach this page without authentication. Do not expose it on an untrusted network — for public deployments read “Publishing behind a reverse proxy” in the README.',
|
|
747
|
+
'diag.writeRefused': 'Writes are disabled: this profile has no host `connection` authentication fence. Without it the plugin cannot tell "the settings page sent this" from "any local process forged this", so saves, imports and deletes all answer 503 (reads still work). Let the host provide the connection service, or — on a single-user device — set DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1 and restart.',
|
|
742
748
|
'diag.hostWarnFence': 'Security notice: the settings route is bound to a non-loopback address ({host}), but the host authentication fence is attached — access still requires a signed-in DSH browser session, and unauthenticated requests are refused with 401/403. Keep it on a trusted network anyway.',
|
|
743
749
|
'diag.hostWarnTrusted': 'Security notice: the settings route is bound to a non-loopback address ({host}) and the host publishes no authentication service; the only thing letting requests in is your {count} trusted hostname(s) — that relaxes a hostname check, it does not authenticate anyone. Keep it on a trusted network or use a tunnel.',
|
|
744
750
|
'diag.groupStorage': 'Storage',
|
|
@@ -995,6 +1001,16 @@ window.__ModuleLoader__.load({
|
|
|
995
1001
|
// keep the editor usable against an older Host that predates them.
|
|
996
1002
|
const MAX_TAGS = 8
|
|
997
1003
|
const MAX_TAG_LEN = 24
|
|
1004
|
+
/**
|
|
1005
|
+
* v1.6.0's trigger list had its own ceilings in the host
|
|
1006
|
+
* (`MAX_TRIGGERS`/`MAX_TRIGGER_LENGTH`). They equal the tag ceilings today,
|
|
1007
|
+
* but that was a numerical coincidence, not a contract: the editor used to
|
|
1008
|
+
* slice at a hard-coded 8 and reuse the tag caps, so changing either host
|
|
1009
|
+
* limit would leave the panel silently disagreeing with the loader. These
|
|
1010
|
+
* two defaults only stand in for a host that predates the published limits.
|
|
1011
|
+
*/
|
|
1012
|
+
const MAX_TRIGGERS = 8
|
|
1013
|
+
const MAX_TRIGGER_LEN = 24
|
|
998
1014
|
const DEFAULT_MAX_TITLE = 120
|
|
999
1015
|
const DEFAULT_MAX_CONTENT = 6000
|
|
1000
1016
|
const DEFAULT_MAX_WHEN = 200
|
|
@@ -1019,9 +1035,22 @@ window.__ModuleLoader__.load({
|
|
|
1019
1035
|
maxWhen: pick('maxWhen', DEFAULT_MAX_WHEN),
|
|
1020
1036
|
maxTags: pick('maxTagsPerEntry', MAX_TAGS),
|
|
1021
1037
|
maxTagLength: pick('maxTagLength', MAX_TAG_LEN),
|
|
1038
|
+
maxTriggers: pick('maxTriggers', MAX_TRIGGERS),
|
|
1039
|
+
maxTriggerLength: pick('maxTriggerLength', MAX_TRIGGER_LEN),
|
|
1022
1040
|
}
|
|
1023
1041
|
}
|
|
1024
1042
|
|
|
1043
|
+
/**
|
|
1044
|
+
* The same ceilings, selected for the box being rendered: tags and trigger
|
|
1045
|
+
* words share the parsing rules but not the limits.
|
|
1046
|
+
*/
|
|
1047
|
+
function capsFor(limits, kind) {
|
|
1048
|
+
const caps = fieldLimitsOf(limits)
|
|
1049
|
+
return kind === 'triggers'
|
|
1050
|
+
? { ...caps, maxTags: caps.maxTriggers, maxTagLength: caps.maxTriggerLength }
|
|
1051
|
+
: caps
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1025
1054
|
/**
|
|
1026
1055
|
* Parse free text typed into the tag box into normalised tag candidates.
|
|
1027
1056
|
* Tags are split on commas (ASCII/full-width), semicolons and newlines —
|
|
@@ -1030,9 +1059,9 @@ window.__ModuleLoader__.load({
|
|
|
1030
1059
|
* the count cap. Both caps come from the snapshot when supplied. Pinned as
|
|
1031
1060
|
* a pure export.
|
|
1032
1061
|
*/
|
|
1033
|
-
function parseTagInput(text, limits) {
|
|
1062
|
+
function parseTagInput(text, limits, kind) {
|
|
1034
1063
|
if (typeof text !== 'string') return []
|
|
1035
|
-
const caps =
|
|
1064
|
+
const caps = capsFor(limits, kind)
|
|
1036
1065
|
const out = []
|
|
1037
1066
|
const seen = new Set()
|
|
1038
1067
|
for (const piece of text.split(/[,,;;\n\r]+/)) {
|
|
@@ -1091,7 +1120,7 @@ window.__ModuleLoader__.load({
|
|
|
1091
1120
|
content: entry.content,
|
|
1092
1121
|
mode: entry.mode,
|
|
1093
1122
|
when: entry.when,
|
|
1094
|
-
triggers: Array.isArray(entry.triggers) ? entry.triggers.slice(0,
|
|
1123
|
+
triggers: Array.isArray(entry.triggers) ? entry.triggers.slice(0, MAX_TRIGGERS) : [],
|
|
1095
1124
|
priority: entry.priority,
|
|
1096
1125
|
enabled: entry.enabled,
|
|
1097
1126
|
tags: Array.isArray(entry.tags) ? entry.tags.slice() : [],
|
|
@@ -1822,6 +1851,7 @@ window.__ModuleLoader__.load({
|
|
|
1822
1851
|
inputId: 'im-entry-triggers',
|
|
1823
1852
|
tags: Array.isArray(draft.triggers) ? draft.triggers : [],
|
|
1824
1853
|
limits: props.limits,
|
|
1854
|
+
kind: 'triggers',
|
|
1825
1855
|
disabled: props.busy,
|
|
1826
1856
|
onChange: (next) => set({ triggers: next }),
|
|
1827
1857
|
})))
|
|
@@ -1853,7 +1883,8 @@ window.__ModuleLoader__.load({
|
|
|
1853
1883
|
function TagInput(props) {
|
|
1854
1884
|
const [text, setText] = React.useState('')
|
|
1855
1885
|
const tags = Array.isArray(props.tags) ? props.tags : []
|
|
1856
|
-
const
|
|
1886
|
+
const kind = props.kind === 'triggers' ? 'triggers' : 'tags'
|
|
1887
|
+
const caps = capsFor(props.limits, kind)
|
|
1857
1888
|
const merge = (pieces) => {
|
|
1858
1889
|
const merged = []
|
|
1859
1890
|
for (const tag of [...tags, ...pieces]) {
|
|
@@ -1862,7 +1893,7 @@ window.__ModuleLoader__.load({
|
|
|
1862
1893
|
props.onChange(merged.slice(0, caps.maxTags))
|
|
1863
1894
|
}
|
|
1864
1895
|
const commit = () => {
|
|
1865
|
-
const parsed = parseTagInput(text, props.limits)
|
|
1896
|
+
const parsed = parseTagInput(text, props.limits, kind)
|
|
1866
1897
|
if (parsed.length > 0) merge(parsed)
|
|
1867
1898
|
setText('')
|
|
1868
1899
|
}
|
|
@@ -1897,7 +1928,7 @@ window.__ModuleLoader__.load({
|
|
|
1897
1928
|
// v is the input's full new value (it already contains what was
|
|
1898
1929
|
// typed before the separator) — do NOT prepend `text`, that
|
|
1899
1930
|
// duplicated it ("b" + "b," -> "bb").
|
|
1900
|
-
const parsed = parseTagInput(v, props.limits)
|
|
1931
|
+
const parsed = parseTagInput(v, props.limits, kind)
|
|
1901
1932
|
if (parsed.length > 0) merge(parsed)
|
|
1902
1933
|
setText('')
|
|
1903
1934
|
} else {
|
|
@@ -1914,7 +1945,10 @@ window.__ModuleLoader__.load({
|
|
|
1914
1945
|
},
|
|
1915
1946
|
onBlur: commit,
|
|
1916
1947
|
}),
|
|
1917
|
-
h('div', { className: 'im-meta' },
|
|
1948
|
+
h('div', { className: 'im-meta' },
|
|
1949
|
+
kind === 'triggers'
|
|
1950
|
+
? t('triggers.hint', { max: caps.maxTags, len: caps.maxTagLength })
|
|
1951
|
+
: t('tags.hint', { max: caps.maxTags, len: caps.maxTagLength })))
|
|
1918
1952
|
}
|
|
1919
1953
|
|
|
1920
1954
|
/**
|
|
@@ -2680,7 +2714,7 @@ window.__ModuleLoader__.load({
|
|
|
2680
2714
|
|
|
2681
2715
|
function adoptLegacy() {
|
|
2682
2716
|
if (busy) return
|
|
2683
|
-
void send('adopt-legacy', { baseRev: revOf() })
|
|
2717
|
+
void send('adopt-legacy', { baseRev: revOf(), confirm: true })
|
|
2684
2718
|
}
|
|
2685
2719
|
|
|
2686
2720
|
function dismissLegacy() {
|
|
@@ -2712,7 +2746,7 @@ window.__ModuleLoader__.load({
|
|
|
2712
2746
|
setError(t('import.notJson', { detail: String(err && err.message ? err.message : err) }))
|
|
2713
2747
|
return
|
|
2714
2748
|
}
|
|
2715
|
-
await send('restore-data', { payload, baseRev: revOf() })
|
|
2749
|
+
await send('restore-data', { payload, baseRev: revOf(), confirm: true })
|
|
2716
2750
|
} catch (err) {
|
|
2717
2751
|
setError(String(err && err.message ? err.message : err))
|
|
2718
2752
|
}
|
|
@@ -2791,6 +2825,26 @@ window.__ModuleLoader__.load({
|
|
|
2791
2825
|
}
|
|
2792
2826
|
}
|
|
2793
2827
|
|
|
2828
|
+
/**
|
|
2829
|
+
* The Electron desktop shell.
|
|
2830
|
+
*
|
|
2831
|
+
* `dsh-app://` is the protocol the renderer is loaded from, so this is a
|
|
2832
|
+
* direct observation rather than a user-agent guess — until 1.6.3 the
|
|
2833
|
+
* panel had NO desktop branch at all: every export fell through to the
|
|
2834
|
+
* generic `blob:` download, while the host's `will-download` handler only
|
|
2835
|
+
* recognises `#dsh-download=` URLs and leaves the rest to Chromium's
|
|
2836
|
+
* default policy, which the page cannot observe. That is why the desktop
|
|
2837
|
+
* export now also offers the in-panel copy instead of claiming a file.
|
|
2838
|
+
*/
|
|
2839
|
+
function isDesktopShell() {
|
|
2840
|
+
try {
|
|
2841
|
+
return typeof location !== 'undefined' && typeof location.protocol === 'string'
|
|
2842
|
+
&& location.protocol === 'dsh-app:'
|
|
2843
|
+
} catch {
|
|
2844
|
+
return false
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2794
2848
|
/**
|
|
2795
2849
|
* Hand `text` to the DSH Go island bridge, in chunks that fit its 16 KB
|
|
2796
2850
|
* message cap (`IslandMessageLimits.maxBytes`). The app reassembles them
|
|
@@ -2861,7 +2915,15 @@ window.__ModuleLoader__.load({
|
|
|
2861
2915
|
link.click()
|
|
2862
2916
|
if (link.parentNode !== null) link.parentNode.removeChild(link)
|
|
2863
2917
|
setTimeout(() => { URL.revokeObjectURL(url) }, 1000)
|
|
2864
|
-
|
|
2918
|
+
if (isDesktopShell()) {
|
|
2919
|
+
// The desktop host cannot confirm this landed: its download handler
|
|
2920
|
+
// only claims `#dsh-download=` URLs, and a blob click is Chromium's
|
|
2921
|
+
// business. Offer the guaranteed route and say what was attempted.
|
|
2922
|
+
setExportFallback(text)
|
|
2923
|
+
setNotice(t('export.desktopHint'))
|
|
2924
|
+
} else {
|
|
2925
|
+
setNotice(t('export.saved'))
|
|
2926
|
+
}
|
|
2865
2927
|
} catch (err) {
|
|
2866
2928
|
setError(String(err && err.message ? err.message : err))
|
|
2867
2929
|
}
|
|
@@ -2902,7 +2964,7 @@ window.__ModuleLoader__.load({
|
|
|
2902
2964
|
if (askImport === CONFIRM_UNAVAILABLE) setError(t('confirm.unavailable'))
|
|
2903
2965
|
return
|
|
2904
2966
|
}
|
|
2905
|
-
await send('import-data', { payload, baseRev: revOf() })
|
|
2967
|
+
await send('import-data', { payload, baseRev: revOf(), confirm: true })
|
|
2906
2968
|
} catch (err) {
|
|
2907
2969
|
setError(String(err && err.message ? err.message : err))
|
|
2908
2970
|
}
|
|
@@ -3092,7 +3154,7 @@ window.__ModuleLoader__.load({
|
|
|
3092
3154
|
// known problem" — an absent field must not manufacture a warning.
|
|
3093
3155
|
const security = view.security !== null && typeof view.security === 'object'
|
|
3094
3156
|
? view.security
|
|
3095
|
-
: { hostGuarded: true, boundHost: '' }
|
|
3157
|
+
: { hostGuarded: true, boundHost: '', writeGate: 'fence' }
|
|
3096
3158
|
// List order is display-only and never changes what the Host injects
|
|
3097
3159
|
// (the injection order is decided host-side). Sorting, filtering and the
|
|
3098
3160
|
// keyword scan all happen once, inside the memoised deriveListState.
|
|
@@ -3334,6 +3396,11 @@ window.__ModuleLoader__.load({
|
|
|
3334
3396
|
? t('diag.hostWarnTrusted', { host: security.boundHost !== '' ? security.boundHost : '?', count: security.trustedHostCount })
|
|
3335
3397
|
: t('diag.hostWarn', { host: security.boundHost !== '' ? security.boundHost : '?' }))
|
|
3336
3398
|
: null,
|
|
3399
|
+
// 1.6.3: a fence-less profile refuses every mutating method by default,
|
|
3400
|
+
// so a save button would fail only AFTER the user typed. Say it before.
|
|
3401
|
+
security.writeGate === 'refused'
|
|
3402
|
+
? h('div', { className: 'im-hostwarn', key: 'writewarn' }, t('diag.writeRefused'))
|
|
3403
|
+
: null,
|
|
3337
3404
|
h('div', { className: 'im-row' },
|
|
3338
3405
|
h('div', null,
|
|
3339
3406
|
h('h3', { className: 'im-h' }, t('panel.title')),
|