@dsh-mobile/mobile-remote 3.3.0 → 3.3.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/lib/client.js CHANGED
@@ -3,7 +3,8 @@
3
3
  //
4
4
  // 打包形态:window.__ModuleLoader__.load({ id, factory })(dsh-client-modules 约定)。
5
5
  // 手写 React.createElement(无 JSX/构建链),依赖由 dsh 客户端运行时提供。
6
- // 数据来源:GET /m/api/qr-config(仅 loopback 可访问,返回地址+口令)。
6
+ // 数据来源:POST /m/api/relay/pairing {mode:"lan"}(默认二维码:局域网加密配对,T-71)与
7
+ // GET /m/api/qr-config(旧版 App 用的不加密二维码:地址+口令)。两者都仅限电脑本机桌面访问。
7
8
 
8
9
  window.__ModuleLoader__.load({
9
10
  // 必须与 package.json 的 name 逐字相同:宿主按包名等待这个 id 注册,对不上就报
@@ -361,6 +362,28 @@ window.__ModuleLoader__.load({
361
362
  );
362
363
  }
363
364
 
365
+ function deviceRow(d) {
366
+ // 注意:这里刻意不显示「设备指纹」。
367
+ // 手机配对时核对的是**电脑**的公钥(配对链接里的 pk),
368
+ // 而 d.id 是**手机**公钥的指纹——两者不是同一个东西,
369
+ // 摆在一起会让人以为能互相对照,比不显示更糟。
370
+ // 电脑侧要展示的是自己的公钥指纹,见下面「本机指纹」那一行。
371
+ return jsxRuntime.jsx(
372
+ "div",
373
+ {
374
+ style: rowStyle,
375
+ children: [
376
+ jsxRuntime.jsx("span", { children: d.name }),
377
+ // T-71: phones paired with the default QR only use the LAN (the relay is never on for them)
378
+ d.via === "lan" ? jsxRuntime.jsx("span", { style: mutedStyle, children: "仅局域网" }, "via") : null,
379
+ jsxRuntime.jsx("span", { style: mutedStyle, children: "最近 " + relativeTime(d.lastSeen, now) }),
380
+ jsxRuntime.jsx("button", { style: btnStyle, onClick: function () { revoke(d); }, children: "撤销" }),
381
+ ],
382
+ },
383
+ "d:" + d.id
384
+ );
385
+ }
386
+
364
387
  var title = jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "18px 0 2px" }, children: "远程访问(手机不在同一 Wi-Fi 时)" });
365
388
  var wrap = function (children) {
366
389
  return jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [title].concat(children) });
