@timo972/cc-router 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/Dockerfile +42 -0
  3. package/LICENSE +21 -0
  4. package/README.md +716 -0
  5. package/accounts.example.json +25 -0
  6. package/dist/cli/cmd-accounts.js +248 -0
  7. package/dist/cli/cmd-client.js +612 -0
  8. package/dist/cli/cmd-configure.js +145 -0
  9. package/dist/cli/cmd-docker.js +140 -0
  10. package/dist/cli/cmd-logs.js +85 -0
  11. package/dist/cli/cmd-models.js +125 -0
  12. package/dist/cli/cmd-service.js +193 -0
  13. package/dist/cli/cmd-setup.js +501 -0
  14. package/dist/cli/cmd-start.js +318 -0
  15. package/dist/cli/cmd-status.js +177 -0
  16. package/dist/cli/cmd-stop.js +100 -0
  17. package/dist/cli/cmd-telemetry.js +58 -0
  18. package/dist/cli/cmd-update.js +37 -0
  19. package/dist/cli/index.js +59 -0
  20. package/dist/config/manager.js +262 -0
  21. package/dist/config/paths.js +21 -0
  22. package/dist/config/telemetry.js +64 -0
  23. package/dist/daemon/launcher.js +163 -0
  24. package/dist/daemon/pid.js +98 -0
  25. package/dist/daemon/service.js +260 -0
  26. package/dist/interceptor/mitmproxy-manager.js +616 -0
  27. package/dist/protocol/anthropic-to-openai.js +51 -0
  28. package/dist/protocol/anthropic-types.js +1 -0
  29. package/dist/protocol/model-ref.js +36 -0
  30. package/dist/protocol/model-routing-config.js +30 -0
  31. package/dist/protocol/openai-response-to-anthropic.js +20 -0
  32. package/dist/protocol/openai-responses-types.js +1 -0
  33. package/dist/protocol/openai-stream-to-anthropic.js +75 -0
  34. package/dist/protocol/openai-to-anthropic.js +61 -0
  35. package/dist/protocol/sse.js +17 -0
  36. package/dist/providers/model-discovery.js +71 -0
  37. package/dist/providers/openai/account-pool.js +11 -0
  38. package/dist/providers/openai/account-record.js +33 -0
  39. package/dist/providers/openai/codex-transport.js +36 -0
  40. package/dist/providers/openai/device-oauth.js +116 -0
  41. package/dist/providers/openai/token-refresher.js +56 -0
  42. package/dist/providers/route-selector.js +8 -0
  43. package/dist/providers/types.js +1 -0
  44. package/dist/proxy/account-deletion.js +44 -0
  45. package/dist/proxy/anthropic-proxy.js +26 -0
  46. package/dist/proxy/anthropic-routing.js +90 -0
  47. package/dist/proxy/lease-lifecycle.js +68 -0
  48. package/dist/proxy/logger.js +39 -0
  49. package/dist/proxy/messages-cross-route.js +179 -0
  50. package/dist/proxy/models-server.js +150 -0
  51. package/dist/proxy/provider-routing.js +14 -0
  52. package/dist/proxy/responses-server.js +91 -0
  53. package/dist/proxy/server.js +875 -0
  54. package/dist/proxy/session-router.js +171 -0
  55. package/dist/proxy/stats.js +25 -0
  56. package/dist/proxy/stream-lifecycle.js +83 -0
  57. package/dist/proxy/token-pool.js +407 -0
  58. package/dist/proxy/token-refresher.js +209 -0
  59. package/dist/proxy/types.js +29 -0
  60. package/dist/ui/Dashboard.js +640 -0
  61. package/dist/ui/accountsApi.js +48 -0
  62. package/dist/ui/modelsApi.js +47 -0
  63. package/dist/utils/claude-config.js +185 -0
  64. package/dist/utils/codex-config.js +62 -0
  65. package/dist/utils/network.js +16 -0
  66. package/dist/utils/platform.js +13 -0
  67. package/dist/utils/self-update.js +239 -0
  68. package/dist/utils/telemetry.js +88 -0
  69. package/dist/utils/token-extractor.js +95 -0
  70. package/dist/utils/token-validator.js +26 -0
  71. package/docker-compose.yml +63 -0
  72. package/litellm-config.yaml +44 -0
  73. package/package.json +69 -0
  74. package/src/interceptor/addon.py +78 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,96 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+
