proxylang 0.13.2 → 0.15.0
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 +45 -41
- package/dist/{build-LwRF2Zm0.js → build-H0uxqVRQ.js} +200 -198
- package/dist/cli.js +6 -3
- package/dist/index.d.ts +18 -10
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
# proxylang
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
家里好几台设备,有的用 Surge,有的用 sing-box,每台的代理配置都要单独维护。节点和规则改一处,要去好几个文件里同步,漏改了也没人提醒。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
proxylang 让你用 TypeScript 把这些配置写在一个地方:节点、分组和规则只写一次,每台设备各自挑出口、客户端和设置,最后生成 Surge、sing-box、Mihomo、Stash 能直接用的配置文件。写错了在生成之前就会报错,不会悄悄丢掉一部分配置。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 支持哪些客户端
|
|
8
|
+
|
|
9
|
+
| 软件 | 支持程度 |
|
|
10
|
+
| -------- | -------- |
|
|
11
|
+
| sing-box | 最完整 |
|
|
12
|
+
| Surge | 较完整 |
|
|
13
|
+
| Mihomo | 常用功能 |
|
|
14
|
+
| Stash | 基础 |
|
|
15
|
+
|
|
16
|
+
目前各客户端只支持最新稳定版,使用旧版的设备请先升级客户端。
|
|
17
|
+
|
|
18
|
+
具体支持哪些平台、版本和功能,见[目标与原生输出](docs/feature/targets/README.md)。
|
|
19
|
+
|
|
20
|
+
## 五分钟上手
|
|
21
|
+
|
|
22
|
+
需要 Node 24(>=24.11.0)或 Node 26。安装 `proxylang`,在项目根目录新建 `proxylang.config.ts`:
|
|
8
23
|
|
|
9
24
|
```ts
|
|
10
25
|
import {
|
|
@@ -47,7 +62,7 @@ const sharedCases = (exits: { ai: Exit }) => [
|
|
|
47
62
|
];
|
|
48
63
|
|
|
49
64
|
const laptop = defineProfile({
|
|
50
|
-
target: { engine: "surge", platform: "macos", version: "6.
|
|
65
|
+
target: { engine: "surge", platform: "macos", version: "6.11.0" },
|
|
51
66
|
proxies: [edge],
|
|
52
67
|
groups: [ai],
|
|
53
68
|
routes: sharedRoutes({ ai }),
|
|
@@ -64,34 +79,21 @@ npx proxylang check
|
|
|
64
79
|
npx proxylang build --validation
|
|
65
80
|
```
|
|
66
81
|
|
|
67
|
-
`check`
|
|
82
|
+
`check` 检查所有设备的配置和测试用例,不读密码,也不写文件。`build --validation` 用假密码生成 `generated/out/laptop.conf`,方便你先看看结果。真正使用时,给 `EDGE_PASSWORD` 设好环境变量,再运行 `npx proxylang build`。生成的文件怎么送到设备上(托管配置、订阅、手动拷贝)由你决定。
|
|
68
83
|
|
|
69
|
-
##
|
|
84
|
+
## 几个基本概念
|
|
70
85
|
|
|
71
|
-
- **一台设备一份 Profile
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
86
|
+
- **一台设备一份 Profile。** 里面写清楚这台设备用哪个客户端的哪个版本、有哪些节点和分组、按什么顺序分流、都不匹配时走哪里。`defineBuild` 里的键名就是生成的文件名。
|
|
87
|
+
- **复用就用函数和数组。** 几台设备共用的规则写成函数,把这台设备的出口当参数传进去。数组可以嵌套,按书写顺序展开,不需要另学一套模板语法。
|
|
88
|
+
- **引用直接写对象。** `to`、`members`、`via`、`fallback` 和用例里的 `expect` 都直接引用前面创建的对象。被引用的节点或分组必须放进同一个 Profile 的 `proxies` 或 `groups`;直连和拒绝用 `outbound.direct`、`outbound.reject`。
|
|
89
|
+
- **从上往下,第一条命中的规则生效。** 都不命中才走 `fallback`。
|
|
90
|
+
- **客户端之间的差异会明说。** 比如 `group.auto()` 在 Surge 上是 Smart,在 sing-box 和 Mihomo 上是 URLTest,Stash 不支持。规则集要为每个客户端分别写来源,proxylang 不会替你转换规则内容。
|
|
76
91
|
|
|
77
|
-
|
|
92
|
+
每个节点和分组有 `id` 和 `name`:`id` 用在报错和测试用例里,`name` 是客户端里显示的名字,不写就用 `id`。改 `name` 可能让客户端忘掉你上次在分组里手动选的节点。
|
|
78
93
|
|
|
79
|
-
##
|
|
94
|
+
## 一份规则集,给不同客户端用
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
| -------- | -------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
83
|
-
| Surge | macOS 6.10.0、iOS 5.21.0 | 完整 `.conf`;`surge.general/hosts/managed`,以及 `surge.tailscale/wireguard` |
|
|
84
|
-
| sing-box | macOS/Linux 1.12.0、1.14.4 | 完整或片段 `.json`;`singBox` 设置,TUN 只在 1.14.4 完整模式可用;`singbox.tailscale` 创建 endpoint |
|
|
85
|
-
| Mihomo | macOS/Linux 1.19.32 | 完整或片段 `.yaml`;完整模式需 `mihomo.listener` |
|
|
86
|
-
| Stash | macOS 4.2.1 | 片段 `.yaml`;宿主提供入口与 DNS,仅支持 select,不支持远程规则集 |
|
|
87
|
-
|
|
88
|
-
sing-box 完整模式默认开启,须提供 `singBox.listener`;Mihomo 默认输出片段。精确能力与模式矩阵见[目标](docs/feature/targets/README.md)。不受支持的行为报 error,不静默省略。
|
|
89
|
-
|
|
90
|
-
Surge 的 `includeSniffed: true` 匹配原域名或嗅探域名;sing-box 1.14.4 的 `domainMatching: "prefer-sniffed"` 对全部域名条件优先使用嗅探域名。两者语义不同。
|
|
91
|
-
|
|
92
|
-
## 跨引擎规则集
|
|
93
|
-
|
|
94
|
-
后续 TypeScript 片段沿用上手示例中的导入和节点。把声明放在 `defineProfile` 之前,再将路由、案例和新增出口列入相应字段。
|
|
96
|
+
下面的片段沿用上手示例里的导入和节点。
|
|
95
97
|
|
|
96
98
|
```ts
|
|
97
99
|
import { ruleSet } from "proxylang";
|
|
@@ -110,13 +112,15 @@ const localServices = ruleSet({
|
|
|
110
112
|
const routes = defineRoutes({ when: localServices, to: outbound.direct });
|
|
111
113
|
```
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
规则集只是匹配条件,出口在路由里另外写。某个客户端没写来源时会报错。同一个地址被引用多次,只生成一份定义;同一个地址写了不同参数也会报错。
|
|
116
|
+
|
|
117
|
+
proxylang 生成配置时不会下载规则集。规则集的下载、更新和缓存都由客户端自己负责。Surge 内置的规则集用 `surge.ruleSets.lan` 和 `surge.ruleSets.system`。
|
|
114
118
|
|
|
115
|
-
##
|
|
119
|
+
## 用测试用例守住分流规则
|
|
116
120
|
|
|
117
|
-
Profile
|
|
121
|
+
每个 Profile 可以写 `cases`:给一个请求,写明它应该走哪个出口。`check` 和 `build` 每次都会跑这些用例,有一个不过就不会生成文件。几台设备共用的用例同样写成函数。
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
远程规则集里有什么,proxylang 看不到,所以用例里要写明“假设这个请求命中了某个规则集”:
|
|
120
124
|
|
|
121
125
|
```ts
|
|
122
126
|
const cases = [
|
|
@@ -129,13 +133,13 @@ const cases = [
|
|
|
129
133
|
];
|
|
130
134
|
```
|
|
131
135
|
|
|
132
|
-
|
|
136
|
+
信息不够、判断不出走哪条规则时,用例会失败,并告诉你还缺什么。`ip` 是请求本身带的地址,`resolvedIp` 是域名解析后的地址。用例只模拟规则匹配:不做 DNS 查询,不管分组当前选的是哪个节点,也不检查节点能不能连通。详见[路由用例](docs/feature/routing-cases/README.md)。
|
|
133
137
|
|
|
134
|
-
##
|
|
138
|
+
## 密码和链式代理
|
|
135
139
|
|
|
136
|
-
`defineSecrets`
|
|
140
|
+
`defineSecrets` 里每个密码可以来自环境变量(`env`),也可以直接写值(`value`)。配置里拿到的只是一个引用,检查和用例都通过之后才会读取真正的值。`--validation` 只用你写的 `validation` 假值,没写就报错,不会退回去读真密码。UUID 和 WireGuard 密钥的假值也要符合格式。
|
|
137
141
|
|
|
138
|
-
|
|
142
|
+
链式代理:先建好中转分组,再把它传给节点。
|
|
139
143
|
|
|
140
144
|
```ts
|
|
141
145
|
const relay = defineProxyGroup({
|
|
@@ -156,11 +160,11 @@ const createExit = (via: typeof relay) =>
|
|
|
156
160
|
const exit = createExit(relay);
|
|
157
161
|
```
|
|
158
162
|
|
|
159
|
-
|
|
163
|
+
流量的路径是 客户端 → Relay → Exit → 目标网站。中转和出口都要放进 Profile,而且不能互相引用成环。也可以用 `proxy.builder(base).name("Exit").via(relay).build()` 从已有节点派生。Surge 里生成 `underlying-proxy`,sing-box 里生成 `detour`;Surge 不允许端口跳跃和 `via` 一起用。
|
|
160
164
|
|
|
161
|
-
##
|
|
165
|
+
## 命令行
|
|
162
166
|
|
|
163
|
-
|
|
167
|
+
命令行固定读取当前目录下的 `proxylang.config.ts`。这个文件是会被执行的代码,只运行你信得过的配置。
|
|
164
168
|
|
|
165
169
|
```sh
|
|
166
170
|
npx proxylang targets
|
|
@@ -170,8 +174,8 @@ npx proxylang build --validation
|
|
|
170
174
|
npx proxylang build
|
|
171
175
|
```
|
|
172
176
|
|
|
173
|
-
`explain`
|
|
177
|
+
`explain` 告诉你一个请求会命中哪条规则、走哪个出口;请求也可以放在文件里,用 `--request-file request.json`。要假设命中规则集,在请求 JSON 的 `ruleSets` 里以规则集 id 为键、`true`/`false` 为值。所有命令都支持 `--json`,参数和输出格式见[命令行说明](docs/feature/build/cli.md)。
|
|
174
178
|
|
|
175
|
-
|
|
179
|
+
`build` 要等所有设备的配置都生成成功,才把 `out` 指向新的一批文件;中途失败的话,`out` 仍然指向上一批。退出码 0 表示成功,1 表示没有发布,2 表示已经发布但清理旧文件失败或需要手动处理,具体看返回的 `code`。旧批次会保留下来,里面有密码,留多久、怎么清理由你决定。详见[构建与发布](docs/feature/build/README.md)。
|
|
176
180
|
|
|
177
|
-
|
|
181
|
+
最后提醒一句:配置能生成、能通过客户端的语法检查,不等于在你的网络里真的能用。proxylang 不会替你启动客户端或接管系统网络,上线前还是要在设备上实际试一下。
|
|
@@ -200,7 +200,7 @@ function unsafeTunResolvers(model) {
|
|
|
200
200
|
const networks = model.tun.address.map((value) => ipaddr.parseCIDR(value));
|
|
201
201
|
return [
|
|
202
202
|
...model.listener ? [model.listener.resolver] : [],
|
|
203
|
-
...(model.dns ?? []).
|
|
203
|
+
...(model.dns ?? []).flatMap(({ server }) => typeof server === "string" ? [isIP(server) ? server : new URL(server).hostname.replace(/^\[|\]$/g, "")] : []),
|
|
204
204
|
...(model.endpoints ?? []).map((endpoint) => endpoint.bootstrapResolver)
|
|
205
205
|
].filter((value) => {
|
|
206
206
|
if (!isIP(value)) return false;
|
|
@@ -422,7 +422,10 @@ const endpointSchema = z.strictObject({
|
|
|
422
422
|
type: z.literal("sing-box-tailscale"),
|
|
423
423
|
id: idSchema,
|
|
424
424
|
hostname: domain$3.refine((x) => !x.includes(".")),
|
|
425
|
-
stateDirectory: z.string().max(4096).refine((
|
|
425
|
+
stateDirectory: z.string().max(4096).refine((value) => {
|
|
426
|
+
if (/[\p{C}$\\]/u.test(value) || /^(?:~|[a-z]:)/i.test(value)) return false;
|
|
427
|
+
return (value.startsWith("/") ? value.slice(1) : value).split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
428
|
+
}),
|
|
426
429
|
acceptRoutes: z.boolean(),
|
|
427
430
|
bootstrapResolver: ip$2,
|
|
428
431
|
authKey: secretSchema.optional(),
|
|
@@ -770,7 +773,7 @@ function dohUrl(value) {
|
|
|
770
773
|
if (!/^https:\/\/[^/]+\//.test(value)) url.pathname = "/dns-query";
|
|
771
774
|
return url;
|
|
772
775
|
}
|
|
773
|
-
const
|
|
776
|
+
const address = z.string().max(2048).refine((value) => {
|
|
774
777
|
if (isIP(value) && !value.includes("%")) return true;
|
|
775
778
|
if (!value.startsWith("https://") || /[\s\p{C},()\\"'?#]/u.test(value)) return false;
|
|
776
779
|
try {
|
|
@@ -782,15 +785,19 @@ const server = z.string().max(2048).refine((value) => {
|
|
|
782
785
|
return false;
|
|
783
786
|
}
|
|
784
787
|
});
|
|
788
|
+
const tailscale = z.strictObject({
|
|
789
|
+
endpoint: z.custom((value) => kindOf(value) === "endpoint"),
|
|
790
|
+
acceptDefaultResolvers: z.boolean().optional()
|
|
791
|
+
});
|
|
785
792
|
const dnsRulesSchema = z.array(z.strictObject({
|
|
786
793
|
pattern: z.string().min(1).max(253).refine((value) => domain$1.test(value.startsWith("*.") ? value.slice(2) : value)),
|
|
787
|
-
server
|
|
794
|
+
server: z.union([address, tailscale])
|
|
788
795
|
})).max(2e3).superRefine((rules, ctx) => {
|
|
789
|
-
if (rules.length > 2e3 || rules.some((
|
|
796
|
+
if (rules.length > 2e3 || rules.some(({ pattern, server }) => pattern.length > 253 || typeof server === "string" && server.length > 2048)) return;
|
|
790
797
|
for (let i = 0; i < rules.length; i++) for (let j = 0; j < i; j++) {
|
|
791
798
|
const a = rules[i], b = rules[j];
|
|
792
799
|
const x = a.pattern.toLowerCase(), y = b.pattern.toLowerCase();
|
|
793
|
-
if (x === y || overlap(x, y) && a.server
|
|
800
|
+
if (x === y || overlap(x, y) && !sameServer(a.server, b.server)) {
|
|
794
801
|
ctx.addIssue({
|
|
795
802
|
code: "custom",
|
|
796
803
|
message: "DNS_RULE_CONFLICT"
|
|
@@ -799,6 +806,10 @@ const dnsRulesSchema = z.array(z.strictObject({
|
|
|
799
806
|
}
|
|
800
807
|
}
|
|
801
808
|
});
|
|
809
|
+
function sameServer(a, b) {
|
|
810
|
+
if (typeof a === "string" || typeof b === "string") return a === b;
|
|
811
|
+
return a.endpoint === b.endpoint && (a.acceptDefaultResolvers ?? false) === (b.acceptDefaultResolvers ?? false);
|
|
812
|
+
}
|
|
802
813
|
function overlap(a, b) {
|
|
803
814
|
const wildA = a.startsWith("*."), wildB = b.startsWith("*.");
|
|
804
815
|
if (wildA && wildB) return a.slice(1).endsWith(b.slice(1)) || b.slice(1).endsWith(a.slice(1));
|
|
@@ -1028,7 +1039,7 @@ function defineBuild(input) {
|
|
|
1028
1039
|
const exitId = (exit) => "builtin" in exit ? exit.builtin : exit.id;
|
|
1029
1040
|
function normalizeRouting(profile, inspected) {
|
|
1030
1041
|
const sets = /* @__PURE__ */ new Map();
|
|
1031
|
-
const
|
|
1042
|
+
const singBox = profile.target.engine === "sing-box";
|
|
1032
1043
|
const lower = (condition) => {
|
|
1033
1044
|
if (condition.type === "all" || condition.type === "any") return {
|
|
1034
1045
|
type: condition.type,
|
|
@@ -1047,7 +1058,7 @@ function normalizeRouting(profile, inspected) {
|
|
|
1047
1058
|
id: condition.id,
|
|
1048
1059
|
canonical,
|
|
1049
1060
|
resource: condition,
|
|
1050
|
-
resolves: !!(
|
|
1061
|
+
resolves: !!(singBox && native?.engine === "sing-box" && native.resolve)
|
|
1051
1062
|
};
|
|
1052
1063
|
}
|
|
1053
1064
|
const ip = [
|
|
@@ -1056,7 +1067,7 @@ function normalizeRouting(profile, inspected) {
|
|
|
1056
1067
|
"ipAsn"
|
|
1057
1068
|
].includes(condition.type);
|
|
1058
1069
|
const noResolve = "noResolve" in condition ? condition.noResolve : void 0;
|
|
1059
|
-
const resolves = ip && (profile.target.engine === "surge" ||
|
|
1070
|
+
const resolves = ip && (profile.target.engine === "surge" || singBox ? noResolve !== true : profile.target.engine === "mihomo" || profile.target.engine === "stash" ? noResolve === false : false);
|
|
1060
1071
|
return {
|
|
1061
1072
|
...condition,
|
|
1062
1073
|
resolves
|
|
@@ -1359,8 +1370,8 @@ function diagnosticView(profile, inspected) {
|
|
|
1359
1370
|
}
|
|
1360
1371
|
//#endregion
|
|
1361
1372
|
//#region src/model/protocols.ts
|
|
1362
|
-
function nodeIsTcpOnly(node, engine
|
|
1363
|
-
return node.type === "http" || node.type === "anytls" && engine !== "surge" &&
|
|
1373
|
+
function nodeIsTcpOnly(node, engine) {
|
|
1374
|
+
return node.type === "http" || node.type === "anytls" && engine !== "surge" && engine !== "sing-box" || node.type === "vmess" || node.type === "vless" && !(engine === "sing-box" && node.packetEncoding) || engine === "surge" && node.type === "shadowsocks" && node.surge?.udpRelay === false;
|
|
1364
1375
|
}
|
|
1365
1376
|
//#endregion
|
|
1366
1377
|
//#region src/model/network.ts
|
|
@@ -1435,13 +1446,24 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1435
1446
|
if (kindOf(exit) !== "builtin" && !listed.has(exit)) error("UNLISTED_EXIT", path, owner);
|
|
1436
1447
|
if (profile.target.engine !== "surge" && "builtin" in exit && !["DIRECT", "REJECT"].includes(exit.builtin)) error("EXIT_UNSUPPORTED", path, owner);
|
|
1437
1448
|
};
|
|
1449
|
+
const tailscaleDnsDefaults = /* @__PURE__ */ new Map();
|
|
1450
|
+
profile.dns?.forEach((rule, i) => {
|
|
1451
|
+
if (typeof rule.server === "string") return;
|
|
1452
|
+
const { endpoint, acceptDefaultResolvers = false } = rule.server;
|
|
1453
|
+
const path = `dns[${i}].server`;
|
|
1454
|
+
reference(endpoint, `${path}.endpoint`, rule);
|
|
1455
|
+
if (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment") error("DNS_UNSUPPORTED", path, rule, "Tailscale DNS requires sing-box standalone");
|
|
1456
|
+
const previous = tailscaleDnsDefaults.get(endpoint);
|
|
1457
|
+
if (previous === void 0) tailscaleDnsDefaults.set(endpoint, acceptDefaultResolvers);
|
|
1458
|
+
else if (previous !== acceptDefaultResolvers) error("TAILSCALE_DNS_OPTIONS_CONFLICT", `${path}.acceptDefaultResolvers`, rule);
|
|
1459
|
+
});
|
|
1438
1460
|
const edges = /* @__PURE__ */ new Map();
|
|
1439
1461
|
for (const resource of resources) {
|
|
1440
1462
|
const path = resource.type === "proxy-group" ? `groups.${resource.id}` : `proxies.${resource.id}`;
|
|
1441
1463
|
if (resource.type === "proxy-group") {
|
|
1442
1464
|
resource.members.forEach((m, i) => {
|
|
1443
1465
|
reference(m, `${path}.members[${i}]`, resource);
|
|
1444
|
-
if (kindOf(m) === "endpoint") error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
|
|
1466
|
+
if (kindOf(m) === "endpoint" && (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment" || resource.algorithm.type !== "select")) error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
|
|
1445
1467
|
});
|
|
1446
1468
|
edges.set(resource, resource.members.filter((m) => kindOf(m) !== "builtin"));
|
|
1447
1469
|
if (resource.algorithm.type === "auto" && profile.target.engine !== "stash") selections.push({
|
|
@@ -1487,7 +1509,7 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1487
1509
|
if (cached !== void 0) return cached;
|
|
1488
1510
|
if (tcpVisiting.has(exit)) return false;
|
|
1489
1511
|
tcpVisiting.add(exit);
|
|
1490
|
-
let tcp = kindOf(exit) === "node" && nodeIsTcpOnly(exit, profile.target.engine
|
|
1512
|
+
let tcp = kindOf(exit) === "node" && nodeIsTcpOnly(exit, profile.target.engine);
|
|
1491
1513
|
for (const edge of edges.get(exit) ?? []) tcp = tcpOnly(edge) || tcp;
|
|
1492
1514
|
tcpVisiting.delete(exit);
|
|
1493
1515
|
tcpCache.set(exit, tcp);
|
|
@@ -1507,7 +1529,7 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1507
1529
|
return unsafe;
|
|
1508
1530
|
};
|
|
1509
1531
|
const requiresTcp = (exit) => rejectUnsupportedSurgeUdp ? unsafeSurgeRelay(exit) : tcpOnly(exit);
|
|
1510
|
-
if (!(profile.target.engine === "sing-box" && profile.
|
|
1532
|
+
if (!(profile.target.engine === "sing-box" && profile.singBox?.unsupportedUdp === "reject")) {
|
|
1511
1533
|
profile.routes.forEach((route, i) => {
|
|
1512
1534
|
if (requiresTcp(route.to) && truthPossibilities(route.when, "udp").includes(true)) error("TCP_ONLY_EXIT", `routes[${i}].to`, route);
|
|
1513
1535
|
});
|
|
@@ -1753,7 +1775,13 @@ function normalizeProfile(profile) {
|
|
|
1753
1775
|
};
|
|
1754
1776
|
}),
|
|
1755
1777
|
fallback: destination(profile.fallback),
|
|
1756
|
-
...profile.dns === void 0 ? {} : { dns: profile.dns }
|
|
1778
|
+
...profile.dns === void 0 ? {} : { dns: profile.dns.map(({ pattern, server }) => ({
|
|
1779
|
+
pattern,
|
|
1780
|
+
server: typeof server === "string" ? server : {
|
|
1781
|
+
...server,
|
|
1782
|
+
endpoint: server.endpoint.id
|
|
1783
|
+
}
|
|
1784
|
+
})) },
|
|
1757
1785
|
...extension
|
|
1758
1786
|
}));
|
|
1759
1787
|
}
|
|
@@ -1852,22 +1880,22 @@ function validateProxyOptions(node, target, diagnostics) {
|
|
|
1852
1880
|
return;
|
|
1853
1881
|
}
|
|
1854
1882
|
const tls = "tls" in node ? node.tls : void 0;
|
|
1855
|
-
const
|
|
1856
|
-
if (node.type === "vless" && !
|
|
1883
|
+
const singBox = target.engine === "sing-box";
|
|
1884
|
+
if (node.type === "vless" && !singBox && (node.flow !== void 0 || node.packetEncoding !== void 0 || node.reality !== void 0 || node.utlsFingerprint !== void 0)) diagnostics.push({
|
|
1857
1885
|
severity: "error",
|
|
1858
1886
|
code: "PROXY_OPTION_UNSUPPORTED",
|
|
1859
1887
|
target: target.id,
|
|
1860
1888
|
path: `proxies.${node.id}`,
|
|
1861
|
-
message: "VLESS 扩展选项仅支持 sing-box
|
|
1889
|
+
message: "VLESS 扩展选项仅支持 sing-box"
|
|
1862
1890
|
});
|
|
1863
1891
|
if (target.engine !== "surge") {
|
|
1864
1892
|
const surgeOptions = "surge" in node ? node.surge : void 0;
|
|
1865
|
-
const supportedUdpDeclaration =
|
|
1893
|
+
const supportedUdpDeclaration = singBox && surgeOptions !== void 0 && [
|
|
1866
1894
|
"trojan",
|
|
1867
1895
|
"anytls",
|
|
1868
1896
|
"shadowsocks"
|
|
1869
1897
|
].includes(node.type) && Object.keys(surgeOptions).length === 1 && "udpRelay" in surgeOptions && surgeOptions.udpRelay === true;
|
|
1870
|
-
if (!
|
|
1898
|
+
if (!singBox && node.tcpFastOpen !== void 0 || singBox && node.type === "anytls" && node.tcpFastOpen === true || !singBox && "skipCertVerify" in node && node.skipCertVerify !== void 0 || !singBox && tls?.skipCertVerify !== void 0 || surgeOptions !== void 0 && !supportedUdpDeclaration) diagnostics.push({
|
|
1871
1899
|
severity: "error",
|
|
1872
1900
|
code: "PROXY_OPTION_UNSUPPORTED",
|
|
1873
1901
|
target: target.id,
|
|
@@ -2269,10 +2297,14 @@ function normalizeSurgeProfile(p) {
|
|
|
2269
2297
|
const tunnels = p.proxies.filter((x) => ["tailscale", "wireguard"].includes(x.type));
|
|
2270
2298
|
if (p.proxies.some((x) => x.type === "sing-box-tailscale")) throw new ProfileDefinitionError("PROFILE_ENDPOINT_UNSUPPORTED");
|
|
2271
2299
|
const groups = p.groups;
|
|
2300
|
+
const dns = p.dns?.flatMap(({ pattern, server }) => typeof server === "string" ? [{
|
|
2301
|
+
pattern,
|
|
2302
|
+
server
|
|
2303
|
+
}] : []);
|
|
2272
2304
|
return lowerSurgeProfile({
|
|
2273
2305
|
target: p.target,
|
|
2274
2306
|
...p.surge,
|
|
2275
|
-
...
|
|
2307
|
+
...dns?.length ? { hosts: [...dns, ...p.surge?.hosts ?? []] } : {},
|
|
2276
2308
|
nodes: nodes.map((n) => {
|
|
2277
2309
|
const { name: _name, ...rest } = n;
|
|
2278
2310
|
return {
|
|
@@ -2402,125 +2434,9 @@ function singboxProxy(node, secret) {
|
|
|
2402
2434
|
return result;
|
|
2403
2435
|
}
|
|
2404
2436
|
//#endregion
|
|
2405
|
-
//#region src/targets/catalog.ts
|
|
2406
|
-
const targetCatalog = deepFreeze([
|
|
2407
|
-
{
|
|
2408
|
-
engine: "sing-box",
|
|
2409
|
-
version: "1.14.4",
|
|
2410
|
-
autoGroup: "urltest",
|
|
2411
|
-
platforms: ["linux", "macos"],
|
|
2412
|
-
protocols: [
|
|
2413
|
-
"hysteria2",
|
|
2414
|
-
"trojan",
|
|
2415
|
-
"http",
|
|
2416
|
-
"anytls",
|
|
2417
|
-
"shadowsocks",
|
|
2418
|
-
"vmess",
|
|
2419
|
-
"vless"
|
|
2420
|
-
],
|
|
2421
|
-
endpoints: ["sing-box-tailscale"],
|
|
2422
|
-
groups: ["select", "urltest"],
|
|
2423
|
-
nativeRuleSets: ["source", "binary"],
|
|
2424
|
-
dns: "typed"
|
|
2425
|
-
},
|
|
2426
|
-
{
|
|
2427
|
-
engine: "sing-box",
|
|
2428
|
-
version: "1.12.0",
|
|
2429
|
-
autoGroup: "urltest",
|
|
2430
|
-
platforms: ["linux", "macos"],
|
|
2431
|
-
protocols: [
|
|
2432
|
-
"hysteria2",
|
|
2433
|
-
"trojan",
|
|
2434
|
-
"http",
|
|
2435
|
-
"anytls",
|
|
2436
|
-
"shadowsocks",
|
|
2437
|
-
"vmess",
|
|
2438
|
-
"vless"
|
|
2439
|
-
],
|
|
2440
|
-
endpoints: ["sing-box-tailscale"],
|
|
2441
|
-
groups: ["select", "urltest"],
|
|
2442
|
-
nativeRuleSets: ["source", "binary"],
|
|
2443
|
-
dns: "typed"
|
|
2444
|
-
},
|
|
2445
|
-
{
|
|
2446
|
-
engine: "surge",
|
|
2447
|
-
version: "5.21.0",
|
|
2448
|
-
autoGroup: "surge-smart",
|
|
2449
|
-
platforms: ["ios"],
|
|
2450
|
-
protocols: [
|
|
2451
|
-
"hysteria2",
|
|
2452
|
-
"trojan",
|
|
2453
|
-
"http",
|
|
2454
|
-
"anytls",
|
|
2455
|
-
"shadowsocks",
|
|
2456
|
-
"vmess"
|
|
2457
|
-
],
|
|
2458
|
-
endpoints: [],
|
|
2459
|
-
groups: ["select", "surge-smart"],
|
|
2460
|
-
nativeRuleSets: ["rule-set", "domain-set"],
|
|
2461
|
-
dns: "general"
|
|
2462
|
-
},
|
|
2463
|
-
{
|
|
2464
|
-
engine: "surge",
|
|
2465
|
-
version: "6.10.0",
|
|
2466
|
-
autoGroup: "surge-smart",
|
|
2467
|
-
platforms: ["macos"],
|
|
2468
|
-
protocols: [
|
|
2469
|
-
"hysteria2",
|
|
2470
|
-
"trojan",
|
|
2471
|
-
"http",
|
|
2472
|
-
"anytls",
|
|
2473
|
-
"shadowsocks",
|
|
2474
|
-
"vmess"
|
|
2475
|
-
],
|
|
2476
|
-
endpoints: [],
|
|
2477
|
-
groups: ["select", "surge-smart"],
|
|
2478
|
-
nativeRuleSets: ["rule-set", "domain-set"],
|
|
2479
|
-
dns: "general"
|
|
2480
|
-
},
|
|
2481
|
-
{
|
|
2482
|
-
engine: "mihomo",
|
|
2483
|
-
version: "1.19.32",
|
|
2484
|
-
autoGroup: "urltest",
|
|
2485
|
-
platforms: ["linux", "macos"],
|
|
2486
|
-
protocols: [
|
|
2487
|
-
"hysteria2",
|
|
2488
|
-
"trojan",
|
|
2489
|
-
"http",
|
|
2490
|
-
"anytls",
|
|
2491
|
-
"shadowsocks",
|
|
2492
|
-
"vmess",
|
|
2493
|
-
"vless"
|
|
2494
|
-
],
|
|
2495
|
-
endpoints: [],
|
|
2496
|
-
groups: ["select", "urltest"],
|
|
2497
|
-
nativeRuleSets: ["yaml", "text"],
|
|
2498
|
-
dns: "clash"
|
|
2499
|
-
},
|
|
2500
|
-
{
|
|
2501
|
-
engine: "stash",
|
|
2502
|
-
version: "4.2.1",
|
|
2503
|
-
autoGroup: null,
|
|
2504
|
-
platforms: ["macos"],
|
|
2505
|
-
protocols: [
|
|
2506
|
-
"hysteria2",
|
|
2507
|
-
"trojan",
|
|
2508
|
-
"http",
|
|
2509
|
-
"anytls",
|
|
2510
|
-
"shadowsocks",
|
|
2511
|
-
"vmess"
|
|
2512
|
-
],
|
|
2513
|
-
endpoints: [],
|
|
2514
|
-
groups: ["select"],
|
|
2515
|
-
nativeRuleSets: [],
|
|
2516
|
-
dns: "external"
|
|
2517
|
-
}
|
|
2518
|
-
]);
|
|
2519
|
-
//#endregion
|
|
2520
2437
|
//#region src/engines/sing-box/render.ts
|
|
2521
2438
|
const DIRECT = "pl-direct";
|
|
2522
2439
|
const DNS = "pl-dns";
|
|
2523
|
-
const RULESET_DIRECT = "pl-ruleset-direct";
|
|
2524
2440
|
const actionTag = (a, name) => a.type === "route" ? name(a.to) : a.type === "direct" ? DIRECT : "pl-reject";
|
|
2525
2441
|
function singCondition(condition) {
|
|
2526
2442
|
switch (condition.type) {
|
|
@@ -2563,14 +2479,12 @@ function singAction(action, name) {
|
|
|
2563
2479
|
function singbox(plan, secret) {
|
|
2564
2480
|
const model = plan.model, target = model.target;
|
|
2565
2481
|
const name = (id) => plan.names?.get(id) ?? id;
|
|
2566
|
-
const modern = targetCatalog.find((entry) => entry.engine === target.engine && entry.version === target.version)?.dns === "typed";
|
|
2567
2482
|
const standalone = target.mode === "standalone";
|
|
2568
|
-
const routedDns =
|
|
2483
|
+
const routedDns = standalone && !!model.dns?.length;
|
|
2569
2484
|
const domainResolver = routedDns ? "pl-routed-dns" : DNS;
|
|
2570
2485
|
const outbounds = [{
|
|
2571
2486
|
type: "direct",
|
|
2572
|
-
tag: DIRECT
|
|
2573
|
-
...!modern && standalone ? { domain_strategy: "prefer_ipv4" } : {}
|
|
2487
|
+
tag: DIRECT
|
|
2574
2488
|
}];
|
|
2575
2489
|
if (model.groups.some((group) => group.members.includes("REJECT"))) outbounds.push({
|
|
2576
2490
|
type: "block",
|
|
@@ -2580,13 +2494,13 @@ function singbox(plan, secret) {
|
|
|
2580
2494
|
...singboxProxy(aliasProxyServer(node, model.serverAliases), secret),
|
|
2581
2495
|
tag: name(node.id),
|
|
2582
2496
|
...node.via ? { detour: name(node.via) } : {},
|
|
2583
|
-
...
|
|
2497
|
+
...routedDns ? { domain_resolver: {
|
|
2584
2498
|
server: domainResolver,
|
|
2585
2499
|
strategy: "prefer_ipv4"
|
|
2586
2500
|
} } : {}
|
|
2587
2501
|
});
|
|
2588
2502
|
for (const group of model.groups) outbounds.push(singboxGroup(group, (id) => singboxMemberTag(name(id))));
|
|
2589
|
-
const rules = model.rules.flatMap((rule) => [...
|
|
2503
|
+
const rules = model.rules.flatMap((rule) => [...needsResolve(rule.when) ? [{
|
|
2590
2504
|
ip_cidr: ["0.0.0.0/0", "::/0"],
|
|
2591
2505
|
invert: true,
|
|
2592
2506
|
action: "resolve"
|
|
@@ -2611,24 +2525,20 @@ function singbox(plan, secret) {
|
|
|
2611
2525
|
inbound: ["pl-dns-listener"],
|
|
2612
2526
|
action: "hijack-dns"
|
|
2613
2527
|
});
|
|
2614
|
-
if (plan.nativeRuleSets.length) {
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2528
|
+
if (plan.nativeRuleSets.length) routing.rule_set = plan.nativeRuleSets.map((r) => ({
|
|
2529
|
+
type: "remote",
|
|
2530
|
+
tag: r.id,
|
|
2531
|
+
url: r.url,
|
|
2532
|
+
format: r.format,
|
|
2533
|
+
update_interval: `${r.intervalSeconds}s`,
|
|
2534
|
+
http_client: {
|
|
2535
|
+
version: 2,
|
|
2536
|
+
...standalone ? { domain_resolver: {
|
|
2619
2537
|
server: DNS,
|
|
2620
2538
|
strategy: "prefer_ipv4"
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
type: "remote",
|
|
2625
|
-
tag: r.id,
|
|
2626
|
-
url: r.url,
|
|
2627
|
-
format: r.format,
|
|
2628
|
-
update_interval: `${r.intervalSeconds}s`,
|
|
2629
|
-
download_detour: routedDns ? RULESET_DIRECT : DIRECT
|
|
2630
|
-
}));
|
|
2631
|
-
}
|
|
2539
|
+
} } : {}
|
|
2540
|
+
}
|
|
2541
|
+
}));
|
|
2632
2542
|
if (model.fallback.type === "reject") rules.push(singAction(model.fallback, name));
|
|
2633
2543
|
else routing.final = actionTag(model.fallback, name);
|
|
2634
2544
|
const config = {
|
|
@@ -2665,21 +2575,17 @@ function singbox(plan, secret) {
|
|
|
2665
2575
|
}] : []
|
|
2666
2576
|
];
|
|
2667
2577
|
config.dns = {
|
|
2668
|
-
servers: [
|
|
2578
|
+
servers: [{
|
|
2669
2579
|
type: "udp",
|
|
2670
2580
|
tag: DNS,
|
|
2671
2581
|
server: listener.resolver,
|
|
2672
2582
|
server_port: 53
|
|
2673
|
-
} : {
|
|
2674
|
-
tag: DNS,
|
|
2675
|
-
address: `udp://${isIP(listener.resolver) === 6 ? `[${listener.resolver}]` : listener.resolver}`,
|
|
2676
|
-
detour: DIRECT
|
|
2677
2583
|
}],
|
|
2678
2584
|
final: DNS,
|
|
2679
2585
|
strategy: "prefer_ipv4",
|
|
2680
2586
|
...model.domainMatching ? { reverse_mapping: true } : {}
|
|
2681
2587
|
};
|
|
2682
|
-
|
|
2588
|
+
routing.default_domain_resolver = {
|
|
2683
2589
|
server: domainResolver,
|
|
2684
2590
|
strategy: "prefer_ipv4"
|
|
2685
2591
|
};
|
|
@@ -2692,21 +2598,33 @@ function singbox(plan, secret) {
|
|
|
2692
2598
|
server: "127.0.0.1",
|
|
2693
2599
|
server_port: model.listener.port
|
|
2694
2600
|
});
|
|
2601
|
+
const tailscaleDnsTags = /* @__PURE__ */ new Map();
|
|
2695
2602
|
dns.rules = model.dns.map((rule, index) => {
|
|
2696
2603
|
const tag = `pl-domain-dns-${index}`;
|
|
2697
|
-
|
|
2604
|
+
const condition = dnsCondition(rule);
|
|
2605
|
+
if (typeof rule.server !== "string") {
|
|
2606
|
+
const { endpoint, acceptDefaultResolvers } = rule.server;
|
|
2607
|
+
const existing = tailscaleDnsTags.get(endpoint);
|
|
2608
|
+
if (existing !== void 0) return {
|
|
2609
|
+
...condition,
|
|
2610
|
+
server: existing
|
|
2611
|
+
};
|
|
2612
|
+
tailscaleDnsTags.set(endpoint, tag);
|
|
2613
|
+
dns.servers.push({
|
|
2614
|
+
type: "tailscale",
|
|
2615
|
+
tag,
|
|
2616
|
+
endpoint: name(endpoint),
|
|
2617
|
+
...acceptDefaultResolvers === void 0 ? {} : { accept_default_resolvers: acceptDefaultResolvers }
|
|
2618
|
+
});
|
|
2619
|
+
} else if (isIP(rule.server)) dns.servers.push({
|
|
2698
2620
|
type: "udp",
|
|
2699
2621
|
tag,
|
|
2700
2622
|
server: rule.server,
|
|
2701
2623
|
server_port: 53
|
|
2702
|
-
} : {
|
|
2703
|
-
tag,
|
|
2704
|
-
address: `udp://${isIP(rule.server) === 6 ? `[${rule.server}]` : rule.server}`,
|
|
2705
|
-
detour: DIRECT
|
|
2706
2624
|
});
|
|
2707
2625
|
else {
|
|
2708
2626
|
const url = dohUrl(rule.server);
|
|
2709
|
-
dns.servers.push(
|
|
2627
|
+
dns.servers.push({
|
|
2710
2628
|
type: "https",
|
|
2711
2629
|
tag,
|
|
2712
2630
|
server: url.hostname.replace(/^\[|\]$/g, ""),
|
|
@@ -2717,15 +2635,10 @@ function singbox(plan, secret) {
|
|
|
2717
2635
|
server: DNS,
|
|
2718
2636
|
strategy: "prefer_ipv4"
|
|
2719
2637
|
}
|
|
2720
|
-
} : {
|
|
2721
|
-
tag,
|
|
2722
|
-
address: url.href,
|
|
2723
|
-
address_resolver: DNS,
|
|
2724
|
-
detour: DIRECT
|
|
2725
2638
|
});
|
|
2726
2639
|
}
|
|
2727
2640
|
return {
|
|
2728
|
-
...
|
|
2641
|
+
...condition,
|
|
2729
2642
|
server: tag
|
|
2730
2643
|
};
|
|
2731
2644
|
});
|
|
@@ -3015,33 +2928,23 @@ function clashConfig(plan, secret) {
|
|
|
3015
2928
|
//#region src/engines/sing-box/check.ts
|
|
3016
2929
|
function engineChecks$2(model) {
|
|
3017
2930
|
const t = model.target;
|
|
3018
|
-
const modern = model.target.version === "1.14.4";
|
|
3019
2931
|
return {
|
|
3020
|
-
node(
|
|
3021
|
-
if (!isIP(node.server) && !modern) error("PROXY_HOSTNAME_MODE_UNSUPPORTED", `proxies.${node.id}.server`);
|
|
3022
|
-
},
|
|
2932
|
+
node() {},
|
|
3023
2933
|
group(group, error) {
|
|
3024
|
-
if (group.members.some((x) => ["DIRECT", "REJECT"].includes(x)) &&
|
|
2934
|
+
if (group.members.some((x) => ["DIRECT", "REJECT"].includes(x)) && group.type !== "select") error("GROUP_BUILTIN_UNSUPPORTED", `groups.${group.id}`);
|
|
3025
2935
|
},
|
|
3026
2936
|
profile(error) {
|
|
3027
2937
|
if (model.dns?.length && t.mode !== "standalone") error("DNS_MODE_UNSUPPORTED", "dns");
|
|
3028
|
-
if (!modern && (model.domainMatching !== void 0 || model.serverAliases !== void 0 || model.cacheFile !== void 0 || model.unsupportedUdp !== void 0)) error("PROGRAM_OPTION_UNSUPPORTED", "singBox");
|
|
3029
2938
|
if (model.cacheFile !== void 0 && t.mode !== "standalone") error("PROGRAM_OPTION_UNSUPPORTED", "singBox.cacheFile");
|
|
3030
2939
|
if (model.tun) {
|
|
3031
|
-
if (
|
|
2940
|
+
if (t.mode !== "standalone") error("TUN_TARGET_UNSUPPORTED", "singBox.tun");
|
|
3032
2941
|
if (unsafeTunResolvers(model).length) error("TUN_DNS_LOOP", "singBox.tun");
|
|
3033
2942
|
}
|
|
3034
2943
|
},
|
|
3035
2944
|
match(m, path, nested, error) {
|
|
3036
|
-
if ("includeSniffed" in m && m.includeSniffed &&
|
|
3037
|
-
if (m.type === "ipCidr" &&
|
|
3038
|
-
|
|
3039
|
-
if (modern && nested && m.noResolve !== true) error("RESOLVE_NESTED", path);
|
|
3040
|
-
}
|
|
3041
|
-
if (m.type === "nativeRuleSet") {
|
|
3042
|
-
if (m.engine === "sing-box" && m.resolve !== void 0 && !modern) error("MATCH_OPTION_UNSUPPORTED", path);
|
|
3043
|
-
if (m.engine === "sing-box" && m.resolve && nested) error("RESOLVE_NESTED", path);
|
|
3044
|
-
}
|
|
2945
|
+
if ("includeSniffed" in m && m.includeSniffed && model.domainMatching !== "prefer-sniffed") error("MATCH_OPTION_UNSUPPORTED", path);
|
|
2946
|
+
if (m.type === "ipCidr" && nested && m.noResolve !== true) error("RESOLVE_NESTED", path);
|
|
2947
|
+
if (m.type === "nativeRuleSet" && m.engine === "sing-box" && m.resolve && nested) error("RESOLVE_NESTED", path);
|
|
3045
2948
|
}
|
|
3046
2949
|
};
|
|
3047
2950
|
}
|
|
@@ -3092,8 +2995,106 @@ function engineChecks(model) {
|
|
|
3092
2995
|
};
|
|
3093
2996
|
}
|
|
3094
2997
|
//#endregion
|
|
2998
|
+
//#region src/targets/catalog.ts
|
|
2999
|
+
const targetCatalog = deepFreeze([
|
|
3000
|
+
{
|
|
3001
|
+
engine: "sing-box",
|
|
3002
|
+
version: "1.14.4",
|
|
3003
|
+
autoGroup: "urltest",
|
|
3004
|
+
platforms: ["linux", "macos"],
|
|
3005
|
+
protocols: [
|
|
3006
|
+
"hysteria2",
|
|
3007
|
+
"trojan",
|
|
3008
|
+
"http",
|
|
3009
|
+
"anytls",
|
|
3010
|
+
"shadowsocks",
|
|
3011
|
+
"vmess",
|
|
3012
|
+
"vless"
|
|
3013
|
+
],
|
|
3014
|
+
endpoints: ["sing-box-tailscale"],
|
|
3015
|
+
groups: ["select", "urltest"],
|
|
3016
|
+
nativeRuleSets: ["source", "binary"],
|
|
3017
|
+
dns: "typed"
|
|
3018
|
+
},
|
|
3019
|
+
{
|
|
3020
|
+
engine: "surge",
|
|
3021
|
+
version: "5.23.0",
|
|
3022
|
+
autoGroup: "surge-smart",
|
|
3023
|
+
platforms: ["ios"],
|
|
3024
|
+
protocols: [
|
|
3025
|
+
"hysteria2",
|
|
3026
|
+
"trojan",
|
|
3027
|
+
"http",
|
|
3028
|
+
"anytls",
|
|
3029
|
+
"shadowsocks",
|
|
3030
|
+
"vmess"
|
|
3031
|
+
],
|
|
3032
|
+
endpoints: [],
|
|
3033
|
+
groups: ["select", "surge-smart"],
|
|
3034
|
+
nativeRuleSets: ["rule-set", "domain-set"],
|
|
3035
|
+
dns: "general"
|
|
3036
|
+
},
|
|
3037
|
+
{
|
|
3038
|
+
engine: "surge",
|
|
3039
|
+
version: "6.11.0",
|
|
3040
|
+
autoGroup: "surge-smart",
|
|
3041
|
+
platforms: ["macos"],
|
|
3042
|
+
protocols: [
|
|
3043
|
+
"hysteria2",
|
|
3044
|
+
"trojan",
|
|
3045
|
+
"http",
|
|
3046
|
+
"anytls",
|
|
3047
|
+
"shadowsocks",
|
|
3048
|
+
"vmess"
|
|
3049
|
+
],
|
|
3050
|
+
endpoints: [],
|
|
3051
|
+
groups: ["select", "surge-smart"],
|
|
3052
|
+
nativeRuleSets: ["rule-set", "domain-set"],
|
|
3053
|
+
dns: "general"
|
|
3054
|
+
},
|
|
3055
|
+
{
|
|
3056
|
+
engine: "mihomo",
|
|
3057
|
+
version: "1.19.34",
|
|
3058
|
+
autoGroup: "urltest",
|
|
3059
|
+
platforms: ["linux", "macos"],
|
|
3060
|
+
protocols: [
|
|
3061
|
+
"hysteria2",
|
|
3062
|
+
"trojan",
|
|
3063
|
+
"http",
|
|
3064
|
+
"anytls",
|
|
3065
|
+
"shadowsocks",
|
|
3066
|
+
"vmess",
|
|
3067
|
+
"vless"
|
|
3068
|
+
],
|
|
3069
|
+
endpoints: [],
|
|
3070
|
+
groups: ["select", "urltest"],
|
|
3071
|
+
nativeRuleSets: ["yaml", "text"],
|
|
3072
|
+
dns: "clash"
|
|
3073
|
+
},
|
|
3074
|
+
{
|
|
3075
|
+
engine: "stash",
|
|
3076
|
+
version: "5.0.0",
|
|
3077
|
+
autoGroup: null,
|
|
3078
|
+
platforms: ["macos"],
|
|
3079
|
+
protocols: [
|
|
3080
|
+
"hysteria2",
|
|
3081
|
+
"trojan",
|
|
3082
|
+
"http",
|
|
3083
|
+
"anytls",
|
|
3084
|
+
"shadowsocks",
|
|
3085
|
+
"vmess",
|
|
3086
|
+
"vless"
|
|
3087
|
+
],
|
|
3088
|
+
endpoints: [],
|
|
3089
|
+
groups: ["select"],
|
|
3090
|
+
nativeRuleSets: [],
|
|
3091
|
+
dns: "external"
|
|
3092
|
+
}
|
|
3093
|
+
]);
|
|
3094
|
+
//#endregion
|
|
3095
3095
|
//#region src/model/paths.ts
|
|
3096
3096
|
function pathsOverlap(a, b) {
|
|
3097
|
+
if (a.startsWith("/") !== b.startsWith("/")) return false;
|
|
3097
3098
|
return a === b || a.startsWith(b.endsWith("/") ? b : `${b}/`) || b.startsWith(a.endsWith("/") ? a : `${a}/`);
|
|
3098
3099
|
}
|
|
3099
3100
|
//#endregion
|
|
@@ -3121,7 +3122,7 @@ function checkTarget(model, checks) {
|
|
|
3121
3122
|
for (const [id, refs] of edges) for (const [index, ref] of refs.entries()) {
|
|
3122
3123
|
const path = registry.get(id)?.type === "select" || registry.get(id)?.type === "urltest" ? `groups.${id}.members[${index}]` : `proxies.${id}.via`;
|
|
3123
3124
|
if (!registry.has(ref) && !["DIRECT", "REJECT"].includes(ref)) error("MISSING_REFERENCE", path);
|
|
3124
|
-
if (registry.get(ref)?.type === "sing-box-tailscale") error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
|
|
3125
|
+
if (registry.get(ref)?.type === "sing-box-tailscale" && (t.engine !== "sing-box" || t.mode !== "standalone" || registry.get(id)?.type !== "select")) error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
|
|
3125
3126
|
}
|
|
3126
3127
|
const state = /* @__PURE__ */ new Map(), tcp = /* @__PURE__ */ new Map();
|
|
3127
3128
|
const visit = (id) => {
|
|
@@ -3132,7 +3133,7 @@ function checkTarget(model, checks) {
|
|
|
3132
3133
|
if (state.get(id) === 2) return tcp.get(id) ?? false;
|
|
3133
3134
|
state.set(id, 1);
|
|
3134
3135
|
const item = registry.get(id);
|
|
3135
|
-
let limited = !!item && "server" in item && nodeIsTcpOnly(item, t.engine
|
|
3136
|
+
let limited = !!item && "server" in item && nodeIsTcpOnly(item, t.engine);
|
|
3136
3137
|
for (const ref of edges.get(id) ?? []) limited = visit(ref) || limited;
|
|
3137
3138
|
state.set(id, 2);
|
|
3138
3139
|
tcp.set(id, limited);
|
|
@@ -3226,7 +3227,8 @@ function prepareProfile(input, key, secrets, checkSecrets = true) {
|
|
|
3226
3227
|
profile: key,
|
|
3227
3228
|
origin: d.origin ?? diagnosticOrigin(p, d.path)
|
|
3228
3229
|
});
|
|
3229
|
-
|
|
3230
|
+
const supportedTarget = targetCatalog.find((d) => d.engine === engine && d.platforms.includes(p.target.platform));
|
|
3231
|
+
if (supportedTarget?.version !== p.target.version) return {
|
|
3230
3232
|
engine,
|
|
3231
3233
|
selections,
|
|
3232
3234
|
ruleSets,
|
|
@@ -3236,8 +3238,8 @@ function prepareProfile(input, key, secrets, checkSecrets = true) {
|
|
|
3236
3238
|
code: "TARGET_UNSUPPORTED",
|
|
3237
3239
|
profile: key,
|
|
3238
3240
|
origin: originOf(p),
|
|
3239
|
-
path: "target",
|
|
3240
|
-
message: "Unsupported exact target"
|
|
3241
|
+
path: supportedTarget ? "target.version" : "target",
|
|
3242
|
+
message: supportedTarget ? `${engine} ${p.target.platform} 只支持最新稳定版 ${supportedTarget.version}` : "Unsupported exact target"
|
|
3241
3243
|
}]
|
|
3242
3244
|
};
|
|
3243
3245
|
const allDiagnostics = (ds) => {
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as definitionDiagnostic, i as targetCatalog } from "./build-
|
|
2
|
+
import { C as definitionDiagnostic, i as targetCatalog } from "./build-H0uxqVRQ.js";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { lstat, open, stat } from "node:fs/promises";
|
|
@@ -11,6 +11,9 @@ let json = false;
|
|
|
11
11
|
function print(value, text) {
|
|
12
12
|
process.stdout.write(json ? JSON.stringify(value, null, 2) + "\n" : (text ?? human(value)) + "\n");
|
|
13
13
|
}
|
|
14
|
+
function diagnosticMessage(diagnostic) {
|
|
15
|
+
return diagnostic.code === "TARGET_UNSUPPORTED" && diagnostic.path === "target.version" ? ` ${diagnostic.message}` : "";
|
|
16
|
+
}
|
|
14
17
|
function human(value) {
|
|
15
18
|
if (!value || typeof value !== "object") return String(value);
|
|
16
19
|
if ("explanation" in value) {
|
|
@@ -18,7 +21,7 @@ function human(value) {
|
|
|
18
21
|
const e = r.explanation;
|
|
19
22
|
return `${r.profile}: ${e.outcome}${e.exit ? " → " + e.exit : ""}${e.needs ? " needs: " + e.needs.kind + (e.needs.kind === "ruleSet" ? " " + e.needs.id : "") : ""}\n${e.trace.map((t) => ` routes[${t.index}]: ${t.matched === null ? "unknown" : t.matched ? "hit" : "miss"}${t.origin ? ` ${t.origin.file}:${t.origin.line}:${t.origin.column}` : ""}`).join("\n")}`;
|
|
20
23
|
}
|
|
21
|
-
if ("diagnostics" in value) return value.diagnostics.map((d) => `${d.code} ${d.path}`).join("\n");
|
|
24
|
+
if ("diagnostics" in value) return value.diagnostics.map((d) => `${d.code} ${d.path}${diagnosticMessage(d)}`).join("\n");
|
|
22
25
|
if ("profiles" in value) return humanCheck(value);
|
|
23
26
|
if ("check" in value) {
|
|
24
27
|
const result = value;
|
|
@@ -35,7 +38,7 @@ function human(value) {
|
|
|
35
38
|
].filter(Boolean).join(" ");
|
|
36
39
|
}
|
|
37
40
|
function humanCheck(check) {
|
|
38
|
-
return check.profiles.map((p) => `${p.ok ? "✓" : "✗"} ${p.key} ${p.target.engine} ${p.target.platform} ${p.target.version}${p.selections.flatMap((s) => s.kind === "algorithm" ? [` auto: ${s.group}→${s.algorithm}`] : s.kind === "ruleSet" ? [` ruleSets: ${s.ruleSet}→${s.branch} (${s.nativeName})`] : []).join("")}\n${p.diagnostics.map((d) => ` ${d.severity} ${d.code} ${d.path}${d.origin ? ` ${d.origin.file}:${d.origin.line}:${d.origin.column}` : ""}`).join("\n")}`).join("\n") + `\ncases: ${check.cases.filter((c) => c.ok).length} passed, ${check.cases.filter((c) => !c.ok).length} failed\n${check.cases.map((c) => ` ${c.ok ? "✓" : "✗"} ${c.profile} "${c.name}": expected ${c.expected}, ${c.actual ? "got " + c.actual : c.outcome}${c.needs ? " needs: " + c.needs.kind + (c.needs.kind === "ruleSet" ? " " + c.needs.id : "") : ""}${c.route ? ` at routes[${c.route.index}]${c.route.origin ? ` ${c.route.origin.file}:${c.route.origin.line}:${c.route.origin.column}` : ""}` : ""}`).join("\n")}\n${check.code}`;
|
|
41
|
+
return check.profiles.map((p) => `${p.ok ? "✓" : "✗"} ${p.key} ${p.target.engine} ${p.target.platform} ${p.target.version}${p.selections.flatMap((s) => s.kind === "algorithm" ? [` auto: ${s.group}→${s.algorithm}`] : s.kind === "ruleSet" ? [` ruleSets: ${s.ruleSet}→${s.branch} (${s.nativeName})`] : []).join("")}\n${p.diagnostics.map((d) => ` ${d.severity} ${d.code} ${d.path}${diagnosticMessage(d)}${d.origin ? ` ${d.origin.file}:${d.origin.line}:${d.origin.column}` : ""}`).join("\n")}`).join("\n") + `\ncases: ${check.cases.filter((c) => c.ok).length} passed, ${check.cases.filter((c) => !c.ok).length} failed\n${check.cases.map((c) => ` ${c.ok ? "✓" : "✗"} ${c.profile} "${c.name}": expected ${c.expected}, ${c.actual ? "got " + c.actual : c.outcome}${c.needs ? " needs: " + c.needs.kind + (c.needs.kind === "ruleSet" ? " " + c.needs.id : "") : ""}${c.route ? ` at routes[${c.route.index}]${c.route.origin ? ` ${c.route.origin.file}:${c.route.origin.line}:${c.route.origin.column}` : ""}` : ""}`).join("\n")}\n${check.code}`;
|
|
39
42
|
}
|
|
40
43
|
function failure(code, detail = {}) {
|
|
41
44
|
print({
|
package/dist/index.d.ts
CHANGED
|
@@ -165,9 +165,13 @@ type GroupAlgorithm = {
|
|
|
165
165
|
readonly intervalSeconds?: number;
|
|
166
166
|
readonly toleranceMs?: number;
|
|
167
167
|
};
|
|
168
|
-
type DnsRule = {
|
|
168
|
+
type DnsRule<Server = string> = {
|
|
169
169
|
readonly pattern: string;
|
|
170
|
-
readonly server:
|
|
170
|
+
readonly server: Server;
|
|
171
|
+
};
|
|
172
|
+
type TailscaleDnsServer<Endpoint> = {
|
|
173
|
+
readonly endpoint: Endpoint;
|
|
174
|
+
readonly acceptDefaultResolvers?: boolean;
|
|
171
175
|
};
|
|
172
176
|
type Tun = {
|
|
173
177
|
readonly address: readonly string[];
|
|
@@ -436,23 +440,23 @@ type Fragments<T> = T | readonly Fragments<T>[];
|
|
|
436
440
|
type Target = {
|
|
437
441
|
readonly engine: "surge";
|
|
438
442
|
readonly platform: "ios";
|
|
439
|
-
readonly version: "5.
|
|
443
|
+
readonly version: "5.23.0";
|
|
440
444
|
} | {
|
|
441
445
|
readonly engine: "surge";
|
|
442
446
|
readonly platform: "macos";
|
|
443
|
-
readonly version: "6.
|
|
447
|
+
readonly version: "6.11.0";
|
|
444
448
|
} | {
|
|
445
449
|
readonly engine: "sing-box";
|
|
446
450
|
readonly platform: "macos" | "linux";
|
|
447
|
-
readonly version: "1.
|
|
451
|
+
readonly version: "1.14.4";
|
|
448
452
|
} | {
|
|
449
453
|
readonly engine: "mihomo";
|
|
450
454
|
readonly platform: "macos" | "linux";
|
|
451
|
-
readonly version: "1.19.
|
|
455
|
+
readonly version: "1.19.34";
|
|
452
456
|
} | {
|
|
453
457
|
readonly engine: "stash";
|
|
454
458
|
readonly platform: "macos";
|
|
455
|
-
readonly version: "
|
|
459
|
+
readonly version: "5.0.0";
|
|
456
460
|
};
|
|
457
461
|
type SecretRef = Secret & SDK<"secret">;
|
|
458
462
|
type Secrets<T extends string = string> = Readonly<Record<T, SecretRef>> & SDK<"secrets">;
|
|
@@ -480,6 +484,8 @@ type SurgeTunnel = PublicSecrets<SurgeTunnel$1> & {
|
|
|
480
484
|
type SingBoxEndpoint = PublicSecrets<TailscaleEndpoint> & {
|
|
481
485
|
readonly name?: string;
|
|
482
486
|
} & SDK<"endpoint">;
|
|
487
|
+
type TailscaleDnsOptions = TailscaleDnsServer<SingBoxEndpoint>;
|
|
488
|
+
type ProfileDnsRule = DnsRule<string | TailscaleDnsOptions>;
|
|
483
489
|
type Builtin = {
|
|
484
490
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
485
491
|
} & SDK<"builtin">;
|
|
@@ -549,7 +555,7 @@ type SingBoxOptions = {
|
|
|
549
555
|
};
|
|
550
556
|
type Common = {
|
|
551
557
|
readonly cases?: Fragments<RouteCase>;
|
|
552
|
-
readonly dns?: Fragments<
|
|
558
|
+
readonly dns?: Fragments<ProfileDnsRule>;
|
|
553
559
|
readonly proxies: Fragments<ProfileProxy>;
|
|
554
560
|
readonly routes: Fragments<Route>;
|
|
555
561
|
readonly fallback: Exit;
|
|
@@ -603,7 +609,7 @@ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition
|
|
|
603
609
|
};
|
|
604
610
|
} ? ProxyGroup : ProxyGroup<Portable>)[];
|
|
605
611
|
readonly routes: readonly Route[];
|
|
606
|
-
readonly dns: readonly
|
|
612
|
+
readonly dns: readonly ProfileDnsRule[];
|
|
607
613
|
readonly cases: readonly RouteCase[];
|
|
608
614
|
readonly surge?: D extends {
|
|
609
615
|
target: {
|
|
@@ -658,6 +664,8 @@ declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<N>;
|
|
|
658
664
|
//#region src/authoring/constructors.d.ts
|
|
659
665
|
export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
660
666
|
export declare function dnsRule(pattern: readonly string[], server: string): DnsRule[];
|
|
667
|
+
export declare function dnsRule(pattern: string, server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>;
|
|
668
|
+
export declare function dnsRule(pattern: readonly string[], server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>[];
|
|
661
669
|
type DomainOptions = {
|
|
662
670
|
readonly includeSniffed?: boolean;
|
|
663
671
|
};
|
|
@@ -1236,4 +1244,4 @@ export declare function runBuild(definition: BuildDefinition, options?: {
|
|
|
1236
1244
|
readonly validation?: boolean;
|
|
1237
1245
|
}): Promise<BuildResult>;
|
|
1238
1246
|
//#endregion
|
|
1239
|
-
export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, Target };
|
|
1247
|
+
export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, TailscaleDnsOptions, Target };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-
|
|
1
|
+
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-H0uxqVRQ.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
//#region src/authoring/resources.ts
|
|
4
4
|
const builtin = (builtin) => created({ builtin }, "builtin");
|
package/package.json
CHANGED