@@ -373,6 +396,16 @@ window.__ModuleLoader__.load({
373
396
  return wrap([jsxRuntime.jsx("div", { style: mutedStyle, children: "无法读取远程访问状态:" + st.message + "(只能在这台电脑的 DSH 桌面端管理)" }, "e")]);
374
397
  }
375
398
  var data = st.data;
399
+ // T-71: the relay is off but phones are paired for the encrypted LAN path. They still
400
+ // need a list and a way to revoke them; nothing about remote access is shown.
401
+ if (!data.enabled && data.lanNoise && (data.devices || []).length > 0 && !relayUi.advertiseWhenOff) {
402
+ var lanRows = [jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "18px 0 2px" }, children: "已配对的手机(" + data.devices.length + ")" }, "dh")];
403
+ data.devices.forEach(function (d) {
404
+ lanRows.push(deviceRow(d));
405
+ });
406
+ lanRows.push(jsxRuntime.jsx("div", { style: mutedStyle, children: "手机丢了或不再使用:撤销后它会立即断开,其它手机不受影响。" }, "foot"));
407
+ return jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column", gap: "6px" }, children: lanRows });
408
+ }
376
409
  if (!data.enabled) {
377
410
  if (!relayUi.advertiseWhenOff) return null;
378
411
  return wrap([
@@ -445,34 +478,135 @@ window.__ModuleLoader__.load({
445
478
  rows.push(jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "4px 0 2px" }, children: "已配对的手机(" + (data.devices || []).length + ")" }, "dh"));
446
479
  if ((data.devices || []).length === 0) rows.push(jsxRuntime.jsx("div", { style: mutedStyle, children: "还没有。点上面的按钮,用手机扫码即可。" }, "none"));
447
480
  (data.devices || []).forEach(function (d) {
448
- // 注意:这里刻意不显示「设备指纹」。
449
- // 手机配对时核对的是**电脑**的公钥(配对链接里的 pk),
450
- // 而 d.id 是**手机**公钥的指纹——两者不是同一个东西,
451
- // 摆在一起会让人以为能互相对照,比不显示更糟。
452
- // 电脑侧要展示的是自己的公钥指纹,见下面「本机指纹」那一行。
453
- rows.push(
481
+ rows.push(deviceRow(d));
482
+ });
483
+ rows.push(jsxRuntime.jsx("div", { style: mutedStyle, children: "手机丢了或不再使用:撤销后它会立即断开,其它手机不受影响。" }, "foot"));
484
+ return wrap(rows);
485
+ }
486
+ exports.RelayPanel = RelayPanel;
487
+
488
+ /**
489
+ * 默认二维码(T-71,D-01 / C-15):局域网加密配对。
490
+ *
491
+ * 以前这一页的第一个二维码是 `DSHREMOTE|地址|口令`:手机之后的每个请求都在局域网上明文带着访问口令,
492
+ * 同一个 Wi-Fi 里谁都能截获。现在第一个二维码是 `dsh://pair?…&lan=…`(不带中继地址):手机在 LAN 桥上
493
+ * 走 Noise 加密握手配对,口令从头到尾不出现在网络上;不需要中继、不需要账号、不收费(D5)。
494
+ * 配对码一次性、5 分钟有效:页面开着时到期自动换新,配对成功也换新(下一台手机用新码)。
495
+ * LAN 桥没开(web 版)或插件太旧时拿不到 → onAvailability(false),页面退回旧二维码并说明它不加密。
496
+ */
497
+ function LanPairing(props) {
498
+ var onAvailability = props && typeof props.onAvailability === "function" ? props.onAvailability : function () {};
499
+ var stHook = useState({ status: "loading" });
500
+ var st = stHook[0];
501
+ var setSt = stHook[1];
502
+ var genHook = useState(0);
503
+ var gen = genHook[0];
504
+ var setGen = genHook[1];
505
+ var nowHook = useState(Date.now());
506
+ var now = nowHook[0];
507
+ var setNow = nowHook[1];
508
+
509
+ useEffect(
510
+ function () {
511
+ var alive = true;
512
+ // 先记下已经在名单里的手机:之后多出来的那台 = 刚用这个码配对的
513
+ relayCall("/status", "GET")
514
+ .then(
515
+ function (s) {
516
+ return ((s && s.devices) || []).map(function (d) {
517
+ return d.id;
518
+ });
519
+ },
520
+ function () {
521
+ return [];
522
+ }
523
+ )
524
+ .then(function (known) {
525
+ return relayCall("/pairing", "POST", { mode: "lan" }).then(function (res) {
526
+ if (!alive) return;
527
+ setNow(Date.now());
528
+ setSt({ status: "ready", uri: res.uri, qr: res.qr, fingerprint: res.fingerprint, expiresAt: res.expiresAt, knownIds: known });
529
+ onAvailability(true);
530
+ });
531
+ })
532
+ .catch(function (err) {
533
+ if (!alive) return;
534
+ setSt({ status: "unavailable", code: err && err.code, message: String((err && err.message) || err) });
535
+ onAvailability(false);
536
+ });
537
+ return function () {
538
+ alive = false;
539
+ };
540
+ },
541
+ [gen]
542
+ );
543
+ useEffect(
544
+ function () {
545
+ if (st.status !== "ready") return undefined;
546
+ var ticks = 0;
547
+ var h = setInterval(function () {
548
+ var t = Date.now();
549
+ setNow(t);
550
+ if (st.expiresAt - t <= 0) {
551
+ setGen(function (g) {
552
+ return g + 1;
553
+ });
554
+ return;
555
+ }
556
+ ticks += 1;
557
+ if (ticks % 4 !== 0) return;
558
+ relayCall("/status", "GET").then(
559
+ function (s) {
560
+ var fresh = ((s && s.devices) || []).filter(function (d) {
561
+ return st.knownIds.indexOf(d.id) < 0;
562
+ });
563
+ if (fresh.length === 0) return;
564
+ toast("已配对:" + fresh[0].name);
565
+ setGen(function (g) {
566
+ return g + 1;
567
+ });
568
+ },
569
+ function () {}
570
+ );
571
+ }, 1000);
572
+ return function () {
573
+ clearInterval(h);
574
+ };
575
+ },
576
+ [st]
577
+ );
578
+
579
+ if (st.status === "loading") return jsxRuntime.jsx("div", { style: { padding: "20px 0", color: "var(--dsw-alias-label-secondary, #888)" }, children: "加载中…" });
580
+ if (st.status !== "ready") return null;
581
+ var countdown = formatCountdown(st.expiresAt - now) || "0:00";
582
+ return jsxRuntime.jsx("div", {
583
+ style: { display: "flex", flexDirection: "column", alignItems: "center", gap: "10px", padding: "14px 0" },
584
+ children: [
585
+ jsxRuntime.jsx("img", { src: st.qr, alt: "加密配对二维码", style: { width: 216, height: 216, borderRadius: "12px", background: "#fff", padding: 8 } }, "img"),
586
+ jsxRuntime.jsx("div", { style: { fontSize: "12px", color: "var(--dsw-alias-label-tertiary, #aaa)" }, children: "打开 App → 扫码连接 → 对准本二维码" }, "how"),
454
587
  jsxRuntime.jsx(
455
588
  "div",
456
589
  {
457
- style: rowStyle,
458
- children: [
459
- jsxRuntime.jsx("span", { children: d.name }),
460
- jsxRuntime.jsx("span", { style: mutedStyle, children: "最近 " + relativeTime(d.lastSeen, now) }),
461
- jsxRuntime.jsx("button", { style: btnStyle, onClick: function () { revoke(d); }, children: "撤销" }),
462
- ],
590
+ style: Object.assign({}, mutedStyle, { textAlign: "center" }),
591
+ children: "手机和电脑在同一个 Wi-Fi 下。连接全程加密,二维码里没有访问口令;不经过任何服务器,免费。一次性配对码," + countdown + " 后自动换新。",
463
592
  },
464
- "d:" + d.id
465
- )
466
- );
593
+ "t"
594
+ ),
595
+ jsxRuntime.jsx("div", { style: Object.assign({}, mutedStyle, { textAlign: "center" }), children: [
596
+ jsxRuntime.jsx("div", { children: "本机指纹(手机上会显示同一串)" }, "l"),
597
+ jsxRuntime.jsx("div", { style: { fontFamily: "monospace", fontSize: "14px", letterSpacing: "1px", color: "#111", userSelect: "all" }, children: formatPairingFingerprint(st.fingerprint) }, "f"),
598
+ ] }, "fp"),
599
+ jsxRuntime.jsx("button", { style: Object.assign({}, btnStyle, { marginLeft: 0 }), onClick: function () { copyText(st.uri); }, children: "复制配对链接" }, "cp"),
600
+ ],
467
601
  });
468
- rows.push(jsxRuntime.jsx("div", { style: mutedStyle, children: "手机丢了或不再使用:撤销后它会立即断开,其它手机不受影响。" }, "foot"));
469
- return wrap(rows);
470
602
  }
