omnicell-router 0.7.0 → 0.8.2

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 (246) hide show
  1. package/backend/dist/cli/clients/activity.d.ts +35 -0
  2. package/backend/dist/cli/clients/activity.js +67 -0
  3. package/backend/dist/cli/clients/base.d.ts +13 -2
  4. package/backend/dist/cli/clients/claude.d.ts +2 -2
  5. package/backend/dist/cli/clients/codex.d.ts +2 -2
  6. package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
  7. package/backend/dist/cli/clients/core-adapters.js +3 -4
  8. package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
  9. package/backend/dist/cli/clients/cursor-proxy.js +421 -0
  10. package/backend/dist/cli/clients/dsh.d.ts +2 -2
  11. package/backend/dist/cli/clients/grok.d.ts +2 -2
  12. package/backend/dist/cli/clients/index.d.ts +8 -1
  13. package/backend/dist/cli/clients/index.js +55 -21
  14. package/backend/dist/cli/clients/kimi.d.ts +2 -2
  15. package/backend/dist/cli/clients/launcher.d.ts +8 -0
  16. package/backend/dist/cli/clients/model-meta.js +1 -1
  17. package/backend/dist/cli/clients/omp.d.ts +2 -2
  18. package/backend/dist/cli/clients/openclaw.d.ts +2 -2
  19. package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
  20. package/backend/dist/cli/clients/opencode-proxy.js +351 -0
  21. package/backend/dist/cli/clients/opencode.d.ts +2 -2
  22. package/backend/dist/cli/clients/pi.d.ts +2 -2
  23. package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
  24. package/backend/dist/cli/clients/plugin-adapters.js +6 -29
  25. package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
  26. package/backend/dist/cli/clients/qoder-proxy.js +497 -0
  27. package/backend/dist/cli/clients/reserved.d.ts +2 -6
  28. package/backend/dist/cli/clients/reserved.js +2 -0
  29. package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
  30. package/backend/dist/cli/index.js +60 -9
  31. package/backend/dist/cli/types.d.ts +29 -8
  32. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  33. package/backend/dist/config/comments-en.js +6 -12
  34. package/backend/dist/config/comments-zh.js +6 -12
  35. package/backend/dist/config/defaults.d.ts +56 -1
  36. package/backend/dist/config/defaults.js +68 -0
  37. package/backend/dist/config/index.d.ts +9 -2
  38. package/backend/dist/config/index.js +26 -3
  39. package/backend/dist/config/types.d.ts +55 -43
  40. package/backend/dist/forward-proxy/egress.d.ts +10 -2
  41. package/backend/dist/forward-proxy/egress.js +42 -4
  42. package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
  43. package/backend/dist/forward-proxy/ordered-relay.js +46 -0
  44. package/backend/dist/forward-proxy/rules.d.ts +66 -19
  45. package/backend/dist/forward-proxy/rules.js +61 -14
  46. package/backend/dist/forward-proxy/server.js +226 -77
  47. package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
  48. package/backend/dist/forward-proxy/system-proxy.js +199 -22
  49. package/backend/dist/harness/common/market.d.ts +3 -3
  50. package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
  51. package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
  52. package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
  53. package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
  54. package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
  55. package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
  56. package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
  57. package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
  58. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
  59. package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
  60. package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
  61. package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
  62. package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
  63. package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
  64. package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
  65. package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
  66. package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
  67. package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
  68. package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
  69. package/backend/dist/harness/translation.js +64 -21
  70. package/backend/dist/harness/types.d.ts +1 -1
  71. package/backend/dist/harness/types.js +1 -1
  72. package/backend/dist/index.js +31 -18
  73. package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
  74. package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
  75. package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
  76. package/backend/dist/ir/adapters/anthropic.js +788 -0
  77. package/backend/dist/ir/adapters/chat.d.ts +15 -0
  78. package/backend/dist/ir/adapters/chat.js +602 -0
  79. package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
  80. package/backend/dist/ir/adapters/google-stream.js +242 -0
  81. package/backend/dist/ir/adapters/google.d.ts +9 -0
  82. package/backend/dist/ir/adapters/google.js +317 -0
  83. package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
  84. package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
  85. package/backend/dist/ir/adapters/openai-responses.js +26 -1
  86. package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
  87. package/backend/dist/ir/adapters/responses-output.js +348 -0
  88. package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
  89. package/backend/dist/ir/adapters/responses-stream.js +178 -0
  90. package/backend/dist/ir/adapters/responses.d.ts +14 -0
  91. package/backend/dist/ir/adapters/responses.js +646 -0
  92. package/backend/dist/ir/errors.d.ts +2 -2
  93. package/backend/dist/ir/types.d.ts +2 -1
  94. package/backend/dist/metrics/request-cost.d.ts +11 -2
  95. package/backend/dist/metrics/request-cost.js +12 -3
  96. package/backend/dist/observability/request-identity.d.ts +1 -1
  97. package/backend/dist/observability/trace-id.d.ts +40 -0
  98. package/backend/dist/observability/trace-id.js +134 -0
  99. package/backend/dist/observability/upstream-events.d.ts +82 -60
  100. package/backend/dist/observability/upstream-events.js +142 -67
  101. package/backend/dist/opencode/catalog/types.d.ts +9 -0
  102. package/backend/dist/opencode/credentials/types.d.ts +2 -2
  103. package/backend/dist/opencode/probe.d.ts +24 -1
  104. package/backend/dist/opencode/probe.js +28 -4
  105. package/backend/dist/opencode/user-config.d.ts +5 -0
  106. package/backend/dist/pipeline/directives.d.ts +6 -2
  107. package/backend/dist/pipeline/directives.js +7 -3
  108. package/backend/dist/pipeline/orchestrator.d.ts +28 -27
  109. package/backend/dist/pipeline/orchestrator.js +220 -194
  110. package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
  111. package/backend/dist/pipeline/unresolved-model.js +43 -0
  112. package/backend/dist/plugins/catalog-def.d.ts +143 -0
  113. package/backend/dist/plugins/catalog-def.js +177 -0
  114. package/backend/dist/plugins/gateways.d.ts +62 -3
  115. package/backend/dist/plugins/gateways.js +139 -2
  116. package/backend/dist/plugins/host.d.ts +42 -5
  117. package/backend/dist/plugins/host.js +454 -38
  118. package/backend/dist/plugins/manifest.d.ts +119 -10
  119. package/backend/dist/plugins/manifest.js +265 -14
  120. package/backend/dist/plugins/pack.js +26 -0
  121. package/backend/dist/plugins/types.d.ts +187 -21
  122. package/backend/dist/protocols/systemone/convert.d.ts +1 -0
  123. package/backend/dist/protocols/systemone/convert.js +6 -1
  124. package/backend/dist/protocols/systemone/decide.js +18 -8
  125. package/backend/dist/providers/anthropic-messages.d.ts +12 -0
  126. package/backend/dist/providers/anthropic-messages.js +53 -0
  127. package/backend/dist/providers/anthropic.d.ts +7 -8
  128. package/backend/dist/providers/anthropic.js +36 -324
  129. package/backend/dist/providers/base.d.ts +14 -2
  130. package/backend/dist/providers/boot-direct.js +68 -38
  131. package/backend/dist/providers/dispatch.d.ts +5 -19
  132. package/backend/dist/providers/dispatch.js +46 -58
  133. package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
  134. package/backend/dist/providers/executors/anthropic-messages.js +3 -0
  135. package/backend/dist/providers/executors/dispatch.d.ts +16 -2
  136. package/backend/dist/providers/executors/dispatch.js +39 -9
  137. package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
  138. package/backend/dist/providers/executors/google-gemini.js +3 -0
  139. package/backend/dist/providers/executors/http-stream.js +16 -3
  140. package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
  141. package/backend/dist/providers/executors/openai-chat.js +3 -0
  142. package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
  143. package/backend/dist/providers/executors/openai-responses.js +3 -0
  144. package/backend/dist/providers/executors/plugin-adapter.js +4 -4
  145. package/backend/dist/providers/google-gemini.d.ts +12 -0
  146. package/backend/dist/providers/google-gemini.js +50 -0
  147. package/backend/dist/providers/google.d.ts +7 -8
  148. package/backend/dist/providers/google.js +35 -308
  149. package/backend/dist/providers/http-json.d.ts +19 -0
  150. package/backend/dist/providers/http-json.js +104 -0
  151. package/backend/dist/providers/http-stream.d.ts +52 -0
  152. package/backend/dist/providers/http-stream.js +423 -0
  153. package/backend/dist/providers/member-match.d.ts +4 -5
  154. package/backend/dist/providers/member-match.js +4 -5
  155. package/backend/dist/providers/openai-chat.d.ts +13 -0
  156. package/backend/dist/providers/openai-chat.js +99 -0
  157. package/backend/dist/providers/openai-compatible.d.ts +7 -4
  158. package/backend/dist/providers/openai-compatible.js +71 -368
  159. package/backend/dist/providers/openai-responses.d.ts +12 -0
  160. package/backend/dist/providers/openai-responses.js +68 -0
  161. package/backend/dist/providers/opencode-proxy.d.ts +5 -5
  162. package/backend/dist/providers/opencode-proxy.js +49 -125
  163. package/backend/dist/providers/plugin-adapter.d.ts +9 -0
  164. package/backend/dist/providers/plugin-adapter.js +31 -0
  165. package/backend/dist/providers/registry.d.ts +49 -24
  166. package/backend/dist/providers/registry.js +97 -55
  167. package/backend/dist/providers/responses.d.ts +7 -28
  168. package/backend/dist/providers/responses.js +45 -253
  169. package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
  170. package/backend/dist/providers/tool-markup-leak.js +57 -0
  171. package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
  172. package/backend/dist/providers/tool-markup-recovery.js +786 -0
  173. package/backend/dist/providers/virtual-meta.d.ts +21 -2
  174. package/backend/dist/providers/virtual-meta.js +49 -9
  175. package/backend/dist/proxy/asset-download.d.ts +54 -0
  176. package/backend/dist/proxy/asset-download.js +420 -0
  177. package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
  178. package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
  179. package/backend/dist/proxy/mihomo-binary.js +62 -51
  180. package/backend/dist/proxy/mihomo-client.js +15 -1
  181. package/backend/dist/proxy/mihomo-config.js +11 -2
  182. package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
  183. package/backend/dist/proxy/mihomo-geo.js +213 -0
  184. package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
  185. package/backend/dist/proxy/mihomo-logs.js +70 -0
  186. package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
  187. package/backend/dist/proxy/mihomo-pac.js +15 -0
  188. package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
  189. package/backend/dist/proxy/mihomo-rules-import.js +7 -7
  190. package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
  191. package/backend/dist/proxy/mihomo-sidecar.js +148 -26
  192. package/backend/dist/quota/adapters/minimax.js +36 -13
  193. package/backend/dist/quota/cli-login.d.ts +8 -0
  194. package/backend/dist/quota/cli-login.js +18 -0
  195. package/backend/dist/quota/declarations.js +10 -0
  196. package/backend/dist/quota/dsl.js +18 -5
  197. package/backend/dist/quota/engine.d.ts +22 -1
  198. package/backend/dist/quota/engine.js +170 -29
  199. package/backend/dist/quota/prober.d.ts +5 -0
  200. package/backend/dist/quota/prober.js +11 -2
  201. package/backend/dist/quota/types.d.ts +87 -8
  202. package/backend/dist/quota/verdict.d.ts +35 -0
  203. package/backend/dist/quota/verdict.js +135 -0
  204. package/backend/dist/ratelimit/admission.d.ts +131 -0
  205. package/backend/dist/ratelimit/admission.js +233 -0
  206. package/backend/dist/ratelimit/rate-limiter.js +6 -0
  207. package/backend/dist/resilience/types.d.ts +2 -2
  208. package/backend/dist/router/layer2-decision.d.ts +1 -1
  209. package/backend/dist/router/layer2-decision.js +5 -8
  210. package/backend/dist/routes/console.js +248 -52
  211. package/backend/dist/routes/mihomo.d.ts +2 -0
  212. package/backend/dist/routes/mihomo.js +334 -29
  213. package/backend/dist/routes/responses.d.ts +87 -8
  214. package/backend/dist/routes/responses.js +314 -33
  215. package/backend/dist/server.js +34 -6
  216. package/backend/dist/session/session-manager.d.ts +6 -0
  217. package/backend/dist/session/session-manager.js +20 -9
  218. package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
  219. package/backend/dist/surfaces/chat-pipeline.js +17 -7
  220. package/backend/dist/surfaces/chat.js +15 -0
  221. package/backend/dist/surfaces/decision-pipeline.js +7 -10
  222. package/backend/dist/surfaces/direct-forward.d.ts +3 -0
  223. package/backend/dist/surfaces/direct-forward.js +206 -0
  224. package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
  225. package/backend/dist/surfaces/rate-limit-response.js +57 -0
  226. package/backend/dist/surfaces/types.d.ts +11 -0
  227. package/backend/dist/trace/tracker.d.ts +32 -1
  228. package/backend/dist/trace/tracker.js +29 -4
  229. package/backend/dist/types/router.d.ts +34 -12
  230. package/backend/dist/types/router.js +35 -6
  231. package/backend/dist/utils/chat-stream.d.ts +21 -8
  232. package/backend/dist/utils/chat-stream.js +46 -9
  233. package/backend/dist/utils/event-ring.d.ts +4 -0
  234. package/backend/dist/utils/event-ring.js +4 -0
  235. package/backend/dist/utils/popularity.js +29 -4
  236. package/backend/dist/utils/proxy.d.ts +7 -0
  237. package/backend/dist/utils/proxy.js +35 -10
  238. package/backend/dist/utils/retry-after.d.ts +21 -0
  239. package/backend/dist/utils/retry-after.js +36 -0
  240. package/bin/ocr.js +2 -2
  241. package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
  242. package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
  243. package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
  244. package/frontend/dist/index.html +2 -2
  245. package/package.json +1 -1
  246. package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
