Skip to content

Add app-store endpoints so clash-cli can read and edit profile config - #13

Open
zifengjiang wants to merge 1 commit into
ProjectClash:mainfrom
zifengjiang:app-store-p0
Open

zifengjiang wants to merge 1 commit into
ProjectClash:mainfrom
zifengjiang:app-store-p0

Conversation

@zifengjiang

Copy link
Copy Markdown

Why

clash-cli can already read and drive the runtime (proxies, rules in force, DNS lookups, connections), but it cannot touch the app's configuration store: a profile's override rules and its per-domain DNS never leave the App Group, so the only way to edit them is the macOS/iOS UI. That blocks scripted setup and lets an AI assistant drive everything except the part that actually persists.

What

Four endpoints on the existing private API surface, registered with the same privateRoutePrefixes helper as the rest of /clash/v1, and guarded by the same check as other app-state routes (overAppGroupSocket or RequestFromManagedListener), so a LAN controller client with the right secret and certificate fingerprint can use them too:

Endpoint Meaning
GET /clash/v1/app/profiles list profiles (id, label, order, active revision, whether it is active)
GET|PUT /clash/v1/app/profiles/{id}/rules read / replace the profile's override rules (override.prependRules, override.appendRules)
GET|PUT /clash/v1/app/profiles/{id}/dns-policy read / patch dns.nameserver-policy and dns.fake-ip-filter in the profile's runtime patch

Design notes:

  • Writes only touch inputs the app already consumes. Derived artifacts (published-rules.yaml, the resolved runtime config, revisions) stay owned by the app.
  • A PUT of DNS policy replaces only the keys it is given; other keys and unknown fields are preserved.
  • The profile store is written back keeping its existing two-space JSON formatting and a trailing newline, so the file stays diff-friendly.
  • Advertised as capability app-store-v1 from /clash/v1/capabilities, so clients can detect it.

Tests

cd bind/clash && go build ./... && go test ./ -run AppStore -count=1

Covers reading a real-shaped store, unknown-field preservation, replace-vs-preserve semantics for both rule lists and per-domain DNS, unknown profile ids, malformed payloads, and that a write leaves unrelated profiles byte-identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant