dsh-mobile-plugin 0.5.52 → 0.5.54

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/README.md CHANGED
@@ -45,6 +45,18 @@
45
45
  - **模型**:随时换模型,看有哪些渠道和可用模型,本机自建的渠道也能直接在手机上配。
46
46
  - **日程与子代理**:定时任务能看、新建、改、暂停恢复、立刻跑一次、删掉;看正在跑的子代理,打断它或者补一句话。
47
47
 
48
+ ### 远程电脑
49
+
50
+ 在家里的 A 电脑打开插件控制台的「远程电脑」,生成并复制绑定信息,再到随身的 B 电脑粘贴添加。绑定信息十分钟内有效、只能使用一次;两台电脑都需要安装支持远程电脑的插件。
51
+
52
+ 绑定后在 B 点击「在桌面端打开」,即可通过本机地址使用 A 的完整 DSH 网页,不需要域名或手机参与。默认自动选择局域网、直连、IPv6、中转或可用隧道;网络变化后重新选路,正常的实时连接不会因细小测速差异被打断。完整网页授权具有远程操作该 DSH 的能力,只向自己信任的电脑发放。
53
+
54
+ 点击后优先由插件随包分发的桌面显示壳开窗口,而不是交给系统默认浏览器。它不是给最终用户双击安装的独立应用,也不做安装器:按平台作为插件的可选依赖 `dsh-mobile-shell-<os>-<cpu>` 一起装,插件把一次性地址和可选的设备名作为命令行参数交给它。一次点击启动一个进程、开一个窗口,窗口标题带设备名;同一台 B 电脑可以同时开多台 A 电脑的窗口,互不干扰。平台包的版本独立于插件,壳没改就不抬版本,插件更新不会重下它;机器上没装对应平台包时自动回退到原来的系统浏览器路径,远程电脑功能照常可用。
55
+
56
+ 每次网页访问允许一小时,临近到期会提示;在 B 的插件控制台主动续期才能继续,到期后须重新打开,绑定关系保留。停止访问、插件退出或 A 撤销授权会断开网页连接,不停止 A 上已经运行的任务。A 可在「可访问本机的电脑」中撤销 B;B 可移除自己保存的绑定。
57
+
58
+ 网页字节在两端插件之间加密,线路只转发密文;长期绑定凭据由宿主凭据存储保存,浏览器只持有本次访问的临时会话。默认只监听本机回环,不把浏览器入口开放给局域网。
59
+
48
60
  ### 连接
49
61
 
50
62
  - 两种连法:经 relay v2 隧道从公网连回来,或者同一个 Wi-Fi 下走局域网直连。
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ // 电脑网页授权独立于手机权限;调整设备权限会同步收回该授权。
2
3
 
