devconfig-gen-singbox 2.0.0__tar.gz
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.
- devconfig_gen_singbox-2.0.0/LICENSE +201 -0
- devconfig_gen_singbox-2.0.0/PKG-INFO +343 -0
- devconfig_gen_singbox-2.0.0/README.md +321 -0
- devconfig_gen_singbox-2.0.0/pyproject.toml +35 -0
- devconfig_gen_singbox-2.0.0/setup.cfg +4 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/__init__.py +67 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/cli.py +163 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/engine.py +217 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/formats.py +708 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/models.py +135 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/__init__.py +8 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/custom.py +92 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/env_provider.py +184 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/json_provider.py +84 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/__init__.py +9 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/data/rules.json +97 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/links.py +24 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/models.py +76 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/plugins/__init__.py +33 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/plugins/anytls.py +129 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/plugins/base.py +117 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/plugins/hysteria2.py +110 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/plugins/tuic.py +90 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/provider.py +362 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/route.py +369 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/providers/singbox/schema.py +362 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/py.typed +0 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/registry.py +39 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen/validation.py +148 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/PKG-INFO +343 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/SOURCES.txt +43 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/dependency_links.txt +1 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/entry_points.txt +3 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/requires.txt +11 -0
- devconfig_gen_singbox-2.0.0/src/devconfig_gen_singbox.egg-info/top_level.txt +1 -0
- devconfig_gen_singbox-2.0.0/tests/test_api_parity.py +69 -0
- devconfig_gen_singbox-2.0.0/tests/test_cli_e2e.py +276 -0
- devconfig_gen_singbox-2.0.0/tests/test_custom_provider.py +79 -0
- devconfig_gen_singbox-2.0.0/tests/test_devconfig_core.py +41 -0
- devconfig_gen_singbox-2.0.0/tests/test_env_provider.py +91 -0
- devconfig_gen_singbox-2.0.0/tests/test_formats.py +180 -0
- devconfig_gen_singbox-2.0.0/tests/test_merge.py +84 -0
- devconfig_gen_singbox-2.0.0/tests/test_provider_metadata.py +121 -0
- devconfig_gen_singbox-2.0.0/tests/test_singbox_provider.py +417 -0
- devconfig_gen_singbox-2.0.0/tests/test_validation.py +101 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 henryliu443
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devconfig_gen_singbox
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Provider-based developer configuration generation engine and CLI
|
|
5
|
+
Author-email: henryliu443 <henryliu443@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: configuration,json,yaml,code-generation,cli
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: yaml
|
|
14
|
+
Requires-Dist: PyYAML>=5.1; extra == "yaml"
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: build; extra == "dev"
|
|
17
|
+
Requires-Dist: wheel; extra == "dev"
|
|
18
|
+
Requires-Dist: PyYAML>=5.1; extra == "dev"
|
|
19
|
+
Provides-Extra: docs
|
|
20
|
+
Requires-Dist: mkdocs-material<10,>=9.5; extra == "docs"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# DevConfig-Gen_SingBox
|
|
24
|
+
|
|
25
|
+
> **A sing-box domain implementation built on top of DevConfig-Gen.**
|
|
26
|
+
> **构建在 `DevConfig-Gen` 之上的 sing-box 领域实现(child / fork)。**
|
|
27
|
+
|
|
28
|
+
[](CHANGELOG.md)
|
|
29
|
+
[](LICENSE)
|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
**`DevConfig-Gen` 是一个以有限领域 Scope 为边界的确定性配置转换引擎。**
|
|
35
|
+
**DevConfig-Gen is a deterministic configuration transformation engine built around bounded domain scopes.**
|
|
36
|
+
|
|
37
|
+
本仓库定义其中一个 scope:有限的 **`singbox` 领域** —— 它的领域模型、校验规则、
|
|
38
|
+
协议转换、配置变体与分享链接表示。`DevConfig-Gen` 提供中立的执行引擎与稳定的
|
|
39
|
+
Provider 契约;本仓库提供 sing-box 专属的领域实现。
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
DevConfig-Gen
|
|
43
|
+
中立引擎 · Provider 契约 · 执行流水线
|
|
44
|
+
│
|
|
45
|
+
▼
|
|
46
|
+
DevConfig-Gen_SingBox
|
|
47
|
+
sing-box 领域 · 校验 · 转换 · server/client 变体
|
|
48
|
+
│
|
|
49
|
+
▼
|
|
50
|
+
下游配置 / downstream configurations
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**父仓库拥有引擎,子仓库拥有领域。**
|
|
54
|
+
**The parent owns the engine. The child owns the domain.**
|
|
55
|
+
|
|
56
|
+
## 快速开始 / Quick Start
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git clone https://github.com/henryliu443/devconfig_gen_singbox.git
|
|
60
|
+
cd devconfig_gen_singbox
|
|
61
|
+
pip install -e ".[yaml]"
|
|
62
|
+
devconfig-gen generate --provider singbox --input examples/singbox.yaml --output-dir dist
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
未安装时亦可直接通过源码运行:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/henryliu443/devconfig_gen_singbox.git
|
|
69
|
+
cd devconfig_gen_singbox
|
|
70
|
+
PYTHONPATH=src python3 -m devconfig_gen.cli generate --provider singbox --input examples/singbox.yaml --output-dir dist
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 本仓库是什么 / What this repository is
|
|
74
|
+
|
|
75
|
+
> **Provider 是有限领域的实现,而不只是格式适配器。**
|
|
76
|
+
> **A Provider is a bounded domain implementation, not merely a format adapter.**
|
|
77
|
+
|
|
78
|
+
通用配置工具可以把一份文档过一遍 schema。领域 Provider 做得更多:它承载某一个
|
|
79
|
+
系统的**知识**——概念、关系、约束、变体与产物——并把结构化 context 转换成经过
|
|
80
|
+
校验、确定性的、系统专属的配置。
|
|
81
|
+
|
|
82
|
+
本仓库**不是**「万能配置生成器」。它刻意选择一个 scope,并在其中把整条链路做完整:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
知识 → 约束 → 转换 → 校验 → 产物
|
|
86
|
+
knowledge → constraints → transformation → validation → artifacts
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 领域 Scope:sing-box / Domain Scope: sing-box
|
|
90
|
+
|
|
91
|
+
本仓库在 DevConfig-Gen 之上实现 **`singbox`** 领域 scope。
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
结构化 context
|
|
95
|
+
│
|
|
96
|
+
▼
|
|
97
|
+
sing-box 领域模型
|
|
98
|
+
│
|
|
99
|
+
▼
|
|
100
|
+
校验 validation
|
|
101
|
+
│
|
|
102
|
+
▼
|
|
103
|
+
领域转换 transformation
|
|
104
|
+
│
|
|
105
|
+
▼
|
|
106
|
+
server / client 配置
|
|
107
|
+
│
|
|
108
|
+
▼
|
|
109
|
+
分享链接 share links
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
领域本身:
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
SingBox Domain
|
|
116
|
+
├── 协议 protocols (anytls / tuic / hysteria2)
|
|
117
|
+
├── 认证 authentication (每个协议独立的 auth)
|
|
118
|
+
├── TLS / Reality (证书路径、REALITY 密钥对、decoy 握手)
|
|
119
|
+
├── server / client 变体
|
|
120
|
+
├── 路由 routing (DNS 分流、route 规则、geo rule set)
|
|
121
|
+
├── 网络/域名语义 (hosts、子域前缀)
|
|
122
|
+
├── 凭据处理 (凭据即显式输入)
|
|
123
|
+
├── 分享链接表示
|
|
124
|
+
└── 产物生成 (server / client / links)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
领域实现位于:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
src/devconfig_gen/providers/singbox/
|
|
131
|
+
├── provider.py # 分派 + 组装(不含任何变体字段名)
|
|
132
|
+
├── schema.py # Context Schema + 结构校验
|
|
133
|
+
├── models.py # 领域数据结构
|
|
134
|
+
├── plugins/ # 每个协议变体一个模块
|
|
135
|
+
│ ├── anytls.py
|
|
136
|
+
│ ├── tuic.py
|
|
137
|
+
│ └── hysteria2.py
|
|
138
|
+
├── route.py # DNS + Route 组装(读 data/rules.json)
|
|
139
|
+
├── links.py # 分享链接聚合
|
|
140
|
+
└── data/rules.json # 内嵌路由规则表
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 父/子架构 / Parent / Child Architecture
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
DevConfig-Gen (父仓库 · 主)
|
|
147
|
+
│ 中立引擎
|
|
148
|
+
│ Provider 契约
|
|
149
|
+
│ 执行流水线
|
|
150
|
+
│
|
|
151
|
+
└── DevConfig-Gen_SingBox (子仓库 · 兵)
|
|
152
|
+
│ sing-box 领域知识
|
|
153
|
+
│ 领域校验
|
|
154
|
+
│ 协议转换
|
|
155
|
+
│ server / client 变体
|
|
156
|
+
│ 分享链接生成
|
|
157
|
+
│
|
|
158
|
+
└── downstream (Automated-sing-box-json-generator —— 只读参考,退役中)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**父仓库拥有中立引擎与 Provider 契约;子仓库拥有领域。**
|
|
162
|
+
**The parent owns the neutral engine and the provider contract; the child owns the domain.**
|
|
163
|
+
|
|
164
|
+
- 权威方向为 **parent → child → downstream**。
|
|
165
|
+
- 核心改动先在父仓库落地,再通过 `upstream` remote 合入本仓库。
|
|
166
|
+
- 本仓库**绝不分叉或重写中立核心**(`engine` / `formats` / `validation`),只新增
|
|
167
|
+
`providers/singbox/`。
|
|
168
|
+
|
|
169
|
+
## 领域模型与转换 / Domain Model & Transformations
|
|
170
|
+
|
|
171
|
+
输入 context 按语义分区:`network`(协议 / 路由 / DNS)、`client`(客户端特有)、
|
|
172
|
+
`options`(产物选项)。`schema.py` 负责归一化,`provider.py` 与各 plugin 负责校验,
|
|
173
|
+
plugin 负责把每个协议转换为它在 sing-box 中的表示。
|
|
174
|
+
|
|
175
|
+
```yaml
|
|
176
|
+
network:
|
|
177
|
+
domain_root: example.com
|
|
178
|
+
subdomain_prefixes: {reality: a1b2c3d4, tuic: e5f6a7b8, hy2: c9d0e1f2}
|
|
179
|
+
tunnel_mode: proxy # none | proxy | tun
|
|
180
|
+
protocols:
|
|
181
|
+
- type: anytls # anytls | tuic | hysteria2
|
|
182
|
+
enabled: true
|
|
183
|
+
port: 23244
|
|
184
|
+
auth: {password: replace-me}
|
|
185
|
+
reality: {private_key: ..., public_key: ..., short_id: ...}
|
|
186
|
+
- type: tuic
|
|
187
|
+
enabled: true
|
|
188
|
+
port: 9443
|
|
189
|
+
auth: {uuid: ..., password: ...}
|
|
190
|
+
tls: {cert_path: /etc/.../tuic.crt, key_path: /etc/.../tuic.key}
|
|
191
|
+
- type: hysteria2
|
|
192
|
+
enabled: true
|
|
193
|
+
port: 7443
|
|
194
|
+
auth: {password: ..., obfs_password: ...}
|
|
195
|
+
tls: {cert_path: /etc/.../hy2.crt, key_path: /etc/.../hy2.key}
|
|
196
|
+
routing: {rules_source: embedded, geoip_cn: true} # custom_rules 可覆盖/补充
|
|
197
|
+
dns: {direct_servers: [223.5.5.5, 119.29.29.29], remote_server: 1.1.1.1}
|
|
198
|
+
client:
|
|
199
|
+
server_ip: 203.0.113.10 # TUN 排除路由
|
|
200
|
+
fingerprint: chrome
|
|
201
|
+
options:
|
|
202
|
+
target: both # server | client | both
|
|
203
|
+
format: json # json | yaml
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**隔离契约。** 每个协议的字段名与结构只存在于 `plugins/<variant>.py`。上游 sing-box
|
|
207
|
+
变化时只改**一个 plugin 文件**;`schema.py` / `provider.py` / `route.py` 与产物契约
|
|
208
|
+
保持不动,不做版本追逐。
|
|
209
|
+
|
|
210
|
+
**独立 auth。** 每个协议各自携带 `auth`(及变体)块——凭据全部是显式输入,不生成、
|
|
211
|
+
不存储、不读环境变量。
|
|
212
|
+
|
|
213
|
+
## 生成产物 / Generated Artifacts
|
|
214
|
+
|
|
215
|
+
| 产物 | 条件 | media type |
|
|
216
|
+
| --- | --- | --- |
|
|
217
|
+
| `sing-box.server.{json,yaml}` | `target != client` | `application/json` / `application/yaml` |
|
|
218
|
+
| `sing-box.client.{json,yaml}` | `target != server` | `application/json` / `application/yaml` |
|
|
219
|
+
| `sing-box-links.txt` | `target != server` | `text/plain` |
|
|
220
|
+
|
|
221
|
+
`{fmt}` 由 `options.format` 决定,产物集合由 `options.target` 决定。
|
|
222
|
+
|
|
223
|
+
## 输入示例 / Input Example
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
devconfig-gen generate --provider singbox --input examples/singbox.yaml --output-dir dist
|
|
227
|
+
devconfig-gen validate --provider singbox --input examples/singbox.yaml
|
|
228
|
+
devconfig-gen schema --provider singbox
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
完整 context 见 [`examples/singbox.yaml`](examples/singbox.yaml)。
|
|
232
|
+
|
|
233
|
+
## 校验与确定性 / Validation & Determinism
|
|
234
|
+
|
|
235
|
+
- **路径感知诊断**:每个问题都以 dotted path 报告,例如
|
|
236
|
+
`network.protocols.0.auth.password`,并一次性收集全部问题。
|
|
237
|
+
- **确定性输出**:JSON/YAML 均保持语义插入顺序;同一输入在多次运行、以及
|
|
238
|
+
CLI 与 Python API 两端都产出 byte-for-byte 一致的产物。
|
|
239
|
+
- **零副作用**:Provider 不读环境变量、不写 state、不调子进程;凭据与子域前缀
|
|
240
|
+
全部显式输入。
|
|
241
|
+
|
|
242
|
+
## 继承自 DevConfig-Gen 的引擎 / Inherited DevConfig-Gen Engine
|
|
243
|
+
|
|
244
|
+
> 本仓库从 DevConfig-Gen 继承以下基础设施:
|
|
245
|
+
|
|
246
|
+
- 确定性生成流水线(`engine.generate` / `generate_pipeline`)
|
|
247
|
+
- 结构化校验与诊断(`Diagnostic` / `ValidationError`)
|
|
248
|
+
- JSON/YAML 序列化(标准库 + 可选 PyYAML,内置子集解析器兜底)
|
|
249
|
+
- 多源合并与 dotted-path 覆盖(`deep_merge`、`--set`)
|
|
250
|
+
- CLI 与 Python API
|
|
251
|
+
|
|
252
|
+
同时也继承中立的 Provider `custom` / `json` / `env`。本仓库在其之上新增领域
|
|
253
|
+
Provider `singbox`:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
devconfig-gen providers
|
|
257
|
+
# custom / env / json / singbox
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
> **这些能力是基础设施。sing-box 领域始终由本子仓库负责。**
|
|
261
|
+
> **These capabilities are infrastructure. The sing-box domain remains the responsibility of this child repository.**
|
|
262
|
+
|
|
263
|
+
## 命令行与 Python API / CLI & Python API
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# 生成 / 校验 / 查看 schema
|
|
267
|
+
devconfig-gen generate --provider singbox --input examples/singbox.yaml --output-dir dist --format yaml
|
|
268
|
+
devconfig-gen validate --provider singbox --input examples/singbox.yaml --json
|
|
269
|
+
devconfig-gen schema --provider singbox
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from devconfig_gen import GenerationRequest, generate, generate_pipeline
|
|
274
|
+
|
|
275
|
+
result = generate(
|
|
276
|
+
"singbox",
|
|
277
|
+
GenerationRequest(
|
|
278
|
+
context={
|
|
279
|
+
"network": {
|
|
280
|
+
"domain_root": "example.com",
|
|
281
|
+
"subdomain_prefixes": {"reality": "a1b2", "tuic": "c3d4", "hy2": "e5f6"},
|
|
282
|
+
"tunnel_mode": "proxy",
|
|
283
|
+
"protocols": [
|
|
284
|
+
{
|
|
285
|
+
"type": "anytls",
|
|
286
|
+
"enabled": True,
|
|
287
|
+
"auth": {"password": "..."},
|
|
288
|
+
"reality": {"private_key": "...", "public_key": "...", "short_id": "..."},
|
|
289
|
+
}
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
"options": {"target": "server"},
|
|
293
|
+
},
|
|
294
|
+
),
|
|
295
|
+
)
|
|
296
|
+
print([a.name for a in result.artifacts]) # ['sing-box.server.json']
|
|
297
|
+
|
|
298
|
+
generate_pipeline(
|
|
299
|
+
"singbox",
|
|
300
|
+
input_path="examples/singbox.yaml",
|
|
301
|
+
output_dir="dist",
|
|
302
|
+
output_format="yaml",
|
|
303
|
+
)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## 文档 / Documentation
|
|
307
|
+
|
|
308
|
+
| 主题 | 本地 | 在线 |
|
|
309
|
+
| --- | --- | --- |
|
|
310
|
+
| 快速开始 | [`docs/getting-started.md`](docs/getting-started.md) | [getting-started](https://henryliu443.github.io/DevConfig-Gen/docs/getting-started/) |
|
|
311
|
+
| CLI 参考 | [`docs/cli.md`](docs/cli.md) | [cli](https://henryliu443.github.io/DevConfig-Gen/docs/cli/) |
|
|
312
|
+
| 输入合并与覆盖 | [`docs/input-and-merge.md`](docs/input-and-merge.md) | [input-and-merge](https://henryliu443.github.io/DevConfig-Gen/docs/input-and-merge/) |
|
|
313
|
+
| 格式支持与产物 | [`docs/formats.md`](docs/formats.md) | [formats](https://henryliu443.github.io/DevConfig-Gen/docs/formats/) |
|
|
314
|
+
| 校验与诊断 | [`docs/validation.md`](docs/validation.md) | [validation](https://henryliu443.github.io/DevConfig-Gen/docs/validation/) |
|
|
315
|
+
| Provider 开发 | [`docs/providers.md`](docs/providers.md) | [providers](https://henryliu443.github.io/DevConfig-Gen/docs/providers/) |
|
|
316
|
+
| Python API | [`docs/python-api.md`](docs/python-api.md) | [python-api](https://henryliu443.github.io/DevConfig-Gen/docs/python-api/) |
|
|
317
|
+
| 架构总览 | [`ARCHITECTURE.md`](ARCHITECTURE.md) | — |
|
|
318
|
+
| Provider 铁标准 | [`PROVIDER_STANDARD.md`](PROVIDER_STANDARD.md) | — |
|
|
319
|
+
|
|
320
|
+
## 开发与测试 / Development & Testing
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
pip install -e ".[yaml]"
|
|
324
|
+
PYTHONPATH=src python3 -m unittest discover -s tests -v
|
|
325
|
+
|
|
326
|
+
# 可重复烟雾:全量单测 + API/CLI 逐字节一致
|
|
327
|
+
python3 scripts/smoke_rounds.py 8
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## 仓库关系 / Repository Relationship
|
|
331
|
+
|
|
332
|
+
- 本仓库是 **子仓库(child / fork)**:`DevConfig-Gen_SingBox`。
|
|
333
|
+
- **父仓库(parent / upstream)** 为
|
|
334
|
+
[`DevConfig-Gen`](https://github.com/henryliu443/DevConfig-Gen),拥有中立核心与
|
|
335
|
+
[`PROVIDER_STANDARD.md`](PROVIDER_STANDARD.md)。
|
|
336
|
+
- 领域 Provider(如 `providers/singbox/`)只存在于**本仓库**,**不回填父仓库**。
|
|
337
|
+
|
|
338
|
+
权威方向为 **parent → child → downstream**。核心改动先在父仓库落地,再经 `upstream`
|
|
339
|
+
remote 合入本仓库;不得分叉或改写中立核心。
|
|
340
|
+
|
|
341
|
+
## 许可证 / License
|
|
342
|
+
|
|
343
|
+
Apache-2.0。详见 [`LICENSE`](LICENSE)。
|