@peterwangze/claude-trigger-router 1.12.0 → 1.14.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.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Claude Trigger Router 是给 Claude Code 用的本地模型路由代理。Claude
7
7
  ## 你会得到什么
8
8
 
9
9
  - 一个本地 Claude Code 代理:默认监听 `127.0.0.1:5678`。
10
- - 一份统一模型配置:用 `Models[]` 管供应商、接口、API key 和模型名。
10
+ - 一份统一模型配置:用 `Models[].id/api/key/interface/model` 管模型接入。
11
11
  - 基础路由:用 `Router.default`、`think`、`longContext`、`background`、`webSearch` 覆盖高频场景。
12
12
  - SmartRouter:用规则、语义匹配、候选模型画像和 LLM 路由选择更合适的模型。
13
13
  - 治理与 UI:通过 `ctr doctor` 和 `ctr ui` 看配置、健康状态、路由原因、trace 和协作证据。
@@ -76,6 +76,8 @@ Router:
76
76
 
77
77
  `interface` 表示上游接口协议,不是厂商名。OpenRouter、DeepSeek 和大多数 OpenAI-compatible 服务通常用 `openai`;Anthropic 官方接口用 `anthropic`。
78
78
 
79
+ 新配置只推荐写 `id/api/key/interface/model/thinking/metadata`。旧字段 `api_base_url/api_key/protocol` 只作为历史配置兼容读取,不作为新配置入口。
80
+
79
81
  ## 配多个模型
80
82
 
81
83
  每个 `Models[]` 项都是一个可被路由引用的模型接入项。路由字段建议引用 `Models[].id`,不要把供应商和模型名散落在各处。
@@ -110,11 +112,14 @@ Router:
110
112
  | `background` | Claude Code 轻量后台请求 |
111
113
  | `webSearch` | 带 web search 工具的请求 |
112
114
 
115
+ 基础路由的实际判断顺序是:显式上游模型 -> `longContext` 阈值 -> `background` -> `think` -> `webSearch` -> `default`。因此超长输入会先进入长上下文槽位;`background` 当前只识别 Claude Code 发出的 `claude-3-5-haiku*` 后台模型请求;如果请求模型已经是 `provider,model` 这类上游引用,基础槽位不会再覆盖。最终定模后还会执行 context window guard,如果已选模型放不下,会优先 fallback 到 `Router.longContext`。
116
+
113
117
  可复制模板:
114
118
 
115
119
  - [config/trigger.example.yaml](config/trigger.example.yaml):最小配置
116
120
  - [config/trigger.routing.yaml](config/trigger.routing.yaml):基础路由五槽位
117
- - [config/trigger.smart-router.yaml](config/trigger.smart-router.yaml):SmartRouter 常用规则
121
+ - [config/trigger.smart-router.yaml](config/trigger.smart-router.yaml):SmartRouter 两模型起步模板
122
+ - [config/trigger.smart-router.advanced.yaml](config/trigger.smart-router.advanced.yaml):SmartRouter 多候选高级模板
118
123
  - [config/trigger.advanced.yaml](config/trigger.advanced.yaml):高级治理示例
119
124
 
120
125
  ## SmartRouter
@@ -138,7 +143,7 @@ SmartRouter:
138
143
  - `SmartRouter.rules` 负责能被关键词稳定识别的任务。
139
144
  - `SmartRouter.candidates` 负责规则未命中时的智能兜底。
140
145
  - `SmartRouter.routing_budget.latency_budget_ms` 和 `confidence_threshold` 用来控制速度/质量取舍。
141
- - `SmartRouter.collaboration.mode` 可表达 `route_only`、`verify_only`、`compare_then_arbiter`、`cascade_on_evidence` 这类协作路径。
146
+ - `SmartRouter.collaboration.mode` 可表达 `route_only`、`verify_only`、`compare_then_arbiter`、`cascade_on_evidence` 这类策略 contract;当前默认仍是单模型 `route_only`,不会默认并发调用多个模型。
142
147
 
143
148
  从 `v1.10.0` 开始,SmartRouter 会把真实 trace 中的质量、失败、延迟、cascade、shadow 和人工校准证据纳入候选模型画像,并在 route decision 中展示 `routingMode`、`collaborationMode` 和 `routingEvidence`。
144
149
 
@@ -146,10 +151,11 @@ SmartRouter:
146
151
 
147
152
  ```bash
148
153
  ctr doctor
154
+ ctr doctor --route-preview --route-text "请做架构设计"
149
155
  ctr ui
150
156
  ```
151
157
 
152
- `ctr doctor` 用来检查配置、服务启动、模型引用、上下文窗口、鉴权状态和可选模型探测。模型探测会消耗少量额度,所以会先征求确认。
158
+ `ctr doctor` 用来检查配置、服务启动、模型引用、上下文窗口、鉴权状态和可选模型探测。`--route-preview` 可以在不调用上游模型、不消耗额度的情况下预演当前请求会命中哪个槽位或 SmartRouter 路径;模型探测会消耗少量额度,所以会先征求确认。
153
159
 
154
160
  `ctr ui` 默认打开:
155
161
 
@@ -218,14 +224,14 @@ ANTHROPIC_AUTH_TOKEN=<managed-key>
218
224
  - 配置指南:[docs/configuration-guide.md](docs/configuration-guide.md)
219
225
  - Models 迁移:[docs/models-migration-guide.md](docs/models-migration-guide.md)
220
226
  - CLI 测试矩阵:[docs/cli-test-matrix.md](docs/cli-test-matrix.md)
221
- - 发布说明:[docs/release-notes-v1.12.0.md](docs/release-notes-v1.12.0.md)
227
+ - 发布说明:[docs/release-notes-v1.14.0.md](docs/release-notes-v1.14.0.md)
222
228
  - 发布验证:[docs/releasing.md](docs/releasing.md)
223
229
 
224
- ## v1.12.0 发布定位
230
+ ## v1.14.0 发布定位
225
231
 
226
- `v1.12.0` 是流式传输韧性与远程中转稳定性修复版。它在 `v1.11.0` 首轮止血基础上继续修复用户复现的 socket 断连和中转卡顿:上游流式中途断开时返回可读 SSE error event,远程中转会在客户端断开时主动取消上游请求,并修复 SSE parser 在多字节字符跨 chunk 时的解析风险。
232
+ `v1.14.0` 是配置产品化最终收口版。它把重点放在用户每天会接触的配置入口:README、配置指南、setup、doctor、`/ui`、保存 API compiled preview 都统一到 `Models[].id/api/key/interface/model/thinking/metadata` 字段心智。
227
233
 
228
- 这个版本不新增 SmartRouter 协作模式、不改变远程客户端配置心智;`v1.10.0` routing advisor、confidence threshold、latency budgetcollaboration contract 继续保留。完整发布边界见 [docs/release-notes-v1.12.0.md](docs/release-notes-v1.12.0.md)。
234
+ 旧字段 `api_base_url/api_key/protocol` 继续兼容读取,但 doctor 修复、UI 保存和配置写回会回到推荐字段。这个版本还让路由槽位、capability warning、保存/预览 warning contract 在 CLI UI 中保持一致。完整发布边界见 [docs/release-notes-v1.14.0.md](docs/release-notes-v1.14.0.md)。
229
235
 
230
236
  ## License
231
237
 
@@ -0,0 +1,214 @@
1
+ # Claude Trigger Router SmartRouter advanced template
2
+ # 复制到 ~/.claude-trigger-router/config.yaml 后,先替换 API Key、模型名和本地模型地址。
3
+ # 这个模板面向已经跑通最小 SmartRouter 的用户,覆盖更多高频智能路由场景:
4
+ # coding / review / architecture / long context / fast reply。
5
+ # 如果你第一次启用 SmartRouter,请优先使用 config/trigger.smart-router.yaml。
6
+
7
+ HOST: "127.0.0.1"
8
+ PORT: 5678
9
+
10
+ LOG: true
11
+ LOG_LEVEL: "debug"
12
+
13
+ Models:
14
+ - id: sonnet
15
+ api: "https://openrouter.ai/api/v1/chat/completions"
16
+ key: "sk-xxx"
17
+ interface: "openai"
18
+ model: "anthropic/claude-sonnet-4"
19
+ thinking: "auto"
20
+ metadata:
21
+ context_window_tokens: 200000
22
+ safe_input_tokens: 180000
23
+
24
+ - id: reviewer
25
+ api: "https://openrouter.ai/api/v1/chat/completions"
26
+ key: "sk-xxx"
27
+ interface: "openai"
28
+ model: "anthropic/claude-sonnet-4"
29
+ thinking: "auto"
30
+ metadata:
31
+ context_window_tokens: 200000
32
+ safe_input_tokens: 180000
33
+
34
+ - id: architect
35
+ api: "https://openrouter.ai/api/v1/chat/completions"
36
+ key: "sk-xxx"
37
+ interface: "openai"
38
+ model: "anthropic/claude-opus-4"
39
+ thinking: "high"
40
+ metadata:
41
+ context_window_tokens: 200000
42
+ safe_input_tokens: 180000
43
+
44
+ - id: long_context
45
+ api: "https://openrouter.ai/api/v1/chat/completions"
46
+ key: "sk-xxx"
47
+ interface: "openai"
48
+ model: "google/gemini-2.5-pro"
49
+ thinking: "auto"
50
+ metadata:
51
+ context_window_tokens: 1000000
52
+ safe_input_tokens: 900000
53
+
54
+ - id: fast_background
55
+ api: "http://localhost:11434/v1/chat/completions"
56
+ key: "ollama"
57
+ interface: "openai"
58
+ model: "qwen2.5-coder:latest"
59
+ thinking: "off"
60
+ metadata:
61
+ context_window_tokens: 32000
62
+ safe_input_tokens: 24000
63
+
64
+ Router:
65
+ default: "sonnet"
66
+ think: "architect"
67
+ longContext: "long_context"
68
+ longContextThreshold: 60000
69
+ background: "fast_background"
70
+ webSearch: "sonnet"
71
+
72
+ SmartRouter:
73
+ enabled: true
74
+ analysis_scope: "last_message"
75
+ rules:
76
+ - name: "long_context"
77
+ priority: 95
78
+ enabled: true
79
+ description: "长文档、长上下文、全文总结或需要大窗口承载的请求"
80
+ patterns:
81
+ - type: exact
82
+ keywords:
83
+ - "长上下文"
84
+ - "长文档"
85
+ - "全文总结"
86
+ - "large context"
87
+ - "long context"
88
+ - type: regex
89
+ pattern: "(长上下文|长文档|全文总结|long context|large context)"
90
+ model: "long_context"
91
+ semantic_profile:
92
+ prototype: "长文档 长上下文 全文 总结 大窗口 large context long document"
93
+
94
+ - name: "architecture"
95
+ priority: 90
96
+ enabled: true
97
+ description: "架构设计、系统设计、技术方案和模块拆分"
98
+ patterns:
99
+ - type: exact
100
+ keywords:
101
+ - "架构设计"
102
+ - "系统设计"
103
+ - "技术方案"
104
+ - "模块拆分"
105
+ - "architecture"
106
+ - "system design"
107
+ - type: regex
108
+ pattern: "(架构|系统设计|技术方案|模块拆分|architecture|system design)"
109
+ model: "architect"
110
+ semantic_profile:
111
+ prototype: "架构 系统设计 技术方案 模块边界 演进路线 architecture system design"
112
+
113
+ - name: "review"
114
+ priority: 80
115
+ enabled: true
116
+ description: "代码审查、风险检查、安全检查和回归风险评估"
117
+ patterns:
118
+ - type: exact
119
+ keywords:
120
+ - "代码审查"
121
+ - "code review"
122
+ - "review code"
123
+ - "检查代码"
124
+ - "安全风险"
125
+ - "回归风险"
126
+ - type: regex
127
+ pattern: "(代码|code).{0,8}(审查|review|检查|审核)"
128
+ model: "reviewer"
129
+ semantic_profile:
130
+ prototype: "代码审查 风险 安全 回归 regression review bug finding"
131
+
132
+ - name: "coding"
133
+ priority: 70
134
+ enabled: true
135
+ description: "实现功能、修复 bug、重构代码和补测试"
136
+ patterns:
137
+ - type: exact
138
+ keywords:
139
+ - "实现"
140
+ - "写代码"
141
+ - "修复 bug"
142
+ - "补测试"
143
+ - "implement"
144
+ - "refactor"
145
+ - "feature"
146
+ - type: regex
147
+ pattern: "(实现|编写|修复|重构|补测试|implement|refactor|feature|bug)"
148
+ model: "sonnet"
149
+ semantic_profile:
150
+ prototype: "实现 功能 修复 bug 重构 单元测试 编程 coding implementation"
151
+
152
+ - name: "fast_reply"
153
+ priority: 10
154
+ enabled: true
155
+ description: "简单问题、快速答复、短答案和低成本后台任务"
156
+ patterns:
157
+ - type: exact
158
+ keywords:
159
+ - "快速回答"
160
+ - "简单回答"
161
+ - "不用详细"
162
+ - "quick"
163
+ - "short answer"
164
+ - "simple"
165
+ - type: regex
166
+ pattern: "(快速回答|简单回答|不用详细|quick|short answer|simple)"
167
+ model: "fast_background"
168
+ semantic_profile:
169
+ prototype: "快速 简单 短答案 低成本 fast quick short answer simple"
170
+
171
+ router_model: "sonnet"
172
+ candidates:
173
+ - model: "sonnet"
174
+ description: "通用 coding、日常调试、多轮任务和默认 Claude Code 体验"
175
+ - model: "reviewer"
176
+ description: "代码审查、风险识别、安全检查和回归影响判断"
177
+ - model: "architect"
178
+ description: "架构设计、系统方案、复杂权衡和高质量长推理"
179
+ - model: "long_context"
180
+ description: "长文档、超长上下文、全文总结和大规格输入"
181
+ - model: "fast_background"
182
+ description: "快速短答、低成本后台任务和简单重复问题"
183
+ cache_ttl: 600000
184
+ max_tokens: 256
185
+ fallback: "default"
186
+ router_hint:
187
+ include_task_summary: true
188
+ include_top_route_candidates: true
189
+
190
+ sticky:
191
+ enabled: true
192
+ session_ttl_ms: 3600000
193
+ fingerprint_similarity_threshold: 0.82
194
+ break_on_explicit_route: true
195
+ # Claude Code 的请求本身会携带会话上下文。
196
+ # 只有明确需要跨模型交接摘要,并接受额外 summarizer 调用时,再开启 alignment。
197
+ alignment:
198
+ enabled: false
199
+ summarizer_model: "sonnet"
200
+ max_summary_tokens: 256
201
+
202
+ semantic:
203
+ enabled: true
204
+ mode: "embedding"
205
+ threshold: 0.2
206
+ prototypes:
207
+ coding: "实现 功能 修复 bug 重构 单元测试 编程 coding implementation"
208
+ review: "代码审查 风险 安全 回归 regression review bug finding"
209
+ architecture: "架构 系统设计 技术方案 模块边界 演进路线 architecture system design"
210
+ long_context: "长文档 长上下文 全文 总结 大窗口 large context long document"
211
+ fast_reply: "快速 简单 短答案 低成本 fast quick short answer simple"
212
+
213
+ Governance:
214
+ enabled: true
@@ -1,7 +1,7 @@
1
- # Claude Trigger Router SmartRouter rule template
2
- # 复制到 ~/.claude-trigger-router/config.yaml 后,先替换 API Key、模型名和本地模型地址。
3
- # 这个模板面向 v1.4.0 的高频智能路由场景:
4
- # coding / review / architecture / long context / fast reply
1
+ # Claude Trigger Router SmartRouter starter template
2
+ # 复制到 ~/.claude-trigger-router/config.yaml 后,先替换 API Key 和上游模型名。
3
+ # 这个模板只需要两个模型:默认模型 + 复杂任务模型。
4
+ # 更多候选、semantic/sticky/governance 和本地 fast model config/trigger.smart-router.advanced.yaml
5
5
 
