Skip to content

feat(api): slugs for every closed set, and core's text in a written register - #35

Merged
fylorn merged 2 commits into
mainfrom
feat/slugs-and-written-copy
Sep 17, 2026
Merged

fylorn merged 2 commits into
mainfrom
feat/slugs-and-written-copy

Conversation

@fylorn

@fylorn fylorn commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What this changes

Two things, one commit each:

  1. Fixed sets are sent as slugs. Any field whose value comes from a set core defines now carries an identifier, and the app picks the label, as trust and billing already worked. Lists that mixed fixed labels into data (rule conditions, dry-run rewrites, plan fields, link test segments) carry keys and values instead of sentences. Sentences with runtime detail (errors, hints, diagnosis findings) stay in core.
  2. Everything core says is in a formal written register. This covers control-plane and gateway errors, configuration validation, link test results, client adoption notes and diagnosis, scan findings and the built-in rule reasons, the diagnostics bundle, the notes written into adopted client configs, twcore's output and help text, and logs.

The workspace goes to 0.4.0. The protocol changes are breaking.

Why

ThinkWatch Lite rewrote its UI copy in a formal register (ThinkWatchProject/ThinkWatch-Lite#36): statements rather than asides or questions, no first or second person, 费用 for amounts, and no explanations of internal mechanics. Several strings it shows verbatim come from core. Some of them it also uses to decide behaviour:

  • GroupView.kind == "手动选" / "轮流" in Config.tsx (three places) and in the tray menu (src-tauri/src/lib.rs), plus a { 按顺序: "fallback", … } table mapping the label back to the config word
  • StorageStatus.level !== "正常" in Dashboard.tsx
  • AttemptView.outcome === "成功" in RequestDrawer.tsx
  • ManualClient.how.replace("网关地址", gateway_base) in Clients.tsx. Core never sent that placeholder, so users read 填我们的地址.

Rewording any of these in core would have broken the app without a compile error. Rewriting the Chinese in place would keep that coupling, so fixed sets become identifiers instead.

Protocol changes

Slugs instead of labels

Field Values
GroupView.kind, DryRunResult.strategy the config word: fallback / select / load-balance / url-test / cheapest
StorageStatus.level ok / metadata_only / stopped / unavailable
ConfigReloaded.origin, ConfigVersion.origin ui / cli / external / rollback / rotation
ConfigRejected.stage syntax / schema / semantics
LocallyAnswered.probe the probe id (health_check …), same as ProbeView.id
QuotaWindow.label → window 5h / 7d / weekly
AttemptView.outcome served / status / error, with new status: Option<u16> and error: Option<String>
LeakSeen.secret, LeakGroup.kind → secret, RedactedItem.what → secret secret type slug, see the table below
AdoptResponse.takes_effect_note → takes_effect immediately / on_restart

Removed because they restated a slug next to them: ProbeView.label / what, DriftView.label (use metric), ScanFinding.kind_label (use kind), DetectedClient.takes_effect_note / verified_note, SpeedEstimate.note and ReplayQuote.note (use billing, cost_micros and the token count). ScanResponse.rules_origin becomes rules_active / rules_custom / rules_disabled.

Structured instead of sentences

Field Before After
RuleView.to target name, or 拒绝 / (只改参数) to: Option<String> plus deny: bool
RuleView.conditions 模型 claude-* · 带缓存 [{ field: "model", values: ["claude-*"] }, { field: "cache", values: ["true"] }]
DryRunResult.set 换模型 → x(会作废整个 prompt cache) [{ field: "model", value: "x" }]
RuleTrace.why 要求 `true`,实际是 `false` mismatch: { field, want: [..], got } or error for a condition that cannot be evaluated
DryRunResult.reason also set for no_match and unavailable only the configured reason of a deny rule (unavailable is explained by skipped)
PlanView.fields env.X = …, 删掉 env.Y, (那把网关密钥) [{ op: "set" | "remove", path, value? }], no value for the gateway key
L1Segment.name DNS 解析 · 代理 stage: { step: "config" | "dns" | "tcp" | "tls" | "handshake", peer: "upstream" | "proxy" }
L1Result.notes socks5h 把域名原样交给代理解析… skipped: [{ stage, reason: "plain_http" | "ip_address" | "proxy_resolves" }]
L1Result.error TCP 握手 · 代理:… the message alone; new failed: Option<L1Stage> says where
L1Result.target for /proxies/test 代理 hk hk
Translated.dropped thinking(扩展思考):OpenAI chat 方言没有对应字段 thinking, top_k, messages.content.thinking …
SecretView.display 环境变量 ${KEY} ${KEY} (masked otherwise, as before)
ManualClient.how …填我们的地址 contains the gateway address

Secret types: anthropic-api-key, openai-api-key, openai-project-key, github-personal-token, github-oauth-token, github-server-token, github-user-token, github-fine-grained-token, slack-bot-token, slack-user-token, slack-app-token, aws-access-key-id, aws-temporary-key-id, google-api-key, google-oauth-token, gitlab-token, stripe-live-key, stripe-restricted-key, npm-token, digitalocean-token, sendgrid-key, private-key, jwt, conn-string-password, internal-ip, internal-domain.

Rows already stored keep the old text: routing JSON in request history has Chinese outcomes, and leaks.kind holds the old names. No migration; the app should show an unknown value as it is.

Follow-up in ThinkWatch Lite

After this is released as v0.4.0, bump the tw-api tag in src-tauri/Cargo.toml and the bundled binary, then:

  • Group strategy: delete the Chinese-to-config lookup in Config.tsx and use g.kind directly. Compare with "select" and "load-balance" in Config.tsx and in the tray group menu (src-tauri/src/lib.rs). Show labels from one table, also used for DryRunResult.strategy in DryRun.tsx.
  • Storage: Dashboard.tsx checks level !== "ok" and labels the three other values. The existing 转发不受影响 suffix stays.
  • Attempt chain: RequestDrawer.tsx colours by outcome === "served" and shows status or error.
  • Labels the app now owns: ConfigRejected.stage (App.tsx, where 错误 is appended today), ConfigVersion.origin (ConfigDialogs.tsx), QuotaWindow.window (UpstreamTable.tsx), probe names and descriptions by id (Config.tsx), LeakGroup.secret (Dashboard.tsx), RedactedItem.secret (App.tsx tooltip), DriftView.metric (Security.tsx), takes_effect / verified (Clients.tsx).
  • Sentences to compose: the scan rule counts (Security.tsx), the replay quote from billing / cost_micros / input_tokens (RequestDrawer.tsx), and the dry-run text for no_match and unavailable (DryRun.tsx).
  • Structured lists: rule targets and conditions (Routes.tsx), dry-run rewrites and mismatches (DryRun.tsx), plan fields (Clients.tsx), and link test segments, skipped steps and failed (upstreams/TestDialogs.tsx, ProxyDialog.tsx, ProxyTable.tsx).
  • Delete the how.replace("网关地址", …) in Clients.tsx.

types.ts mirrors all of the above. copy.test.ts does not see strings core sends at runtime; this PR adds the matching check on the core side (below).

How it was verified

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test --workspace: 1284 passed, 0 failed, 2 ignored (the real-network L1 tests, updated for the new stage fields).
  • scripts/smoke.sh: 48 passed, 0 failed. It warns that memory is 33 MB against the 30 MB target, which the script counts as within its no-regression limit of 40 MB.
  • New bin/twcore/tests/copy.rs reads every string literal in product code (comments and test modules excluded) and the rule reasons in crates/tw-scan/data/rules.yaml. It fails on the spoken forms Lite's copy.test.ts rejects, first and second person, and the forms removed here. Adding a scratch file with "连不上上游,你看看" made it fail on 连不上, 你 and 看看.
  • New tests pin GroupType::slug() to the word serde reads from the config, and assert that each ConditionView.field is a key of When.
  • Tests that asserted on old wording now assert on slugs or the new wording, for example the attempt chain (served / status 503 / 429), LocallyAnswered.probe == "health_check" and ConfigRejected.stage == "schema".

Nothing here touches forwarding, redaction, masking or credential handling beyond renaming what a redaction hit is called. Masking of keys in plan fields and diffs is unchanged: key fields carry no value.

Notes for review

  • Where the line is. A value from a fixed set becomes a slug; a sentence carrying runtime detail stays text. Errors could also become codes with parameters, but that is a much larger change and was not asked for.
  • Adoption file formats are unchanged. The === ThinkWatch 接管开始 === markers and the Chinese keys of *.thinkwatch.json (怎么手动还原, 文件是我们建的 …) are read back on restore. Changing them would strand clients adopted by an earlier version. Only the prose inside changed, and the copy test lists those two keys as format.
  • Internal identifiers are unchanged: the implicit route name 默认, built-in scan rule ids such as 你现在是 (users disable rules by id), and the history file tag ext.
  • Punctuation: errors have no trailing 。 so the app can place them in a sentence. Notes, findings and warnings are full sentences.
  • The Codex quota mapping (primary → weekly, secondary → 5h) keeps the existing labels as they were.
  • CONTROL_API_VERSION stays 1, as with earlier breaking changes: the app pins core by tag and bundles the binary from the same release.
  • Base is main, as with the recent PRs, although CONTRIBUTING and the base guard still point to dev.

🤖 Generated with Claude Code

fylorn and others added 2 commits September 17, 2026 19:43
The desktop app decided behaviour by comparing the Chinese text core sent:
`GroupView.kind == "手动选"` and `"轮流"` in four places plus the tray menu,
a table mapping 按顺序 back to `fallback`, `StorageStatus.level !== "正常"`
and `AttemptView.outcome === "成功"`. Rewording any of those in core broke
the app with no compile error, and the wording is exactly what the app is
now rewriting into a formal register.

A field whose value comes from a fixed set core defines now carries an
identifier, as `trust` and `billing` already did, and the app maps it to
its own label:

- `GroupView.kind`, `DryRunResult.strategy`: the config word
  (`fallback` / `select` / `load-balance` / `url-test` / `cheapest`)
- `StorageStatus.level`: `ok` / `metadata_only` / `stopped` / `unavailable`
- `ConfigReloaded.origin`, `ConfigVersion.origin`: `ui` / `cli` /
  `external` / `rollback` / `rotation`
- `ConfigRejected.stage`: `syntax` / `schema` / `semantics`
- `LocallyAnswered.probe`: the probe id
- `QuotaWindow.label` becomes `window`: `5h` / `7d` / `weekly`
- `AttemptView.outcome`: `served` / `status` / `error`, with `status` and
  `error` beside it
- `LeakSeen.secret`, `LeakGroup.secret` (was `kind`) and
  `RedactedItem.secret` (was `what`): the secret type, such as
  `anthropic-api-key`
- `L1Segment` carries a `stage` (`step` + `peer`); `L1Result.notes`
  becomes `skipped` with a reason, and `failed` names the stage an error
  happened at
- `AdoptResponse.takes_effect_note` becomes `takes_effect`

Labels that only restated a slug next to them are gone:
`ProbeView.label` / `what`, `DriftView.label`, `ScanFinding.kind_label`,
`DetectedClient.takes_effect_note` / `verified_note`,
`SpeedEstimate.note`, `ReplayQuote.note`. The scan rule summary
(`rules_origin`) becomes `rules_active` / `rules_custom` /
`rules_disabled`.

Lists that mixed fixed labels into data are structured:
`RuleView.to` is optional with a `deny` flag instead of 拒绝 or
(只改参数), and `RuleView.conditions`, `DryRunResult.set`,
`RuleTrace.mismatch` and `PlanView.fields` carry keys and values instead
of sentences such as 带缓存 or 删掉 env.X. `Translated.dropped` lists the
dropped fields by position. `SecretView.display` no longer prefixes
环境变量.

`ManualClient.how` now contains the gateway address. The app replaced a
网关地址 placeholder that core never sent, so the steps said 填我们的地址.

Sentences that carry runtime detail (errors, hints, diagnosis findings)
stay in core; the CLI and the diagnostics bundle keep their own labels.
The workspace goes to 0.4.0 for the app to pin.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The desktop app now follows a written register: statements rather than
asides or questions, no first or second person, 费用 for amounts, and no
explanations of internal mechanics. Much of what it displays is written
here, and read like someone talking: 连不上上游。检查 base_url…,
密钥要你自己在 Zed 的界面里填一次 —— 我们够不着, 补丁自检没过 … 这是个 bug,
请把配置文件贴到 issue 里. The same sentences reach AI clients as gateway
errors and people reading the CLI, the logs and the diagnostics bundle.

Rewritten: control-plane and gateway errors, configuration validation,
link test results, client adoption notes and diagnosis findings, scan
findings and the built-in rule reasons, the diagnostics bundle, the notes
written into adopted client configs, twcore's output and help text, and
logs. Terms follow the app: 上游, 接口地址, 网关密钥, 请求记录, 非官方端点,
按量计费. Names are quoted as 「name」 instead of in backticks, which the UI
shows literally. Errors carry no trailing 。, so the UI can place them in a
sentence.

The adoption file formats stay as they are: the comment block markers and
the Chinese keys of `*.thinkwatch.json` are read back on restore, so
changing them would strand clients adopted by an earlier version. Only the
prose inside them changed.

`bin/twcore/tests/copy.rs` reads the string literals in product code and
the rule reasons in `rules.yaml`, and fails on the spoken forms the app's
`copy.test.ts` rejects plus the ones removed here. The app's test only
sees its own `.tsx` files, so without this nothing checks what core sends.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit e975a0a into main Sep 17, 2026
2 checks passed
@fylorn
fylorn deleted the feat/slugs-and-written-copy branch September 17, 2026 13:52
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