@marktrue/dsh-mobile-remote 3.3.1-alpha.2 → 3.3.1-alpha.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 +42 -2
- package/docs/03-api.md +44 -5
- package/docs/04-security.md +11 -0
- package/docs/09-compatibility.md +5 -1
- package/lib/endpoint-registry.js +4 -0
- package/lib/experimental-bundles.js +121 -0
- package/lib/host-settings-whitelist.js +207 -0
- package/lib/host-settings.js +695 -0
- package/lib/index.js +370 -12
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -60,6 +60,9 @@ import {
|
|
|
60
60
|
probeHostPluginManager,
|
|
61
61
|
UPDATE_CHANNEL,
|
|
62
62
|
} from "./host-update-capabilities.js";
|
|
63
|
+
// issue #106:DSH 设置只读查看器的宿主侧白名单投影(固定白名单 + 三层脱敏)。
|
|
64
|
+
import { buildHostSettingsView } from "./host-settings.js";
|
|
65
|
+
import { HOST_SETTINGS_WHITELIST_VERSION } from "./host-settings-whitelist.js";
|
|
63
66
|
import { runHostManagerUpdate } from "./host-manager-update.js";
|
|
64
67
|
import {
|
|
65
68
|
TRANSACTION_PHASE,
|
|
@@ -119,6 +122,16 @@ import {
|
|
|
119
122
|
SSE_REJECT_LOG_WINDOW_MS,
|
|
120
123
|
sseConnectionStats,
|
|
121
124
|
} from "./sse-connections.js";
|
|
125
|
+
import {
|
|
126
|
+
EXPERIMENTAL_BUNDLES,
|
|
127
|
+
EXPERIMENTAL_TABLE_VERSION,
|
|
128
|
+
EXPERIMENTAL_TARGET_DSH,
|
|
129
|
+
HIDDEN_BUNDLES,
|
|
130
|
+
classifyPluginBundle,
|
|
131
|
+
experimentalTableMatches,
|
|
132
|
+
normalizeAvailability,
|
|
133
|
+
normalizeInstalled,
|
|
134
|
+
} from "./experimental-bundles.js";
|
|
122
135
|
|
|
123
136
|
/** Cordis 插件名(cordis.patch.yml 中按此 id 引用)。 */
|
|
124
137
|
export const name = "mobile-remote";
|
|
@@ -1565,6 +1578,40 @@ function sniffImageBufferType(buf) {
|
|
|
1565
1578
|
return null;
|
|
1566
1579
|
}
|
|
1567
1580
|
|
|
1581
|
+
/**
|
|
1582
|
+
* issue #170:解析一个受支持的图片类型,**扩展名与内容不一致时以内容为准**。
|
|
1583
|
+
*
|
|
1584
|
+
* 为什么不再要求「扩展名推定类型 === magic 嗅探类型」:
|
|
1585
|
+
* magic 嗅探的**目的**就是不信任扩展名。扩展名与内容不符在日常里极常见——截图工具、
|
|
1586
|
+
* 浏览器「另存为」、下载重命名、IM 转存都会产生 `.png` 里装 JPEG 这种文件。既然已经
|
|
1587
|
+
* 用 magic 确认"这是受支持的图片",再因为扩展名不符而拒绝,等于**安全校验通过后又用
|
|
1588
|
+
* 不可信信号否决它**,逻辑自相矛盾(此前 `docs/screenshots/04-chat.png` 就是这样被
|
|
1589
|
+
* 415 拒绝的,见 #170)。
|
|
1590
|
+
*
|
|
1591
|
+
* 安全边界**一条不降**:
|
|
1592
|
+
* - 扩展名仍必须在 `IMAGE_EXTENSIONS` 白名单内(`.svg`/`.heic`/`.avif`/任意未知扩展名照旧拒绝);
|
|
1593
|
+
* - magic 仍必须嗅探成功且属于受支持集合(嗅探不出 → null,调用方照旧 415,防止把非图片
|
|
1594
|
+
* 文件改名成 `.png` 蒙混过关);
|
|
1595
|
+
* - 返回的 `contentType` 恒为**嗅探值**,绝不用扩展名推定值去声明类型。
|
|
1596
|
+
*
|
|
1597
|
+
* @param {string} extension 小写扩展名(含点),来自服务端自身的 `extname()`,不是客户端输入。
|
|
1598
|
+
* @param {Buffer} bytes 已读入内存并通过大小校验的文件内容。
|
|
1599
|
+
* @returns {{contentType: string, mismatch: boolean} | null} 不受支持时返回 null。
|
|
1600
|
+
*/
|
|
1601
|
+
function resolveSupportedImageType(extension, bytes) {
|
|
1602
|
+
if (!IMAGE_EXTENSIONS.has(extension)) return null;
|
|
1603
|
+
const sniffed = sniffImageBufferType(bytes);
|
|
1604
|
+
if (!sniffed) return null;
|
|
1605
|
+
// 嗅探器目前只会返回白名单里的四种类型;保留显式成员判断,避免日后扩张嗅探器时
|
|
1606
|
+
// 意外接受一个扩展名白名单外的类型(那时 content-type 会与契约不一致)。
|
|
1607
|
+
if (sniffed !== IMAGE_EXTENSIONS.get(extension)) {
|
|
1608
|
+
const supported = new Set(IMAGE_EXTENSIONS.values());
|
|
1609
|
+
if (!supported.has(sniffed)) return null;
|
|
1610
|
+
return { contentType: sniffed, mismatch: true };
|
|
1611
|
+
}
|
|
1612
|
+
return { contentType: sniffed, mismatch: false };
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1568
1615
|
/** 从图片头解析像素尺寸(支持 PNG/GIF/WebP/JPEG);解析不到返回 null。 */
|
|
1569
1616
|
function imageDimensions(buf) {
|
|
1570
1617
|
try {
|
|
@@ -4565,7 +4612,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4565
4612
|
return { state: "unknown", reasonCode: "runtime-unknown" };
|
|
4566
4613
|
}
|
|
4567
4614
|
|
|
4568
|
-
/**
|
|
4615
|
+
/**
|
|
4616
|
+
* 把宿主 `listBundles()` 行投影成 App 可渲染的只读清单(不暴露内部诊断原文/路径)。
|
|
4617
|
+
*
|
|
4618
|
+
* #153:新增 `official`/`optional`/`availability`/`installed`/`category`/`hidden` 六个
|
|
4619
|
+
* **顶层**字段。它们不能塞进 `source`:`source` 是既有契约(App 与 `deepEqual` 测试都按
|
|
4620
|
+
* 形状断言),扩进去会让旧断言与旧 App 同时失真。
|
|
4621
|
+
*/
|
|
4569
4622
|
function pluginInventoryFromBundles(bundles, runtimeByEntryId, runtimeAvailable = false) {
|
|
4570
4623
|
const rows = Array.isArray(bundles) ? bundles : [];
|
|
4571
4624
|
return rows
|
|
@@ -4588,6 +4641,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4588
4641
|
current: bundle.name === pluginPackageName,
|
|
4589
4642
|
health,
|
|
4590
4643
|
compatibility,
|
|
4644
|
+
// #153:分类事实由宿主判定,App 只渲染(谓词见 lib/experimental-bundles.js)。
|
|
4645
|
+
official: typeof bundle.official === "boolean" ? bundle.official : null,
|
|
4646
|
+
optional: typeof bundle.optional === "boolean" ? bundle.optional : null,
|
|
4647
|
+
availability: normalizeAvailability(bundle.availability),
|
|
4648
|
+
installed: normalizeInstalled(bundle.installed),
|
|
4649
|
+
category: classifyPluginBundle(bundle),
|
|
4650
|
+
hidden: HIDDEN_BUNDLES.has(bundle.name),
|
|
4591
4651
|
// #146:只允许宿主已配置渠道的升级;不提供卸载/启停/重启。
|
|
4592
4652
|
updateAvailable: null,
|
|
4593
4653
|
updateKind: bundle.update === "registry" || bundle.update === "git" ? bundle.update : "",
|
|
@@ -4622,6 +4682,9 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4622
4682
|
: typeof bundle.version === "string" ? bundle.version : "",
|
|
4623
4683
|
source: { kind: "registry", label: "配置渠道" },
|
|
4624
4684
|
installed: false,
|
|
4685
|
+
// #153:可安装行同样带分类事实,App 才能在对应 Tab 的「可安装」段渲染。
|
|
4686
|
+
category: classifyPluginBundle(bundle),
|
|
4687
|
+
hidden: HIDDEN_BUNDLES.has(bundle.name),
|
|
4625
4688
|
}));
|
|
4626
4689
|
}
|
|
4627
4690
|
|
|
@@ -4666,6 +4729,13 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4666
4729
|
current: moduleName === pluginPackageName,
|
|
4667
4730
|
health: pluginEntryHealth(entry),
|
|
4668
4731
|
compatibility: { ok: null, state: "unknown", requirements: "" },
|
|
4732
|
+
// #153:独立配置条目不是 bundle,分类写死 unclassified(不按包名猜)。
|
|
4733
|
+
official: null,
|
|
4734
|
+
optional: null,
|
|
4735
|
+
availability: null,
|
|
4736
|
+
installed: null,
|
|
4737
|
+
category: classifyPluginBundle({ independent: true }),
|
|
4738
|
+
hidden: HIDDEN_BUNDLES.has(moduleName),
|
|
4669
4739
|
updateAvailable: null,
|
|
4670
4740
|
management: {
|
|
4671
4741
|
readOnly: true,
|
|
@@ -4681,6 +4751,162 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4681
4751
|
return { rows, unresolved };
|
|
4682
4752
|
}
|
|
4683
4753
|
|
|
4754
|
+
/**
|
|
4755
|
+
* 当前运行 DSH 的版本(#153)。唯一可信来源是宿主 `profileContext.installAnchor` 指向的
|
|
4756
|
+
* `package.json`:它就是正在运行的 dsh 应用清单。读不到返回 ""(fail-closed:表不匹配)。
|
|
4757
|
+
*/
|
|
4758
|
+
function readDshRuntimeVersion() {
|
|
4759
|
+
let anchor = "";
|
|
4760
|
+
try {
|
|
4761
|
+
const profileContext = ctx.get?.("profileContext");
|
|
4762
|
+
if (typeof profileContext?.installAnchor === "string") anchor = profileContext.installAnchor.trim();
|
|
4763
|
+
} catch { anchor = ""; }
|
|
4764
|
+
if (anchor === "") return "";
|
|
4765
|
+
try {
|
|
4766
|
+
const parsed = JSON.parse(readFileSync(anchor, "utf8"));
|
|
4767
|
+
return typeof parsed?.version === "string" ? parsed.version.trim() : "";
|
|
4768
|
+
} catch { return ""; }
|
|
4769
|
+
}
|
|
4770
|
+
|
|
4771
|
+
/**
|
|
4772
|
+
* #153 根级分类投影:告诉 App 这张静态表对不对得上当前 DSH 版本。
|
|
4773
|
+
*
|
|
4774
|
+
* `matched === false` 时 App **仍按分类展示**(用户已裁决),但页面要提示表未覆盖当前版本。
|
|
4775
|
+
* 这里只给事实,不改判任何一行的分类——分类在行上,且只由 `classifyPluginBundle` 决定。
|
|
4776
|
+
*/
|
|
4777
|
+
function pluginClassificationView() {
|
|
4778
|
+
const dshVersion = readDshRuntimeVersion();
|
|
4779
|
+
return {
|
|
4780
|
+
tableVersion: EXPERIMENTAL_TABLE_VERSION,
|
|
4781
|
+
targetDsh: EXPERIMENTAL_TARGET_DSH,
|
|
4782
|
+
dshVersion,
|
|
4783
|
+
matched: experimentalTableMatches(dshVersion),
|
|
4784
|
+
source: "static-table",
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4788
|
+
// ── #153:registry(安装源)校验与投影 ─────────────────────────────
|
|
4789
|
+
//
|
|
4790
|
+
// App 的「安装源选择」只影响**解析本次安装/检查所用 registry**,不写 profile、
|
|
4791
|
+
// 不写 .npmrc、不落插件状态目录;spec 仍由宿主 installTarget 决定,因此“手动 URL”
|
|
4792
|
+
// 不能让手机安装任意包。允许 localhost/私网(内网 Verdaccio/Nexus 是合法用例),
|
|
4793
|
+
// 不加私网黑名单;风险见 docs/04-security.md。
|
|
4794
|
+
const REGISTRY_MAX_LENGTH = 2048;
|
|
4795
|
+
|
|
4796
|
+
/**
|
|
4797
|
+
* 校验并规范化 App 传来的 registry URL。
|
|
4798
|
+
*
|
|
4799
|
+
* 返回 `{ok:true, registry, href}` 或 `{ok:false, detail}`;`detail` **只给类别,
|
|
4800
|
+
* 不回显原文**(原文可能带凭据,进入错误响应/日志即泄露)。
|
|
4801
|
+
* 规范化与宿主 `normalizeRegistry` 幂等:pathname 末尾补 `/`,输出 `href`。
|
|
4802
|
+
*/
|
|
4803
|
+
function validateRegistryUrl(value) {
|
|
4804
|
+
if (typeof value !== "string") return { ok: false, detail: "not-string" };
|
|
4805
|
+
if (value === "") return { ok: false, detail: "empty" };
|
|
4806
|
+
if (value.length > REGISTRY_MAX_LENGTH) return { ok: false, detail: "too-long" };
|
|
4807
|
+
// 控制字符与任何空白都拒绝:它们会被 URL 解析器静默裁剪,等于接受了一个“不同的”源。
|
|
4808
|
+
if (/[\u0000-\u001f\u007f]/.test(value)) return { ok: false, detail: "control-char" };
|
|
4809
|
+
if (/\s/.test(value)) return { ok: false, detail: "whitespace" };
|
|
4810
|
+
let parsed;
|
|
4811
|
+
try {
|
|
4812
|
+
parsed = new URL(value);
|
|
4813
|
+
} catch {
|
|
4814
|
+
return { ok: false, detail: "unparsable" };
|
|
4815
|
+
}
|
|
4816
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
4817
|
+
return { ok: false, detail: "unsupported-protocol" };
|
|
4818
|
+
}
|
|
4819
|
+
if (parsed.hostname === "") return { ok: false, detail: "missing-host" };
|
|
4820
|
+
if (parsed.username !== "" || parsed.password !== "") return { ok: false, detail: "has-credentials" };
|
|
4821
|
+
if (parsed.hash !== "") return { ok: false, detail: "has-fragment" };
|
|
4822
|
+
if (parsed.search !== "") return { ok: false, detail: "has-query" };
|
|
4823
|
+
// 与宿主 normalizeRegistry 幂等:先补尾斜杠再取 href。
|
|
4824
|
+
if (!parsed.pathname.endsWith("/")) parsed.pathname += "/";
|
|
4825
|
+
return { ok: true, registry: parsed.href };
|
|
4826
|
+
}
|
|
4827
|
+
|
|
4828
|
+
/**
|
|
4829
|
+
* 把一个**宿主已知**的 registry 变成可回显的安全值。
|
|
4830
|
+
*
|
|
4831
|
+
* P0:带凭据的条目整条丢弃(返回 `null` 由调用方过滤),不做“脱敏回显”——
|
|
4832
|
+
* 只去掉密码仍会暴露用户名/主机关系,且下游容易误当成可复用的源。
|
|
4833
|
+
*/
|
|
4834
|
+
function safeRegistryValue(value) {
|
|
4835
|
+
if (value === null || value === undefined) return null;
|
|
4836
|
+
const checked = validateRegistryUrl(value);
|
|
4837
|
+
return checked.ok ? checked.registry : null;
|
|
4838
|
+
}
|
|
4839
|
+
|
|
4840
|
+
/** 只保留可安全回显的 registry;`drop` 记录被丢弃条数(不含内容)。 */
|
|
4841
|
+
function safeRegistryList(values) {
|
|
4842
|
+
const kept = [];
|
|
4843
|
+
let drop = 0;
|
|
4844
|
+
for (const value of Array.isArray(values) ? values : []) {
|
|
4845
|
+
const safe = safeRegistryValue(value);
|
|
4846
|
+
if (safe === null) { drop += 1; continue; }
|
|
4847
|
+
kept.push(safe);
|
|
4848
|
+
}
|
|
4849
|
+
return { kept, drop };
|
|
4850
|
+
}
|
|
4851
|
+
|
|
4852
|
+
/** `display` 只给主机名+路径,永不回显 userinfo/query/fragment。 */
|
|
4853
|
+
function registryDisplay(href) {
|
|
4854
|
+
try {
|
|
4855
|
+
const parsed = new URL(href);
|
|
4856
|
+
return `${parsed.host}${parsed.pathname}`;
|
|
4857
|
+
} catch {
|
|
4858
|
+
return "";
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
/**
|
|
4863
|
+
* #153 C2:当前宿主“会问哪些 registry”的**只读**投影。
|
|
4864
|
+
*
|
|
4865
|
+
* 宿主 `pluginManager.registries()` 给出配置的首选源、回退源,以及 pnpm 自身配置
|
|
4866
|
+
* 解析出来的源(`resolved`,可能为 null)。旧宿主没有该方法 → `supported:false`
|
|
4867
|
+
* 但仍是 HTTP 200(不是 404/500):App 据此显示“当前电脑端不提供安装源信息”。
|
|
4868
|
+
* 本端点永不写 registry(`writable:false` 恒为 false)。
|
|
4869
|
+
*/
|
|
4870
|
+
async function readHostRegistries() {
|
|
4871
|
+
const manager = pluginManagerService();
|
|
4872
|
+
const unavailable = { ok: true, supported: false, complete: false, reason: "host-registry-unavailable", writable: false, registries: [] };
|
|
4873
|
+
if (!manager || typeof manager.registries !== "function") return unavailable;
|
|
4874
|
+
let raw;
|
|
4875
|
+
try {
|
|
4876
|
+
raw = await manager.registries();
|
|
4877
|
+
} catch {
|
|
4878
|
+
return unavailable;
|
|
4879
|
+
}
|
|
4880
|
+
if (!raw || typeof raw !== "object") return unavailable;
|
|
4881
|
+
const entries = [];
|
|
4882
|
+
let dropped = 0;
|
|
4883
|
+
const push = (value, kind, role, id) => {
|
|
4884
|
+
const safe = safeRegistryValue(value);
|
|
4885
|
+
if (safe === null) { dropped += 1; return; }
|
|
4886
|
+
entries.push({ id, kind, url: safe, display: registryDisplay(safe), role });
|
|
4887
|
+
};
|
|
4888
|
+
const primary = raw.registry === undefined ? undefined : raw.registry;
|
|
4889
|
+
if (primary === null) {
|
|
4890
|
+
// pnpm 自身配置的源:把解析结果作为信息给出,但角色标成 resolved,不当“首选”。
|
|
4891
|
+
if (typeof raw.resolved === "string" && raw.resolved !== "") push(raw.resolved, "pnpm", "resolved", "pnpm");
|
|
4892
|
+
} else if (primary !== undefined) {
|
|
4893
|
+
push(primary, "registry", "primary", "registry");
|
|
4894
|
+
}
|
|
4895
|
+
const fallbacks = Array.isArray(raw.fallbackRegistries) ? raw.fallbackRegistries : [];
|
|
4896
|
+
fallbacks.forEach((value, index) => {
|
|
4897
|
+
if (value === null || value === undefined) { dropped += 1; return; }
|
|
4898
|
+
push(value, "registry", "fallback", `fallback:${index}`);
|
|
4899
|
+
});
|
|
4900
|
+
return {
|
|
4901
|
+
ok: true,
|
|
4902
|
+
supported: true,
|
|
4903
|
+
complete: dropped === 0,
|
|
4904
|
+
reason: dropped === 0 ? "" : "registry-entries-dropped",
|
|
4905
|
+
writable: false,
|
|
4906
|
+
registries: entries,
|
|
4907
|
+
};
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4684
4910
|
async function readHostPluginInventory() {
|
|
4685
4911
|
let manager = null;
|
|
4686
4912
|
try { manager = ctx.get?.("pluginManager") ?? null; } catch { manager = null; }
|
|
@@ -4754,6 +4980,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4754
4980
|
// #156:当前宿主是否允许手机触发重启;只读能力位,不触发重启。
|
|
4755
4981
|
restartSupported: hostRestartSupported(),
|
|
4756
4982
|
},
|
|
4983
|
+
// #153:分类表与当前 DSH 版本的对账事实(App 只提示,不改判)。
|
|
4984
|
+
classification: pluginClassificationView(),
|
|
4757
4985
|
plugins,
|
|
4758
4986
|
installable: bundlesAvailable ? pluginInstallableFromBundles(bundles) : [],
|
|
4759
4987
|
};
|
|
@@ -4795,6 +5023,10 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4795
5023
|
outcomeUnknown: op.outcomeUnknown,
|
|
4796
5024
|
cancelled: op.cancelled,
|
|
4797
5025
|
errorCode: op.errorCode,
|
|
5026
|
+
// #153:逐项源归因——App 能说明“这次装/升问了哪些源、用的是哪个”,不静默换源。
|
|
5027
|
+
registries: [...op.registries],
|
|
5028
|
+
attempt: op.attempt === null ? null : { index: op.attempt.index, total: op.attempt.total },
|
|
5029
|
+
answeredRegistry: op.answeredRegistry,
|
|
4798
5030
|
startedAt: op.startedAt,
|
|
4799
5031
|
finishedAt: op.finishedAt,
|
|
4800
5032
|
};
|
|
@@ -4832,6 +5064,10 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4832
5064
|
outcomeUnknown: false,
|
|
4833
5065
|
cancelled: false,
|
|
4834
5066
|
errorCode: "",
|
|
5067
|
+
// #153:源归因快照(安装/升级用;卸载/启停恒为空/null)。
|
|
5068
|
+
registries: [],
|
|
5069
|
+
attempt: null,
|
|
5070
|
+
answeredRegistry: null,
|
|
4835
5071
|
startedAt: Date.now(),
|
|
4836
5072
|
finishedAt: null,
|
|
4837
5073
|
};
|
|
@@ -4856,6 +5092,17 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4856
5092
|
if (!opId) return;
|
|
4857
5093
|
const op = pluginOperations.get(opId);
|
|
4858
5094
|
if (!op || op.status !== "running") return;
|
|
5095
|
+
// #153:宿主逐次尝试 registry 时把“问了哪些源/第几次”记到快照上(不写日志原文)。
|
|
5096
|
+
const attempt = payload?.attempt;
|
|
5097
|
+
if (attempt && typeof attempt === "object") {
|
|
5098
|
+
const safe = safeRegistryValue(attempt.registry);
|
|
5099
|
+
if (safe !== null) {
|
|
5100
|
+
const index = Number.isFinite(attempt.index) ? attempt.index : 0;
|
|
5101
|
+
const total = Number.isFinite(attempt.total) ? attempt.total : 0;
|
|
5102
|
+
if (!op.registries.includes(safe)) op.registries.push(safe);
|
|
5103
|
+
op.attempt = index > 0 ? { index, total } : op.attempt;
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
4859
5106
|
if (op.action === "install") {
|
|
4860
5107
|
if (payload.phase === "installing") markPluginOperationStep(op, "install");
|
|
4861
5108
|
else if (payload.phase === "applying") markPluginOperationStep(op, "enable");
|
|
@@ -4868,6 +5115,22 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4868
5115
|
else if (step === "restoring") markPluginOperationStep(op, "restore");
|
|
4869
5116
|
}
|
|
4870
5117
|
|
|
5118
|
+
/**
|
|
5119
|
+
* #153:把宿主事务结果里的 registry 事实投影到操作快照。
|
|
5120
|
+
*
|
|
5121
|
+
* 只回显**可安全出网**的 URL(带凭据的整条丢弃)。`answeredRegistry` 只在事务确实
|
|
5122
|
+
* 从某个源取到包时才给:失败时不能声称“是它答的”。
|
|
5123
|
+
*/
|
|
5124
|
+
function notePluginRegistryFacts(op, change, succeeded) {
|
|
5125
|
+
const asked = [];
|
|
5126
|
+
for (const value of Array.isArray(change?.registries) ? change.registries : []) {
|
|
5127
|
+
const safe = safeRegistryValue(value);
|
|
5128
|
+
if (safe !== null && !asked.includes(safe)) asked.push(safe);
|
|
5129
|
+
}
|
|
5130
|
+
if (asked.length > 0) op.registries = asked;
|
|
5131
|
+
if (succeeded && op.registries.length > 0) op.answeredRegistry = op.registries[op.registries.length - 1];
|
|
5132
|
+
}
|
|
5133
|
+
|
|
4871
5134
|
function finishPluginOperation(op, action, result, error) {
|
|
4872
5135
|
if (!op || op.status !== "running") return;
|
|
4873
5136
|
op.finishedAt = Date.now();
|
|
@@ -4915,6 +5178,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4915
5178
|
op.status = "succeeded";
|
|
4916
5179
|
op.restartRequired = application === "restart-required";
|
|
4917
5180
|
}
|
|
5181
|
+
notePluginRegistryFacts(op, change, op.status === "succeeded");
|
|
4918
5182
|
return;
|
|
4919
5183
|
}
|
|
4920
5184
|
op.fromVersion = typeof result?.from === "string" ? result.from : "";
|
|
@@ -4935,6 +5199,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4935
5199
|
op.status = "succeeded";
|
|
4936
5200
|
op.restartRequired = application === "restart-required";
|
|
4937
5201
|
}
|
|
5202
|
+
notePluginRegistryFacts(op, change, op.status === "succeeded");
|
|
4938
5203
|
}
|
|
4939
5204
|
|
|
4940
5205
|
function pluginManagerService() {
|
|
@@ -4958,7 +5223,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4958
5223
|
});
|
|
4959
5224
|
}
|
|
4960
5225
|
|
|
4961
|
-
async function startPluginInstall(name) {
|
|
5226
|
+
async function startPluginInstall(name, registry) {
|
|
4962
5227
|
const manager = pluginManagerService();
|
|
4963
5228
|
if (!manager || typeof manager.installBundle !== "function") {
|
|
4964
5229
|
throw Object.assign(new Error("plugin-manager-unavailable"), { httpStatus: 409, code: "plugin-manager-unavailable" });
|
|
@@ -4982,6 +5247,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4982
5247
|
requestId: op.opId,
|
|
4983
5248
|
saveExact: true,
|
|
4984
5249
|
...(expectedVersion ? { expected: { name, version: expectedVersion } } : {}),
|
|
5250
|
+
...(registry === undefined ? {} : { registry }),
|
|
4985
5251
|
});
|
|
4986
5252
|
finishPluginOperation(op, "install", result, null);
|
|
4987
5253
|
} catch (error) {
|
|
@@ -4991,7 +5257,7 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4991
5257
|
return op;
|
|
4992
5258
|
}
|
|
4993
5259
|
|
|
4994
|
-
async function startPluginUpdate(name, version) {
|
|
5260
|
+
async function startPluginUpdate(name, version, registry) {
|
|
4995
5261
|
const manager = pluginManagerService();
|
|
4996
5262
|
if (!manager || typeof manager.updateBundle !== "function") {
|
|
4997
5263
|
throw Object.assign(new Error("plugin-manager-unavailable"), { httpStatus: 409, code: "plugin-manager-unavailable" });
|
|
@@ -5011,7 +5277,11 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
5011
5277
|
(async () => {
|
|
5012
5278
|
markPluginOperationStep(op, "check");
|
|
5013
5279
|
try {
|
|
5014
|
-
|
|
5280
|
+
// 宿主 updateBundle 原生接受 options.registry;不传则沿用宿主自己的解析顺序。
|
|
5281
|
+
const result = await manager.updateBundle(name, version, {
|
|
5282
|
+
requestId: op.opId,
|
|
5283
|
+
...(registry === undefined ? {} : { registry }),
|
|
5284
|
+
});
|
|
5015
5285
|
finishPluginOperation(op, "update", result, null);
|
|
5016
5286
|
} catch (error) {
|
|
5017
5287
|
finishPluginOperation(op, "update", null, error);
|
|
@@ -9003,10 +9273,18 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9003
9273
|
|
|
9004
9274
|
|
|
9005
9275
|
// ── #146:配置渠道安装/升级(宿主事务;失败由宿主自动回滚) ──
|
|
9276
|
+
// #153:`registry` 可选,只影响本次解析(不持久化);逐项源归因见下方 requested/answered/attempts。
|
|
9006
9277
|
if (rest === "/plugin-inventory/versions") {
|
|
9007
9278
|
if (requireGet(method, res)) return;
|
|
9008
9279
|
const name = (url.searchParams.get("name") ?? "").trim();
|
|
9009
9280
|
if (name === "" || name.length > 200) return error(res, 400, "invalid-plugin-name");
|
|
9281
|
+
const requestedRaw = url.searchParams.get("registry");
|
|
9282
|
+
let requestedRegistry;
|
|
9283
|
+
if (requestedRaw !== null) {
|
|
9284
|
+
const checked = validateRegistryUrl(requestedRaw);
|
|
9285
|
+
if (!checked.ok) return error(res, 400, "registry-invalid", checked.detail);
|
|
9286
|
+
requestedRegistry = checked.registry;
|
|
9287
|
+
}
|
|
9010
9288
|
const manager = pluginManagerService();
|
|
9011
9289
|
if (!manager || typeof manager.listVersions !== "function") return error(res, 409, "plugin-manager-unavailable");
|
|
9012
9290
|
let installed;
|
|
@@ -9019,10 +9297,23 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9019
9297
|
if (!installed) return error(res, 404, "plugin-not-installed");
|
|
9020
9298
|
if (installed.update === "git") return error(res, 409, "git-update-desktop-required");
|
|
9021
9299
|
if (installed.update !== "registry") return error(res, 409, "plugin-not-updatable");
|
|
9300
|
+
const attribution = (list) => {
|
|
9301
|
+
const attempts = [];
|
|
9302
|
+
for (const attempt of Array.isArray(list?.attempts) ? list.attempts : []) {
|
|
9303
|
+
const safe = safeRegistryValue(attempt?.registry);
|
|
9304
|
+
if (safe === null) continue;
|
|
9305
|
+
attempts.push({ registry: safe, problem: typeof attempt?.problem === "string" ? attempt.problem : "" });
|
|
9306
|
+
}
|
|
9307
|
+
return {
|
|
9308
|
+
requestedRegistry: requestedRegistry ?? null,
|
|
9309
|
+
answeredRegistry: safeRegistryValue(list?.registry),
|
|
9310
|
+
attempts,
|
|
9311
|
+
};
|
|
9312
|
+
};
|
|
9022
9313
|
try {
|
|
9023
|
-
const list = await manager.listVersions(name);
|
|
9314
|
+
const list = await manager.listVersions(name, requestedRegistry === undefined ? undefined : { registry: requestedRegistry });
|
|
9024
9315
|
if (list?.status === "refused") {
|
|
9025
|
-
return sendJson(res, 200, { ok: true, supported: true, status: "refused", problem: list.problem, reason: list.reason });
|
|
9316
|
+
return sendJson(res, 200, { ok: true, supported: true, status: "refused", problem: list.problem, reason: list.reason, ...attribution(list) });
|
|
9026
9317
|
}
|
|
9027
9318
|
return sendJson(res, 200, {
|
|
9028
9319
|
ok: true,
|
|
@@ -9043,11 +9334,29 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9043
9334
|
: null,
|
|
9044
9335
|
})),
|
|
9045
9336
|
omitted: Number.isFinite(list?.omitted) ? list.omitted : 0,
|
|
9337
|
+
...attribution(list),
|
|
9046
9338
|
});
|
|
9047
9339
|
} catch {
|
|
9048
9340
|
return error(res, 503, "plugin-versions-unavailable");
|
|
9049
9341
|
}
|
|
9050
9342
|
}
|
|
9343
|
+
// #153 C2:当前宿主会问哪些 registry(只读;App 不能增删)。
|
|
9344
|
+
if (rest === "/plugin-inventory/registries") {
|
|
9345
|
+
// 显式 GET/HEAD 形态:与 /plugin-inventory 一致,端点登记门禁据此判 GET/HEAD。
|
|
9346
|
+
if (method !== "GET" && method !== "HEAD") return error(res, 405, "method-not-allowed");
|
|
9347
|
+
try {
|
|
9348
|
+
const payload = await readHostRegistries();
|
|
9349
|
+
if (method === "HEAD") {
|
|
9350
|
+
res.writeHead(200, { "cache-control": "no-store" });
|
|
9351
|
+
res.end();
|
|
9352
|
+
return;
|
|
9353
|
+
}
|
|
9354
|
+
return sendJson(res, 200, payload);
|
|
9355
|
+
} catch {
|
|
9356
|
+
// 宿主读取失败也不暴露原始错误:old/failed 一律 supported=false。
|
|
9357
|
+
return sendJson(res, 200, { ok: true, supported: false, complete: false, reason: "host-registry-unavailable", writable: false, registries: [] });
|
|
9358
|
+
}
|
|
9359
|
+
}
|
|
9051
9360
|
if (rest === "/plugin-inventory/install") {
|
|
9052
9361
|
if (method !== "POST") return error(res, 405, "method-not-allowed");
|
|
9053
9362
|
let body;
|
|
@@ -9055,8 +9364,14 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9055
9364
|
catch { return error(res, 400, "bad-request", "body must be JSON"); }
|
|
9056
9365
|
const name = typeof body?.name === "string" ? body.name.trim() : "";
|
|
9057
9366
|
if (name === "" || name.length > 200) return error(res, 400, "invalid-plugin-name");
|
|
9367
|
+
let registry;
|
|
9368
|
+
if (body?.registry !== undefined && body?.registry !== null) {
|
|
9369
|
+
const checked = validateRegistryUrl(body.registry);
|
|
9370
|
+
if (!checked.ok) return error(res, 400, "registry-invalid", checked.detail);
|
|
9371
|
+
registry = checked.registry;
|
|
9372
|
+
}
|
|
9058
9373
|
try {
|
|
9059
|
-
const op = await startPluginInstall(name);
|
|
9374
|
+
const op = await startPluginInstall(name, registry);
|
|
9060
9375
|
return sendJson(res, 200, { ok: true, operation: publicPluginOperation(op) });
|
|
9061
9376
|
} catch (e) {
|
|
9062
9377
|
return error(res, Number(e?.httpStatus) || 503, e?.code || "plugin-install-failed");
|
|
@@ -9071,8 +9386,15 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
9071
9386
|
const version = typeof body?.version === "string" ? body.version.trim() : "";
|
|
9072
9387
|
if (name === "" || name.length > 200) return error(res, 400, "invalid-plugin-name");
|
|
9073
9388
|
if (version === "" || version.length > 100 || !/^[0-9A-Za-z][0-9A-Za-z.+_-]*$/.test(version)) return error(res, 400, "invalid-plugin-version");
|
|
9389
|
+
// #153:“检查到的版本装不上”本质是检查与升级问的源不同;这里同样接受 registry。
|
|
9390
|
+
let registry;
|
|
9391
|
+
if (body?.registry !== undefined && body?.registry !== null) {
|
|
9392
|
+
const checked = validateRegistryUrl(body.registry);
|
|
9393
|
+
if (!checked.ok) return error(res, 400, "registry-invalid", checked.detail);
|
|
9394
|
+
registry = checked.registry;
|
|
9395
|
+
}
|
|
9074
9396
|
try {
|
|
9075
|
-
const op = await startPluginUpdate(name, version);
|
|
9397
|
+
const op = await startPluginUpdate(name, version, registry);
|
|
9076
9398
|
return sendJson(res, 200, { ok: true, operation: publicPluginOperation(op) });
|
|
9077
9399
|
} catch (e) {
|
|
9078
9400
|
return error(res, Number(e?.httpStatus) || 503, e?.code || "plugin-update-failed");
|
|
@@ -11714,6 +12036,39 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
11714
12036
|
return;
|
|
11715
12037
|
}
|
|
11716
12038
|
|
|
12039
|
+
// ── #106:DSH 设置只读查看器(固定白名单 + 三层脱敏,宿主 fail-closed) ──
|
|
12040
|
+
// 手机端只看**宿主白名单投影**过的项:App 不保存白名单副本、不拼路径、不猜 schema;
|
|
12041
|
+
// 响应里没有的项就是不可见。本端点永不写设置(`writable:false` 恒为 false),
|
|
12042
|
+
// 非 GET/HEAD 一律 405;不写日志、不回显原始值/路径/凭据。
|
|
12043
|
+
if (rest === "/host-settings") {
|
|
12044
|
+
// 显式 GET/HEAD 形态:与 /plugin-inventory/registries 一致,端点登记门禁据此判 GET/HEAD。
|
|
12045
|
+
if (method !== "GET" && method !== "HEAD") return error(res, 405, "method-not-allowed");
|
|
12046
|
+
let view;
|
|
12047
|
+
try {
|
|
12048
|
+
view = buildHostSettingsView({
|
|
12049
|
+
settings: ctx.get("settings"),
|
|
12050
|
+
readSection: readSettingsSectionStrict,
|
|
12051
|
+
hostVersion: readDshRuntimeVersion,
|
|
12052
|
+
pluginVersion,
|
|
12053
|
+
});
|
|
12054
|
+
} catch {
|
|
12055
|
+
// 投影自身抛错也 fail-closed:整页降级,不返回半份数据。
|
|
12056
|
+
view = {
|
|
12057
|
+
ok: true, supported: false, complete: false, reason: "projection-failed",
|
|
12058
|
+
writable: false, whitelistVersion: HOST_SETTINGS_WHITELIST_VERSION,
|
|
12059
|
+
generatedAt: new Date().toISOString(),
|
|
12060
|
+
host: { dshVersion: "", pluginVersion: pluginVersion() },
|
|
12061
|
+
groups: [], namespaces: [],
|
|
12062
|
+
};
|
|
12063
|
+
}
|
|
12064
|
+
if (method === "HEAD") {
|
|
12065
|
+
res.writeHead(200, { "cache-control": "no-store" });
|
|
12066
|
+
res.end();
|
|
12067
|
+
return;
|
|
12068
|
+
}
|
|
12069
|
+
return sendJson(res, 200, view);
|
|
12070
|
+
}
|
|
12071
|
+
|
|
11717
12072
|
// ── 工作区与目录浏览(移动端新建会话选工作目录) ──
|
|
11718
12073
|
if (rest === "/workspaces") {
|
|
11719
12074
|
if (requireGet(method, res)) return;
|
|
@@ -12209,8 +12564,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
12209
12564
|
let head;
|
|
12210
12565
|
try { head = readFileSync(realTarget); } catch { return error(res, 404, "image-not-found"); }
|
|
12211
12566
|
if (head.length > IMAGE_MAX_BYTES) return error(res, 413, "image-too-large");
|
|
12212
|
-
const
|
|
12213
|
-
if (!
|
|
12567
|
+
const headType = resolveSupportedImageType(regexExtension, head);
|
|
12568
|
+
if (!headType) return error(res, 415, "unsupported-image-type");
|
|
12214
12569
|
const dims = imageDimensions(head);
|
|
12215
12570
|
if (!dims) return error(res, 415, "unsupported-image-type");
|
|
12216
12571
|
if (dims.width <= 0 || dims.height <= 0 ||
|
|
@@ -12296,8 +12651,9 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
12296
12651
|
const bytes = opened.bytes;
|
|
12297
12652
|
if (bytes.length === 0) return error(res, 404, "image-not-found");
|
|
12298
12653
|
if (bytes.length > IMAGE_MAX_BYTES) return error(res, 413, "image-too-large");
|
|
12299
|
-
const
|
|
12300
|
-
if (!
|
|
12654
|
+
const resolvedType = resolveSupportedImageType(extension, bytes);
|
|
12655
|
+
if (!resolvedType) return error(res, 415, "unsupported-image-type");
|
|
12656
|
+
const sniffed = resolvedType.contentType;
|
|
12301
12657
|
const dims = imageDimensions(bytes);
|
|
12302
12658
|
if (!dims) return error(res, 415, "unsupported-image-type");
|
|
12303
12659
|
if (dims.width <= 0 || dims.height <= 0 ||
|
|
@@ -12312,6 +12668,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
12312
12668
|
"cache-control": "private, max-age=86400",
|
|
12313
12669
|
etag,
|
|
12314
12670
|
"x-content-type-options": "nosniff",
|
|
12671
|
+
// issue #170:扩展名推定类型与实际内容不一致时的排查标记(不泄露路径)。
|
|
12672
|
+
...(resolvedType.mismatch ? { "x-image-type-mismatch": "true" } : {}),
|
|
12315
12673
|
connection: "close",
|
|
12316
12674
|
};
|
|
12317
12675
|
if (String(req.headers?.["if-none-match"] ?? "") === etag) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktrue/dsh-mobile-remote",
|
|
3
|
-
"version": "3.3.1-alpha.
|
|
3
|
+
"version": "3.3.1-alpha.3",
|
|
4
4
|
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(当前 Android 端,iOS 未开发)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"qrcode"
|
|
53
53
|
],
|
|
54
54
|
"optionalDependencies": {
|
|
55
|
-
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.3.1-alpha.
|
|
55
|
+
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.3.1-alpha.3-app"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.
|
|
59
|
-
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <=0.2.
|
|
60
|
-
"@deepseek-ai/dsh-sandbox-policy": ">=0.1.0-rc.6 <=0.2.
|
|
61
|
-
"@deepseek-ai/dsh-scope": ">=0.1.0-rc.6 <=0.2.
|
|
58
|
+
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.3 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2 || >=0.2.3-0 <0.2.3",
|
|
59
|
+
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <=0.2.3 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2 || >=0.2.3-0 <0.2.3",
|
|
60
|
+
"@deepseek-ai/dsh-sandbox-policy": ">=0.1.0-rc.6 <=0.2.3 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2 || >=0.2.3-0 <0.2.3",
|
|
61
|
+
"@deepseek-ai/dsh-scope": ">=0.1.0-rc.6 <=0.2.3 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2 || >=0.2.3-0 <0.2.3",
|
|
62
62
|
"@deepseek-ai/schemastery": ">=3.18.1",
|
|
63
63
|
"dsh-codex-connect": ">=0.1.0-alpha.4.5"
|
|
64
64
|
},
|