6
6
  HOST: "127.0.0.1"
7
7
  PORT: 5678
@@ -20,76 +20,26 @@ Models:
20
20
  context_window_tokens: 200000
21
21
  safe_input_tokens: 180000
22
22
 
23
- - id: reviewer
24
- api: "https://openrouter.ai/api/v1/chat/completions"
25
- key: "sk-xxx"
26
- interface: "openai"
27
- model: "anthropic/claude-sonnet-4"
28
- thinking: "auto"
29
- metadata:
30
- context_window_tokens: 200000
31
- safe_input_tokens: 180000
32
-
33
- - id: architect
34
- api: "https://openrouter.ai/api/v1/chat/completions"
23
+ - id: reasoner
24
+ api: "https://api.deepseek.com/chat/completions"
35
25
  key: "sk-xxx"
36
26
  interface: "openai"
37
- model: "anthropic/claude-opus-4"
27
+ model: "deepseek-reasoner"
38
28
  thinking: "high"
39
29
  metadata:
40
- context_window_tokens: 200000
41
- safe_input_tokens: 180000
42
-
43
- - id: long_context
44
- api: "https://openrouter.ai/api/v1/chat/completions"
45
- key: "sk-xxx"
46
- interface: "openai"
47
- model: "google/gemini-2.5-pro"
48
- thinking: "auto"
49
- metadata:
50
- context_window_tokens: 1000000
51
- safe_input_tokens: 900000
52
-
53
- - id: fast_background
54
- api: "http://localhost:11434/v1/chat/completions"
55
- key: "ollama"
56
- interface: "openai"
57
- model: "qwen2.5-coder:latest"
58
- thinking: "off"
59
- metadata:
60
- context_window_tokens: 32000
61
- safe_input_tokens: 24000
30
+ context_window_tokens: 64000
31
+ safe_input_tokens: 56000
62
32
 
