8.1 KiB
AI Handoff: sing-box Raw Config Editor V1
Copy-Paste Prompt
Implement V1 of a raw sing-box.json editor in this repository.
Important: do exactly this scope and do not expand the product into a form builder, schema designer, or template system.
Product goal
Replace the current Маршруты page with a dedicated sing-box config editor
page.
The user should edit a mostly final raw sing-box.json directly inside the
app.
The app should almost not modify that config.
Critical product decisions
- V1 is only for
sing-box. - This is an engine-specific page. In the future other cores may get their own pages with their own architecture.
- Delete the
Маршрутыpage from the UI navigation for this task. - Do not build a template engine.
- Do not build GUI fields for route rules, DNS, TLS, transports, or outbounds.
- Do not use
RoutingSettingsto drivesing-boxanymore. - The editor is the source of truth for
sing-boxconfig. - The user edits a fully formed JSON config.
- The app may only do minimal runtime patching when necessary.
- The only intended V1 runtime patch for usability is quick node switching:
if the config contains an outbound with tag
proxy, the app may replace that outbound with the currently selectedNodeconverted to asing-boxoutbound before launch. - If no outbound tag
proxyexists, the app should launch the config as-is. - The config editor page is not tightly bound to the
Серверыpage, but selected nodes must still remain useful for quick switching as described above. Маршрутыmust not affectsing-boxat all after this change.- Do not call
sing-box checkin V1. - Validation in V1 should stay light:
- read file
- parse JSON
- show JSON parse errors clearly
- Keep the implementation simple and pragmatic.
Quick node switching rule
Use this exact convention:
- if the edited config contains an outbound object with
"tag": "proxy", then right before launchingsing-box, replace that outbound object with the currently selected node converted through the existing sing-box conversion path; - preserve the tag as
proxy; - do not rewrite the rest of the config;
- do not merge
RoutingSettingsinto the config; - do not generate route rules from GUI state;
- if the selected node uses an unsupported transport for native sing-box conversion, fail with a clear user-visible error instead of silently falling back to the old routing builder.
Storage
Store sing-box editor files under:
data/templates/sing-box/
For V1, one active config file is enough.
Persist in app state only what is needed to reopen that active config, such as:
- active config file name or relative path
UI requirements
Add a dedicated page for sing-box config editing with:
- large plain text editor for JSON
- open file / save file / save buttons
- new config button if useful
- validate button
- apply button or save-and-apply button
- optional pretty-format button if easy
- status/error area
Do not build advanced schema UI.
Behavior requirements
- The page edits raw JSON text.
- The page can load and save JSON files from the sing-box config folder.
- Validation only parses JSON and reports syntax errors with useful messages.
- Connecting in sing-box mode should use the saved editor config as the base
config instead of building config from
RoutingSettings. - Before launch, optionally patch only the
proxyoutbound from the selected node as described above. - Write the final runtime config to the existing runtime file path used by the app for sing-box launch.
- Keep existing node storage and node selection behavior.
- Keep app-managed behavior minimal.
Things you must not do
- do not create a placeholder/template DSL
- do not add route-rule form controls
- do not keep old
Маршрутыpage visible - do not silently combine editor JSON with
RoutingSettings - do not auto-generate a whole sing-box config from the selected node
- do not add heavy validation via external process execution
- do not rebuild or smoke-start the app automatically
Acceptance criteria
- The
Маршрутыpage is removed from navigation. - There is a dedicated sing-box editor page in the UI.
- The page loads/saves raw JSON from
data/templates/sing-box/. - JSON syntax errors are shown clearly.
- In sing-box mode, the app launches from the editor config instead of the old routing builder.
- If outbound tag
proxyexists and a selected node is available, that one outbound is replaced from the selected node before launch. - If outbound tag
proxydoes not exist, the config is launched unchanged. Маршрутыno longer affect sing-box behavior.- Unsupported selected-node transports for proxy replacement produce a clear error instead of silent fallback.
- The implementation remains simple and does not introduce a template system.
Files to read first
xray_fluent/ui/main_window.pyxray_fluent/ui/routing_page.pyxray_fluent/application/controller.pyxray_fluent/singbox_config_builder.pyxray_fluent/singbox_manager.pyxray_fluent/profiles/models.pyxray_fluent/profiles/storage.pyxray_fluent/constants.pydocs/sing-box/runtime-config.md
Implementation strategy
- Add storage path support for sing-box config files.
- Add a small editor page widget for raw JSON editing.
- Wire it into main navigation and remove the old routing page from visible UI.
- Add controller methods to:
- load active sing-box config text
- save sing-box config text
- parse/validate JSON
- build final runtime config from editor JSON plus optional
proxyoutbound replacement
- Change sing-box connect flow to use editor config as base config.
- Keep the old builder code available only as internal helper for outbound conversion or fallback paths unrelated to this feature.
- Do not do a large cleanup refactor unless required to make the feature work.
Output expectations
Make the code changes directly.
After implementation, report:
- what changed
- which files were added/modified
- how node-to-proxy replacement works
- what limitations remain in V1
Final Decisions
These decisions are already made and should not be re-opened:
sing-boxonly in V1- separate engine-specific page
- no route forms
- no template engine
- raw JSON editor
Маршрутыremoved from UIМаршрутыdo not influence sing-box anymore- minimal runtime patching only
proxyoutbound replacement from selected node is allowed- no
sing-box checkin V1
Clarifying Notes
Why proxy replacement is allowed
The product still needs fast server switching using existing Node storage.
The narrowest possible solution is to reserve tag proxy as the single
replaceable outbound convention.
This keeps the editor raw and simple while preserving current node utility.
What "almost does not touch the config" means
It means:
- do not rebuild full config from app state
- do not merge route GUI state
- do not synthesize DNS/routing sections from forms
- only patch the selected-node outbound when the config opts into that by
containing tag
proxy
What to do with unsupported nodes
If selected node conversion cannot produce a native sing-box outbound, show a clear error and abort connect for that path. Do not silently switch to the old hybrid generator in this V1 unless that fallback is already trivial and fully compatible with the raw-config model.
Prefer explicit failure over hidden behavior.
Suggested Minimal UX
- page title:
sing-box - main editor area
- buttons:
ОткрытьСохранитьПроверить JSONПрименить
- small hint text:
- config is raw
sing-box.json - outbound tag
proxywill be replaced by the selected server if present
- config is raw
Recommended Technical Shortcut
Do not over-model this in AppState.
For V1, it is enough to add a couple of fields to settings or state for:
- active sing-box config file path or name
- maybe unsaved editor text handling if you choose to persist it
Do not invent a large new profile schema.