# Tunla config document, version 3

Instructions for an AI assistant helping a user configure **Tunla**, a split-tunnel VPN app for iPhone and Mac.

## How this works

The user copied a short prompt from Tunla ("Prompt" in the app's agent view) with this link, and attached their
**current setup** as the file `tunla-setup.json`: a JSON object with `about` (a note), `current` (the whole
setup, in this document's form), `selectedProfile` and `credentialsShared`. The setup file is not a config
document itself.

1. Read this document, then the attached setup (if you can run code, parse it rather than retyping it). Ask the user
   what they want if they haven't said.
2. Reply with **one config document** (`"splitvpn": 3`, described below) in a single ```json code block, or as a
   downloadable `.json` file if the document is long. **Tunla only adds** in this mode: each profile in your
   document becomes a **new** profile (renamed "Name 2" if the name is taken), and new VPNs, proxies, chains and
   subscriptions are created; a document that would change or delete anything the user already has (an existing VPN,
   proxy, chain, subscription or profile, or which profile is selected) is refused. So write a complete new profile
   (its `rules`, `variables` and `default`) that refers to the existing VPNs, proxies and chains by name, and
   list only new ones under `vpns`, `proxies`, `chains` and `subscriptions`. Don't send `selectProfile`.
3. Say in one or two sentences what the document changes. The user brings your reply back into Tunla (paste, or the
   file), which checks it, shows what it changes and applies it only when the user taps Apply. If Tunla finds problems,
   the user will paste them back to you: fix the document and send it again, whole.

You can't run Tunla's tools here: where this document mentions `get_setup`, read "the attached setup";
`validate_config` and `apply_config` are what Tunla does with the document you send. Don't ask the user for
passwords that are already saved (`"•set"`). Applying never connects or disconnects the VPN.

**Working with the user**

- Prefer a few broad rules (`+.domain`, `geosite:`) over many near-identical ones; use a variable when several
  rules should move together; use a chain to reach a VPN or proxy through another one.
- Set a profile's `default` only when the user wants everything through a VPN or proxy (a full tunnel); leaving it
  `direct` keeps Tunla out of the way of everything else.
- When a change affects the profile the user is connected with, ask them to reconnect.

---

## 1. Document

```json
{
  "splitvpn": 3,
  "summary": "Everything through the work VPN, Acme via the HK chain, Japan through my own proxy, Netflix direct",
  "vpns": [
    { "name": "Work VPN", "type": "anyconnect", "server": "https://vpn.acme.com", "username": "alice", "password": "•set" },
    { "name": "Home", "type": "wireguard", "wireguard": "[Interface]\nPrivateKey = •set\nAddress = 10.7.0.2/32\n[Peer]\nPublicKey = xTIB…Dg=\nEndpoint = home.example.net:51820\nAllowedIPs = 0.0.0.0/0" },
    { "name": "Old SSTP", "delete": true }
  ],
  "proxies": [
    { "name": "Tokyo SS", "link": "ss://YWVzLTI1Ni1nY206cGFzcw@203.0.113.5:8388#Tokyo" },
    { "name": "HK Trojan", "type": "trojan", "server": "hk.example.net", "port": 443, "password": "s3cret", "sni": "hk.example.net" }
  ],
  "chains": [
    { "name": "Work via HK", "hops": ["proxy:HK Trojan", "Work VPN"] }
  ],
  "subscriptions": [
    { "name": "Provider", "url": "https://sub.provider.example/link/abc123def456", "autoRefresh": 12 }
  ],
  "profiles": [
    { "name": "Work", "fallbackDNS": ["1.1.1.1", "8.8.8.8"],
      "variables": [ { "name": "exit", "to": "proxy:Tokyo SS" } ],
      "default": { "to": "Work VPN" },
      "rules": [
        { "match": "+.acme.com", "to": "Work via HK" },
        { "match": "10.20.0.0/16", "to": "Work VPN" },
        { "match": "+.netflix.com", "to": "direct", "dns": "device" },
        { "match": "geosite:category-ads-all", "to": "block" },
        { "match": "+.example.jp", "to": "$exit" }
    ]},
    { "name": "Travel", "delete": true }
  ],
  "selectProfile": "Work"
}
```

| Field | Type | Required | Meaning |
|---|---|---|---|
| `splitvpn` | number | yes | The integer `3`. (`2`, `1` and `1.1` are earlier formats: always write `3`.) |
| `summary` | string ≤ 200 chars | yes | One line describing the change (activity log). |
| `vpns` | array of VPN | no | VPNs to **create, update or delete** by name. VPNs already in the app don't need to be listed; rules can refer to them by name. |
| `proxies` | array of Proxy | no | The user's own proxies ("My proxies") to **create, update or delete** by name (at most 200 entries). |
| `chains` | array of Chain | no | Named chains to **create, update or delete** by name (at most 100 entries). |
| `subscriptions` | array of Subscription | no | Proxy subscriptions to **create, update or delete** by name. |
| `profiles` | array of Profile | no | Profiles to **create, replace or delete** by name (at most 50). |
| `profile` | Profile | no | Shorthand for one entry of `profiles` (both may be given; names must differ). |
| `selectProfile` | string | no | The profile the next Connect uses (a profile of the app or of this document). It never connects. |

Unknown fields are errors (keeps typos visible). Everything left out stays as it is. Applying order: VPN deletes,
VPN creates/updates (and credentials), subscriptions, proxies, chains, profiles (variables, then rules), selection.

### Names and references

| Written as | Refers to |
|---|---|
| `"direct"`, `"block"` | The normal network; refused. Exactly these lowercase words (`"Direct"` is a name). Only as a rule's or default rule's `to`. |
| `"Work VPN"` | A VPN or a chain, by name (case-insensitive; VPNs and chains share one namespace). |
| `"proxy:Tokyo SS"` | One of the user's own proxies, by name (case-insensitive). |
| `"proxy:1111111111111111"` | A server by id: a subscription's server (16 hex digits) or one of the user's own (a UUID), from `servers` / `list_servers`. |
| `"$exit"` | A variable of the same profile. |

A rule's `to` and the default rule's `to` may be any of these. A variable's `to` and a chain's `hops` are narrower (see their tables). A
reference to something that is gone (a server that left its subscription after a refresh, a deleted proxy) is shown by
`get_setup` in `unsupported` and fails closed in the tunnel; a document using it gets `unknown-vpn`. A subscription's
server is found again after a refresh by its subscription and name, then by its address (the id can change).

### Credentials: hidden values and `"•set"`

Unless the user turns on **"Share existing credentials with the agent"** in the session view (off by default, reset
when the session ends), every output shows an existing credential as `"•set"` when it is present (and leaves the field
out when it isn't): VPN passwords and PSKs, WireGuard `PrivateKey` / `PresharedKey`, OpenVPN inline keys (the contents
of `<key>`, `<tls-auth>`, `<tls-crypt>`, `<tls-crypt-v2>`, `<pkcs12>`, `<secret>`, and inline `<auth-user-pass>` /
`<http-proxy-user-pass>` pairs), the user's own proxies' `password` / `uuid`, servers' credential fields
(`password`, `uuid`, `private-key`, `pre-shared-key`, `auth` and their variants), and the token or query part of
subscription links: `https://sub.example.com/api/v1/••••` (scheme, host and leading known path words such as
`api`, `v1`, `client`, `sub`, `link`, `clash` stay; the first segment that isn't one of those words, and everything after
it, is hidden, so a short token like `/link/aB3xYz9KqLmPwQrT` never shows).

**Writes may always set or replace credentials.** A field left out keeps its value. Writing `"•set"` back means
"unchanged" (as a whole field, or as a key's value inside a WireGuard / OpenVPN config, a proxy's `password` / `uuid`,
or the masked link as a subscription's `url`), so a document built from `get_setup` can be sent back as it is. `"•set"`
where nothing is saved is an error (`vpn-field`, `proxy-field`, or `subscription-fetch` for a link). `""` removes a saved password or PSK (Tunla then asks
at the next Connect).

### Profile

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | If a profile with this name (case-insensitive) exists, its rules are **replaced** by `rules`. Otherwise a new profile is created. |
| `fallbackDNS` | array of IPv4 strings | no | Resolvers used for "device DNS" when the device's own DNS can't be read. Omitted means keep the existing value (or `1.1.1.1, 8.8.8.8` for a new profile). |
| `variables` | array of Variable | no | The profile's variables. Left out: keep the existing ones (none for a new profile). Given: the profile's variables become exactly this list; a variable keeps its identity when its name stays (so a running tunnel switches it at once). At most 50. |
| `default` | Default rule | no | Where traffic that no rule matches goes. Left out: keep the existing one (`direct` for a new profile). `get_setup` shows it only when it isn't `direct`. |
| `rules` | array of Rule | yes (unless `delete`) | One flat, ordered rule list. **Top to bottom, first match wins.** At most 2000 rules per profile. Folders were removed: an entry with a `folder` key (or with `rules` and no `match`) gets `removed`; send its rules in place, in order (`"enabled": false` on each for a disabled folder). |
| `delete` | `true` | no | Removes the profile (only `name` may accompany it). The profile the tunnel is running can't be deleted, nor the last one (`delete-in-use`). Deleting the selected profile selects another one (or `selectProfile`). |

### Rule

| Field | Type | Required | Meaning |
|---|---|---|---|
| `match` | string | yes | `corp.com` (exactly that name), `=corp.com` (same, explicit), `*.corp.com` (subdomains only, not `corp.com`), `+.corp.com` (corp.com **and** all subdomains), an IPv4 address / CIDR like `10.0.0.0/8`, or `geosite:<list>[@attr]` / `geoip:<cc>` / `geoip:private`. Lowercase. No URLs, ports or paths. IPv6 is not supported. |
| `to` | string | yes | `"direct"` (normal network), `"block"` (refused), a VPN or chain **name**, `"proxy:<name or id>"` or `"$variable"` (in this document or in the app; see "Names and references"). |
| `backups` | | | **Removed** (`removed`): a rule has one target. While it is down (a VPN not connected, a chain whose exit is down, a missing proxy) the rule's traffic fails closed. Use a variable to switch rules by hand. |
| `dns` | string | no | How matching names are resolved (domain rules only; ignored for IP rules). `"vpn"` (default: the VPN's own DNS, through the VPN; for a proxy, the proxy server resolves the name; for a chain, its exit decides), `"device"`, `"server:<IPv4>"` (through the rule's VPN when `to` is a VPN), `"fixed:<IPv4>[,<IPv4>…]"` (fixed answer, like a hosts entry). For `direct` / `block`, `"vpn"` means device DNS. |
| `enabled` | boolean | no | Default `true`. Disabled rules are kept but ignored. |
| `note` | string ≤ 200 chars | no | Shown in the app. |

`geosite:<list>` matches a v2fly domain-list-community list (`geosite:cn`, `geosite:netflix`,
`geosite:category-ads-all`, `geosite:geolocation-!cn`) and is a domain rule (decided at DNS time; `dns` applies).
`geosite:<list>@<attr>` keeps only the entries tagged with that attribute (`geosite:google@cn`). `geoip:<cc>` matches a
country's IPv4 ranges (DB-IP, ISO 3166 alpha-2, lowercase) and `geoip:private` the RFC 1918, 100.64/10, 169.254/16 and
127/8 ranges; both are IP rules (`dns` is ignored). Names no domain rule matches are resolved through the device's DNS
and their addresses then meet the IP rules, `geoip:` included. List names and attributes: 1–64 of
`a-z 0-9 - ! _ . &`. Use `list_geo` to find list names, attributes and countries. Countries that need very many routes
(over 50,000, e.g. `geoip:us` sent to a VPN) are refused when connecting.

### Default rule

The profile's last rule, after every other one: where traffic goes that no rule matches. `{"to": …, "dns": …}`.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `to` | string | yes | Like a rule's `to`: `"direct"` (the default), `"block"`, a VPN or chain name, `"proxy:<name or id>"`, `"$variable"`. |
| `dns` | string | no | How names no rule matches are resolved when `to` isn't `direct`: `"vpn"` (default: the target's DNS, through it; a proxy resolves the name itself), `"device"`, `"server:<IPv4>"` (through the target). Never `"fixed:…"` (`dns-syntax`). |

- `"direct"`: the **split tunnel**, as always: only the rules' traffic and names enter the tunnel; everything else never
  sees Tunla.
- Anything else: a **full tunnel**. All IPv4 traffic and every DNS name go into the tunnel; the rules above are the
  exceptions (a `direct` rule's traffic then leaves through the tunnel's own direct path, a Direct IP rule's ranges stay
  out of the tunnel). The device's local networks, link-local and multicast stay local. IPv6 is blocked (AAAA answers
  are empty), so nothing leaks outside the rules. When the target is down, unmatched traffic fails closed, never direct.
  `"block"` is an allow-list: only what a rule sends somewhere works.
