@singbox-iac/cli 0.1.0 → 0.1.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.
@@ -0,0 +1,61 @@
1
+ # Contributing
2
+
3
+ ## English
4
+
5
+ Thanks for contributing to `Singbox IaC`.
6
+
7
+ Recommended workflow:
8
+
9
+ 1. Open or discuss an issue first for non-trivial changes.
10
+ 2. Keep changes aligned with the OpenSpec flow in [`openspec/`](./openspec/).
11
+ 3. Prefer small, reviewable pull requests.
12
+ 4. Add or update tests for behavior changes.
13
+ 5. Run the validation commands before opening a PR:
14
+
15
+ ```bash
16
+ npm run lint
17
+ npm run typecheck
18
+ npm test
19
+ npm run build
20
+ ```
21
+
22
+ For packaging and distribution changes, also run:
23
+
24
+ ```bash
25
+ npm run release:check
26
+ ```
27
+
28
+ ## 中文
29
+
30
+ 感谢参与 `Singbox IaC` 的开发。
31
+
32
+ 建议流程:
33
+
34
+ 1. 非小改动先提 issue 或先沟通设计。
35
+ 2. 尽量遵循 [`openspec/`](./openspec/) 中已有的规格和 change 结构。
36
+ 3. 优先提交小而清晰、容易 review 的 PR。
37
+ 4. 如果行为发生变化,请补测试或更新测试。
38
+ 5. 提交 PR 前至少执行:
39
+
40
+ ```bash
41
+ npm run lint
42
+ npm run typecheck
43
+ npm test
44
+ npm run build
45
+ ```
46
+
47
+ 如果改动涉及打包、安装或发布,还应执行:
48
+
49
+ ```bash
50
+ npm run release:check
51
+ ```
52
+
53
+ ## Scope
54
+
55
+ Good contribution areas:
56
+
57
+ - new route verification scenarios
58
+ - more natural-language intent coverage
59
+ - more subscription compatibility fixtures
60
+ - more developer or video-site templates
61
+ - macOS operational improvements
package/README-en.md ADDED
@@ -0,0 +1,337 @@
1
+ # Singbox IaC
2
+
3
+ [简体中文](./README.md)
4
+
5
+ [![CI](https://github.com/menlong999/singbox-iac/actions/workflows/ci.yml/badge.svg)](https://github.com/menlong999/singbox-iac/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/%40singbox-iac%2Fcli)](https://www.npmjs.com/package/@singbox-iac/cli)
7
+ [![license](https://img.shields.io/npm/l/%40singbox-iac%2Fcli)](https://github.com/menlong999/singbox-iac/blob/main/LICENSE)
8
+
9
+ Policy-first subscription compiler for `sing-box` on macOS.
10
+
11
+ `Singbox IaC` treats provider subscriptions as node input instead of final configuration. It combines those inputs with fixed route policy, rule sets, and user intent to generate verifiable, publishable, and schedulable `sing-box` configs.
12
+
13
+ ## Overview
14
+
15
+ This is a developer-focused proxy infrastructure CLI. It is not just an “import subscription” tool. It connects subscriptions, rules, verification, publishing, and scheduling into one controllable workflow.
16
+
17
+ Core ideas:
18
+
19
+ - subscriptions provide nodes
20
+ - policy defines routing
21
+ - generated configs must be verifiable
22
+ - process-aware routing and site-aware routing are first-class workflows
23
+
24
+ ## Why This Exists
25
+
26
+ Many macOS users rely on GUI clients like Clash Verge, upstream subscriptions, global JavaScript merge scripts, Proxifier, and ad-hoc rule groups. That stack can work, but it has several recurring problems:
27
+
28
+ - provider groups are too coarse for real developer workflows
29
+ - GUI merge behavior and script patching are opaque
30
+ - route priority can drift when the upstream subscription changes
31
+ - some AI IDEs and desktop tools do not respect the normal system proxy path
32
+ - TUN or global mode can slow down unrelated local browsing
33
+ - GUI shells consume more resources than a headless proxy runtime should
34
+
35
+ `Singbox IaC` compresses that problem into:
36
+
37
+ `subscription -> parse -> compile -> verify -> apply -> schedule`
38
+
39
+ ## Architecture
40
+
41
+ ```mermaid
42
+ flowchart LR
43
+ A["Subscription URL / Local subscription file"] --> B["Fetcher + Decoder"]
44
+ B --> C["Parser (Trojan links -> IR)"]
45
+ C --> D["Compiler"]
46
+ E["Natural-language intent / Minimal DSL"] --> D
47
+ F["Built-in policy + Rule Sets (.srs)"] --> D
48
+ D --> G["Generated sing-box staging config"]
49
+ G --> H["Check + Route Verification"]
50
+ H --> I["Apply live config"]
51
+ I --> J["Reload / Run sing-box"]
52
+ I --> K["launchd schedule"]
53
+ ```
54
+
55
+ The system has three layers:
56
+
57
+ - input layer: subscriptions, rule sets, and user intent
58
+ - compile layer: parser, compiler, and policy assembly
59
+ - runtime layer: validation, publish, reload, and schedule
60
+
61
+ ## User Journey
62
+
63
+ ```mermaid
64
+ flowchart TD
65
+ A["User provides subscription URL + one sentence"] --> B["setup"]
66
+ B --> C["Detect local environment<br/>macOS / sing-box / Chrome / AI CLI"]
67
+ C --> D["Generate rules from intent"]
68
+ D --> E["Sync local rule sets"]
69
+ E --> F["Build staging config"]
70
+ F --> G["Verify critical routes"]
71
+ G --> H["Apply live config"]
72
+ H --> I["Install schedule"]
73
+ I --> J["Run or reload sing-box"]
74
+ ```
75
+
76
+ Typical developer path:
77
+
78
+ 1. paste the subscription URL
79
+ 2. describe routing needs in one sentence
80
+ 3. let the tool generate config and verify key routes
81
+ 4. use Proxifier for process-aware apps and the normal proxy listener for browsers
82
+ 5. let `launchd` keep the config updated
83
+
84
+ ## Core Capabilities
85
+
86
+ ### 1. Natural-language authoring
87
+
88
+ You can describe routing goals in plain language instead of editing raw `sing-box` JSON:
89
+
90
+ - `GitHub and other dev sites should use Hong Kong`
91
+ - `Antigravity process traffic should use the US`
92
+ - `Gemini should use Singapore`
93
+ - `Apple TV and Netflix should use Singapore`
94
+
95
+ The tool compiles those intents into internal rules and then into a `sing-box` config.
96
+
97
+ ### 2. Minimal DSL
98
+
99
+ For advanced users, a small YAML DSL still exists for fine-grained exceptions instead of forcing them to edit a full `sing-box` JSON file.
100
+
101
+ Good fits:
102
+
103
+ - one domain must use `AI-Out`
104
+ - one inbound must always use a specific group
105
+ - one site must stay direct
106
+ - one port should be rejected
107
+
108
+ ### 3. Process-aware routing
109
+
110
+ This is one of the most important features for developer workflows.
111
+
112
+ Some AI IDEs, language servers, or desktop tools do not obey the normal system proxy path. `Singbox IaC` provides a dedicated `in-proxifier` listener so Proxifier can force selected processes into an isolated path and then pin them to a specific outbound group or leaf node.
113
+
114
+ Typical use cases:
115
+
116
+ - `Antigravity`
117
+ - Cursor
118
+ - AI IDEs or language servers
119
+ - desktop apps that do not respect system proxy settings
120
+
121
+ This lets you keep those apps on a dedicated ingress and egress path without letting general site-based routing split them apart.
122
+
123
+ ### 4. Site-aware routing
124
+
125
+ The other common need is service-level routing:
126
+
127
+ - `GitHub`, Google services, and dev sites through Hong Kong or Singapore
128
+ - `Gemini`, `OpenAI`, and `Anthropic` through different AI egress groups
129
+ - `Google Stitch` through a dedicated country-specific egress
130
+ - China IPs and domains direct
131
+ - video sites like `Netflix`, `YouTube`, `Amazon Prime`, and `Apple TV` split by region
132
+
133
+ ## What It Does
134
+
135
+ - Fetch Base64 Trojan subscriptions and parse share links
136
+ - Compile deterministic `sing-box` configs with fixed route priority
137
+ - Provide separate listeners for regular proxy traffic and Proxifier traffic
138
+ - Verify routes with real `sing-box` and headless Chrome
139
+ - Generate rules from one natural-language sentence
140
+ - Sync local `.srs` rule sets automatically
141
+ - Publish validated configs to `~/.config/sing-box/config.json`
142
+ - Install `launchd` schedules for recurring updates on macOS
143
+
144
+ ## Install
145
+
146
+ Install `sing-box` first so the `sing-box` binary is available in your `PATH`.
147
+
148
+ Official docs:
149
+
150
+ - [sing-box package manager docs](https://sing-box.sagernet.org/installation/package-manager/)
151
+
152
+ Then install this CLI:
153
+
154
+ ```bash
155
+ npm install -g @singbox-iac/cli
156
+ singbox-iac --help
157
+ ```
158
+
159
+ ## Quick Start
160
+
161
+ ### One-step onboarding
162
+
163
+ ```bash
164
+ singbox-iac setup \
165
+ --subscription-url 'your subscription URL' \
166
+ --prompt 'GitHub and developer sites go through Hong Kong, Antigravity process traffic goes through the US, Gemini goes through Singapore, update every 30 minutes'
167
+ ```
168
+
169
+ `setup` will:
170
+
171
+ - create `~/.config/singbox-iac/builder.config.yaml`
172
+ - create `~/.config/singbox-iac/rules/custom.rules.yaml`
173
+ - check local environment readiness
174
+ - download default local `.srs` rule sets
175
+ - turn one sentence into routing rules
176
+ - build `~/.config/singbox-iac/generated/config.staging.json`
177
+
178
+ For a more guided first-run path:
179
+
180
+ ```bash
181
+ singbox-iac setup \
182
+ --subscription-url 'your subscription URL' \
183
+ --prompt 'GitHub and developer sites go through Hong Kong, Antigravity process traffic goes through the US, Gemini goes through Singapore, update every 30 minutes' \
184
+ --ready
185
+ ```
186
+
187
+ `--ready` additionally performs:
188
+
189
+ - route verification
190
+ - live config publish
191
+ - recurring schedule installation
192
+
193
+ ### Manual foreground run
194
+
195
+ ```bash
196
+ singbox-iac run
197
+ ```
198
+
199
+ Default local listeners:
200
+
201
+ - `127.0.0.1:39097` for browser/system proxy traffic
202
+ - `127.0.0.1:39091` for Proxifier process traffic
203
+
204
+ ### Day-to-day usage
205
+
206
+ ```bash
207
+ singbox-iac update --reload
208
+ ```
209
+
210
+ That command performs:
211
+
212
+ - fetch
213
+ - build
214
+ - verify
215
+ - apply
216
+ - optional reload
217
+
218
+ ### Background schedule
219
+
220
+ ```bash
221
+ singbox-iac schedule install
222
+ ```
223
+
224
+ ## Natural-Language Authoring
225
+
226
+ For common cases, you do not need to learn raw `sing-box` JSON or even the DSL.
227
+
228
+ Examples:
229
+
230
+ ```bash
231
+ singbox-iac author \
232
+ --prompt 'GitHub and dev sites should use Hong Kong, Antigravity process traffic should use a dedicated US path, Gemini should use Singapore'
233
+ ```
234
+
235
+ ```bash
236
+ singbox-iac author \
237
+ --prompt 'Google services and GitHub use Hong Kong, Amazon Prime and Apple TV use Singapore, China traffic stays direct, update every 45 minutes' \
238
+ --update
239
+ ```
240
+
241
+ The authoring layer supports:
242
+
243
+ - deterministic local intent parsing by default
244
+ - optional local AI CLI integration
245
+ - preview before writing
246
+ - closed-loop update after rule generation
247
+
248
+ ## How It Works With sing-box
249
+
250
+ This project does not replace the `sing-box` core binary. It generates and manages `sing-box` configuration.
251
+
252
+ Typical flow:
253
+
254
+ 1. fetch subscription
255
+ 2. parse nodes
256
+ 3. compile staging config
257
+ 4. validate the config
258
+ 5. verify critical routes
259
+ 6. publish to the live config path
260
+ 7. reload or start `sing-box`
261
+
262
+ Default live config path:
263
+
264
+ ```text
265
+ ~/.config/sing-box/config.json
266
+ ```
267
+
268
+ ## Security
269
+
270
+ This project is designed to keep sensitive inputs local by default:
271
+
272
+ - your subscription URL is stored only in the local builder config
273
+ - generated configs are written to your local config directory
274
+ - natural-language authoring defaults to a deterministic local parser
275
+ - local AI CLI integration is optional
276
+ - the repository ignores local tokens, caches, generated configs, and `.env` files
277
+
278
+ The project does not automatically upload subscription URLs to any remote service. Unless you explicitly configure an external AI CLI or external command, the default authoring path does not depend on an external API.
279
+
280
+ ## Common Commands
281
+
282
+ ```bash
283
+ singbox-iac init
284
+ singbox-iac setup
285
+ singbox-iac author
286
+ singbox-iac build
287
+ singbox-iac check
288
+ singbox-iac apply
289
+ singbox-iac run
290
+ singbox-iac verify
291
+ singbox-iac update
292
+ singbox-iac doctor
293
+ singbox-iac schedule install
294
+ singbox-iac schedule remove
295
+ singbox-iac templates list
296
+ ```
297
+
298
+ ## Project Structure
299
+
300
+ - [rules-dsl.md](./docs/rules-dsl.md)
301
+ - [rule-templates.md](./docs/rule-templates.md)
302
+ - [natural-language-authoring.md](./docs/natural-language-authoring.md)
303
+ - [runtime-on-macos.md](./docs/runtime-on-macos.md)
304
+ - [openspec/project.md](./openspec/project.md)
305
+
306
+ ## Current Status
307
+
308
+ The project is already a usable MVP-plus CLI:
309
+
310
+ - real subscription ingestion works
311
+ - real route verification works
312
+ - real publish flow works
313
+ - natural-language authoring works
314
+ - the npm package is published
315
+ - macOS `launchd` integration is available
316
+
317
+ High-value next steps:
318
+
319
+ - support more protocols beyond Trojan
320
+ - expand natural-language coverage
321
+ - add more provider presets for local AI CLIs
322
+ - make first-run onboarding feel even closer to true one-command usage
323
+
324
+ ## Contributing
325
+
326
+ Contributions are welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md).
327
+
328
+ Especially welcome:
329
+
330
+ - new developer scenario templates
331
+ - compatibility samples from more subscription providers
332
+ - improved natural-language intent coverage
333
+ - new verification scenarios
334
+
335
+ ## License
336
+
337
+ [MIT](./LICENSE)