dsh-instruction-memory 1.6.6 → 1.6.7

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,7 +7,81 @@
7
7
  > 1.0.13 起由 CI 经 OIDC Trusted Publishing 发布(首个带 provenance 的版本)。
8
8
  > 这些历史 tag **不应回填**——npm 上的版本号已被占用。
9
9
 
10
- ## [1.6.6] — 2026-12-02
10
+ ## [1.6.7] — 2026-12-04
11
+
12
+ 第四轮审计(技术评审团三条线:架构 / 应用安全 / 验收)的修复批次。本轮**没有新功能**,只修审计
13
+ 在 1.6.3→1.6.6 之间确认的缺陷,其中两条是"一端坏、另一端好"的真差异。
14
+
15
+ 先把前提说清楚:**1.6.4 从未发布**——无 tag、无独立提交、npm 上 `@1.6.4` 返回 404,其客户端改动
16
+ (444+/101−)被压进了 1.6.5 的提交。上一节的 `[1.6.4]` 已改标「未发布」。因此"近三个版本"实际是
17
+ 1.6.3 / 1.6.5 / 1.6.6,而"1.6.5 修好了 1.6.4 的 P0"这句话在证据上不可二分。
18
+
19
+ ### 修复(写门)
20
+
21
+ - **A1 · 门禁 verb 抛错不再决定整个请求**(`lib/index.js` `connectionGateVerdict`)。1.6.6 按
22
+ "第一个存在的 verb"择一,且调用方把抛错归一成 401——于是当宿主同时暴露 `requestRejection`
23
+ (内部可能转调 `admit`,而 `admit()` 在未 inject `connection.authentication` 的 fiber 上会抛)
24
+ 时,**读也 401,设置页整页打不开**,提示还误导成"需要登录"。现在三个 verb 按强度逐个试,
25
+ 抛错记日志继续下一个,全部不可用才拒绝,并在文案里说明"这是宿主版本不匹配,不是登录问题"。
26
+ - **A2 · trust-only 门只放行读,写一律 503**(`connectionGateVerdict` / `rejectUntrustedCaller` /
27
+ `writeGateRefusal`)。`isTrustedRequest` 只校验来源,宿主源码自述它 "never establishes identity"。
28
+ 在只暴露该 verb 的宿主(0.2.3-alpha.3 形状)上,本机任意进程带 `Host: 127.0.0.1:PORT` 即可穿过,
29
+ 而本路由的每一次写都会进"注入到此后每轮对话"的文本。现在把"门只证来源"这一档标成
30
+ `gate-trust-only`:读照常(面板要能打开并说清原因),写返 503 并给出原因与两条出路。
31
+ - **A2 附带**:`admit()` 从"最后备选"提到 `isTrustedRequest` 之前——它是唯一能确认身份的 verb,
32
+ 有它就不该退到弱的那一档。
33
+ - **B1 · 只有桌面端会踩的死锁,改为说清楚**(`writeGateRefusal` 的 403 文案)。fence-less 且用户
34
+ 按 503 文案设了 `DSH_INSTRUCTION_MEMORY_ALLOW_UNGUARDED_WRITES=1` 之后,写仍要求 `Origin` 或
35
+ `Sec-Fetch-Site: same-origin`,而桌面壳转发时会**删掉这两个头**——桌面端永久 403、网页端能写。
36
+ **判定不改**(放宽来源校验等于签收一个调用方自带的头,这正是 1.6.3 已否决的设计),只把事实写进
37
+ 文案:桌面端该开关无效,要写只能让宿主提供 `connection` 服务。
38
+
39
+ ### 修复(客户端)
40
+
41
+ - **A3 · `confirmThen` 不再有返回值**(`lib/client.js`)。1.6.5 三个分支都 `return true`,返回值零
42
+ 信息量;而 1.6.4 的 P0("点删除→确定→什么都不发生")正是一个把它当布尔读的调用点。现在函数返回
43
+ `undefined`,调用点统一是"裸调用 + `return`"(九处已全部是这个形态),`lint.mjs` 新增**位置门禁**:
44
+ `confirmThen(` 不得出现在 `if (...)` / `while` / `switch` 头、`return`、三元 `?`、`&&` / `||` / `!`
45
+ 或普通的 `=` 赋值之后;注释里引用的示例不误报。
46
+ - **A4 · 待确认条从单槽改为队列**(`pendingConfirm` → `pendingConfirms`)。原来第二条问题会**覆盖**
47
+ 第一条:用户看到一条,点【确认】执行的却是第二条动作(意图错位,不只是丢失)。现在队列头部渲染、
48
+ 确认/取消各弹出队首、下一条自动接上;打开编辑器仍清空整个队列(此时用户已不在这批问题上)。
49
+ - **A4 连带 · 一次性闸门改成按问题 id**(`confirmFiringRef`)。队列化把这个布尔闸门的两个错解同时暴露
50
+ 出来:一直保持 `true` 会把**下一条**永久锁死(它的按钮永远是 disabled),每次出队都重置又会让一次
51
+ 双击执行**两条不同的**删除。现在闸门存"刚执行的那条问题的 id",只对同一条判等;`ui-test` 新增
52
+ 「连续排队两条 → 两条都能依次确认」的用例,正是这条的回归。
53
+ - **B2 · 桌面分支在 http 入口也能认出来**(`isDesktopShell`)。判据原来只认 `location.protocol ===
54
+ 'dsh-app:'`,而桌面宿主同时用 `http://127.0.0.1:PORT` 提供同一个 profile——从那个入口打开时桌面
55
+ 分支不启用,导出退化成"已请求保存",保底 JSON 不给。现在补一条"回环 host + UA 含 `Electron`"。
56
+
57
+ ### 修复(交付面)
58
+
59
+ - **A5 · CHANGELOG 不再把未发布批次写成已发布**。`[1.6.4]` 改标「未发布(内容已并入 1.6.5)」;
60
+ 1.6.5 的"工作区仍未提交"一条更正为已在 `101f0a5` 提交。`check-metadata.mjs` 新增双向校验:
61
+ 每个 `## [x.y.z]` 节要么有 `v<版本>` tag、要么写明未发布(1.0.10–1.0.12 按文件头的既有声明豁免);
62
+ 反过来,`package.json` 的版本必须有同名节与同名 tag。无 git 时只跳过 tag 那一半,不静默通过。
63
+
64
+ ### 测试
65
+
66
+ - `contract-test.mjs`:翻转 `alpha.3 fence: isTrustedRequest() true admits a write`,改为"读 200 /
67
+ 写 503"两条;新增 `1.6.7: a throwing requestRejection falls through to admit()(读仍 200)`与
68
+ `1.6.7: every verb throwing is still a refusal (401)`。
69
+ - `lint.mjs`:确认门禁从"第二实参是否含 `send(`"扩到"调用所处的语法位置",并豁免注释。
70
+ - `check-metadata.mjs`:见上。
71
+ - 全量:`node test-all.mjs` → 九段全绿;本轮另跑了一次单段 `contract` / `ui` / `mobile-shape` 复核。
72
+
73
+ ### 已知边界(本轮仍未解决,不要当成已修)
74
+
75
+ - **桌面渲染进程(`dsh-app://app`)仍无端到端证据**:`grep isDesktopShell|desktopHint *.mjs` 在
76
+ 本轮之前零命中,B2 的修复也只到"判据正确",没有真窗口点击、导出落地、`EventSource` 走自定义
77
+ 协议的实测。这一条是验收门,不是代码缺陷。
78
+ - **alpha.3 实机仍未复测**:A2 的 503 档在单元层面已锁,但没有在真实的 0.2.3-alpha.3 宿主上跑过;
79
+ 复测产物需同时记录宿主版本与探测到的 verb,否则"通过"不可解释。
80
+ - **W1(网页端 cookie 按 Host 名签发,`localhost` / `[::1]` 混用即 401)** 仍归宿主,插件侧只在
81
+ 文档里写明"用 `127.0.0.1`"。
82
+ - **`1.6.4` 的客户端改动** 仍在 1.6.5 的提交里,无法按版本二分;只能按本节叙述回溯。
83
+
84
+
11
85
 