471
- exports.RelayPanel = RelayPanel;
603
+ exports.LanPairing = LanPairing;
472
604
 
473
605
  /**
474
606
  * 设置页 section:连接移动端设备。
475
- * 挂载后从 /m/api/qr-config 拉取地址与口令,渲染二维码 + 连接信息。
607
+ * 第一个二维码是局域网加密配对(LanPairing)。旧版 App(1.1 及更早)读不了它:它们用的
608
+ * `DSHREMOTE|地址|口令` 二维码收在「旧版 App」后面,并写明不加密。插件拿不到加密配对时(LAN 桥没开),
609
+ * 旧二维码直接显示,同样写明不加密。
476
610
  */
477
611
  function MobileDeviceSection() {
478
612
  var state = useState({ status: "loading", urls: [], token: "" });
@@ -482,6 +616,13 @@ window.__ModuleLoader__.load({
482
616
  var reloadHook = useState(0);
483
617
  var reloadKey = reloadHook[0];
484
618
  var setReloadKey = reloadHook[1];
619
+ // null = 还不知道;true = 有局域网加密配对;false = 没有(只能用旧二维码)
620
+ var lanHook = useState(null);
621
+ var lan = lanHook[0];
622
+ var setLan = lanHook[1];
623
+ var legacyHook = useState(false);
624
+ var legacyOpen = legacyHook[0];
625
+ var setLegacyOpen = legacyHook[1];
485
626
 
486
627
  useEffect(function () {
487
628
  var alive = true;
@@ -510,59 +651,84 @@ window.__ModuleLoader__.load({
510
651
  };
511
652
  }, [reloadKey]);
512
653
 
513
- if (data.status === "loading") {
514
- return jsxRuntime.jsx("div", { style: { padding: "20px 0", color: "var(--dsw-alias-label-secondary, #888)" }, children: "加载中…" });
515
- }
516
- if (data.status === "error") {
517
- return jsxRuntime.jsx("div", {
518
- style: { padding: "20px 0", color: "var(--dsw-alias-text-danger, #e5484d)" },
519
- children: "无法获取连接信息:" + data.message + "(确认手机连接插件已启用,且路径为 /m)",
520
- });
521
- }
522
-
523
- // v3.0.0 review:二维码 URL 携带挂载路径(App 端解析后使用,不再写死 /m)
524
- // PR #32:路径拼接的坑与取舍见上方 buildQrPayload 注释
525
- var mount = String(data.basePath || "/m").replace(/\/+$/, "");
526
- var qrPayload = buildQrPayload(data);
527
- var qrSrc = mount + "/qr.png?text=" + encodeURIComponent(qrPayload);
528
-
529
- return jsxRuntime.jsx("div", {
530
- style: { display: "flex", flexDirection: "column", gap: "6px", padding: "4px 0 16px" },
531
- children: [
532
- jsxRuntime.jsx("div", {
533
- style: { fontSize: "13px", color: "var(--dsw-alias-label-secondary, #888)", lineHeight: "1.6" },
534
- children: "用手机 DSH Remote App 扫描下方二维码,自动填入电脑地址与访问口令,即可远程发消息、看进度、收通知、审批决策。",
535
- }),
654
+ /** 旧二维码(不加密)+ 连接信息。 */
655
+ function legacyBlock() {
656
+ if (data.status === "loading") {
657
+ return [jsxRuntime.jsx("div", { style: { padding: "20px 0", color: "var(--dsw-alias-label-secondary, #888)" }, children: "加载中…" }, "lg-l")];
658
+ }
659
+ if (data.status === "error") {
660
+ return [
661
+ jsxRuntime.jsx(
662
+ "div",
663
+ {
664
+ style: { padding: "20px 0", color: "var(--dsw-alias-text-danger, #e5484d)" },
665
+ children: "无法获取连接信息:" + data.message + "(确认手机连接插件已启用,且路径为 /m)",
666
+ },
667
+ "lg-e"
668
+ ),
669
+ ];
670
+ }
671
+ // v3.0.0 review:二维码 URL 携带挂载路径(App 端解析后使用,不再写死 /m)
672
+ // PR #32:路径拼接的坑与取舍见上方 buildQrPayload 注释
673
+ var mount = String(data.basePath || "/m").replace(/\/+$/, "");
674
+ var qrPayload = buildQrPayload(data);
675
+ var qrSrc = mount + "/qr.png?text=" + encodeURIComponent(qrPayload);
676
+ return [
677
+ jsxRuntime.jsx(
678
+ "div",
679
+ {
680
+ style: {
681
+ padding: "10px 12px",
682
+ borderRadius: "8px",
683
+ background: "rgba(245,166,35,.12)",
684
+ border: "1px solid rgba(245,166,35,.45)",
685
+ fontSize: "12.5px",
686
+ lineHeight: "1.6",
687
+ },
688
+ children:
689
+ "⚠️ 这个二维码不加密:用它连接后,手机的每个请求都会在局域网上明文带着访问口令,同一个 Wi-Fi 里的人可以截获并控制这台电脑上的 agent。只给还不能更新的旧版 App(1.1 及更早)用;更新 App 后请改扫" +
690
+ (lan ? "上面的加密二维码。" : "加密二维码(需要打开 LAN 桥)。"),
691
+ },
692
+ "lg-warn"
693
+ ),
536
694
  data.token
537
695
  ? null
538
- : jsxRuntime.jsx("div", {
539
- style: {
540
- padding: "10px 12px",
541
- borderRadius: "8px",
542
- background: "rgba(229,72,77,.12)",
543
- border: "1px solid rgba(229,72,77,.4)",
544
- color: "var(--dsw-alias-text-danger, #e5484d)",
545
- fontSize: "12.5px",
546
- lineHeight: "1.6",
696
+ : jsxRuntime.jsx(
697
+ "div",
698
+ {
699
+ style: {
700
+ padding: "10px 12px",
701
+ borderRadius: "8px",
702
+ background: "rgba(229,72,77,.12)",
703
+ border: "1px solid rgba(229,72,77,.4)",
704
+ color: "var(--dsw-alias-text-danger, #e5484d)",
705
+ fontSize: "12.5px",
706
+ lineHeight: "1.6",
707
+ },
708
+ children:
709
+ "⚠️ 访问口令为空:现在只有这台电脑能连接,手机连不上。要让手机连接,请删掉 cordis.patch.yml 里空的 authToken(默认的 \"@auto\" 会自动生成口令),或打开 lanBridge / 中继,然后重启。",
547
710
  },
548
- children:
549
- "⚠️ 访问口令为空:现在只有这台电脑能连接,手机连不上。要让手机连接,请删掉 cordis.patch.yml 里空的 authToken(默认的 \"@auto\" 会自动生成口令),或打开 lanBridge / 中继,然后重启。",
550
- }),
551
- jsxRuntime.jsx("div", {
552
- style: { display: "flex", flexDirection: "column", alignItems: "center", gap: "10px", padding: "14px 0" },
553
- children: [
554
- jsxRuntime.jsx("img", {
555
- src: qrSrc,
556
- alt: "连接二维码",
557
- style: { width: 216, height: 216, borderRadius: "12px", background: "#fff", padding: 8 },
558
- }),
559
- jsxRuntime.jsx("div", {
560
- style: { fontSize: "12px", color: "var(--dsw-alias-label-tertiary, #aaa)" },
561
- children: "打开 App → 扫码连接 → 对准本二维码",
562
- }),
563
- ],
564
- }),
565
- jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "8px 0 2px" }, children: "连接信息" }),
711
+ "lg-empty"
712
+ ),
713
+ jsxRuntime.jsx(
714
+ "div",
715
+ {
716
+ style: { display: "flex", flexDirection: "column", alignItems: "center", gap: "10px", padding: "14px 0" },
717
+ children: [
718
+ jsxRuntime.jsx("img", {
719
+ src: qrSrc,
720
+ alt: "连接二维码(不加密)",
721
+ style: { width: 216, height: 216, borderRadius: "12px", background: "#fff", padding: 8 },
722
+ }, "img"),
723
+ jsxRuntime.jsx("div", {
724
+ style: { fontSize: "12px", color: "var(--dsw-alias-label-tertiary, #aaa)" },
725
+ children: "旧版 App → 扫码连接 → 对准本二维码",
726
+ }, "how"),
727
+ ],
728
+ },
729
+ "lg-qr"
730
+ ),
731
+ jsxRuntime.jsx("div", { style: { fontSize: "13px", fontWeight: 600, margin: "8px 0 2px" }, children: "连接信息" }, "lg-h"),
566
732
  data.urls.map(function (u) {
567
733
  return jsxRuntime.jsx(
568
734
  "div",
@@ -599,14 +765,46 @@ window.__ModuleLoader__.load({
599
765
  })
600
766
  : null,
601
767
  ],
602
- }
768
+ },
769
+ "lg-token"
603
770
  ),
604
771
  jsxRuntime.jsx("div", {
605
772
  style: { fontSize: "12px", color: "var(--dsw-alias-label-tertiary, #aaa)", marginTop: "6px" },
606
773
  children: "二维码包含访问口令,仅在本机显示;请勿截屏转发。App 与手机浏览器(/m 网页)共用同一连接。",
607
- }),
608
- jsxRuntime.jsx(RelayPanel, { onCredentialsChanged: function () { setReloadKey(function (k) { return k + 1; }); } }),
609
- ],
774
+ }, "lg-foot"),
775
+ ];
776
+ }
777
+
778
+ var children = [
779
+ jsxRuntime.jsx("div", {
780
+ style: { fontSize: "13px", color: "var(--dsw-alias-label-secondary, #888)", lineHeight: "1.6" },
781
+ children: "用手机 DSH Mobile App 扫描下方二维码配对,即可远程发消息、看进度、收通知、审批决策。",
782
+ }, "intro"),
783
+ jsxRuntime.jsx(LanPairing, { onAvailability: setLan }, "lan"),
784
+ ];
785
+ if (lan === false) {
786
+ children.push(
787
+ jsxRuntime.jsx(
788
+ "div",
789
+ { style: mutedStyle, children: "这台电脑上局域网加密通道不可用(LAN 桥没有在监听,例如 DSH 网页版)。下面是不加密的旧二维码。" },
790
+ "lan-off"
791
+ )
792
+ );
793
+ children = children.concat(legacyBlock());
794
+ } else if (lan === true) {
795
+ children.push(
796
+ jsxRuntime.jsx(
797
+ "div",
798
+ { style: { display: "flex" }, children: jsxRuntime.jsx("button", { style: Object.assign({}, btnStyle, { marginLeft: 0 }), onClick: function () { setLegacyOpen(!legacyOpen); }, children: legacyOpen ? "收起旧版二维码" : "旧版 App(1.1 及更早)扫不了上面的码?显示旧版二维码(不加密)" }) },
799
+ "lg-toggle"
800
+ )
801
+ );
802
+ if (legacyOpen) children = children.concat(legacyBlock());
803
+ }
804
+ children.push(jsxRuntime.jsx(RelayPanel, { onCredentialsChanged: function () { setReloadKey(function (k) { return k + 1; }); } }, "relay"));
805
+ return jsxRuntime.jsx("div", {
806
+ style: { display: "flex", flexDirection: "column", gap: "6px", padding: "4px 0 16px" },
807
+ children: children,
610
808
  });
611
809
  }