63
33
  Router:
64
34
  default: "sonnet"
65
- think: "architect"
66
- longContext: "long_context"
35
+ think: "reasoner"
36
+ longContext: "sonnet"
67
37
  longContextThreshold: 60000
68
- background: "fast_background"
69
- webSearch: "sonnet"
70
38
 
71
39
  SmartRouter:
72
40
  enabled: true
73
41
  analysis_scope: "last_message"
74
42
  rules:
75
- - name: "long_context"
76
- priority: 95
77
- enabled: true
78
- description: "长文档、长上下文、全文总结或需要大窗口承载的请求"
79
- patterns:
80
- - type: exact
81
- keywords:
82
- - "长上下文"
83
- - "长文档"
84
- - "全文总结"
85
- - "large context"
86
- - "long context"
87
- - type: regex
88
- pattern: "(长上下文|长文档|全文总结|long context|large context)"
89
- model: "long_context"
90
- semantic_profile:
91
- prototype: "长文档 长上下文 全文 总结 大窗口 large context long document"
92
-
93
43
  - name: "architecture"
94
44
  priority: 90
95
45
  enabled: true
@@ -100,12 +50,11 @@ SmartRouter:
100
50
  - "架构设计"
101
51
  - "系统设计"
102
52
  - "技术方案"
103
- - "模块拆分"
104
53
  - "architecture"
105
54
  - "system design"
106
55
  - type: regex
107
- pattern: "(架构|系统设计|技术方案|模块拆分|architecture|system design)"
108
- model: "architect"
56
+ pattern: "(架构|系统设计|技术方案|architecture|system design)"
57
+ model: "reasoner"
109
58
  semantic_profile:
110
59
  prototype: "架构 系统设计 技术方案 模块边界 演进路线 architecture system design"
111
60
 
@@ -119,95 +68,29 @@ SmartRouter:
119
68
  - "代码审查"
120
69
  - "code review"
121
70
  - "review code"