12
86
  写门禁恢复对 DSH 0.2.3-alpha.3 的兼容。
13
87
 
@@ -126,10 +200,10 @@ null:宿主明明已经完成会话鉴权,设置页却只能读,所有写
126
200
  (装载、注入进组装后的提示、路由应答、设置页下发)再扩声明;本轮只把 guard 的假红改成 SKIP。
127
201
  - 无 Android 真机:手机侧仍为代码级结论(帧预算现在按壳的真实口径计算,但壳侧丢弃行为未在
128
202
  设备上确认)。
129
- - 工作区仍未提交(`mobile-shape-test.mjs` 与 `test-all.mjs` 是新增文件);不提交则别的机器/CI
130
- 的 `npm test` 会 `MODULE_NOT_FOUND`,`prepublishOnly` 会拒绝发布。
203
+ - ~~工作区仍未提交(`mobile-shape-test.mjs` 与 `test-all.mjs` 是新增文件)~~:**1.6.7 更正**——
204
+ 两者已在 `101f0a5`(1.6.5)提交,`npm test` 九段全跑;本条在发布时即已过期。
131
205
 
132
- ## [1.6.4] — 2026-11-21
206
+ ## [1.6.4] — 未发布(内容已并入 1.6.5)
133
207
 
134
208
  DSH Go(Android + WebView island)适配批次(技术方案评审团三条线的结论)。**没有引入新的手机功能,