- The servers the tunnel itself dials (VPN gateways, proxy servers) always resolve to their real addresses and stay
  outside the tunnel, so sign-ins and reconnects work whatever `default` says.

### VPN

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | Unique name (case-insensitive; shared with chains). If a VPN with this name exists, the listed fields **update** it (its `type` must match). Otherwise a new VPN is created. |
| `type` | string | yes (unless `delete`) | `anyconnect`, `globalprotect`, `fortinet`, `f5`, `pulse`, `sstp`, `ikev2`, `wireguard`, `openvpn`. |
| `server` | string | yes for new (not wireguard / openvpn) | Gateway address. `https://host[:port][/path]` for anyconnect/globalprotect/fortinet/f5/pulse/sstp, `host[:port]` for ikev2. |
| `username` | string | no | Login name (also OpenVPN's `auth-user-pass` user). Not for wireguard. |
| `password` | string | no | The saved password (every type but wireguard). `"•set"` keeps it, `""` removes it. |
| `psk` | string | no | ikev2 only, with `ikev2Auth: "psk"`: the pre-shared key (the same saved secret as `password`; give one of them). |
| `group` | string | no | anyconnect: tunnel group. globalprotect: preferred gateway (`host[:port]` or its label). fortinet/pulse: realm. |
| `remoteID` | string | no | ikev2 only: server identity (IDr), often the server's DNS name. |
| `ikev2Auth` | string | no | ikev2 only: `"eap"` (username + password, default) or `"psk"`. A new ikev2 VPN with `psk` uses `"psk"`. |
| `wireguard` | string ≤ 16 KiB | yes for new wireguard | The full wg-quick configuration (`[Interface]` and at least one `[Peer]`). `PrivateKey = •set` / `PresharedKey = •set` keep the saved keys (a peer's by its `PublicKey`). |
| `openvpn` | string ≤ 256 KiB | yes for new openvpn | The full `.ovpn` configuration (at least one `remote` line), inline blocks included. A block whose content is `•set` keeps the saved one. |
| `via` | | | **Removed** (`removed`): chains are named items now (`chains`). |
| `autoReconnect` | boolean | no | Default `false`. |
| `sso` | string | no | `"off"` (ask if the gateway needs it; default), `"inApp"`, `"system"` (system browser; anyconnect, fortinet, globalprotect only). Portal types only. |
| `delete` | `true` | no | Removes the VPN and its saved password (only `name`, and optionally `type`, may accompany it). Refused while rules, default rules, variables or chains still use it after the document is applied (`delete-in-use`): change those in the same document. |

### Subscription

A subscription is a list of proxy servers from a provider (a link Tunla refreshes) or pasted content. Its servers
appear in `get_setup` / `list_servers`; rules, variables and chains use them one by one (`"proxy:<id>"`). Its
own rules are ignored. Refreshing (`refresh_subscriptions`, or a new link in a document) works only while the tunnel is
disconnected.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | Unique name (case-insensitive). An existing subscription is updated with the listed fields; otherwise one is created. |
| `url` | string ≤ 2048 | `url` or `content` for new | An `https://` link. A new or changed link is **fetched immediately** (within about 40 s), and the result is in the tool output; if it fails, nothing is applied (`subscription-fetch`). The masked link from `get_setup` means "unchanged". A changed link for an existing subscription is refused while the tunnel is connected (`subscription-fetch`: that would refresh it, which only happens disconnected); a new subscription is fine. |
| `content` | string | | The subscription itself (Clash YAML, a base64 URI list, sing-box JSON…), instead of `url`. Read immediately; content with no usable servers is `subscription-fetch`. New content for an existing subscription is refused while connected, like a changed link. |
| `userAgent` | string 1–200 | no | The User-Agent sent when fetching (some providers answer per client). Default `clash.meta`. |
| `autoRefresh` | integer 0–720 | no | Refresh interval in hours; `0` = manual. Default 12 for links. |
| `delete` | `true` | no | Removes the subscription and its stored servers (only `name` may accompany it). References to its servers stay and fail closed until changed. |

### Proxy (the user's own, "My proxies")

A proxy server the user (or an agent) added directly: from a share link, or from fields. Stored like a subscription's
servers (Tunla's own files). Rules, variables and chains refer to it as
`"proxy:<name>"`. Entries match by name (case-insensitive): an existing proxy is **updated** with the listed fields
(its identity stays, so everything using it keeps using it), otherwise one is created.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | Unique among the user's own proxies. |
| `link` | string ≤ 4096 | `link` or `type` for new | A share link: `ss://` (SIP002, SS-2022, legacy base64), `trojan://`, `vmess://` (v2rayN base64 JSON), `socks5://` (also `socks://`, `socks5h://`), `http://`, `https://` (`[user:pass@]host:port[#name]`). `udp=1` in the query (`"udp": "1"` in v2rayN JSON) marks a proxy that relays UDP; without it the proxy is TCP only. Replaces the whole proxy; no other field may accompany it. Never shown in outputs. |
| `type` | string | `link` or `type` for new | `ss`, `trojan`, `vmess`, `socks5`, `http` or `https` (an HTTP proxy over TLS). Changing it on an existing proxy starts its credentials over (`http` ↔ `https` keeps them). |
| `server` | string | yes for new (fields) | Host name or IP address. |
| `port` | integer 1–65535 | no | Default 443. |
| `username` | string | no | socks5, http, https only: the proxy's username (SOCKS5: ≤ 255 bytes; HTTP: no `:`). Not a secret: shown in outputs. |
| `password` | string | ss, trojan; optional for socks5 / http / https (needs `username`) | The password (SS-2022: the base64 key). `"•set"` keeps it. |
| `uuid` | string | vmess | The user id (a UUID). `"•set"` keeps it. |
| `cipher` | string | no | ss: `aes-128-gcm`, `aes-256-gcm` (default), `chacha20-ietf-poly1305`, `2022-blake3-aes-128-gcm`, `2022-blake3-aes-256-gcm`, `2022-blake3-chacha20-poly1305`. vmess: `auto` (default), `aes-128-gcm`, `chacha20-poly1305`. Not for trojan. |
| `sni` | string | no | trojan, vmess with `tls`, https: the TLS server name. |
| `skipCertVerify` | boolean | no | trojan / vmess with `tls` / https: don't check the server's certificate. |
| `tls` | boolean | no | vmess only (an HTTPS proxy is `"type": "https"`). |
| `network` | string | no | `tcp` (default) or `ws` (trojan, vmess). |
| `wsPath`, `wsHost` | string | no | With `network: "ws"`: the path (default `/`) and the Host header. |
| `udp` | boolean | no | `true`: the server relays UDP (Shadowsocks UDP relay, Trojan / VMess UDP in the stream, SOCKS5 UDP ASSOCIATE). **Default `false`** (most proxies relay none): apps' UDP through it is refused at once, and a VPN that needs UDP can't be chained behind it. Not for http / https (`proxy-field`: CONNECT is TCP only). |
| `delete` | `true` | no | Removes the proxy (only `name` may accompany it). Refused while rules, default rules, variables or chains still use it after the document is applied (`delete-in-use`). |

A proxy Tunla can't speak (e.g. a Shadowsocks plugin from a link, a VMess `alterId` other than 0) is saved with a
`proxy-unsupported` warning: rules and chains using it fail closed. Updating an existing proxy's fields keeps the
settings this format doesn't show (a plugin, `alpn`, a client fingerprint, grpc options, an `alterId`); a new `link`
replaces everything. `get_setup` lists such an unsupported proxy under `unsupported` with those settings named. An
SS-2022 `password` must be a base64 key of the method's size (16 bytes for `2022-blake3-aes-128-gcm`, 32 for the others;
`proxy-field` otherwise). Plain `socks5` and `http` are unencrypted between the device and the proxy.

### Chain

A named path: `hops[0]` is dialled directly, each next hop is reached through the one before it, and traffic leaves
through the last hop (the exit). "Work via HK" = `["proxy:HK Trojan", "Work VPN"]`. A chain is a connection like a VPN:
rules and variables target it by name. Nothing is refused for using a hop directly and in chains at once (A, B
and "B via A" together; B behind different hops in different chains): the tunnel reuses what has the same path and runs
a separate connection where the path differs (for a VPN that means a second session to its gateway; if the gateway
refuses it, that chain alone fails, with the gateway's error). A chain never connects directly when a hop is down: it
fails closed.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | Unique name, shared with VPNs (case-insensitive); not `direct` / `block`. An existing chain is **updated**; otherwise one is created. |
| `hops` | array of strings | yes (unless `delete`) | 2–9 hops, entry first: VPN names and `"proxy:<name or id>"` (never a chain, a variable, `direct` or `block`), each at most once. A VPN that needs UDP (`wireguard`, `ikev2`, `openvpn` over UDP) needs the hop in front of it to relay UDP: a VPN does; a proxy does only with `udp: true` (never http / https); a Shadowsocks or SOCKS5 server's UDP relay works behind a hop only if that hop relays UDP too (Trojan and VMess carry UDP inside their TCP stream). AnyConnect and GlobalProtect use TCP there (their UDP fast path is turned off). |
| `delete` | `true` | no | Removes the chain (only `name` may accompany it). Refused while rules, default rules or variables still use it after the document is applied (`delete-in-use`). |

### Variable

A profile's named pointer: rules and the default rule use it as `"$name"`. Changing where it points re-routes all of them at once,
also in a running tunnel (`set_variable`, or a document that changes an existing variable of the running profile): new
connections use the new target, existing ones through the old target are reset, DNS answers follow, and nothing goes
direct while it switches.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `name` | string 1–60 chars | yes | Unique in the profile (case-insensitive), written without `$`; not `direct` / `block`. |
| `to` | string | no | A VPN or chain name, or `"proxy:<name or id>"` (never `direct`, `block` or another variable). Left out: it points at nothing yet, and rules using it fail closed (`variable-unset` warning). |

---

## 2. Validation

`validate_config` and `apply_config` apply the same rules. Every problem has a **path** (JSONPath-like, e.g.
`$.profiles[0].rules[3].rules[0].match`), a **code** and a message. Errors block applying; warnings don't. Messages
never quote a value that looks like key material, and never a credential or a subscription link.

**Errors**

| Code | When |
|---|---|
| `version` | `splitvpn` missing, or not `3`, `2`, `1` or `1.1` (`3.0`, `2.0`, `1.0`, `"3"`, `4` are refused). |
| `type` | Wrong JSON type for a field (also `autoRefresh` outside 0–720, a `userAgent` with control characters, a proxy `port` outside 1–65535). |
| `unknown-field` | A field not in this spec (in a version 1 document: any version 2 field; in a version 1 or 2 document: `proxies`, `chains`, `variables`). |
| `missing` | A required field is missing or empty (a new VPN's `server` / `wireguard` / `openvpn`, a new subscription's `url` or `content`, a new proxy's `type` (or `link`), a chain's `hops`…). |
| `too-long` | A string or list over its limit (also more than 50 variables, 200 proxies or 100 chains). |
| `match-syntax` | `match` isn't a valid domain pattern, IPv4/CIDR or geo selector. Domains: labels of `a-z 0-9 -` (and `_`), 1–63 chars, not starting or ending with `-`, at least two labels, total ≤ 253. No scheme, port, path, `*` in the middle, or uppercase. |
| `reserved-range` | An IP rule overlaps `198.18.0.0/15` (used internally by Tunla). |
| `dns-syntax` | `dns` isn't one of the forms above, or has a bad IPv4 (a default rule's `dns` can't be `fixed:`). |
| `unknown-vpn` | A name that refers to nothing usable: a rule's or default rule's `to`, a variable's `to`, or a chain hop that names no VPN, chain, proxy or variable (in the document or the app), a proxy that's gone; `direct` / `block` as a variable's `to`, a variable pointing at a variable; a VPN, proxy or chain to delete that doesn't exist. |
| `vpn-type` | Unknown `type`, or an update that changes an existing VPN's type (in version 1: `wireguard` / `openvpn` in `vpns`). |
| `vpn-field` | A field that doesn't apply to the type or to a delete, a bad `server`, a WireGuard config without `[Interface]` / `[Peer]`, an OpenVPN config without `remote`, `password` with `psk`, `"•set"` where nothing is saved. |
| `proxy-field` | A share link that can't be read (or isn't ss / trojan / vmess / socks5 / http / https), `link` with other fields, a field that doesn't apply to the type (`uuid` on ss, `tls` on trojan, `password` on vmess, `username` on ss, `udp: true` on http, `sni` on socks5…; for an update that leaves `type` out, checked against the saved proxy's type), an unknown `type`, `cipher` or `network`, a missing or bad server / password / uuid (SS-2022 keys are base64), a SOCKS5 / HTTP password without a username, `"•set"` where nothing is saved. |
| `duplicate-vpn` | Two entries with the same name in one list (`vpns`, `proxies`, `chains`, `subscriptions`, profiles, a profile's `variables`); a chain named like a VPN (or the reverse); a reserved name (`direct`, `block`) or a `$` in a variable's name. |
| `chain-hops` | A chain with fewer than two hops, a hop listed twice, or a hop that is a chain, a variable, `direct` or `block`. |
| `chain-udp` | A VPN that needs UDP behind a hop that can't relay UDP for it (a proxy not marked `udp: true`, an HTTP(S) proxy, or a Shadowsocks / SOCKS5 server behind a hop that relays no UDP). Reported at the chain's `hops`, or at the VPN / proxy entry whose change breaks an existing chain (e.g. an OpenVPN config switched to UDP, a proxy set to `udp: false`). |
| `depth` | A chain with more than 9 hops. |
| `geo-list` | A `geosite:` list or `@attribute`, or a `geoip:` country, that the app's geo data doesn't have. |
| `unknown-subscription` | A subscription to delete that doesn't exist. |
| `delete-in-use` | Deleting a VPN, proxy or chain that rules, default rules, variables or chains still use once the document is applied, unless the same document also changes those; deleting the profile the tunnel is running, or every profile. |
| `subscription-fetch` | A new or changed link that isn't an https URL, that couldn't be fetched, or content that couldn't be read; `url` together with `content`; a masked link that isn't the masked form of the stored one; a changed link or content for an existing subscription while the tunnel is connected. Nothing is applied. |
| `unknown-profile` | `selectProfile`, or a profile to delete, names no profile. |
| `needs-pro` | The document goes over Tunla Free's limits where the current setup doesn't: more than 1 VPN or own proxy in total, more than 1 rule (the default rule doesn't count) or 1 profile, or any subscription, chain or variable (a bigger count than now, or a new kind). Keeping or reducing what the setup already has is allowed. Only on Free (or after the trial); the user starts the trial or gets Pro in the app. Nothing is applied. |
| `removed` | `groups` (server groups), a VPN's `via`, a rule's (or default rule's) `backups`, or a rule folder, in any version. Use one proxy per rule, a variable (switched by hand), or a named chain; send a folder's rules in place, in one flat list. |

**Warnings**

| Code | When |
|---|---|
| `shadowed` | A rule can never match because an earlier enabled rule always matches first (e.g. `corp.com` after `+.corp.com`, or `10.1.0.0/16` after `10.0.0.0/8`). |
| `duplicate-rule` | The same `match` appears twice in a profile (the second is shadowed). |
| `dns-ignored` | `dns` set on an IP rule. |
| `no-rules-for-vpn` | A new VPN that no rule, variable, or chain used by them, of the document's profiles uses. |
| `broad-route` | An IP rule of `/8` or wider sent to a VPN, proxy, chain or variable. Legal, but sends a lot of traffic through it. |
| `direct-dns-server` | `dns: "server:…"` on a `direct` rule (that server is queried directly, not through a VPN). |
| `geo-data-missing` | A `geosite:` / `geoip:` rule while the app has no geo data for it yet (it matches nothing until `update_geo_data`). |
| `proxy-unsupported` | A proxy Tunla can't speak (a Shadowsocks plugin, VMess `alterId` > 0…): rules and chains using it fail closed. |
| `variable-unset` | A variable without `to` that an enabled rule (or the default rule) uses: those rules fail closed until it points somewhere. |

At most 500 issues are listed (errors first); `omitted` counts the rest.

---

## 3. The setup (`get_setup`)

`get_setup` returns `{current, selectedProfile, credentialsShared}`. `current` is the whole setup **in this document's
form** (`"splitvpn": 3`), masked per section 1:

- `vpns`: every VPN with all its document fields, `password` / `psk` and the WireGuard / OpenVPN configs;
- `proxies`: the user's own proxies in document form (fields, never a link; `password` / `uuid` masked; `udp: true`
  only for those that relay UDP; an HTTP proxy over TLS as `"type": "https"`);
- `chains`: every chain with its `hops` (names as in "Names and references");
- `subscriptions`: `name`, `kind` (`link` / `file`), `url` (masked), `userAgent`, `autoRefresh`, `nodeCount`,
  `lastRefresh`, `lastError`, `refreshable`;
- `servers`: id, name, `proto`, region, supported, subscription (`"My proxies"` for the user's own), `latencyMS`,
  `lastTested`, `server` (address), `port`, `settings` (credential fields masked), `udp: true` for a server that relays
  UDP (left out otherwise: TCP only, the default); at most 500 (`serversOmitted` counts the rest; `list_servers` pages through all);
- `profiles`: every profile with its `variables`, rules and `default` (left out when it is `direct`);
- `unsupported`: things the app holds that the format can't express or that refer to something gone, each `{profile?,
  vpn?, proxy?, path, code, message}`: a single-label rule `jira`, an `http://` server, a
  fallback DNS list that isn't IPv4, **a rule, default rule, variable or chain hop whose proxy, VPN or chain is missing** (it
  fails closed until changed; `code` is `unknown-vpn`), **a chain that can't work** (a hop listed twice, too few or too
  many hops: `chain-hops`; a VPN that needs UDP behind a hop that can't relay it: `chain-udp`), **a proxy or chain entry
  this format can't write back** (e.g. a name over 60 characters: `too-long` at `$.proxies[i].name` / `$.chains[i].name`)
  and **a proxy Tunla can't use** (`proxy-unsupported`, naming settings the document doesn't show). A document
  replacing that profile must rewrite or drop them. Rules, variables and `set_variable` treat a chain that can't work like
  a missing one (shown as missing; `set_variable` refuses it).
- `warnings`: the setup's own warnings, same shape as `unsupported`. None are produced at the moment (left out).

Sending `current` (or its `vpns`, `proxies`, `chains` and `profiles`) back unchanged changes nothing.
