Skip to content

refactor!: keep only what both gateways use in the shared layer - #164

Merged
fylorn merged 1 commit into
mainfrom
refactor/shared-layer-one-side
Sep 24, 2026
Merged

fylorn merged 1 commit into
mainfrom
refactor/shared-layer-one-side

Conversation

@fylorn

@fylorn fylorn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

A shared component used by only one side moves back to that side. After this, the server edition (ThinkWatch) depends on tw-dialect, tw-guard and tw-breaker and nothing else.

What moved where

Before After
tw-wire (usage sniffing) tw_dialect::usage. One Usage (the IR one, now with cache_1h). The sniffer hands each usage object to the dialect's own usage() parser, so every formula (Gemini's, OpenAI's cache subtraction, …) exists once. The Anthropic parser now reads the 1h cache-write breakdown, which only the sniffer understood before.
tw_upstream::upstream_url + key= stripping tw_dialect::url (without_gateway_key is public, for the WS path)
tw_upstream header helpers (STRIP, forward_headers*, apply_headers, overridden, response_headers, gemini_path_with_model) tw-gateway forward (desktop only)
tw_upstream::{sigv4, eventstream} + the bedrock_stream test + the bedrock-feature CI step server edition
tw-crypto server edition
tw-types: chat DTOs deleted (unused in both repos)
tw-types: GatewayError, CallCtx, substitute_template, parse_retry_after_seconds server edition
tw-types: Retention, PRIVATE_RANGES tw-config
tw-guard → tw-secret (one mask_secret) inlined; tw-guard no longer pulls tw-secret into the server edition

tw-types now holds only Msg/msg! and is desktop-only, as is tw-secret.

Guards

  • crates/tw-dialect/tests/layer_one.rs runs cargo metadata and fails if a layer-one crate depends on a layer-two one (checked by adding tw-secret back to tw-guard: it fails with tw-guard → tw-secret).
  • New CI job enterprise: when a layer-one path changes, it checks out ThinkWatch at the branch with this PR's head name if it exists (else dev), patches the three layer-one crates to this checkout, and runs cargo check --workspace --all-targets. ThinkWatch has no sqlx::query! macros, so no database is needed. This PR's counterpart is the same-named ThinkWatch branch refactor/shared-layer-one-side.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (proxy unset) — all green.
  • ThinkWatch branch against this checkout: fmt, clippy (--all-targets and --lib), and unit tests are all green.

Cargo Cargo.toml member comments and both READMEs' "Crate layers" sections describe the new split.

🤖 Generated with Claude Code

A shared component used by only one side moves back to that side. After
this, the server edition depends on tw-dialect, tw-guard and tw-breaker
and nothing else.

- tw-wire is merged into tw-dialect as `tw_dialect::usage`. There is one
  `Usage` (the IR one, now with `cache_1h`), and the sniffer hands each
  usage object to the dialect's own `usage()` parser instead of carrying
  a second copy of every formula. The Anthropic parser now reads the 1h
  cache-write breakdown, which only the sniffer understood before.
- tw-upstream is split: `upstream_url` and the gateway-key stripping move
  to `tw_dialect::url` (`without_gateway_key` is public for the WS path);
  the header helpers move into tw-gateway's `forward`; SigV4 and
  eventstream unframing move to the server edition, along with the
  bedrock-feature CI step.
- tw-crypto moves to the server edition (the desktop never used it).
- tw-types keeps only `Msg`/`msg!`. The unused chat DTOs are deleted;
  `GatewayError`, `CallCtx` and friends move to the server edition;
  `Retention` and `PRIVATE_RANGES` move into tw-config.
- tw-guard inlines its one masking helper and no longer pulls tw-secret
  into the server edition.
- A test (`tw-dialect/tests/layer_one.rs`) fails if a layer-one crate
  depends on a layer-two one, and a new CI job builds the server edition
  against every change to layer one, using a same-named ThinkWatch branch
  when one exists and `dev` otherwise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fylorn
fylorn merged commit 7d0f00b into main Sep 24, 2026
3 checks passed
@fylorn
fylorn deleted the refactor/shared-layer-one-side branch September 24, 2026 06:33
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