3
4
  /**
4
5
  * 每设备凭据库:签发、校验、吊销手机端的持久化凭据。
@@ -211,6 +212,7 @@ function issue(instanceId, device, hostToken, ttlMs = DEFAULT_TTL_MS, extra = {}
211
212
  // **只在真给了数组时才写这一格**:不写 = 全权,这是老记录与现网设备的兼容命门,
212
213
  // 绝不能在这里补一个默认数组把「没设置」变成「设置成某个子集」。
213
214
  if (Array.isArray(extra?.permissions)) record.permissions = extra.permissions.slice();
215
+ if (extra?.remoteWeb === true && deviceKey && keyId) { record.remoteWeb = true; record.kind = 'computer'; }
214
216
  prune(now);
215
217
  records.push(record);
216
218
  rebuildIndex();
@@ -248,6 +250,7 @@ function setDevicePermissions(instanceId, deviceId, permissions) {
248
250
  for (const record of records) {
249
251
  if (record.instanceId !== instanceId || record.deviceId !== deviceId || !isLive(record)) continue;
250
252
  record.permissions = wanted.slice();
253
+ if (record.remoteWeb === true) record.remoteWeb = false;
251
254
  count += 1;
252
255
  }
253
256
  if (count) save();
@@ -305,6 +308,17 @@ function findByKeyId(instanceId, keyId) {
305
308
  return null;
306
309
  }
307
310
 
311
+ /** 电脑通道只用它签署已吊销/到期的拒绝,不把失效记录恢复为授权。 */
312
+ function lookupRemoteByKeyId(instanceId, keyId) {
313
+ refresh();
314
+ if (typeof keyId !== 'string' || !keyId) return null;
315
+ for (let i = records.length - 1; i >= 0; i -= 1) {
316
+ const record = records[i];
317
+ if (record.instanceId === instanceId && record.keyId === keyId && record.deviceKey) return record;
318
+ }
319
+ return null;
320
+ }
321
+
308
322
  /**
309
323
  * 记一次「这台设备刚连上过」。
310
324
  *
@@ -402,6 +416,22 @@ function revokeAllByInstance(instanceId) {
402
416
  return count;
403
417
  }
404
418
 
419
+ /** 本实例仍有效的电脑网页授权,只返回管理清单需要的公开字段。 */
420
+ function listRemoteComputers(instanceId) {
421
+ refresh();
422
+ const now = Date.now();
423
+ const devices = new Map();
424
+ for (const record of records) {
425
+ if (record.instanceId !== instanceId || record.remoteWeb !== true || !isLive(record, now)) continue;
426
+ const previous = devices.get(record.deviceId);
427
+ if (!previous || record.createdAt > previous.createdAt) devices.set(record.deviceId, {
428
+ deviceId: record.deviceId, name: record.name || '', platform: record.platform || '',
429
+ lastSeenAt: Number(record.lastSeenAt) || 0, createdAt: Number(record.createdAt) || 0,
430
+ });
431
+ }
432
+ return [...devices.values()];
433
+ }
434
+
405
435
  function listActive() {
406
436
  load();
407
437
  const now = Date.now();
@@ -428,7 +458,7 @@ function scanDevices(instanceId, now = Date.now()) {
428
458
  /** 名下有过活记录的 deviceId:这种设备在活动清单里已经有一行,历史那半不能再出现它。 */
429
459
  const living = new Set();
430
460
  for (const record of records) {
431
- if (record.instanceId !== instanceId) continue;
461
+ if (record.instanceId !== instanceId || record.kind === 'computer') continue;
432
462
  const key = String(record.deviceId || '');
433
463
  const createdAt = Number(record.createdAt) || 0;
434
464
  if (isLive(record, now)) {
@@ -644,7 +674,7 @@ function activeDigests(instanceId) {
644
674
  // 记录只在新签发时追加,倒着走就是 createdAt 倒序:超出上限时被截掉的是最老的。
645
675
  for (let i = records.length - 1; i >= 0 && live.length < MAX_ACTIVE_DIGESTS; i -= 1) {
646
676
  const record = records[i];
647
- if (record.instanceId !== instanceId || !isLive(record, now)) continue;
677
+ if (record.instanceId !== instanceId || record.kind === 'computer' || !isLive(record, now)) continue;
648
678
  live.push({ hash: record.hash, ...(record.expiresAt ? { expiresAt: record.expiresAt } : {}) });
649
679
  }
650
680
  return live;
@@ -671,12 +701,14 @@ module.exports = {
671
701
  lookup,
672
702
  isLive,
673
703
  findByKeyId,
704
+ lookupRemoteByKeyId,
674
705
  touch,
675
706
  renew,
676
707
  refresh,
677
708
  setReadOnly,
678
709
  isReadOnly,
679
710
  listActive,
711
+ listRemoteComputers,
680
712
  listDevices,
681
713
  listHistory,
682
714
  listDevicesWithHistory,
@@ -3,8 +3,7 @@
3
3
  这个目录随 `dsh-mobile-plugin` 的 npm 包一起发布,装的是**我们自己发的官方扩展**。宿主只认
4
4
  `catalog.json` 里登记的 slug,目录里有但没登记的一律不下发。当前清单是空的。
5
5
 
6
- **Office 预览不走这里**:它发在 APP 分发系统(`platform = extension`),源码、渲染器与那六个库
7
- 在独立仓库 `dsh-office-plugin`,手机上的扩展市场页读的就是分发系统清单。
6
+ **Office / PDF 阅览由 App 内置提供**,不列入扩展清单,也不需要在这里安装。
8
7
 
9
8
  第三方扩展不经过这里。作者在自己的插件包里声明 `dshMobileExtensions` 就能让他的手机拉到,
10
9
  不用提 PR、不用我们审 —— 见 `dsh-mobile-extensions` 仓库的作者须知第 8 节(同包 `docs/` 下那份是
package/lib/client.js CHANGED
@@ -1427,28 +1427,45 @@ window.__ModuleLoader__.load({
1427
1427
  const dialog = diagnosisDialog();
1428
1428
 
1429
1429
  /**
1430
- * 点一下手机图标,**直接就是这一屏控制台**(2026-11-13 用户拍板)。
1430
+ * 那一页交给系统浏览器时打开的地址。
1431
1431
  *
1432
- * 改掉的是原先那两层:第一层「进入控制台 / 报错调试」两块大按钮、第二层才是页面。
1433
- * 理由有两条:
1434
- * 1. 那一层唯一的作用是让人多按一次 —— 而这一窗存在的意义就是「点进来就能扫码 /
1435
- * 看手机连没连上」,中间夹一层只是把正门多砌一道门槛;
1436
- * 2. 那颗「进入控制台」以前是**跳去浏览器**,用的是宿主报的 `panelUrl`。云服务器上
1437
- * 用户从公网 IP 打开 DSH 时,那个地址常常是本机的 `127.0.0.1:端口`,跳过去必然
1438
- * 打不开。现在整页就地嵌、地址按 `document.baseURI` 推(见 `panelPageUrlOf`),
1439
- * 公网、域名、反代子路径三种都能对上。
1440
- *
1441
- * 调试页没删:它退到操作栏里的「报错调试」一颗按钮(次要样式)。那一屏是排障用的,
1442
- * 不该跟日常那一屏抢第一眼。
1432
+ * 网页(`http(s)`)里用**同源推算**的地址(`panelPageUrlOf`):公网 / 域名 / 反代
1433
+ * 子路径都能对上,宿主报的 `panelUrl` 反而常是 `127.0.0.1`,从公网打开的人点过去
1434
+ * 必然打不开。桌面壳里那条同源地址是 `dsh-app://`,系统浏览器不认,只能换用宿主
1435
+ * 报的绝对 http(s) 地址(`outcome.url`,与早先「进入控制台」跳的是同一个)。
1443
1436
  */
1437
+ const browserPageUrl = (page) => {
1438
+ if (isWebPage(window)) return page === 'debug' ? debugPage : consolePage;
1439
+ const root = String(outcome.url || '').replace(/\/console\/?$/, '').replace(/\/+$/, '');
1440
+ if (!/^https?:\/\//i.test(root)) return '';
1441
+ return page === 'debug' ? `${root}/debug` : root;
1442
+ };
1444
1443
  const openBrowser = (page) => {
1444
+ const url = browserPageUrl(page);
1445
+ if (!url) {
1446
+ dialog.note(t('consolePopupBlocked'));
1447
+ return;
1448
+ }
1449
+ // 桌面壳里 `window.open` 一律被拒:交给页面导航,由壳的 `will-navigate`
1450
+ // 把外部 http(s) 地址转给系统浏览器(与 `openConfigurationPage` 同一条路)。
1451
+ if (!isWebPage(window)) {
1452
+ window.location.href = url;
1453
+ dialog.dispose();
1454
+ return;
1455
+ }
1445
1456
  if (typeof window === 'undefined' || typeof window.open !== 'function') return;
1446
- const opened = window.open(page || consolePage, '_blank', 'noreferrer');
1457
+ const opened = window.open(url, '_blank', 'noreferrer');
1447
1458
  // 开出去了就彻底销毁:用户已经不在这一窗里看了,没必要继续留着一整页。
1448
1459
  if (opened) dialog.dispose();
1449
1460
  else dialog.note(t('consolePopupBlocked'));
1450
1461
  };
1451
1462
 
1463
+ /**
1464
+ * 点一下手机图标,**直接就是这一屏控制台**:不再有「进入控制台 / 报错调试」那一层
1465
+ * 中间入口。那一层唯一的作用是让人多按一次,而这一窗存在的意义就是「点进来就能扫码 /
1466
+ * 看手机连没连上」。调试页没删,退到操作栏里的「报错调试」一颗次要按钮,那一屏排障用,
1467
+ * 不该跟日常那一屏抢第一眼。
1468
+ */
1452
1469
  dialog.open({
1453
1470
  title: t('consoleTitle'),
1454
1471
  wide: true,
@@ -1462,8 +1479,8 @@ window.__ModuleLoader__.load({
1462
1479
  },
1463
1480
  actions: [
1464
1481
  { label: t('consoleReload'), onClick: () => { dialog.dispose(); openPanel(); } },
1465
- { label: t('consoleOpenBrowser'), primary: true, onClick: () => openBrowser(consolePage) },
1466
- { label: t('consoleTroubleshoot'), onClick: () => openBrowser(debugPage) },
1482
+ { label: t('consoleOpenBrowser'), primary: true, onClick: () => openBrowser('console') },
1483
+ { label: t('consoleTroubleshoot'), onClick: () => openBrowser('debug') },
1467
1484
  { label: t('diagCopy'), onClick: () => void copyConsole() },
1468
1485
  { label: t('diagClose'), onClick: () => dialog.hide() },
1469
1486
  ],
package/lib/impl.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * `lib/sidecar-lifecycle.cjs`、路由表在 `lib/routes/*`,这些实现不许搬回来
5
5
  * (`test/assembly-layer.test.cjs` 钉着)。
6
6
  */
7
+ // 远程电脑入口独立装配,手机端路由与权限保持原有边界。
7
8
  import { createRequire } from 'node:module'
8
9
  import os from 'node:os'
9
10
  import path from 'node:path'
@@ -36,6 +37,7 @@ const { resolvePort } = require('./relay/port-allocator.cjs')
36
37
  const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
37
38
  const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
38
39
  const { createPreviewService } = require('./relay/preview.js')
40
+ const { mountRemoteComputers } = require('./remote/runtime.cjs')
39
41
  // 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
40
42
  const hostWeb = require('./mobile/host-web.js')
41
43
  // 本机设备凭据库:/api/relay/revoke-all 必须同时吊销局域网直连的 dshc_ 凭据,
@@ -536,10 +538,13 @@ function apply(ctx) {
536
538
  })
537
539
  ctx.effect(() => () => preview.close(), `${name}: preview pipes`)
538
540
 
541
+ const remoteComputers = mount('远程电脑', () => mountRemoteComputers({ ctx, state, credentials, registerRoute, lanPortInUse: advertisedLanPort, tailcat, p2p, log: warn }))
542
+
539
543
  // 移动端路由表在 lib/routes/mobile-api.js:那里是一张可以对着 App 侧 apiPaths.ts
540
544
  // 核对的「路径 → handler」表,不用在 1000 行装配代码里翻。
541
545
  mount('移动端路由', () => registerMobileRoutes({
542
546
  registerRoute,
547
+ remoteComputers,
543
548
  // 直连隧道:已配对的手机走这条拿到自己的入口地址,不用重新扫码。
544
549
  tailcat,
545
550
  // 点对点隧道:会合那一步(手机报上候选、这里把它拉起来并回自己的候选)。
@@ -1,3 +1,4 @@
1
+ // 文件浏览保留真实目录路径,仅把全空白输入视为缺省目录。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -82,7 +83,8 @@ async function listingRow(directory, name) {
82
83
  */
83
84
  async function handleDirectoryListing(_ctx, req, res) {
84
85
  const url = new URL(req.url, 'http://x');
85
- const asked = (url.searchParams.get('path') || '').trim();
86
+ const rawPath = url.searchParams.get('path') || '';
87
+ const asked = rawPath.trim() ? rawPath : '';
86
88
  if (asked && !fullyQualified(asked)) {
87
89
  return fail(res, 'bad-request', `cannot list "${asked}": not a fully qualified path`);
88
90
  }
@@ -1,3 +1,4 @@
1
+ // 本地目录浏览与宿主网关一致,保留路径中的首尾空格。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -232,7 +233,7 @@ async function subagentInterrupt(ctx, payload, signal) {
232
233
  * `formatDirectoryError` 已经按它们写好了文案,两条路对客户端应当不可区分。
233
234
  */
234
235
  async function localListDirectory(ctx, payload, signal) {
235
- const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path.trim() : undefined;
236
+ const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path : undefined;
236
237
  try {
237
238
  return ok(await listDirectory(path, { signal }));
238
239
  } catch (error) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
+ * 操作记录回传接口下线,不再保留对应权限映射。
4
5
  * 按设备发放的权限子集:权限位、档位、以及「移动路由 → 所需权限位」的分类表。
5
6
  *
6
7
  * 这是本次安全边界收紧的**唯一真源**:路由守卫按这里判位,配对档位按这里展开成权限数组,
@@ -300,9 +301,6 @@ const MAP = Object.freeze({
300
301
  '/api/mobile/v1/directory/create': V.FILES_WRITE,
301
302
  // 把这一轮回答落成文件:带正文写盘,落点与 file/create 同一份允许区,归 files.write。
302
303
  '/api/mobile/v1/session/write-body': V.FILES_WRITE,
303
- // 操作记录回传:本质是往宿主磁盘写文件(`mobile-traces/`),与文件写入同档;以前误挂在
304
- // BASE 上,等于任何已鉴权设备都能不限量写盘。
305
- '/api/mobile/v1/perf-trace': V.FILES_WRITE,
306
304
  // 项目写入队列的暂停 / 恢复:只切插件自己的队列开关,**一个文件都不写**,所以 POST 也算
307
305
  // view(给 files.write 会把只读设备挡在一件它本来就做不了的事之外,没有收益)。
308
306
  '/api/mobile/v1/project/writes': { GET: V.VIEW, POST: V.VIEW },
@@ -1,3 +1,4 @@
1
+ // 浏览、创建和工作区登记透传真实路径,保留目录名称末尾的空格。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -159,7 +160,7 @@ async function handleWorkspaces(ctx, req, res) {
159
160
  async function handleListDirectory(ctx, req, res) {
160
161
  const url = new URL(req.url, 'http://x');
161
162
  const path = url.searchParams.get('path');
162
- const payload = path && path.trim() ? { path: path.trim() } : {};
163
+ const payload = path && path.trim() ? { path } : {};
163
164
  const { value, error } = unwrap(await callHost(ctx, 'listDirectory', payload));
164
165
  if (error) return sendJson(res, 400, { ok: false, error });
165
166
  sendJson(res, 200, { ok: true, listing: value });
@@ -185,9 +186,9 @@ async function handleDirectoryRoots(_ctx, _req, res) {
185
186
  */
186
187
  async function handleCreateDirectory(ctx, req, res) {
187
188
  const body = await readJsonBody(req, 64 * 1024);
188
- const path = body && typeof body.path === 'string' ? body.path.trim() : '';
189
+ const path = body && typeof body.path === 'string' ? body.path : '';
189
190
  const name = body && typeof body.name === 'string' ? body.name.trim() : '';
190
- if (!path || !name) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path 或 name' } });
191
+ if (!path.trim() || !name) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path 或 name' } });
191
192
  const { value, error } = unwrap(await callHost(ctx, 'createDirectory', { path, name }));
192
193
  if (error) return sendJson(res, 400, { ok: false, error });
193
194
  sendJson(res, 200, { ok: true, path: value && value.path });
@@ -200,8 +201,8 @@ async function handleCreateDirectory(ctx, req, res) {
200
201
  */
201
202
  async function handleCreateWorkspace(ctx, req, res) {
202
203
  const body = await readJsonBody(req, 64 * 1024);
203
- const path = body && typeof body.path === 'string' ? body.path.trim() : '';
204
- if (!path) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path' } });
204
+ const path = body && typeof body.path === 'string' ? body.path : '';
205
+ if (!path.trim()) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path' } });
205
206
  const { value, error } = unwrap(await callWorkspace(ctx, 'create', { path }));
206
207
  if (error) return sendJson(res, 400, { ok: false, error });
207
208
  sendJson(res, 200, { ok: true, workspace: value && value.workspace, created: !!(value && value.created) });