612
810
 
package/lib/config.js CHANGED
@@ -291,12 +291,14 @@ export const Config = z.object({
291
291
  * Break reminder (T-15, plan §5.7, D10). After 2 hours of continuous activity from any client
292
292
  * (a gap of 10 minutes or more starts the count again) the PC sends one reminder: an SSE
293
293
  * `break/reminder` event for the app, plus a push when no app is connected. At most once per
294
- * 2 hours, never in quiet hours. On by default; `enabled: false` turns it off for this PC,
295
- * and the app's own setting (`breakReminder` in `/api/assistant`) turns it off for the user.
294
+ * 2 hours, never in quiet hours. A-13 (3.3.1): it runs once the app has sent its own switch
295
+ * (`breakReminder` in `/api/assistant`; store apps up to 3.2.7 have none, and the reminder's
296
+ * text points at that switch). `enabled: true` turns it on for this PC without that switch,
297
+ * `enabled: false` turns it off for this PC whatever the app says.
296
298
  */
297
299
  breakReminder: z
298
300
  .object({
299
- enabled: z.boolean().default(true),
301
+ enabled: z.boolean(),
300
302
  })
301
- .default({ enabled: true }),
303
+ .default({}),
302
304
  });
@@ -2,7 +2,7 @@ import { constants as fsConstants } from "node:fs";
2
2
  import { realpath, open, lstat } from "node:fs/promises";