5
+ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ---
8
+
9
+ ## [0.7.0] — 2026-07-26
10
+
11
+ First release of `@timo972/cc-router`, an independently maintained fork of
12
+ [VictorMinemu/CC-Router](https://github.com/VictorMinemu/CC-Router). Adds
13
+ cache-aware session routing and a round of security hardening.
14
+
15
+ ### ⚠️ Breaking
16
+
17
+ - **The package moved to `@timo972/cc-router`.** The old package name is no
18
+ longer used by this project. Reinstall rather than upgrade in place:
19
+
20
+ ```bash
21
+ npm uninstall -g ai-cc-router
22
+ npm install -g @timo972/cc-router
23
+ ```
24
+
25
+ Update checks and the CLI's install hints now resolve against the new name.
26
+ Existing `~/.cc-router` configuration and accounts are unaffected.
27
+
28
+ - **Auto-update is off by default.** New releases are announced but not
29
+ installed. Opt back in with `autoUpdate: true` in `~/.cc-router/config.json`
30
+ or `CC_ROUTER_AUTO_UPDATE=1`.
31
+
32
+ - **Server mode now requires a proxy secret.** The "skip — no password" option
33
+ is gone, and the router refuses to bind a non-loopback interface without a
34
+ secret. Loopback-only setups are unchanged.
35
+
36
+ - **Telemetry is opt-in.** Nothing is sent unless you run
37
+ `cc-router telemetry on`.
38
+
39
+ ### Added
40
+
41
+ - **Cache-aware session routing.** Requests from one Claude Code session stay on
42
+ one account, preserving prompt-cache locality instead of scattering a
43
+ conversation's shared prefix across per-account caches. New sessions are
44
+ placed by fewest in-flight requests, then fewest bound sessions, then most
45
+ rate-limit headroom, with a rotating round-robin tie-break.
46
+ - **Load-aware account leases** with ownership-checked acquisition and release,
47
+ so concurrent streams cannot corrupt each other's account state.
48
+ - **Passive stream lifecycle diagnostics** on `cc-router status --json` and
49
+ `/cc-router/health`, for diagnosing stalled streams without buffering or
50
+ altering response bytes.
51
+ - **[docs/session-routing.md](docs/session-routing.md)** — operational guide for
52
+ running the router across a team.
53
+
54
+ ### Changed
55
+
56
+ - Streaming stays byte-transparent: no synthetic `message_stop`, and no retry
57
+ once response bytes have started. `proxyRequestTimeoutMs` now covers only the
58
+ pre-header phase and is disarmed once a response begins, so long thinking
59
+ pauses are no longer cut off.
60
+ - `cc-router configure` manages Claude Code's event- and byte-level stream idle
61
+ watchdogs at 30 minutes. Restart running Claude Code processes to pick them up.
62
+ - Unauthenticated `/cc-router/health` returns only `{status}`; the account
63
+ inventory and recent logs require the proxy secret.
64
+ - `~/.cc-router` is created `0700`; `accounts.json` and `config.json` are written
65
+ `0600`, so other local users can no longer read OAuth tokens or the secret.
66
+
67
+ ### Fixed
68
+
69
+ - Concurrent SSE streams are routed per Claude session rather than sharing state.
70
+ - Token refresh serializes account ownership and joins an in-flight refresh
71
+ during request preparation, instead of racing a second refresh.
72
+ - Refresh ownership is reserved across account deletion.
73
+ - Claude config mutations are guarded and schema-validated, and watchdog backups
74
+ survive the config lifecycle.
75
+ - Idle session counts expire on read rather than accumulating.
76
+ - SSE lifecycle line retention is bounded.
77
+ - Deflaked the started-stream timeout assertion, which allowed only 50 ms for the
78
+ upstream response and failed under parallel CI load.
79
+
80
+ ### Security
81
+
82
+ - Strict semver validation on registry responses before the version reaches a
83
+ child process, and `shell:true` dropped from the update spawn — closes a
84
+ Windows command-injection path.
85
+ - Release pipeline publishes with `--provenance` under least-privilege
86
+ permissions, with actions pinned by commit SHA.
87
+ - mitmproxy root CA can now be removed at teardown (`cc-router client disconnect`)
88
+ instead of leaving a trusted root installed permanently.
89
+ - Docker runs as non-root with digest-pinned images, `cap_drop: ALL`,
90
+ `no-new-privileges`, loopback-bound ports, and a required `LITELLM_MASTER_KEY`.
91
+ `--detailed_debug` was dropped — it logged the injected OAuth bearer.
92
+ - `docs/security.md` corrected on telemetry, file permissions, and TLS.
93
+ - `http-proxy-middleware` 3.0.5 → 3.0.7 for GHSA-gcq2-9pq2-cxqm (high). The
94
+ affected APIs are not used here.
95
+
96
+ [0.7.0]: https://github.com/Timo972/cc-router/releases/tag/v0.7.0
package/Dockerfile ADDED
@@ -0,0 +1,42 @@
1
+ # ── Build stage ───────────────────────────────────────────────────────────────
2
+ # Pinned by digest (immutable) — a moving tag could ship unexpected/compromised
3
+ # content. Update deliberately: `crane digest node:22-alpine`.
4
+ FROM node:22-alpine@sha256:16e22a550f3863206a3f701448c45f7912c6896a62de43add43bb9c86130c3e2 AS builder
5
+ WORKDIR /app
6
+
7
+ COPY package*.json ./
8
+ RUN npm ci
9
+
10
+ COPY tsconfig.json ./
11
+ COPY src/ ./src/
12
+ RUN npm run build
13
+
14
+ # ── Runtime stage ─────────────────────────────────────────────────────────────
15
+ FROM node:22-alpine@sha256:16e22a550f3863206a3f701448c45f7912c6896a62de43add43bb9c86130c3e2 AS runtime
16
+ WORKDIR /app
17
+
18
+ ENV NODE_ENV=production
19
+ # Port defaults — overridden by docker-compose environment section
20
+ ENV PORT=3456
21
+ ENV ACCOUNTS_PATH=/app/accounts.json
22
+
23
+ # Install only production deps
24
+ COPY package*.json ./
25
+ RUN npm ci --omit=dev && npm cache clean --force
26
+
27
+ COPY --from=builder /app/dist ./dist
28
+
29
+ # Drop root: the node:alpine base already ships an unprivileged `node` user (uid
30
+ # 1000). Any RCE in the process is then non-root with no write access outside
31
+ # the app dir. NOTE (Linux hosts): the mounted accounts.json must be
32
+ # readable/writable by uid 1000, or set `user:` in docker-compose to match the
33
+ # host owner — otherwise token-refresh writes will fail.
34
+ RUN chown -R node:node /app
35
+ USER node
36
+
37
+ EXPOSE 3456
38
+
39
+ # accounts.json is expected to be mounted at runtime via docker-compose volume
40
+ # The container will exit with a clear error if it's not present
41
+ ENTRYPOINT ["node", "dist/cli/index.js"]
42
+ CMD ["start"]
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CC-Router Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.