135
209
  而是把三处"看起来能用、实际静默失效"的路径修掉**,并把 Android 分支第一次纳入自动化门禁。
package/lib/client.js CHANGED
@@ -2320,9 +2320,32 @@ window.__ModuleLoader__.load({
2320
2320
  * untrustworthy the question is parked here and rendered as a row with
2321
2321
  * 【确认】/【取消】; the action keeps working, one tap later.
2322
2322
  */
2323
- const [pendingConfirm, setPendingConfirm] = React.useState(null)
2324
- /** R2 (1.6.5): one activation of the confirm button runs the action once. */
2325
- const confirmFiringRef = React.useRef(false)
2323
+ /**
2324
+ * 1.6.7 (A4): a QUEUE, not a single slot.
2325
+ *
2326
+ * `pendingConfirm` used to be one slot: a second question arriving before
2327
+ * the first was answered OVERWROTE it, so the user saw one bar, clicked
2328
+ * 【确认】, and the action that ran was the second one. Losing a question
2329
+ * is annoying; running a different destructive action than the one you
2330
+ * read is the failure mode that matters.
2331
+ *
2332
+ * The bar still shows one question at a time (head of the queue); the
2333
+ * rest wait their turn.
2334
+ */
2335
+ const [pendingConfirms, setPendingConfirms] = React.useState([])
2336
+ const pendingConfirm = pendingConfirms.length > 0 ? pendingConfirms[0] : null
2337
+ /**
2338
+ * R2 (1.6.5) / 1.6.7 (A4): one activation runs THAT question's action once.
2339
+ *
2340
+ * It stores the id of the parked question that was just fired, not a
2341
+ * boolean. With a queue a boolean has two wrong answers: keeping it
2342
+ * `true` locks the NEXT question out (its button stays disabled forever,
2343
+ * because nothing re-arms it once the queue advances), and resetting it on
2344
+ * every dequeue lets a double tap fire two DIFFERENT deletes. An id
2345
+ * compares equal only against the same question.
2346
+ */
2347
+ const confirmFiringRef = React.useRef(null)
2348
+ const confirmSeqRef = React.useRef(0)
2326
2349
  /**
2327
2350
  * The single confirmation entry point (1.6.5 contract).
2328
2351
  *
@@ -2335,22 +2358,32 @@ window.__ModuleLoader__.load({
2335
2358
  * silent no-op on desktop and, later, what made a leftover approval leak
2336
2359
  * into the next action with the same wording.
2337
2360
  *
2338
- * So every call site reads `if (confirmThen(message, action)) return` and
2339
- * the action body exists in exactly one place.
2361
+ * So every call site is a bare `confirmThen(...)` followed by `return`:
2362
+ * the guard always stops the caller, and the action body exists in
2363
+ * exactly one place.
2340
2364
  */
2341
2365
  const confirmThen = (message, action) => {
2342
2366
  const ask = askConfirm(message)
2343
2367
  if (ask === CONFIRM_YES) {
2344
2368
  void action()
2345
- return true
2369
+ return
2346
2370
  }
2347
2371
  if (ask === CONFIRM_UNAVAILABLE) {
2348
- // A fresh question re-arms the one-shot firing guard (R2).
2349
- confirmFiringRef.current = false
2350
- setPendingConfirm({ message, action })
2351
- return true
2372
+ // A fresh question gets a fresh id, so the one-shot firing guard
2373
+ // (R2) still distinguishes "the same question twice" from "the next
2374
+ // question" (1.6.7 A4).
2375
+ confirmSeqRef.current += 1
2376
+ setPendingConfirms((queue) => queue.concat([{ message, action, id: confirmSeqRef.current }]))
2352
2377
  }
2353
- return true
2378
+ // 1.6.7 (A3): NO return value.
2379
+ //
2380
+ // 1.6.5 answered `true` from every branch, which made the value pure
2381
+ // noise — and the 1.6.4 P0 ("click delete → confirm → nothing happens")
2382
+ // was exactly a call site that read it as a boolean. Call sites now
2383
+ // read `confirmThen(...)` followed by `return`: the guard always stops
2384
+ // the caller, and the action exists in one place. `lint.mjs` refuses
2385
+ // the call inside `if (...)` / `? :` / an assignment / `return`, so the
2386
+ // old shape cannot come back unnoticed.
2354
2387
  }
2355
2388
  /** True once the event stream has failed long enough to stop pretending. */
2356
2389
  const [liveDown, setLiveDown] = React.useState(false)
@@ -3091,8 +3124,32 @@ window.__ModuleLoader__.load({
3091
3124
  */
3092
3125
  function isDesktopShell() {
3093
3126
  try {
3094
- return typeof location !== 'undefined' && typeof location.protocol === 'string'
3095
- && location.protocol === 'dsh-app:'
3127
+ if (typeof location === 'undefined' || typeof location.protocol !== 'string') return false
3128
+ // The renderer's own protocol: an unmistakeable observation.
3129
+ if (location.protocol === 'dsh-app:') return true
3130
+ /**
3131
+ * 1.6.7 (B2): the desktop host ALSO serves the same profile over
3132
+ * `http://127.0.0.1:PORT`, and that is how the panel is usually
3133
+ * opened (the Web GUI URL this session runs against is exactly that
3134
+ * shape). Judging only `dsh-app:` therefore missed the desktop
3135
+ * surface on the http entry: the export fell through to the generic
3136
+ * `export.saved` ("requested a save") and the guaranteed in-panel
3137
+ * copy was never offered, even though this IS the shell whose
3138
+ * `will-download` handler cannot confirm a blob.
3139
+ *
3140
+ * The extra test is loopback host + an Electron user agent, which
3141
+ * only the shell presents. A plain browser on the same loopback URL
3142
+ * keeps the ordinary browser branch, so the message stays accurate
3143
+ * there.
3144
+ */
3145
+ const host = typeof location.hostname === 'string' ? location.hostname : ''
3146
+ const loopback = host === '127.0.0.1' || host === 'localhost'
3147
+ || host === '[::1]' || host === '::1'
3148
+ if (!loopback) return false
3149
+ const agent = typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string'
3150
+ ? navigator.userAgent
3151
+ : ''
3152
+ return agent.indexOf('Electron') !== -1
3096
3153
  } catch {
3097
3154
  return false
3098
3155
  }
@@ -4295,22 +4352,27 @@ window.__ModuleLoader__.load({
4295
4352
  // delete survived on the host's idempotency, but import/restore
4296
4353
  // were never verified. `busy` also blocks it here, so an action
4297
4354
  // that is already in flight cannot be re-fired from the bar.
4298
- disabled: busy === true || confirmFiringRef.current === true,
4355
+ disabled: busy === true
4356
+ || (pendingConfirm !== null && confirmFiringRef.current === pendingConfirm.id),
4299
4357
  onClick: () => {
4300
4358
  const pending = pendingConfirm
4301
- if (pending === null || confirmFiringRef.current === true) return
4302
- // Stays true until the NEXT question is parked: a second
4303
- // activation in the same tick (double tap, touch jitter) must
4304
- // not run the action twice. The delete survived on the host's
4305
- // idempotency; import/restore never had that guarantee.
4306
- confirmFiringRef.current = true
4307
- setPendingConfirm(null)
4359
+ if (pending === null || confirmFiringRef.current === pending.id) return
4360
+ // Stays set to THIS question's id: a second activation of the
4361
+ // same bar (double tap, touch jitter) must not run the action
4362
+ // twice, while the NEXT question — a different id — is still
4363
+ // confirmable. The delete survived on the host's idempotency;
4364
+ // import/restore never had that guarantee.
4365
+ confirmFiringRef.current = pending.id
4366
+ // 1.6.7 (A4): pop the HEAD. Any other parked question keeps
4367
+ // its place and is shown next, instead of having been
4368
+ // silently overwritten by this one.
4369
+ setPendingConfirms((queue) => queue.slice(1))
4308
4370
  void pending.action()
4309
4371
  },
4310
4372
  }, t('confirm.yes')),
4311
4373
  h('button', {
4312
4374
  className: 'im-btn',
4313
- onClick: () => setPendingConfirm(null),
4375
+ onClick: () => setPendingConfirms((queue) => queue.slice(1)),
4314
4376
  }, t('confirm.no'))))
4315
4377
  : null,
4316
4378
  error === '' && notice !== '' ? h('div', { className: 'im-ok', role: 'status', 'aria-live': 'polite' }, notice) : null,
@@ -4483,7 +4545,10 @@ window.__ModuleLoader__.load({
4483
4545
  // A6 (1.6.5): the editor is an early return, so a confirmation
4484
4546
  // parked in the list view would be invisible while the draft
4485
4547
  // is open — the action would hang until the editor closed.
4486
- setPendingConfirm(null)
4548
+ // 1.6.7 (A4): that applies to the whole QUEUE now, and it is
4549
+ // still an intentional drop — the operator opened an editor,
4550
+ // so they are no longer answering those questions.
4551
+ setPendingConfirms([])
4487
4552
  setDraft(cloneEntry(entry))
4488
4553
  setProfileDraft(null)
4489
4554
  setError('')