3
3
  import { isAbsolute, relative, resolve, sep } from "node:path";
4
4
  import { createHash } from "node:crypto";
5
- import { isProtectedFile, isProtectedPath } from "./protected-paths.js";
5
+ import { isProtectedFile, isProtectedPath, isStillAt } from "./protected-paths.js";
6
6
 
7
7
  const UNTRACKED_PREVIEW_MAX = 512 * 1024;
8
8
  const SIGNATURE_SAMPLE_BYTES = 4096;
@@ -18,11 +18,30 @@ async function readPrefix(path, maximum, expected) {
18
18
  const opened = await handle.stat();
19
19
  if (isProtectedFile(opened)) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
20
20
  if (!sameRegularFile(expected, opened)) throw new Error("file changed while opening preview");
21
+ if (!isStillAt(path, opened)) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
21
22
  const buffer = Buffer.alloc(maximum + 1);
22
23
  const { bytesRead } = await handle.read(buffer, 0, maximum + 1, 0);
23
24
  return { bytes: buffer.subarray(0, bytesRead), truncated: bytesRead > maximum };
24
25
  } finally { await handle.close(); }
25
26
  }
27
+ /**
28
+ * A-06: `git diff` (unstaged and staged previews) reads the worktree file itself, so before it runs,
29
+ * the worktree file must not be (a hard link to) a protected file. A symlink is fine: git shows its
30
+ * target text, not the content. A file that is missing or special is left to git.
31
+ */
32
+ async function assertWorktreeFileNotProtected(path) {
33
+ if (isProtectedPath(path)) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
34
+ let handle;
35
+ try {
36
+ handle = await open(path, readOnlyNoFollow | (fsConstants.O_NONBLOCK ?? 0));
37
+ } catch {
38
+ return; // missing (a deletion), a symlink (ELOOP), unreadable: git shows no protected content
39
+ }
40
+ try {
41
+ const opened = await handle.stat();
42
+ if (opened.isFile() && (isProtectedFile(opened) || !isStillAt(path, opened))) throw Object.assign(new Error("path-protected"), { code: "path-protected" });
43
+ } finally { await handle.close(); }
44
+ }
26
45
  async function sampledFileSignature(path, info) {
27
46
  const handle = await open(path, readOnlyNoFollow);
28
47
  try {
@@ -232,6 +251,7 @@ export function createBundledGitReadProvider(ctx) {
232
251
  return { diff: "", binary: false, additions: 0, deletions: 0, notice: "unavailable" };
233
252
  }
234
253
  }
254
+ await assertWorktreeFileNotProtected(resolve(root, path));
235
255
  return { diff: await run(root, args, true), binary: false, additions: null, deletions: null };
236
256
  },
237
257
  async commitPreview(root, oid, path) {
File without changes