@@ -52,9 +52,25 @@ export interface ModelRegistration {
52
52
  * expansion); POOL MEMBERSHIP never does — pools are the per-tier
53
53
  * projection of the member lists, so a model may serve in several tiers
54
54
  * at once.
55
+ *
56
+ * `undefined` is the FOURTH state, not an error: no tier's member list
57
+ * claims the model, so it joins NO candidate pool. It is a plain optional
58
+ * value rather than a widened union so TIER_RANK / failover chains / the
59
+ * session ratchet keep operating on the strict four-value TierLevel; every
60
+ * reader must therefore state what "no home tier" means for it.
61
+ */
62
+ tier?: TierLevel;
63
+ /**
64
+ * USD per 1M tokens, when the model's price is actually KNOWN.
65
+ *
66
+ * Absent means "unknown", never "free": a vendor may publish no dollar
67
+ * price at all (qoder publishes only a `price_factor` credit multiplier), in
68
+ * which case every cost surface must say so instead of inventing one. Cost
69
+ * consumers therefore treat a missing `pricing` as unpriceable. Nothing
70
+ * infers TIER MEMBERSHIP from price any more — a model joins the pools its
71
+ * `tiers[t].members` list claims, full stop.
55
72
  */
56
- tier: TierLevel;
57
- pricing: ModelPricing;
73
+ pricing?: ModelPricing;
58
74
  /** Resolved wire for direct execution (model-level npm beats provider npm).
59
75
  * Core shapes plus PLUGIN-owned wire ids — the plugin half is open-ended,
60
76
  * filled from the loaded plugin manifests (`providers/plugin-wires.ts`). */
