dsh-instruction-memory 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,70 @@
7
7
  > 1.0.13 起由 CI 经 OIDC Trusted Publishing 发布(首个带 provenance 的版本)。
8
8
  > 这些历史 tag **不应回填**——npm 上的版本号已被占用。
9
9
 
10
+ ## [1.6.2] — 2026-11-19
11
+
12
+ 第二轮增量审计(桌面端 runtime 已升到 0.2.2-rc.5)的修复批次,主体是**修 1.6.1 自己引入的一个
13
+ 回归**,以及让测试真正覆盖"桌面壳转发"这种请求形状。
14
+
15
+ ### 修复(1.6.1 的回归)
16
+
17
+ - **`reload` 放回 `READ_ONLY_METHODS`**。1.6.1 把 `export-to-dir` / `send-feedback` 移出只读集合时
18
+ 连 `reload` 一起删掉了,而同一提交的注释、CHANGELOG、README、提交信息**四处**都写着"reload 有意
19
+ 保留"。触发条件是「桌面壳转发(必然剥掉 `Origin` 与 `Sec-Fetch-Site`)+ profile 没有
20
+ `connection` 服务」,此时面板「重新载入」会永久 403。本机 3080 有 `connection` 门,所以线上看不
21
+ 见——这正是它需要一条**不带 origin** 的用例才抓得住的原因。
22
+
23
+ ### 修复(说明与事实不符)
24
+
25
+ - **写门的注释与拒绝文案**。原文称 `Sec-Fetch-Site` "script cannot set it",并告诉用户
26
+ "本机脚本 / curl 的写入会被拒绝"。两者都错:`Origin` 与 `Sec-Fetch-Site` 是普通请求头,本机任何
27
+ 进程都能自带一个(实测加一行 `Sec-Fetch-Site: same-origin` 即把 403 变 200)。现在注释与文案都
28
+ 按"只挡浏览器跨站,不是身份校验"表述,并指向 `REQUIRE_AUTH_FENCE=1` 或宿主的 `connection`。
29
+ - **只读集合的注释**。"它们只读内存、不写任何东西"对 `state` / `read-source` 不准确——两者在首次
30
+ 运行时会物化一份默认空 store。改为"物化的内容是本插件自己的默认值,从不是调用方给的"。
31
+
32
+ ### 修复(测试)
33
+
34
+ - **`section-order-test.mjs` 的 asar 分支此前是死代码**。asar 目录里文件的 `offset` 是**字符串**,
35
+ 而该测试要求 `typeof offset === 'number'`,于是每次读 `app.asar` 都抛错并静默回退到 profile 树。
36
+ 这台机器上 `profiles/node_modules/@deepseek-ai/dsh-system-prompt` 是 TRAE 打包的
37
+ **0.2.2-alpha.2** junction,而真正在跑的是 asar 里的 **0.2.2-rc.5**,于是测试打印了七条绿行、
38
+ 断言的是没人使用的那份宿主。现在:`offset` 两种写法都接受;桌面安装优先;**每个存在的副本都
39
+ 单独断言**,并在每行标出种类与版本(如 `[asar v0.2.2-rc.5]`、`[profile v0.2.2-alpha.2]`)。
40
+ - **`contract-test.mjs` 增加「desktop-forward」形状用例组**:不带 `Origin`、不带
41
+ `Sec-Fetch-Site` 的请求,`reload` / `state` / `history-list` 必须 200,`save-entry` /
42
+ `send-feedback` / `export-to-dir` 必须 403;并把 `READ_ONLY_METHODS` 的成员从源码钉住
43
+ (多一个或少一个都要红)。此前全部用例的默认头都带 `origin`,这个形状从未被测过。
44
+ - **`ui-test.mjs` 覆盖导入确认的两条分支**:取消 → 一个 rev 都不变;无对话框 → 拒绝合并并给出
45
+ 可读提示。1.6.1 加了这个确认却没有任何测试。
46
+ - **`section-order-test.mjs` 兼容 CRLF 检出**。CI 在 Windows 上用 `core.autocrlf` 检出,同一份
47
+ `lib/index.js` 到那边是 CRLF;按 `\n` 锚定的正则本地全绿、只在 Windows runner 上失败。读取后
48
+ 先归一化行尾。
49
+
50
+ ### 修复(存储)
51
+
52
+ - **临时文件在 rename 前消失时重写一次**。CI(Node 22)上出现过一次
53
+ `保存失败:ENOENT … rename 'memory.json.tmp-…' -> 'memory.json'`:临时文件在 `close()` 与
54
+ `rename()` 之间被本进程之外的清理者删掉了(安全扫描器、索引器、runner 清理 `/tmp`),
55
+ 于是用户看到"保存失败",而存储其实完全健康。现在遇到该 ENOENT 会重写一次临时文件再 rename;
56
+ 目标目录不存在(ENOENT 的另一种含义)仍立即失败并保留原错误信息。
57
+
58
+ ### 兼容性
59
+
60
+ - 存储格式不变(`version: 2`)。宿主契约复核:rc.3 → 0.2.2-rc.5 的 10 个依赖点零漂移
61
+ (`SECTION_ORDERS` 900/1000 未动、950 仍空;`forwardWebRequest` 仍删 4 个头并注入 cookie;
62
+ `will-download` 仍只认 `#dsh-download=`)。
63
+ - 装配:`npm test` 现为 8 个脚本(新增 `section-order-test.mjs` 已在 1.6.1 加入);本版在
64
+ Node 24 与 Node 22 上各自全绿。
65
+
66
+ ### 未做
67
+
68
+ - 真实宿主点击级验证(面板渲染、SSE 重连、导出取消分支)仍未执行:GUI 需 launch token,本轮无
69
+ 凭据。`host-smoke` 作业仍是人工项。
70
+ - 跨进程并发写依旧是"锁超时后继续写"的活性优先策略(未改)。
71
+ - `resources\app.reapply-failed-20261119\` 是桌面壳 reapply 失败留下的整份 rc.5 副本,属环境残留,
72
+ 未清理(会让后续取证读错树,建议 owner 删除)。
73
+
10
74
  ## [1.6.1] — 2026-11-18
11
75
 
12
76
  一次针对"桌面端 / 网页端两个宿主"的缺陷审计(架构、授权安全、验收边界三方独立复查 + 代码级复核)
package/README.md CHANGED
@@ -729,21 +729,30 @@ DNS 重绑定恰好推翻了它**:`evil.com` 解析到 `127.0.0.1` 之后,
729
729
  即使某些技巧(如 `no-cors` fetch)不带 `Origin`,`evil.com` 发来的请求仍会被标记为
730
730
  `cross-site`——命中即 **403**。在回环绑定(受保护)时 **`cross-site` 与 `same-site` 都拒绝**:
731
731
  "同站"判定不看端口,而回环上的任何其他端口都是别人跑的本地服务,放行 `same-site` 等于让任意
732
- 本地页面改写你的长期指令。`none`(用户直接导航)放行;curl、Node 与 2020 年前的老浏览器根本
733
- 不发这个头,也不受影响(它们由 Host 与 content-type 校验兜底)。
732
+ 本地页面改写你的长期指令。`none`(用户直接导航)放行。
733
+
734
+ curl、Node 与 2020 年前的老浏览器根本不发这个头——在**有** `connection` 门时它们由宿主与
735
+ content-type 校验兜底;在**没有**门的 profile 里,1.6.1 起「写方法必须带来源标记」这条规则会把
736
+ 它们的写请求拒成 **403**(见下一节)。
734
737
 
735
738
  注意这一整套 Host / `Origin` / `Sec-Fetch-Site` 判定**只在没有 `connection` 服务时执行**。
736
739
  有门时它由宿主做(宿主接受回环、`trustedHosts` 与监听地址,并校验 `Origin` 与 `Host` 同源、
737
740
  `Sec-Fetch-Site` 不是 `cross-site`),本插件不再重复判——重复判会把反代域名全部 403;
738
741
  没有门时非回环绑定直接 503,根本走不到这里。
739
742
 
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。
743
+ **没有 `connection` 时,哪些方法还算"只读"(1.6.2 更正)**:写门把方法分成两拨——只读集合
744
+ (`state`、`history-list`、`read-source`、`export-data`、`reload`)直接放行,其余一律要求浏览器
745
+ 来源标记(`Origin` 或 `Sec-Fetch-Site: same-origin`),否则 403。`export-to-dir` 与
746
+ `send-feedback` **不在**只读集合里:前者往备份目录写文件,后者用**你自己的 SMTP 账号**发信,
747
+ 两者都是需要来源确认的写操作。1.6.0 及以前它们被错放进只读集合,等于让本机任意进程(Android
748
+ 上则是任何装了 App 的程序)绕过写门发信;1.6.1 修复时又把 `reload` 一并误删,1.6.2 已放回——
749
+ 它只重读磁盘、首次落盘幂等,而桌面壳转发时会剥掉 `Origin`,删掉会让「重新载入」在无门 profile
750
+ 上直接 403。
751
+
752
+ **这条规则只挡浏览器跨站,不是身份校验**:`Origin` 与 `Sec-Fetch-Site` 都是普通请求头,本机
753
+ 任何进程都能自带一个(实测:加一行 `Sec-Fetch-Site: same-origin` 就把 403 变成 200)。无门
754
+ profile 的写入对**同机进程**不设防;真正的边界是宿主的 `connection` 服务,或
755
+ `DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1`(此时整个路由 fail-closed,连只读方法都是 503)。
747
756
 
748
757
  ### 宿主的鉴权门(connection):非回环绑定没有它就直接拒绝
749
758
 
package/lib/index.js CHANGED
@@ -3308,15 +3308,24 @@ export function apply(ctx, deps = {}) {
3308
3308
  // user profile) personal notes, so on a multi-user POSIX host it must not
3309
3309
  // land world-readable the way a bare writeFile (0666 & ~umask = 0644)
3310
3310
  // would. Windows ignores the bit and inherits the directory ACL instead.
3311
- const tmpHandle = await open(tmpPath, 'w', 0o600)
3312
- try {
3313
- await tmpHandle.writeFile(text, 'utf8')
3314
- // Flush the temp file BEFORE the rename publishes it: otherwise a
3315
- // power cut can leave the new name pointing at unwritten blocks.
3316
- await tmpHandle.sync()
3317
- } finally {
3318
- await tmpHandle.close()
3311
+ //
3312
+ // Kept as a closure rather than inlined because the rename below may have
3313
+ // to reconstruct the temp file: a cleaner process that removes files in
3314
+ // $TMPDIR (a security scanner, an indexer, a CI runner tidying /tmp)
3315
+ // deletes it between close() and rename(), and the user would then be told
3316
+ // their save failed even though nothing about the store was wrong.
3317
+ const persistTemp = async () => {
3318
+ const tmpHandle = await open(tmpPath, 'w', 0o600)
3319
+ try {
3320
+ await tmpHandle.writeFile(text, 'utf8')
3321
+ // Flush the temp file BEFORE the rename publishes it: otherwise a
3322
+ // power cut can leave the new name pointing at unwritten blocks.
3323
+ await tmpHandle.sync()
3324
+ } finally {
3325
+ await tmpHandle.close()
3326
+ }
3319
3327
  }
3328
+ await persistTemp()
3320
3329
  // Both rolling copies stand for the PREVIOUS good version, so both are
3321
3330
  // taken before the atomic replace, and neither may ever be renamed into
3322
3331
  // place (see the long note above).
@@ -3390,8 +3399,23 @@ export function apply(ctx, deps = {}) {
3390
3399
  try {
3391
3400
  await rename(tmpPath, storePath)
3392
3401
  } catch (err) {
3393
- await unlink(tmpPath).catch(() => {})
3394
- throw err
3402
+ if (err === null || err === undefined || err.code !== 'ENOENT') {
3403
+ await unlink(tmpPath).catch(() => {})
3404
+ throw err
3405
+ }
3406
+ // The temp file was removed by something outside this process between
3407
+ // close() and rename(). Rewriting it once costs one small write and
3408
+ // turns a spurious "保存失败" into a normal save; a missing store
3409
+ // DIRECTORY (the other meaning of ENOENT here) fails again immediately
3410
+ // and keeps its original error.
3411
+ logInfo('the store temp file disappeared before rename; rewriting it once')
3412
+ await persistTemp()
3413
+ try {
3414
+ await rename(tmpPath, storePath)
3415
+ } catch (retryErr) {
3416
+ await unlink(tmpPath).catch(() => {})
3417
+ throw retryErr
3418
+ }
3395
3419
  }
3396
3420
  // Make the directory entry itself durable: without this the rename can be
3397
3421
  // lost on power failure even though the file contents were flushed.
@@ -6024,29 +6048,39 @@ export function apply(ctx, deps = {}) {
6024
6048
  * instead of relying on an orange warning in the panel.
6025
6049
  * 2. Without a fence, a mutation must carry a browser origin marker: either
6026
6050
  * `Origin` or `Sec-Fetch-Site: same-origin`. A page always sends one of
6027
- * the two, so the settings page is unaffected; a bare process is refused
6028
- * (403). `Sec-Fetch-Site` is accepted because script cannot set it — it is
6029
- * the browser's own claim, not the caller's.
6051
+ * the two, so the settings page is unaffected, and a process that sends
6052
+ * neither is refused (403).
6053
+ *
6054
+ * Read rule 2 as a CROSS-SITE guard, not as authentication. Both are
6055
+ * ordinary request headers, so a process on this machine can set either
6056
+ * one and walk straight through — verified: adding
6057
+ * `Sec-Fetch-Site: same-origin` alone turns a 403 into a 200. Nothing
6058
+ * here can distinguish that from a browser. The only real boundaries for
6059
+ * a fence-less profile are the host's `connection` service (below) or
6060
+ * DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1.
6030
6061
  *
6031
6062
  * Set DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1 to make the whole route fail
6032
6063
  * closed instead of falling back to these two rules.
6033
6064
  */
6034
6065
  /**
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.
6066
+ * Methods that are safe to serve with no gate in front of them: they answer
6067
+ * from what is already in memory. `state` and `read-source` can materialise
6068
+ * the default empty store on first use, but its content is this plugin's own
6069
+ * default and never the caller's, so nothing an attacker sends reaches disk.
6070
+ *
6071
+ * 1.6.1 removed two entries that were never read-only: `export-to-dir` writes
6072
+ * a file into the backup directory, and `send-feedback` sends mail through the
6073
+ * operator's own SMTP account (a cool-down is a rate limit, not an
6074
+ * authorisation).
6038
6075
  *
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).
6076
+ * `reload` stays, and 1.6.2 is the fix for having dropped it by accident: it
6077
+ * only re-reads the store, and it is the one write-shaped call the panel makes
6078
+ * on its own — a desktop shell deletes `Origin` and `Sec-Fetch-Site` when it
6079
+ * forwards (see TRUSTED_HOSTS above), so gating it turned the "重新载入"
6080
+ * button into a permanent 403 on any profile without a `connection` service.
6047
6081
  */
6048
6082
  const READ_ONLY_METHODS = new Set([
6049
- 'state', 'history-list', 'read-source', 'export-data',
6083
+ 'state', 'history-list', 'read-source', 'export-data', 'reload',
6050
6084
  ])
6051
6085
 
6052
6086
  const writeGateRefusal = (method, headers) => {
@@ -6068,9 +6102,9 @@ export function apply(ctx, deps = {}) {
6068
6102
  if (origin === '' && fetchSite !== 'same-origin') {
6069
6103
  return {
6070
6104
  status: 403,
6071
- message: '拒绝无来源标记的修改请求:当前 profile 没有宿主的会话鉴权门,因此修改必须来自浏览器'
6072
- + '(带 Origin 或 Sec-Fetch-Site: same-origin)。设置页读写不受影响;本机脚本 / curl 的写入会被拒绝。'
6073
- + '如需完全关闭该路由,设置 DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1。',
6105
+ message: '拒绝无来源标记的修改请求:当前 profile 没有宿主的会话鉴权门,因此修改必须带浏览器来源标记'
6106
+ + '(Origin 或 Sec-Fetch-Site: same-origin)。设置页不受影响。这不是身份校验——两个头本机进程也能自带;'
6107
+ + '要真正关闭该路由,请设置 DSH_INSTRUCTION_MEMORY_REQUIRE_AUTH_FENCE=1,或让宿主提供 connection 服务。',
6074
6108
  }
6075
6109
  }
6076
6110
  return null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-instruction-memory",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
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",