122
- - "检查代码"
123
- - "安全风险"
124
- - "回归风险"
71
+ - "风险评估"
125
72
  - type: regex
126
73
  pattern: "(代码|code).{0,8}(审查|review|检查|审核)"
127
- model: "reviewer"
74
+ model: "reasoner"
128
75
  semantic_profile:
129
76
  prototype: "代码审查 风险 安全 回归 regression review bug finding"
130
77
 
131
- - name: "coding"
132
- priority: 70
133
- enabled: true
134
- description: "实现功能、修复 bug、重构代码和补测试"
135
- patterns:
136
- - type: exact
137
- keywords:
138
- - "实现"
139
- - "写代码"
140
- - "修复 bug"
141
- - "补测试"
142
- - "implement"
143
- - "refactor"
144
- - "feature"
145
- - type: regex
146
- pattern: "(实现|编写|修复|重构|补测试|implement|refactor|feature|bug)"
147
- model: "sonnet"
148
- semantic_profile:
149
- prototype: "实现 功能 修复 bug 重构 单元测试 编程 coding implementation"
150
-
151
- - name: "fast_reply"
152
- priority: 10
153
- enabled: true
154
- description: "简单问题、快速答复、短答案和低成本后台任务"
155
- patterns:
156
- - type: exact
157
- keywords:
158
- - "快速回答"
159
- - "简单回答"
160
- - "不用详细"
161
- - "quick"
162
- - "short answer"
163
- - "simple"
164
- - type: regex
165
- pattern: "(快速回答|简单回答|不用详细|quick|short answer|simple)"
166
- model: "fast_background"
167
- semantic_profile:
168
- prototype: "快速 简单 短答案 低成本 fast quick short answer simple"
169
-
78
+ # 规则未命中时,真实请求会先调用 router_model 选择候选模型。
79
+ # 如果你希望首包更快,可以先删除 router_model/candidates,只保留上面的 rules。
170
80
  router_model: "sonnet"
171
81
  candidates:
172
82
  - model: "sonnet"
173
83
  description: "通用 coding、日常调试、多轮任务和默认 Claude Code 体验"
174
- - model: "reviewer"
175
- description: "代码审查、风险识别、安全检查和回归影响判断"
176
- - model: "architect"
177
- description: "架构设计、系统方案、复杂权衡和高质量长推理"
178
- - model: "long_context"
179
- description: "长文档、超长上下文、全文总结和大规格输入"
180
- - model: "fast_background"
181
- description: "快速短答、低成本后台任务和简单重复问题"
84
+ - model: "reasoner"
85
+ description: "架构设计、代码审查、复杂推理和严谨分析"
182
86
  cache_ttl: 600000
183
- max_tokens: 256
87
+ max_tokens: 192
184
88
  fallback: "default"
185
89
  router_hint:
186
90
  include_task_summary: true
187
91
  include_top_route_candidates: true
188
92
 
189
- sticky:
190
- enabled: true
191
- session_ttl_ms: 3600000
192
- fingerprint_similarity_threshold: 0.82
193
- break_on_explicit_route: true
194
- # Claude Code 的请求本身会携带会话上下文。
195
- # 只有明确需要跨模型交接摘要,并接受额外 summarizer 调用时,再开启 alignment。
196
- alignment:
197
- enabled: false
198
- summarizer_model: "sonnet"
199
- max_summary_tokens: 256
200
-
201
93
  semantic:
202
94
  enabled: true
203
95
  mode: "embedding"
204
- threshold: 0.2
205
- prototypes:
206
- coding: "实现 功能 修复 bug 重构 单元测试 编程 coding implementation"
207
- review: "代码审查 风险 安全 回归 regression review bug finding"
208
- architecture: "架构 系统设计 技术方案 模块边界 演进路线 architecture system design"
209
- long_context: "长文档 长上下文 全文 总结 大窗口 large context long document"
210
- fast_reply: "快速 简单 短答案 低成本 fast quick short answer simple"
211
-
212
- Governance:
213
- enabled: true
96
+ threshold: 0.25