lynx-proxy 0.0.1 → 0.0.2
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 +50 -1
- package/dist/index.d.mts +1 -11
- package/dist/index.mjs +4436 -2442
- package/dist/tui.d.mts +8 -0
- package/dist/tui.mjs +4415 -0
- package/dist/web-assets/assets/index-CW9fIDIC.js +9 -0
- package/dist/web-assets/assets/index-D-xo-2WP.css +1 -0
- package/dist/web-assets/index.html +13 -0
- package/dist/web.d.mts +1 -0
- package/dist/web.mjs +2633 -0
- package/package.json +28 -14
- package/CLI.md +0 -259
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lynx-proxy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A lightweight HTTP client proxy for personal use",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"proxy",
|
|
@@ -26,35 +26,49 @@
|
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"dist",
|
|
29
|
+
"!dist/**/*.map",
|
|
30
|
+
"!dist/*.map",
|
|
29
31
|
"README.md",
|
|
30
|
-
"LICENSE"
|
|
31
|
-
"CLI.md"
|
|
32
|
+
"LICENSE"
|
|
32
33
|
],
|
|
33
34
|
"exports": {
|
|
34
35
|
".": "./dist/index.mjs",
|
|
35
36
|
"./package.json": "./package.json"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|
|
38
|
-
"build": "tsdown",
|
|
39
|
-
"
|
|
39
|
+
"build": "tsdown && pnpm --filter @lynx/web-frontend build",
|
|
40
|
+
"build:server": "tsdown",
|
|
41
|
+
"build:web": "pnpm --filter @lynx/web-frontend build",
|
|
40
42
|
"start": "node dist/index.mjs",
|
|
41
|
-
"dev": "pnpm
|
|
42
|
-
"
|
|
43
|
-
"
|
|
43
|
+
"dev:proxy": "pnpm build && node dist/index.mjs proxy start",
|
|
44
|
+
"dev:cli": "pnpm build && node --inspect=9229 dist/index.mjs",
|
|
45
|
+
"dev:web": "pnpm --filter @lynx/web-frontend dev",
|
|
46
|
+
"typecheck": "tsc --noEmit && pnpm --filter @lynx/web-frontend typecheck",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"lint": "oxlint",
|
|
49
|
+
"lint:fix": "oxlint --fix"
|
|
44
50
|
},
|
|
45
51
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
52
|
+
"node": ">=22.19.0"
|
|
47
53
|
},
|
|
48
|
-
"packageManager": "pnpm@11.
|
|
54
|
+
"packageManager": "pnpm@11.20.0",
|
|
49
55
|
"devDependencies": {
|
|
56
|
+
"@types/cli-progress": "^3.11.6",
|
|
50
57
|
"@types/js-yaml": "^4.0.9",
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"
|
|
58
|
+
"@types/node": "^26.0.1",
|
|
59
|
+
"@types/unzipper": "^0.10.11",
|
|
60
|
+
"oxlint": "^1.72.0",
|
|
61
|
+
"tsdown": "^0.22.3",
|
|
53
62
|
"typescript": "^6.0.3",
|
|
54
63
|
"vitest": "^4.1.9"
|
|
55
64
|
},
|
|
56
65
|
"dependencies": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
66
|
+
"@earendil-works/pi-tui": "^0.80.3",
|
|
67
|
+
"axios": "^1.18.1",
|
|
68
|
+
"cli-progress": "^3.12.0",
|
|
69
|
+
"js-yaml": "^5.2.0",
|
|
70
|
+
"picocolors": "^1.1.1",
|
|
71
|
+
"smol-toml": "^1.7.0",
|
|
72
|
+
"unzipper": "^0.12.5"
|
|
59
73
|
}
|
|
60
74
|
}
|
package/CLI.md
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
# CLI 命令文档
|
|
2
|
-
|
|
3
|
-
本文档按当前代码的实际行为描述 LynxProxy CLI。凡标注“未实现”的命令目前只输出提示,不会控制后台进程。
|
|
4
|
-
|
|
5
|
-
## 可执行入口与开发脚本
|
|
6
|
-
|
|
7
|
-
`package.json` 中声明的可执行命令为 `lynx`,指向构建产物 `dist/index.mjs`。修改 TypeScript 源码后需要先构建:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
pnpm install
|
|
11
|
-
pnpm build
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
常用脚本:
|
|
15
|
-
|
|
16
|
-
| 命令 | 实际效果 |
|
|
17
|
-
| --- | --- |
|
|
18
|
-
| `pnpm build` | 使用 `tsdown` 构建 `src/index.ts` 到 `dist/index.mjs` |
|
|
19
|
-
| `pnpm debug` | 运行 `tsdown --watch`,只进入构建监听模式 |
|
|
20
|
-
| `pnpm start` | 执行 `node dist/index.mjs`,按当前 profile 前台启动代理 |
|
|
21
|
-
| `pnpm dev` | 当前脚本为 `pnpm debug && node --inspect=9229 dist/index.mjs proxy start`;由于 `pnpm debug` 通常不会退出,后半段通常不会执行 |
|
|
22
|
-
| `pnpm test` | 运行 `vitest run` 执行自动化测试 |
|
|
23
|
-
|
|
24
|
-
推荐的本地验证启动方式:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
pnpm build
|
|
28
|
-
pnpm start
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
`pnpm start` 按当前选中的 profile 启动。要使用某个配置文件,先用 `lynx config add <name> --file <path>` 加入 profile,再用 `lynx config use <name>` 选中:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pnpm build
|
|
35
|
-
lynx config add home --file config.example.toml
|
|
36
|
-
lynx config use home
|
|
37
|
-
lynx
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## 配置目录与默认加载规则
|
|
41
|
-
|
|
42
|
-
默认配置目录为:
|
|
43
|
-
|
|
44
|
-
```text
|
|
45
|
-
~/.config/lynx-proxy/
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
如果设置了 `XDG_CONFIG_HOME`,则使用:
|
|
49
|
-
|
|
50
|
-
```text
|
|
51
|
-
$XDG_CONFIG_HOME/lynx-proxy/
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
默认目录内的文件:
|
|
55
|
-
|
|
56
|
-
| 路径 | 用途 |
|
|
57
|
-
| --- | --- |
|
|
58
|
-
| `user.json` | 选择当前 profile,例如 `{ "profile": "home" }` |
|
|
59
|
-
| `profile/<name>.toml\|yaml\|yml\|json` | Clash 风格 profile 配置 |
|
|
60
|
-
| `state.json` | 保存 CLI 写入的 per-profile 可变状态,例如代理组选择 |
|
|
61
|
-
|
|
62
|
-
启动时,加载顺序为:
|
|
63
|
-
|
|
64
|
-
1. 如果存在 `user.json`,读取其中的 `profile`。
|
|
65
|
-
2. 在 `profile/` 目录解析同名 `.toml`、`.yaml`、`.yml` 或 `.json` 文件。
|
|
66
|
-
3. 叠加 `state.json` 中以解析后的 profile 文件名为 key 的代理组选择状态。
|
|
67
|
-
4. 前台启动本地 HTTP 代理服务。
|
|
68
|
-
5. 如果没有 `user.json`,但当前工作目录存在 `config.toml`,则兼容性加载 `./config.toml`。
|
|
69
|
-
6. 如果二者都不存在,则创建默认配置目录和 `user.json`,然后报错提示用户通过 `lynx config add` 添加 profile。
|
|
70
|
-
|
|
71
|
-
要加载某个配置文件作为 profile,统一通过 `lynx config add <name> --file <path>` 加入,再用 `lynx config use <name>` 选中;不存在绕过 profile 选择直接指定配置文件的顶层选项。
|
|
72
|
-
|
|
73
|
-
## 顶层命令
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
lynx [options]
|
|
77
|
-
lynx <command> [options]
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
| 命令/参数 | 实际效果 |
|
|
81
|
-
| --- | --- |
|
|
82
|
-
| `lynx` | 按默认加载规则读取当前 profile,并前台启动代理 |
|
|
83
|
-
| `lynx --help` / `lynx -h` | 输出顶层帮助 |
|
|
84
|
-
| `lynx --version` / `lynx -v` | 输出当前硬编码版本 `1.0.0` |
|
|
85
|
-
| `lynx config ...` | 执行配置管理子命令 |
|
|
86
|
-
| `lynx proxy ...` | 执行代理服务控制子命令 |
|
|
87
|
-
| `lynx groups ...` | 执行代理组选择和规则管理子命令 |
|
|
88
|
-
|
|
89
|
-
注意:当前实现只在第一个参数就是 `config`、`proxy` 或 `groups` 时进入子命令模式。顶层不再提供直接指定配置文件的选项;服务配置应先通过 `lynx config add` 加入 profile,再用 `lynx config use` 选中。
|
|
90
|
-
|
|
91
|
-
因此支持:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
lynx config add home --file config.example.toml
|
|
95
|
-
lynx config use home
|
|
96
|
-
lynx proxy start
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
不支持(会按未知参数报错):
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
lynx proxy start --config config.example.toml
|
|
103
|
-
lynx --config config.example.toml proxy start
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## `lynx proxy`
|
|
107
|
-
|
|
108
|
-
`lynx proxy` 只关注代理服务/daemon 的状态控制,不负责导入或临时指定配置文件。需要使用新配置时,先通过 `lynx config add` 加入 profile,再用 `lynx config use` 选中。`proxy start` 会按当前 profile 后台启动 daemon,并把运行状态写入配置目录下的 `runtime/proxy-daemon.json`,日志写入 `runtime/proxy-daemon.log`。
|
|
109
|
-
|
|
110
|
-
| 命令 | 实际效果 |
|
|
111
|
-
| --- | --- |
|
|
112
|
-
| `lynx proxy` / `lynx proxy --help` | 输出 `proxy` 子命令帮助 |
|
|
113
|
-
| `lynx proxy start` | 按默认加载规则读取当前 profile,并后台启动 daemon;如果已有运行中的 daemon 则提示 PID |
|
|
114
|
-
| `lynx proxy status` | 检查 daemon state 和 PID 存活状态;运行中时输出 PID、监听地址、profile、启动时间、日志路径和控制 socket 是否就绪;发现 stale state 时自动清理 |
|
|
115
|
-
| `lynx proxy stop` | 向运行中的 daemon 发送 `SIGTERM`,等待退出并清理 runtime state |
|
|
116
|
-
| `lynx proxy restart` | 先停止已有 daemon,再按当前 profile 重新后台启动 |
|
|
117
|
-
| `lynx proxy reload` | 当前不做热重载;提示使用 `lynx proxy restart` 应用配置变更 |
|
|
118
|
-
| `lynx proxy logs` | 输出 daemon 日志文件内容 |
|
|
119
|
-
|
|
120
|
-
当前 daemon 控制示例:
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
lynx proxy start
|
|
124
|
-
lynx proxy status
|
|
125
|
-
lynx proxy logs
|
|
126
|
-
lynx proxy stop
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## `lynx config`
|
|
130
|
-
|
|
131
|
-
`lynx config` 管理运行时用户配置、profile 文件和 `state.json` 中的状态字段。
|
|
132
|
-
|
|
133
|
-
| 命令 | 实际效果 |
|
|
134
|
-
| --- | --- |
|
|
135
|
-
| `lynx config` / `lynx config --help` | 输出 `config` 子命令帮助 |
|
|
136
|
-
| `lynx config list` | 创建默认配置目录和 `user.json`;列出 `profile/` 目录中的 profile 文件,并用 `*` 标记当前 profile |
|
|
137
|
-
| `lynx config current` | 输出用户配置路径、状态文件路径、当前 profile、profile 目录、解析到的 profile 路径、state key、有效监听地址、全局选择和代理组选择 |
|
|
138
|
-
| `lynx config use <profile>` | 校验并选择 profile,把 `<profile>` 写入 `user.json`;不修改 `state.json` |
|
|
139
|
-
| `lynx config add <name> --file <path>` | 校验源配置可加载,将源配置复制到 profile 目录;不覆盖已有文件 |
|
|
140
|
-
| `lynx config add <name> --template` | 创建内置模板 profile;`<name>` 的扩展名决定 TOML/YAML/JSON,无扩展名默认 `.toml`;不覆盖已有文件 |
|
|
141
|
-
| `lynx config add <name> --url <url>` | 从订阅 URL 抓取配置,校验通过后存为 profile(无扩展名默认 `.yaml`),并把 `url`、更新时间、流量信息写入 `state.json`;抓取或校验失败不留下文件、不写 state;支持 `--user-agent <ua>` 覆盖默认 UA;`--file`/`--template`/`--url` 三者互斥 |
|
|
142
|
-
| `lynx config update [profile]` | 用 `state.json` 记录的 `url` 重新抓取订阅,校验通过后整份覆盖 profile 文件,并更新 `time` 和 `subInfo`;省略 `profile` 时更新当前 profile;非订阅 profile(无 url)报错;校验失败保留旧文件 |
|
|
143
|
-
| `lynx config info [profile]` | 显示订阅 URL、上次更新时间、流量用量(download+upload / total)和到期时间;非订阅 profile 给出提示 |
|
|
144
|
-
| `lynx config show [profile]` | 输出指定 profile 或当前 profile 的原始文件内容 |
|
|
145
|
-
| `lynx config remove <profile>` | 删除非当前 profile;如果目标是当前 profile,会拒绝删除 |
|
|
146
|
-
| `lynx config path` | 输出配置根目录、`user.json`、`state.json` 和 profile 目录路径 |
|
|
147
|
-
|
|
148
|
-
profile 名称只能是 profile 目录下的文件名,不能是绝对路径、相对路径、`..` 或包含路径分隔符的值。
|
|
149
|
-
|
|
150
|
-
示例:
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
lynx config path
|
|
154
|
-
lynx config add default --template
|
|
155
|
-
lynx config add home --file config.example.toml
|
|
156
|
-
lynx config add airport --url https://sub.example.com/link
|
|
157
|
-
lynx config update airport
|
|
158
|
-
lynx config info airport
|
|
159
|
-
lynx config list
|
|
160
|
-
lynx config use home
|
|
161
|
-
lynx config current
|
|
162
|
-
lynx config show home
|
|
163
|
-
lynx config remove old-profile
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
订阅说明:
|
|
167
|
-
|
|
168
|
-
- `config add --url` 默认走直连抓取(不经上游代理),默认使用类 clash 的 User-Agent(机场常按 UA 决定是否返回 Clash 格式),可用 `--user-agent` 覆盖。
|
|
169
|
-
- `config update` 整份覆盖 profile 文件:用 `groups rule set` 做的本地规则修改会被新订阅冲掉。
|
|
170
|
-
- 更新后若 `groups select` 选中的节点在新配置中已不存在,运行时由 router 的“回退到组内第一个可解析成员”逻辑降级处理,不会崩溃。
|
|
171
|
-
- 订阅 profile 更新后需 `lynx proxy restart` 才生效,不热加载。
|
|
172
|
-
- 不实现自动定时更新(`interval`/`cron` 字段保留但本版本不消费)。
|
|
173
|
-
|
|
174
|
-
## `lynx groups`
|
|
175
|
-
|
|
176
|
-
`lynx groups` 管理当前或指定 profile 的代理组选择,并提供规则目标修改命令。
|
|
177
|
-
|
|
178
|
-
| 命令 | 实际效果 |
|
|
179
|
-
| --- | --- |
|
|
180
|
-
| `lynx groups` / `lynx groups --help` | 输出 `groups` 子命令帮助 |
|
|
181
|
-
| `lynx groups list [--profile <profile>]` | 列出 profile 中的所有 `proxy-groups`、当前选择和组内成员 |
|
|
182
|
-
| `lynx groups current [--profile <profile>]` | 输出 profile 路径、state 路径、state key、全局选择和所有代理组选择;daemon 正在运行当前 profile 时显示其内存中实际生效的值(来源标记为 `running daemon (live)`),否则显示 `state.json` 的内容 |
|
|
183
|
-
| `lynx groups use <group> [--profile <profile>]` | 校验 `<group>` 存在,并在 `state.json` 中写入名为 `GLOBAL` 的选择记录;daemon 在跑时实时下发 |
|
|
184
|
-
| `lynx groups select <group> <proxy> [--profile <profile>]` | 校验 `<group>` 存在且 `<proxy>` 是该组成员,然后写入该组的选择记录;daemon 在跑时实时下发 |
|
|
185
|
-
| `lynx groups mode <rule\|global\|direct\|script> [--profile <profile>]` | 校验模式合法并写入 `state.json` 的 `mode` 字段;daemon 在跑时实时下发 |
|
|
186
|
-
| `lynx groups unset <group> [--profile <profile>]` | 删除该组在 `state.json` 中的显式选择,使其回退到 profile 默认选择或组内默认成员;daemon 在跑时实时下发 |
|
|
187
|
-
| `lynx groups rule list [--profile <profile>]` | 按索引列出原始规则和目标,并输出有效默认路由 |
|
|
188
|
-
| `lynx groups rule set <rule\|index\|MATCH> <target> [--profile <profile>]` | 校验目标为 `DIRECT`、已存在代理或已存在代理组,然后修改 profile 文件中的规则目标 |
|
|
189
|
-
|
|
190
|
-
示例:
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
lynx groups list
|
|
194
|
-
lynx groups current
|
|
195
|
-
lynx groups use "🔰国外流量"
|
|
196
|
-
lynx groups select "🔰国外流量" trojan-main
|
|
197
|
-
lynx groups mode global
|
|
198
|
-
lynx groups unset "🔰国外流量"
|
|
199
|
-
lynx groups rule list
|
|
200
|
-
lynx groups rule set MATCH DIRECT
|
|
201
|
-
lynx groups rule set 0 "🔰国外流量"
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
注意:
|
|
205
|
-
|
|
206
|
-
- `groups use`、`groups select`、`groups mode` 和 `groups unset` 只修改 `state.json`,不改写 profile 文件。当 daemon 正在运行当前 profile 时,这些命令会在写盘后通过 Unix domain socket 控制通道(`runtime/control.sock`)实时下发给 daemon,无需重启;daemon 未运行时静默跳过,提示下次启动生效。Windows 平台暂不支持控制通道,变更需重启生效。
|
|
207
|
-
- `groups rule set` 会直接重写 profile 文件,且不走控制通道,需 `lynx proxy restart` 生效。JSON 会重新格式化为两空格缩进;TOML 使用 `smol-toml.stringify`;YAML 使用 `js-yaml.dump`。这可能丢失原始注释和排版。
|
|
208
|
-
- 当前没有专门的 `lynx groups rule --help` 分支;该命令会按未知 rule 子命令报错。
|
|
209
|
-
|
|
210
|
-
## `state.json` 实际格式
|
|
211
|
-
|
|
212
|
-
当前实现写入的新格式示例:
|
|
213
|
-
|
|
214
|
-
```json
|
|
215
|
-
{
|
|
216
|
-
"version": 1,
|
|
217
|
-
"files": [
|
|
218
|
-
{
|
|
219
|
-
"name": "home.toml",
|
|
220
|
-
"selected": [
|
|
221
|
-
{
|
|
222
|
-
"name": "GLOBAL",
|
|
223
|
-
"now": "🔰国外流量"
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
"name": "🔰国外流量",
|
|
227
|
-
"now": "trojan-main"
|
|
228
|
-
}
|
|
229
|
-
]
|
|
230
|
-
}
|
|
231
|
-
]
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
含义:
|
|
236
|
-
|
|
237
|
-
- `files[].name` 是解析后的 profile 文件名,例如 `home.toml`。
|
|
238
|
-
- `selected[].name = "GLOBAL"` 表示当前启用的全局代理组选择,由 `lynx groups use` 写入。
|
|
239
|
-
- 其他 `selected[].name` 表示具体代理组名,对应的 `now` 是该组当前选择的成员,由 `lynx groups select` 写入。
|
|
240
|
-
|
|
241
|
-
旧的 `profiles` 格式仍可被读取并转换为当前内存结构,但新写入使用 `version/files/selected` 结构。
|
|
242
|
-
|
|
243
|
-
## 当前限制与规划中的能力
|
|
244
|
-
|
|
245
|
-
当前已实现:
|
|
246
|
-
|
|
247
|
-
- 前台启动 HTTP 代理;
|
|
248
|
-
- TOML/YAML/JSON profile 加载;
|
|
249
|
-
- `user.json` profile 选择;
|
|
250
|
-
- `state.json` 代理组选择覆盖;
|
|
251
|
-
- profile 添加、查看、切换、删除;
|
|
252
|
-
- 规则列表和规则目标修改。
|
|
253
|
-
|
|
254
|
-
当前未实现或不完整:
|
|
255
|
-
|
|
256
|
-
- 后台 daemon 启动、停止、重启、reload、status PID 校验和日志跟踪;
|
|
257
|
-
- `pnpm dev` 一条命令同时 watch 构建并启动调试进程;
|
|
258
|
-
- `lynx groups rule --help`;
|
|
259
|
-
- `groups rule set` 对 TOML/YAML 注释和原始排版的无损保留。
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";UAYiB,UAAA;EACb,WAAA;EACA,IAAA;EACA,OAAA;AAAA;AAAA,iBAGY,YAAA,CAAa,IAAA,sBAA0B,UAAA;AAAA,iBA8BjC,IAAA,CAClB,IAAA,uBACD,OAAA"}
|