@@ -72,6 +88,9 @@ export interface ModelRegistration {
72
88
  * is treated as supporting the FULL `EFFORT_LADDER` (all 6 levels, `none`
73
89
  * included) — see `modelSupportsEfforts` in types/router.ts. */
74
90
  supportsReasoningEffort?: boolean;
91
+ /** The vendor's on/off fact (ADR-0035): `false` = the model ALWAYS thinks;
92
+ * `none` is withheld from every resolved effort set at routing time. */
93
+ reasoningDisableable?: boolean;
75
94
  supportsPromptCaching?: boolean;
76
95
  /**
77
96
  * Tri-state sampling-parameter capability flag (from the models.dev catalog).
@@ -120,24 +139,17 @@ export interface ModelRegistration {
120
139
  */
121
140
  variants?: ModelVariant[];
122
141
  /**
123
- * Inputs captured by the smart-match boot paths (boot-direct / sync).
124
- * Presence marks the model as RUNTIME-RECLASSIFIABLE: the registry replays
125
- * tiers[t].match + catalog overrides against these inputs without a restart.
126
- * Hand-configured models omit it and keep their explicit tier forever.
142
+ * Provenance: this model's tier is DERIVED from `tiers[t].members`, so the
143
+ * registry is allowed to re-project it at every commit. Hand-configured
144
+ * models (an explicit `tier` in the defs file) omit the stamp and their
145
+ * tier is permanent — member-list edits never move them (ADR-0003).
146
+ *
147
+ * Only the PRESENCE matters; there is no payload. It is the one switch the
148
+ * registry branches on to tell "machine-assigned" from "operator-declared".
127
149
  */
128
- tierMatch?: {
129
- rawInputPerM?: number;
130
- reasoningFlag: boolean;
131
- };
150
+ autoTier?: true;
132
151
  /** Explicit tier from the defs-file model definition (catalog overrides are read live) */
133
152
  configTier?: TierLevel;
134
- /**
135
- * Fourth state: no tier's member list claims the model. It joins NO
136
- * candidate pool. Kept as a flag rather than widening `tier` so
137
- * TIER_RANK / failover chains / session ratchet keep operating on the
138
- * strict four-state TierLevel.
139
- */
140
- unclassified?: boolean;
141
153
  /**
142
154
  * The home tier's thinking-level translation (the first claiming member
143
155
  * rule's effortMap, re-applied on every commit). Pools carry their OWN
@@ -192,8 +204,8 @@ export interface FallbackConfig {
192
204
  }
193
205
  /**
194
206
  * Per-tier composition policy. Pool membership has exactly ONE basis: the
195
- * explicit `members` list below — a model matching no rule ends up
196
- * `unclassified` and joins no pool. List order IS the chain/priority order;
207
+ * explicit `members` list below — a model no rule matches carries no home
208
+ * tier and joins no pool. List order IS the chain/priority order;
197
209
  * selection strategy and per-rule weights shape HOW the pool is used,
198
210
  * never WHO is in it.
199
211
  */
@@ -230,23 +242,6 @@ export interface TierPolicy {
230
242
  /** explicit member list — routing's ONLY pool-membership source. */
231
243
  members?: TierMemberRule[];
232
244
  selection?: 'priority' | 'weighted' | 'round_robin';
233
- /**
234
- * @deprecated never consulted by routing or boot seeding. The classifier
235
- * survives as the suggestion engine (catalog suggestions, /tiers
236
- * preview / save-time checks) and still reads this config.
237
- */
238
- match?: {
239
- patterns?: string[];
240
- minInputPerM?: number;
241
- maxInputPerM?: number;
242
- exclude?: string[];
243
- /**
244
- * Anchor-exclude: a model matching ANY condition (patterns / price
245
- * band / thinking-effort flag) of one of these tiers may not be AUTO-claimed by
246
- * THIS tier. Runtime filter derived from the other tiers' own conditions.
247
- */
248
- excludeTiers?: TierLevel[];
249
- };
250
245
  }
251
246
  export interface TiersConfig {
252
247
  /**
@@ -301,6 +296,12 @@ export interface MihomoSubscription {
301
296
  url: string;
302
297
  /** Refresh interval in seconds (mihomo proxy-provider `interval`). */
303
298
  interval?: number;
299
+ /** Fetch through this proxy or group name (mihomo proxy-provider `proxy`).
300
+ * Absent follows the rule set: the download is an INNER connection, so
301
+ * `MATCH` routes it into the generated group, which is DIRECT until a
302
+ * working node exists. A subscription host the local network blocks (TLS
303
+ * handshake timeout, SNI reset) needs a reachable node or group here. */
304
+ proxy?: string;
304
305
  /** Absent or true = included in the generated config. */
305
306
  enabled?: boolean;
306
307
  }
@@ -398,10 +399,12 @@ export interface MihomoManualNode {
398
399
  * `controllerPort`. The controller secret and subscription URLs are
399
400
  * operator secrets: redacted in env archives, never written to logs.
400
401
  */
401
- /** Rule kinds the generated config can carry WITHOUT external data — every
402
- * entry needs a single payload and no geo database or remote rule set, so an
403
- * operator-authored rule can never fail silently at load time. */
404
- export type MihomoRuleType = 'DOMAIN' | 'DOMAIN-SUFFIX' | 'DOMAIN-KEYWORD' | 'IP-CIDR' | 'IP-CIDR6' | 'DST-PORT' | 'SRC-PORT' | 'PROCESS-NAME' | 'PROCESS-PATH';
402
+ /** Rule kinds the generated config can carry. Everything except `GEOIP` /
403
+ * `GEOSITE` is data-free — one payload, no database. The geo types are
404
+ * evaluated from the core's geo files (downloaded through the console, never
405
+ * at boot); a geo-rule config without those files is refused before the core
406
+ * parses it. `RULE-SET` stays out: it fetches a remote document at load. */
407
+ export type MihomoRuleType = 'DOMAIN' | 'DOMAIN-SUFFIX' | 'DOMAIN-KEYWORD' | 'IP-CIDR' | 'IP-CIDR6' | 'GEOIP' | 'GEOSITE' | 'DST-PORT' | 'SRC-PORT' | 'PROCESS-NAME' | 'PROCESS-PATH';
405
408
  /** Where a custom rule sends the match. `PROXY` is rewritten to the configured
406
409
  * group name at render time, so a renamed group cannot orphan the rules. */
407
410
  export type MihomoRuleTarget = 'PROXY' | 'DIRECT' | 'REJECT';
@@ -488,7 +491,8 @@ export interface MihomoConfig {
488
491
  * Operator-authored rules, matched in order BEFORE the final `MATCH,<group>`.
489
492
  * They are the only rule source the console accepts: a subscription's own
490
493
  * `rules:`/`proxy-groups:` stay out (ADR-0022), because importing them means
491
- * importing a second, conflicting set of groups.
494
+ * importing a second, conflicting set of groups. Absent = the shipped LAN
495
+ * direct baseline is seeded; an explicit list (even empty) is authoritative.
492
496
  */
493
497
  rules?: MihomoCustomRule[];
494
498
  /** group name → node name. Restored via the controller after start. */
@@ -497,7 +501,8 @@ export interface MihomoConfig {
497
501
  /**
498
502
  * Outbound proxy for upstream calls (model providers, Layer2 decision layer, catalog sync).
499
503
  * Resolution order: loopback targets are NEVER proxied → excludes (force direct)
500
- * → includes (non-empty: ONLY matches go through proxy) → the effective endpoint → direct.
504
+ * → includes (allowlist: an EMPTY list means nothing is proxied) → the effective
505
+ * endpoint → direct.
501
506
  *
502
507
  * The effective endpoint is `proxy.url` in `manual` mode and
503
508
  * `http://127.0.0.1:<mihomo.mixedPort>` in `mihomo` mode (ADR-0022).
@@ -509,7 +514,14 @@ export interface MihomoConfig {
509
514
  * - `claude-*` / `claude` → bare model-id match (wildcard / substring)
510
515
  * If both lists are set, excludes are evaluated first (matched = force direct),
511
516
  * then includes gate what remains.
512
- * With no explicit proxy resolved, Bun still honors HTTP_PROXY/HTTPS_PROXY/NO_PROXY.
517
+ *
518
+ * Nothing is configured until a model is named: `enabled: true` with an empty
519
+ * `includes` list sends every upstream call DIRECT (ADR-0022, amendment
520
+ * 2026-12). A call with no `{ provider, model }` match target (catalog sync,
521
+ * logo fetch, update check) is ALWAYS direct — `*` does not reach it either;
522
+ * the connectivity probe DOES carry a match target and is gated normally.
523
+ * Host-scoped `forwardProxy.rules` rows are a different vocabulary and use
524
+ * `outboundProxyUrl()`, which has no list gate (ADR-0018 §4).
513
525
  */
514
526
  export interface ProxyConfig {
515
527
  enabled?: boolean;
@@ -17,7 +17,8 @@ export declare function currentInterceptPosture(): InterceptPosture;
17
17
  * Claims are read from the LIVE plugin registry on every call (the host swaps it
18
18
  * atomically on install/uninstall/disable, ADR-0017), and the posture comes from
19
19
  * the live config ref — so neither a plugin install nor a console save needs a
20
- * restart.
20
+ * restart. The egress callback is live for the same reason: the tier that owns a
21
+ * claimed host's leg may be the plugin's own code answering for THIS request.
21
22
  */
22
23
  export declare function ruleDecision(host: string): RuleDecision;
23
24
  /**
@@ -36,7 +37,7 @@ export declare function ruleTunnels(host: string): boolean;
36
37
  * proxy URL is resolved straight from the outbound proxy settings.
37
38
  */
38
39
  export interface TransitEgress {
39
- /** Rule-table egress for this host: true = via the outbound proxy, false = direct, undefined = no table installed. */
40
+ /** Egress decided for this host — table and claim together: true = via the outbound proxy, false = direct, undefined = no table installed. */
40
41
  proxy?: boolean;
41
42
  }
42
43
  export declare function transitEgressFor(host: string): TransitEgress;
@@ -90,6 +91,13 @@ export interface UpstreamFailure {
90
91
  }
91
92
  /** Our own hang guard's code (never a socket error). */
92
93
  export declare const UPSTREAM_TIMEOUT_CODE = "OCR_UPSTREAM_TIMEOUT";
94
+ /** Human label for a failed origin leg: the socket code when it has one. */
95
+ export declare function failureLabel(err: unknown): string;
96
+ export declare function shouldRetryOriginLeg(err: unknown, state: {
97
+ headersSent: boolean;
98
+ sentBytes: number;
99
+ attempts: number;
100
+ }): boolean;
93
101
  /**
94
102
  * Classify an origin-leg error.
95
103
  *
@@ -2,7 +2,7 @@ import http from 'node:http';
2
2
  import https from 'node:https';
3
3
  import net from 'node:net';
4
4
  import { DEFAULT_FORWARD_PROXY_INTERCEPT } from '../config/defaults.js';
5
- import { listGatewayHosts } from '../plugins/gateways.js';
5
+ import { listGatewayHosts, claimEgressFor } from '../plugins/gateways.js';
6
6
  import { resolveHost } from './rules.js';
7
7
  import { outboundProxyUrl } from '../utils/proxy.js';
8
8
  /**
@@ -44,11 +44,13 @@ export function currentInterceptPosture() {
44
44
  * Claims are read from the LIVE plugin registry on every call (the host swaps it
45
45
  * atomically on install/uninstall/disable, ADR-0017), and the posture comes from
46
46
  * the live config ref — so neither a plugin install nor a console save needs a
47
- * restart.
47
+ * restart. The egress callback is live for the same reason: the tier that owns a
48
+ * claimed host's leg may be the plugin's own code answering for THIS request.
48
49
  */
49
50
  export function ruleDecision(host) {
50
51
  return resolveHost(host, currentRules(), {
51
52
  claimed: listGatewayHosts(),
53
+ claimEgress: claimEgressFor,
52
54
  intercept: currentInterceptPosture(),
53
55
  });
54
56
  }
@@ -64,10 +66,15 @@ export function ruleTunnels(host) {
64
66
  return ruleDecision(host).tunnel;
65
67
  }
66
68
  export function transitEgressFor(host) {
69
+ const decision = ruleDecision(host);
67
70
  const rules = currentRules();
68
- if (!rules || rules.length === 0)
71
+ // An empty table means "no table installed", which is the historical DIRECT.
72
+ // A claim's own leg is not a table row, so the escape must not swallow it:
73
+ // relaying direct while every preview of the same host reads `proxy` is
74
+ // exactly the preview/reality split this module exists to prevent.
75
+ if ((!rules || rules.length === 0) && !decision.egressClaim)
69
76
  return {};
70
- return { proxy: ruleDecision(host).action === 'proxy' };
77
+ return { proxy: decision.action === 'proxy' };
71
78
  }
72
79
  const HOP_BY_HOP = {
73
80
  connection: true,
@@ -230,6 +237,37 @@ const TLS_HANDSHAKE_CODES = {
230
237
  /** Our own hang guard's code (never a socket error). */
231
238
  export const UPSTREAM_TIMEOUT_CODE = 'OCR_UPSTREAM_TIMEOUT';
232
239
  const DNS_CODES = { ENOTFOUND: true, EAI_AGAIN: true, EAI_FAIL: true, EAI_NONAME: true };
240
+ /**
241
+ * Origin-leg failures that provably delivered nothing. An exchange is replayed
242
+ * ONLY when nothing was written toward the origin (`sentBytes === 0`) and no
243
+ * response byte reached the client, so the retry can never double-execute a
244
+ * request the origin already saw. The outbound proxy in between (mihomo/Clash)
245
+ * does close freshly opened tunnels; without this, one dropped tunnel surfaces
246
+ * as a 502 in the client and the hub gives up.
247
+ */
248
+ const RETRYABLE_ORIGIN_CODES = {
249
+ ERR_SOCKET_CLOSED: true,
250
+ ECONNRESET: true,
251
+ EPIPE: true,
252
+ };
253
+ /** Human label for a failed origin leg: the socket code when it has one. */
254
+ export function failureLabel(err) {
255
+ if (err && typeof err === 'object') {
256
+ if ('code' in err && typeof err.code === 'string' && err.code)
257
+ return err.code;
258
+ if ('message' in err && typeof err.message === 'string' && err.message)
259
+ return err.message;
260
+ }
261
+ return String(err);
262
+ }
263
+ export function shouldRetryOriginLeg(err, state) {
264
+ if (state.headersSent || state.sentBytes > 0 || state.attempts >= 1)
265
+ return false;
266
+ if (!err || typeof err !== 'object' || !('code' in err))
267
+ return false;
268
+ const { code } = err;
269
+ return typeof code === 'string' && RETRYABLE_ORIGIN_CODES[code] === true;
270
+ }
233
271
  /**
234
272
  * Classify an origin-leg error.
235
273
  *
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Orders what a decrypted client stream produced ahead of an asynchronous hop.
3
+ *
4
+ * The MITM leg reads the client's plaintext (a `tls.Socket`) and forwards it to
5
+ * a loopback socket that feeds the inner HTTP server. Those two halves do not
6
+ * become ready at the same moment: `net.connect()` returns a socket immediately
7
+ * but connects on a later tick, while decrypted chunks keep arriving. Writing a
8
+ * chunk to the (unconnected) socket queues it, so a later flush of the buffered
9
+ * head lands AFTER it — the parser then reads a body fragment where it expects a
10
+ * request line and answers `400` to a request it never saw. One small request
11
+ * hides this (single chunk); a large prompt does not.
12
+ *
13
+ * So: everything pushed before `attach` is held, and `attach` hands the sink the
14
+ * held bytes first, in order. After that, chunks go straight through.
15
+ */
16
+ export declare class OrderedRelay {
17
+ #private;
18
+ /** Hold a chunk, or hand it to the sink once one is attached. */
19
+ push(chunk: Buffer): void;
20
+ /**
21
+ * Install the sink and flush what was held. `onAttach` runs after the flush,
22
+ * so a caller can flip its own "connected" state knowing the backlog landed.
23
+ */
24
+ attach(sink: (chunk: Buffer) => void, onAttach?: () => void): void;
25
+ /** Chunks held while no sink was attached (diagnostics / tests). */
26
+ get held(): number;
27
+ /** The held bytes in arrival order, joined — what a sniffer looks at. */
28
+ snapshot(): Buffer;
29
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Orders what a decrypted client stream produced ahead of an asynchronous hop.
3
+ *
4
+ * The MITM leg reads the client's plaintext (a `tls.Socket`) and forwards it to
5
+ * a loopback socket that feeds the inner HTTP server. Those two halves do not
6
+ * become ready at the same moment: `net.connect()` returns a socket immediately
7
+ * but connects on a later tick, while decrypted chunks keep arriving. Writing a
8
+ * chunk to the (unconnected) socket queues it, so a later flush of the buffered
9
+ * head lands AFTER it — the parser then reads a body fragment where it expects a
10
+ * request line and answers `400` to a request it never saw. One small request
11
+ * hides this (single chunk); a large prompt does not.
12
+ *
13
+ * So: everything pushed before `attach` is held, and `attach` hands the sink the
14
+ * held bytes first, in order. After that, chunks go straight through.
15
+ */
16
+ export class OrderedRelay {
17
+ #pending = [];
18
+ #sink;
19
+ /** Hold a chunk, or hand it to the sink once one is attached. */
20
+ push(chunk) {
21
+ if (this.#sink) {
22
+ this.#sink(chunk);
23
+ return;
24
+ }
25
+ this.#pending.push(chunk);
26
+ }
27
+ /**
28
+ * Install the sink and flush what was held. `onAttach` runs after the flush,
29
+ * so a caller can flip its own "connected" state knowing the backlog landed.
30
+ */
31
+ attach(sink, onAttach) {
32
+ this.#sink = sink;
33
+ for (const chunk of this.#pending)
34
+ sink(chunk);
35
+ this.#pending.length = 0;
36
+ onAttach?.();
37
+ }
38
+ /** Chunks held while no sink was attached (diagnostics / tests). */
39
+ get held() {
40
+ return this.#pending.length;
41
+ }
42
+ /** The held bytes in arrival order, joined — what a sniffer looks at. */
43
+ snapshot() {
44
+ return Buffer.concat(this.#pending);
45
+ }
46
+ }
@@ -1,3 +1,4 @@
1
+ import type { ClaimEgressSource } from '../plugins/gateways.js';
1
2
  import type { ForwardProxyRule, InterceptPosture, RuleEgress, RuleExit, RuleIngress } from '../config/types.js';
2
3
  /**
3
4
  * The forward-proxy rule table (ADR-0018).
@@ -50,17 +51,31 @@ export interface RuleDecision {
50
51
  /** Intercept (false) or blind tunnel (true). */
51
52
  tunnel: boolean;
52
53
  /**
53
- * `loopback` / `rule` / `claim` / `fallback` — why.
54
+ * `loopback` / `rule` / `claim` / `fallback` — why the connection is
55
+ * decrypted or tunneled the way it is.
54
56
  *
55
- * - `rule` → a row decided (a SPECIFIC row always does; the catch-all
56
- * row does when it is `reject`);
57
+ * - `rule` → a row decided the ingress axis (a SPECIFIC row always does;
58
+ * the catch-all row does when it is `reject`);
57
59
  * - `claim` → no specific row, but a live client-gateway plugin claims the
58
- * host: decrypted (ADR-0018 Revision 4);
59
- * - `fallback` → no row decided the decrypt axis: the catch-all's `egress`
60
- * applies and the connection is tunneled unless the audit
61
- * posture (`intercept: 'all'`) is on.
60
+ * host, so it is decrypted (ADR-0018 Revision 4);
61
+ * - `fallback` → nothing decided the decrypt axis: the connection is tunneled
62
+ * unless the audit posture (`intercept: 'all'`) is on.
62
63
  */
63
64
  reason: 'loopback' | 'rule' | 'claim' | 'fallback';
65
+ /**
66
+ * Set ONLY when a claiming gateway decided the EXIT — the tier of the claim
67
+ * that spoke (ADR-0018 Revision 5). It is the one fact a caller needs apart
68
+ * from the decision, for two reasons:
69
+ *
70
+ * - an empty rule table means "no table opinion = the historical direct", and
71
+ * that escape must not swallow a declaration, because a declaration is not a
72
+ * table row (`transitEgressFor`);
73
+ * - a specific row's `egress` is INERT over a host whose claim spoke — the
74
+ * console says so instead of letting the operator believe their row applies.
75
+ * That holds even when the row names the same leg: "the claim owns this
76
+ * exit" is the truth either way.
77
+ */
78
+ egressClaim?: ClaimEgressSource;
64
79
  /** Position in the table (present only for `reason: 'rule'`). */
65
80
  ruleIndex?: number;
66
81
  /** The glob that matched (present only for `reason: 'rule'`). */
@@ -72,11 +87,30 @@ export interface ResolveOptions {
72
87
  claimed?: ReadonlySet<string>;
73
88
  /** Interception posture; absent = `DEFAULT_FORWARD_PROXY_INTERCEPT`. */
74
89
  intercept?: InterceptPosture;
90
+ /**
91
+ * Ask the claim of a host what outbound leg it wants (`claimEgressFor()`).
92
+ * Receives the host TRIMMED and LOWERCASED (the resolver normalizes before
93
+ * asking), so an implementation's lookup is an exact match.
94
+ *
95
+ * A callback, not a snapshot map, because the answer is the plugin's CODE
96
+ * running per request: a gateway may route the mapped models of one host one
97
+ * way and its unmapped ones another, and a saved config must take effect
98
+ * without rebuilding any table.
99
+ *
100
+ * It outranks every `egress` in the table, because the claim is the unit of
101
+ * ownership for the leg (ADR-0018 Revision 5). It is outranked by the two things
102
+ * that are not opinions about a leg: `reject` (permission to read a host is
103
+ * not permission to reach it) and loopback (cycle safety).
104
+ */
105
+ claimEgress?: (host: string) => {
106
+ action: RuleEgress;
107
+ source: ClaimEgressSource;
108
+ } | undefined;
75
109
  }
76
110
  /** The complete lint vocabulary, as RUNTIME data so the console's mirror can be
77
111
  * parity-checked (forward-proxy-console-vocabulary-parity.test.ts) instead of
78
112
  * drifting silently. */
79
- export declare const RULE_WARNING_CODES: readonly ['invalid-rule', 'unreachable-rule', 'no-catch-all', 'catch-all-intercepts', 'proxy-rule-without-proxy'];
113
+ export declare const RULE_WARNING_CODES: readonly ["invalid-rule", "unreachable-rule", "no-catch-all", "catch-all-intercepts", "proxy-rule-without-proxy", "claim-owns-egress"];
80
114
  export type RuleWarningCode = (typeof RULE_WARNING_CODES)[number];
81
115
  export interface RuleWarning {
82
116
  code: RuleWarningCode;
@@ -95,20 +129,25 @@ export declare function normalizeRules(raw: unknown): ForwardProxyRule[];
95
129
  * absolute-URI leg, the tunnels, h2-forward, the client-gateway relay) and the
96
130
  * console preview call this, so they can never disagree.
97
131
  *
98
- * Order (ADR-0018 Revision 4):
132
+ * Order (ADR-0018 Revision 4, with the exit half amended by Revision 5):
99
133
  *
100
134
  * 1. loopback → direct + tunnel (unchanged invariant)
101
- * 2. a SPECIFIC matching row → that row's `ingress`/`egress`, verbatim: the
102
- * operator outranks a claim, so `reject` and
103
- * `passthrough` can both override one
104
- * 3. the host is CLAIMED → the catch-all's `egress`, decrypted
105
- * 4. `intercept: 'all'` → the catch-all's `egress`, decrypted (audit)
106
- * 5. otherwise → the catch-all's `egress`, blind tunnel
135
+ * 2. `reject` → the admission gate, from ANY row that matches
136
+ * first: permission to READ a host is never
137
+ * permission to REACH it, so no claim un-blocks
138
+ * 3. a SPECIFIC matching row → that row's `ingress` verbatim; the `egress` is
139
+ * the claim's when a gateway spoke for this host
140
+ * and the table's otherwise
141
+ * 4. the host is CLAIMED → decrypted, on the claim's egress when it made
142
+ * one, otherwise the catch-all's
143
+ * 5. `intercept: 'all'` → the catch-all's `egress`, decrypted (audit)
144
+ * 6. otherwise → the catch-all's `egress`, blind tunnel
107
145
  *
108
146
  * The catch-all row's `ingress` is therefore only the default posture for hosts
109
- * nothing declares — except `reject`, which keeps its admission-gate meaning
110
- * (an operator blocklist no claim can un-block; write a specific row above it
111
- * for the exception).
147
+ * nothing declares. A row's `egress` is a statement about the hosts the TABLE
148
+ * owns; over a claimed host the claim owns the leg (Revision 5), which is why
149
+ * `lintRules` flags the inert half instead of letting the operator read a rule
150
+ * that no longer routes anything.
112
151
  */
113
152
  export declare function resolveHost(host: string, rules?: ForwardProxyRule[], options?: ResolveOptions): RuleDecision;
114
153
  /**
@@ -124,8 +163,16 @@ export declare function resolveHost(host: string, rules?: ForwardProxyRule[], op
124
163
  * `'claims'` it decrypts nothing for the hosts nothing claims — exactly the
125
164
  * misconfiguration the operator cannot see in the row itself, hence the
126
165
  * `catch-all-intercepts` warning.
166
+ *
167
+ * `claimedEgress` is the snapshot of hosts whose client-gateway claim speaks
168
+ * about the leg (Revision 5). Over such a host the row's `egress` is not consulted, so
169
+ * a row that EXPLICITLY declared a different one gets `claim-owns-egress`: the
170
+ * operator typed a leg that routes nothing, and the only way to see that is to
171
+ * be told. Absent (boot, before any plugin loads) simply means no opinion is
172
+ * knowable yet, which is why it is a parameter and not something the
173
+ * function reads.
127
174
  */
128
- export declare function lintRules(raw: unknown, proxyEnabled: boolean, intercept?: InterceptPosture): RuleWarning[];
175
+ export declare function lintRules(raw: unknown, proxyEnabled: boolean, intercept?: InterceptPosture, claimedEgress?: ReadonlyMap<string, RuleEgress>): RuleWarning[];
129
176
  export declare function hasCatchAllRule(rules?: {
130
177
  match: string;
131
178
  }[]): boolean;
@@ -105,6 +105,7 @@ export const RULE_WARNING_CODES = [
105
105
  'no-catch-all',
106
106
  'catch-all-intercepts',
107
107
  'proxy-rule-without-proxy',
108
+ 'claim-owns-egress',
108
109
  ];
109
110
  /**
110
111
  * Structural normalization: trims matches and drops unknown values /
@@ -120,20 +121,25 @@ export function normalizeRules(raw) {
120
121
  * absolute-URI leg, the tunnels, h2-forward, the client-gateway relay) and the
121
122
  * console preview call this, so they can never disagree.
122
123
  *
123
- * Order (ADR-0018 Revision 4):
124
+ * Order (ADR-0018 Revision 4, with the exit half amended by Revision 5):
124
125
  *
125
126
  * 1. loopback → direct + tunnel (unchanged invariant)
126
- * 2. a SPECIFIC matching row → that row's `ingress`/`egress`, verbatim: the
127
- * operator outranks a claim, so `reject` and
128
- * `passthrough` can both override one
129
- * 3. the host is CLAIMED → the catch-all's `egress`, decrypted
130
- * 4. `intercept: 'all'` → the catch-all's `egress`, decrypted (audit)
131
- * 5. otherwise → the catch-all's `egress`, blind tunnel
127
+ * 2. `reject` → the admission gate, from ANY row that matches
128
+ * first: permission to READ a host is never
129
+ * permission to REACH it, so no claim un-blocks
130
+ * 3. a SPECIFIC matching row → that row's `ingress` verbatim; the `egress` is
131
+ * the claim's when a gateway spoke for this host
132
+ * and the table's otherwise
133
+ * 4. the host is CLAIMED → decrypted, on the claim's egress when it made
134
+ * one, otherwise the catch-all's
135
+ * 5. `intercept: 'all'` → the catch-all's `egress`, decrypted (audit)
136
+ * 6. otherwise → the catch-all's `egress`, blind tunnel
132
137
  *
133
138
  * The catch-all row's `ingress` is therefore only the default posture for hosts
134
- * nothing declares — except `reject`, which keeps its admission-gate meaning
135
- * (an operator blocklist no claim can un-block; write a specific row above it
136
- * for the exception).
139
+ * nothing declares. A row's `egress` is a statement about the hosts the TABLE
140
+ * owns; over a claimed host the claim owns the leg (Revision 5), which is why
141
+ * `lintRules` flags the inert half instead of letting the operator read a rule
142
+ * that no longer routes anything.
137
143
  */
138
144
  export function resolveHost(host, rules, options) {
139
145
  // Brackets are IPv6 syntax, not part of the name: a CONNECT target arrives as
@@ -143,6 +149,12 @@ export function resolveHost(host, rules, options) {
143
149
  return { action: 'direct', tunnel: false, reason: 'fallback' };
144
150
  if (isLoopbackHost(h))
145
151
  return { action: 'direct', tunnel: true, reason: 'loopback' };
152
+ // Whose opinion, if any, owns the EXIT of this host. The caller injects it
153
+ // because it is the plugin's code answering, per request (Revision 5); a claim that
154
+ // has nothing to say returns undefined and the table decides. The host is
155
+ // lowercased before the lookup: a claim key is an exact host name and
156
+ // manifests are hand-written, so one host must never get two spellings.
157
+ const claim = options?.claimEgress?.(h.toLowerCase());
146
158
  let catchAll;
147
159
  for (let i = 0; i < (rules?.length ?? 0); i += 1) {
148
160
  const rule = rules[i];
@@ -151,13 +163,20 @@ export function resolveHost(host, rules, options) {
151
163
  if (!globMatch(rule.match, h))
152
164
  continue;
153
165
  if (rule.match !== '*') {
154
- return {
166
+ const row = {
155
167
  action: ruleExit(rule.egress, rule.ingress),
156
168
  tunnel: isPassthroughIngress(rule.ingress),
157
169
  reason: 'rule',
158
170
  ruleIndex: i,
159
171
  match: rule.match,
160
172
  };
173
+ // `reject` is an admission verdict, not a leg: there is nothing to route.
174
+ if (rule.ingress === 'reject' || !claim)
175
+ return row;
176
+ // The claim OWNS the exit over this host, so the row's `egress` is inert —
177
+ // even when it happens to name the same leg. Crediting the row would teach
178
+ // the operator that their row applies when removing it changes nothing.
179
+ return { ...row, action: claim.action, egressClaim: claim.source };
161
180
  }
162
181
  // The catch-all: first match wins, so nothing after it is reachable and its
163
182
  // ingress is the DEFAULT posture, resolved below.
@@ -170,8 +189,11 @@ export function resolveHost(host, rules, options) {
170
189
  // No specific row decided: the catch-all's egress still governs where the
171
190
  // bytes go (an absent catch-all means the historical `direct`).
172
191
  const egress = catchAll?.rule.egress ?? 'direct';
173
- if (isClaimedHost(options?.claimed, h))
174
- return { action: egress, tunnel: false, reason: 'claim' };
192
+ if (isClaimedHost(options?.claimed, h)) {
193
+ return claim
194
+ ? { action: claim.action, tunnel: false, reason: 'claim', egressClaim: claim.source }
195
+ : { action: egress, tunnel: false, reason: 'claim' };
196
+ }
175
197
  if ((options?.intercept ?? DEFAULT_FORWARD_PROXY_INTERCEPT) === 'all') {
176
198
  return { action: egress, tunnel: false, reason: 'fallback' };
177
199
  }
@@ -190,8 +212,16 @@ export function resolveHost(host, rules, options) {
190
212
  * `'claims'` it decrypts nothing for the hosts nothing claims — exactly the
191
213
  * misconfiguration the operator cannot see in the row itself, hence the
192
214
  * `catch-all-intercepts` warning.
215
+ *
216
+ * `claimedEgress` is the snapshot of hosts whose client-gateway claim speaks
217
+ * about the leg (Revision 5). Over such a host the row's `egress` is not consulted, so
218
+ * a row that EXPLICITLY declared a different one gets `claim-owns-egress`: the
219
+ * operator typed a leg that routes nothing, and the only way to see that is to
220
+ * be told. Absent (boot, before any plugin loads) simply means no opinion is
221
+ * knowable yet, which is why it is a parameter and not something the
222
+ * function reads.
193
223
  */
194
- export function lintRules(raw, proxyEnabled, intercept = DEFAULT_FORWARD_PROXY_INTERCEPT) {
224
+ export function lintRules(raw, proxyEnabled, intercept = DEFAULT_FORWARD_PROXY_INTERCEPT, claimedEgress) {
195
225
  const entries = Array.isArray(raw) ? raw : [];
196
226
  const warnings = [];
197
227
  const seen = new Set();
@@ -234,6 +264,23 @@ export function lintRules(raw, proxyEnabled, intercept = DEFAULT_FORWARD_PROXY_I
234
264
  if (egress === 'proxy' && !proxyEnabled) {
235
265
  warnings.push({ code: 'proxy-rule-without-proxy', ruleIndex, detail: match });
236
266
  }
267
+ // Revision 5 — over a host whose claim speaks about the leg, the ROW's `egress` is
268
+ // never consulted. Only an explicitly typed one is worth reporting (an
269
+ // inherited default claims the operator never made), and never the catch-all:
270
+ // `*` still routes every host nothing claims, so flagging it would bury the
271
+ // rows that are genuinely inert in `detail`. A `reject` row is exempt too:
272
+ // there is no leg to route, so its `egress` is not being shadowed.
273
+ if (claimedEgress?.size && match !== '*' && rule.ingress !== 'reject' && (entry ?? {}).egress !== undefined) {
274
+ const shadowed = [...claimedEgress].filter(([host, action]) => action !== egress && globMatch(match, host));
275
+ if (shadowed.length > 0) {
276
+ const [host, action] = shadowed[0];
277
+ warnings.push({
278
+ code: 'claim-owns-egress',
279
+ ruleIndex,
280
+ detail: `egress "${egress}" unused on ${host} (its gateway routes "${action}")${shadowed.length > 1 ? `, +${shadowed.length - 1} more` : ''}`,
281
+ });
282
+ }
283
+ }
237
284
  });
238
285
  if (catchAllAt < 0)
239
286
  warnings.push({ code: 'no-catch-all' });